mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
support native libs for .classpath format
This commit is contained in:
@@ -71,7 +71,7 @@ public abstract class AbstractEclipseClasspathReader<T> {
|
||||
boolean exported,
|
||||
String libName,
|
||||
String url,
|
||||
String srcUrl, ExpandMacroToPathMap macroMap);
|
||||
String srcUrl, String nativeRoot, ExpandMacroToPathMap macroMap);
|
||||
|
||||
protected abstract String expandEclipsePath2Url(T rootModel, String path);
|
||||
|
||||
@@ -178,7 +178,12 @@ public abstract class AbstractEclipseClasspathReader<T> {
|
||||
}
|
||||
}
|
||||
|
||||
addModuleLibrary(rootModel, element, exported, getPresentableName(path, libs), url, srcUrl, macroMap);
|
||||
String nativeRoot = getNativeLibraryRoot(element);
|
||||
if (nativeRoot != null) {
|
||||
nativeRoot = expandEclipsePath2Url(rootModel, nativeRoot);
|
||||
}
|
||||
|
||||
addModuleLibrary(rootModel, element, exported, getPresentableName(path, libs), url, srcUrl, nativeRoot, macroMap);
|
||||
}
|
||||
else if (kind.equals(EclipseXml.VAR_KIND)) {
|
||||
int slash = path.indexOf("/");
|
||||
@@ -201,7 +206,11 @@ public abstract class AbstractEclipseClasspathReader<T> {
|
||||
eclipseModuleManager.registerEclipseSrcVariablePath(srcUrl, srcPathAttr);
|
||||
}
|
||||
}
|
||||
addModuleLibrary(rootModel, element, exported, libName, url, srcUrl, macroMap);
|
||||
String nativeRoot = getNativeLibraryRoot(element);
|
||||
if (nativeRoot != null) {
|
||||
nativeRoot = expandEclipsePath2Url(rootModel, nativeRoot);
|
||||
}
|
||||
addModuleLibrary(rootModel, element, exported, libName, url, srcUrl, nativeRoot, macroMap);
|
||||
}
|
||||
else if (kind.equals(EclipseXml.CON_KIND)) {
|
||||
if (path.equals(EclipseXml.ECLIPSE_PLATFORM)) {
|
||||
@@ -242,6 +251,18 @@ public abstract class AbstractEclipseClasspathReader<T> {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getNativeLibraryRoot(Element element) {
|
||||
final Element attributes = element.getChild(EclipseXml.ATTRIBUTES_TAG);
|
||||
if (attributes != null) {
|
||||
for (Element attributeElement : attributes.getChildren(EclipseXml.ATTRIBUTE_TAG)) {
|
||||
if (EclipseXml.DLL_LINK.equals(attributeElement.getAttributeValue(EclipseXml.NAME_ATTR))) {
|
||||
return attributeElement.getAttributeValue(EclipseXml.VALUE_ATTR);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static int srcVarStart(String srcPath) {
|
||||
return srcPath.startsWith("/") ? 1 : 0;
|
||||
}
|
||||
|
||||
@@ -76,4 +76,5 @@ public interface EclipseXml {
|
||||
@NonNls String LINKED_RESOURCES = "linkedResources";
|
||||
@NonNls String LINK = "link";
|
||||
@NonNls String JAVADOC_LOCATION = "javadoc_location";
|
||||
@NonNls String DLL_LINK = "org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY";
|
||||
}
|
||||
|
||||
+1
@@ -151,6 +151,7 @@ class JpsEclipseClasspathReader extends AbstractEclipseClasspathReader<JpsModule
|
||||
String libName,
|
||||
String url,
|
||||
String srcUrl,
|
||||
String nativeRoot,
|
||||
ExpandMacroToPathMap macroMap) {
|
||||
final JpsLibrary jpsLibrary = rootModel.addModuleLibrary(libName, JpsJavaLibraryType.INSTANCE);
|
||||
final JpsDependenciesList dependenciesList = rootModel.getDependenciesList();
|
||||
|
||||
@@ -34,6 +34,7 @@ import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import com.intellij.openapi.vfs.ex.http.HttpFileSystem;
|
||||
import com.intellij.util.Function;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.idea.eclipse.EPathCommonUtil;
|
||||
@@ -202,10 +203,21 @@ public class EJavadocUtil {
|
||||
}
|
||||
|
||||
static void setupJavadocAttributes(Element orderEntry, LibraryOrderEntry libraryOrderEntry, final ModuleRootModel model) {
|
||||
setupAttributes(orderEntry, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String s) {
|
||||
return toEclipseJavadocPath(model, s);
|
||||
}
|
||||
}, JAVADOC_LOCATION, libraryOrderEntry.getRootUrls(JavadocOrderRootType.getInstance()));
|
||||
}
|
||||
|
||||
static void setupAttributes(Element orderEntry,
|
||||
Function<String, String> fun,
|
||||
String attributeName,
|
||||
String[] roots) {
|
||||
final List<String> eclipseUrls = new ArrayList<String>();
|
||||
final String[] docUrls = libraryOrderEntry.getRootUrls(JavadocOrderRootType.getInstance());
|
||||
if (docUrls.length > 0) {
|
||||
eclipseUrls.add(toEclipseJavadocPath(model, docUrls[0]));
|
||||
if (roots.length > 0) {
|
||||
eclipseUrls.add(fun.fun(roots[0]));
|
||||
}
|
||||
|
||||
final List children = new ArrayList(orderEntry.getChildren(ATTRIBUTES_TAG));
|
||||
@@ -214,7 +226,7 @@ public class EJavadocUtil {
|
||||
final ArrayList attTags = new ArrayList(attsElement.getChildren(ATTRIBUTE_TAG));
|
||||
for (Object a : attTags) {
|
||||
Element attElement = (Element)a;
|
||||
if (Comparing.strEqual(attElement.getAttributeValue("name"), JAVADOC_LOCATION)) {
|
||||
if (Comparing.strEqual(attElement.getAttributeValue("name"), attributeName)) {
|
||||
final String javadocPath = attElement.getAttributeValue("value");
|
||||
if (!eclipseUrls.remove(javadocPath)) {
|
||||
attElement.detach();
|
||||
@@ -232,7 +244,7 @@ public class EJavadocUtil {
|
||||
|
||||
final Element attrElement = new Element(ATTRIBUTE_TAG);
|
||||
child.addContent(attrElement);
|
||||
attrElement.setAttribute("name", JAVADOC_LOCATION);
|
||||
attrElement.setAttribute("name", attributeName);
|
||||
attrElement.setAttribute("value", docUrl);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -153,13 +153,20 @@ public class EclipseClasspathReader extends AbstractEclipseClasspathReader<Modif
|
||||
boolean exported,
|
||||
String libName,
|
||||
String url,
|
||||
String srcUrl, ExpandMacroToPathMap macroMap) {
|
||||
String srcUrl,
|
||||
String nativeRoot,
|
||||
ExpandMacroToPathMap macroMap) {
|
||||
final Library library = rootModel.getModuleLibraryTable().getModifiableModel().createLibrary(libName);
|
||||
final Library.ModifiableModel modifiableModel = library.getModifiableModel();
|
||||
modifiableModel.addRoot(url, OrderRootType.CLASSES);
|
||||
if (srcUrl != null) {
|
||||
modifiableModel.addRoot(srcUrl, OrderRootType.SOURCES);
|
||||
}
|
||||
|
||||
if (nativeRoot != null) {
|
||||
modifiableModel.addRoot(nativeRoot, NativeLibraryOrderRootType.getInstance());
|
||||
}
|
||||
|
||||
EJavadocUtil.appendJavadocRoots(element, rootModel, myCurrentRoots, modifiableModel);
|
||||
modifiableModel.commit();
|
||||
|
||||
|
||||
+12
-1
@@ -28,6 +28,7 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.Function;
|
||||
import gnu.trove.THashMap;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -86,7 +87,7 @@ public class EclipseClasspathWriter {
|
||||
return classpathElement;
|
||||
}
|
||||
|
||||
private void createClasspathEntry(@NotNull OrderEntry entry, @NotNull Element classpathRoot, @NotNull ModuleRootModel model) throws ConversionException {
|
||||
private void createClasspathEntry(@NotNull OrderEntry entry, @NotNull Element classpathRoot, @NotNull final ModuleRootModel model) throws ConversionException {
|
||||
EclipseModuleManager eclipseModuleManager = EclipseModuleManagerImpl.getInstance(entry.getOwnerModule());
|
||||
if (entry instanceof ModuleSourceOrderEntry) {
|
||||
boolean shouldPlaceSeparately = eclipseModuleManager.isExpectedModuleSourcePlace(Arrays.binarySearch(model.getOrderEntries(), entry));
|
||||
@@ -185,6 +186,16 @@ public class EclipseClasspathWriter {
|
||||
setOrRemoveAttribute(orderEntry, EclipseXml.SOURCEPATH_ATTR, addSrcRoots ? (eclipseSrcVariablePath != null ? eclipseSrcVariablePath : srcRelativePath) : null);
|
||||
|
||||
EJavadocUtil.setupJavadocAttributes(orderEntry, libraryOrderEntry, model);
|
||||
|
||||
final String[] nativeRoots = libraryOrderEntry.getUrls(NativeLibraryOrderRootType.getInstance());
|
||||
if (nativeRoots.length > 0) {
|
||||
EJavadocUtil.setupAttributes(orderEntry, new Function<String, String>() {
|
||||
@Override
|
||||
public String fun(String nativeRoot) {
|
||||
return EPathUtil.collapse2EclipsePath(nativeRoot, model);
|
||||
}
|
||||
}, EclipseXml.DLL_LINK, nativeRoots);
|
||||
}
|
||||
setExported(orderEntry, libraryOrderEntry);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry including="**" kind="src" path="src" />
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" />
|
||||
<classpathentry kind="lib" path="test.jar">
|
||||
<attributes>
|
||||
<attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="target"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin" />
|
||||
</classpath>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>test</name>
|
||||
<comment/>
|
||||
<projects/>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments/>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -150,6 +150,10 @@ public class EclipseClasspathTest extends IdeaTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNativeLibs() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testAccessrulez() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user