eclipse: do my best to retrieve the relative url (IDEA-53826)

This commit is contained in:
anna
2010-04-13 18:17:49 +04:00
parent 0fb62780eb
commit 02a973e8a2
10 changed files with 107 additions and 4 deletions
@@ -69,6 +69,25 @@ public class EPathUtil {
return secondSlIdx != -1 && secondSlIdx + 1 < path.length() ? path.substring(secondSlIdx + 1) : null;
}
public static boolean areUrlsPointTheSame(String ideaUrl, String eclipseUrl) {
final String path = VfsUtil.urlToPath(eclipseUrl);
if (ideaUrl.contains(path)) {
return true;
}
else {
final String relativeToModulePath = getRelativeToModulePath(path);
final int relativeIdx = ideaUrl.indexOf(relativeToModulePath);
if (relativeIdx != -1) {
final String pathToProjectFile = VfsUtil.urlToPath(ideaUrl.substring(0, relativeIdx));
if (Comparing.strEqual(getRelativeModuleName(path),
EclipseProjectFinder.findProjectName(pathToProjectFile))) {
return true;
}
}
}
return false;
}
@Nullable
static String expandEclipseRelative2ContentRoots(final @NotNull List<String> currentRoots,
final @NotNull String rootPath,
@@ -48,6 +48,8 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import static org.jetbrains.idea.eclipse.conversion.EPathUtil.areUrlsPointTheSame;
/**
* Read/write .eml
*/
@@ -142,7 +144,7 @@ public class IdeaSpecificSettings {
for (Object r : libElement.getChildren(SRCROOT_ATTR)) {
final String url = ((Element)r).getAttributeValue("url");
modifiableModel.addRoot(url, OrderRootType.SOURCES);
if (srcUrlsFromClasspath != null && srcUrlsFromClasspath.length == 1 && url.contains(VfsUtil.urlToPath(srcUrlsFromClasspath[0]))) { //remove compound root
if (srcUrlsFromClasspath != null && srcUrlsFromClasspath.length == 1 && areUrlsPointTheSame(url, srcUrlsFromClasspath[0])) { //remove compound root
modifiableModel.removeRoot(srcUrlsFromClasspath[0], OrderRootType.SOURCES);
srcUrlsFromClasspath = null;
}
@@ -295,8 +297,8 @@ public class IdeaSpecificSettings {
for (Object r : libElement.getChildren(relativeModuleName)) {
final String root = PathMacroManager.getInstance(project).expandPath(((Element)r).getAttributeValue(PROJECT_RELATED));
for (Iterator<String> iterator = urls.iterator(); iterator.hasNext();) {
String url = iterator.next();
if (root.contains(VfsUtil.urlToPath(url))) {
final String url = iterator.next();
if (areUrlsPointTheSame(root, url)) {
iterator.remove();
modifiableModel.removeRoot(url, orderRootType);
modifiableModel.addRoot(root, orderRootType);
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ws-internals</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main"/>
<classpathentry kind="src" output="build/tests/classes" path="src/test"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4">
<attributes>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="/ws-internals/lib/ant-contrib-1.0/ant-contrib-1.0b3.jar" sourcepath="/ws-internals/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/ws-internals/lib/ant-contrib-1.0/ant-contrib-1.0b3-bin.zip!/ant-contrib/docs/api"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="build/classes"/>
</classpath>
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>sourceRootPaths</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<component>
<exclude-output />
<contentEntry url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/bin" />
</contentEntry>
<lib name="ant-contrib-1.0b3.jar" scope="COMPILE">
<srcroot url="jar://$MODULE_DIR$/../anotherPath/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip!/ant-contrib/test/src" />
<srcroot url="jar://$MODULE_DIR$/../anotherPath/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip!/ant-contrib/src/java" />
<srcroot url="jar://$MODULE_DIR$/../anotherPath/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip!/ant-contrib/test/resources/walls/testB" />
<srcroot url="jar://$MODULE_DIR$/../anotherPath/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip!/ant-contrib/test/resources/design/src" />
<srcroot url="jar://$MODULE_DIR$/../anotherPath/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip!/ant-contrib/test/resources/walls/testC" />
<srcroot url="jar://$MODULE_DIR$/../anotherPath/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip!/ant-contrib/test/resources/walls/testA" />
<relative-module-src project-related="jar://$PROJECT_DIR$/srcPath/anotherPath/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip!/ant-contrib/test/src" />
<relative-module-src project-related="jar://$PROJECT_DIR$/srcPath/anotherPath/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip!/ant-contrib/src/java" />
<relative-module-src project-related="jar://$PROJECT_DIR$/srcPath/anotherPath/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip!/ant-contrib/test/resources/walls/testB" />
<relative-module-src project-related="jar://$PROJECT_DIR$/srcPath/anotherPath/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip!/ant-contrib/test/resources/design/src" />
<relative-module-src project-related="jar://$PROJECT_DIR$/srcPath/anotherPath/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip!/ant-contrib/test/resources/walls/testC" />
<relative-module-src project-related="jar://$PROJECT_DIR$/srcPath/anotherPath/lib/ant-contrib-1.0/ant-contrib-1.0b3-src.zip!/ant-contrib/test/resources/walls/testA" />
</lib>
</component>
@@ -40,6 +40,7 @@ import java.io.IOException;
public abstract class Eclipse2ModulesTest extends IdeaTestCase {
@NonNls
protected static final String DEPEND_MODULE_NAME = "ws-internals";
private String myDependantModulePath = "ws-internals";
protected abstract String getTestPath();
@@ -76,7 +77,7 @@ public abstract class Eclipse2ModulesTest extends IdeaTestCase {
public VirtualFile compute() {
final VirtualFile baseDir = getProject().getBaseDir();
assert baseDir != null;
return LocalFileSystem.getInstance().refreshAndFindFileByPath(baseDir.getPath() + "/" + workspaceRoot + "/ws-internals");
return LocalFileSystem.getInstance().refreshAndFindFileByPath(baseDir.getPath() + "/" + workspaceRoot + "/" + myDependantModulePath);
}
}
);
@@ -92,4 +93,8 @@ public abstract class Eclipse2ModulesTest extends IdeaTestCase {
}
});
}
public void setDependantModulePath(String dependantModulePath) {
myDependantModulePath = dependantModulePath;
}
}
@@ -35,4 +35,9 @@ public class EclipseEml2ModulesTest extends Eclipse2ModulesTest{
public void testSourceRootPaths() throws Exception {
doTest("srcPath", "sourceRootPaths");
}
public void testAnotherSourceRootPaths() throws Exception {
setDependantModulePath("anotherPath");
doTest("srcPath", "sourceRootPaths");
}
}