eclipse: rewrite src root in .eml if var is broken (IDEA-56333)

This commit is contained in:
anna
2010-07-07 21:59:29 +04:00
parent 3b333fc938
commit 733fc448db
11 changed files with 90 additions and 33 deletions
@@ -159,7 +159,7 @@ public class EclipseClasspathWriter {
}
}
}
if (addSrcRoots) setOrRemoveAttribute(orderEntry, EclipseXml.SOURCEPATH_ATTR, eclipseSrcVariablePath != null ? eclipseSrcVariablePath : srcRelativePath);
setOrRemoveAttribute(orderEntry, EclipseXml.SOURCEPATH_ATTR, addSrcRoots ? (eclipseSrcVariablePath != null ? eclipseSrcVariablePath : srcRelativePath) : null);
EJavadocUtil.setupJavadocAttributes(orderEntry, libraryOrderEntry, myModel);
setExported(orderEntry, libraryOrderEntry);
@@ -240,20 +240,10 @@ public class IdeaSpecificSettings {
element.setAttribute("scope", scope.name());
if (((LibraryOrderEntry)entry).isModuleLevel()) {
final String[] urls = entry.getUrls(OrderRootType.SOURCES);
if (urls.length > 1) {
for (String url : urls) {
Element srcElement = new Element(SRCROOT_ATTR);
srcElement.setAttribute("url", url);
element.addContent(srcElement);
}
}
else if (urls.length == 1 && urls[0].contains(JarFileSystem.JAR_SEPARATOR)) {
final VirtualFile virtualFile = JarFileSystem.getInstance().findFileByPath(VfsUtil.urlToPath(urls[0]));
if (virtualFile != null) {
Element srcElement = new Element(SRCROOT_ATTR);
srcElement.setAttribute("url", urls[0]);
element.addContent(srcElement);
}
for (String url : urls) {
Element srcElement = new Element(SRCROOT_ATTR);
srcElement.setAttribute("url", url);
element.addContent(srcElement);
}
for (String srcUrl : entry.getUrls(OrderRootType.SOURCES)) {
@@ -4,5 +4,7 @@
<contentEntry url="file://$MODULE_DIR$" />
<lib name="jar-all-5.zip" scope="COMPILE">
<srcroot url="jar://$MODULE_DIR$/lib/jar-all-5.zip!/doc/api" />
<relative-module-src project-related="jar://$PROJECT_DIR$/test/lib/jar-all-5.zip!/doc/api" />
<relative-module-cls project-related="jar://$PROJECT_DIR$/test/lib/jar-all-5.zip!/" />
</lib>
</component>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="var" path="variable/test.jar" />
<classpathentry kind="output" path="bin" />
</classpath>
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<component>
<exclude-output />
<contentEntry url="file://$MODULE_DIR$" />
<lib name="test.jar" scope="COMPILE">
<srcroot url="jar://$MODULE_DIR$/../srcvariableidea1/test.jar!/" />
</lib>
</component>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="var" path="variable/test.jar" sourcepath="/srcvariable/test.jar" />
<classpathentry kind="output" path="bin" />
</classpath>
@@ -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>
@@ -31,6 +31,7 @@ import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.JDOMUtil;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.IdeaTestCase;
@@ -76,11 +77,18 @@ public class EclipseEmlTest extends IdeaTestCase {
final EclipseClasspathStorageProvider.EclipseClasspathConverter converter =
new EclipseClasspathStorageProvider.EclipseClasspathConverter(module);
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
final Element classpathElement = JDOMUtil.loadDocument(new String(FileUtil.loadFileText(new File(path, EclipseXml.DOT_CLASSPATH_EXT)))).getRootElement();
converter.getClasspath(rootModel, classpathElement);
rootModel.commit();
checkModule(path, module);
}
protected static void checkModule(String path, Module module) throws WriteExternalException, IOException, JDOMException {
ModifiableRootModel rootModel;
rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
final Element root = new Element("component");
IdeaSpecificSettings.writeIDEASpecificClasspath(root, rootModel);
rootModel.dispose();
@@ -34,7 +34,7 @@ import java.util.Map;
public class EclipseLibrariesModificationsTest extends EclipseVarsTest {
private void doTest(String[] classRoots, String[] sourceRoots) throws Exception {
private void doTestCreate(String[] classRoots, String[] sourceRoots) throws Exception {
final Project project = getProject();
final String path = project.getBaseDir().getPath() + "/test";
final Module module = EclipseClasspathTest.setUpModule(path, project);
@@ -54,38 +54,60 @@ public class EclipseLibrariesModificationsTest extends EclipseVarsTest {
}
public void testReplacedWithVariables() throws Exception {
doTest(new String[]{"/variableidea/test.jar!/"}, new String[]{"/srcvariableidea/test.jar!/"});
doTestCreate(new String[]{"/variableidea/test.jar!/"}, new String[]{"/srcvariableidea/test.jar!/"});
}
public void testCantReplaceWithVariables() throws Exception {
doTest(new String[]{"/variableidea1/test.jar!/"}, new String[]{"/srcvariableidea/test.jar!/"});
doTestCreate(new String[]{"/variableidea1/test.jar!/"}, new String[]{"/srcvariableidea/test.jar!/"});
}
public void testReplacedWithVariablesNoSrcExistOnDisc() throws Exception {
doTest(new String[]{"/variableidea/test.jar!/"}, new String[]{"/srcvariableidea/test.jar!/"});
doTestCreate(new String[]{"/variableidea/test.jar!/"}, new String[]{"/srcvariableidea/test.jar!/"});
}
public void testReplacedWithVariablesCantReplaceSrc() throws Exception {
doTest(new String[]{"/variableidea/test.jar!/"}, new String[]{"/srcvariableidea1/test.jar!/"});
doTestCreate(new String[]{"/variableidea/test.jar!/"}, new String[]{"/srcvariableidea1/test.jar!/"});
}
public void testReplacedWithVariablesNoSources() throws Exception {
doTest(new String[]{"/variableidea/test.jar!/"}, new String[]{});
doTestCreate(new String[]{"/variableidea/test.jar!/"}, new String[]{});
}
public void testReplacedExistingWithVariablesCantReplaceSrc() throws Exception {
doTestExisting(new String[]{"/variableidea/test.jar!/"}, new String[]{"/srcvariableidea1/test.jar!/"});
}
private void doTestExisting(String[] classRoots, String[] sourceRoots) throws Exception {
final Project project = getProject();
final String path = project.getBaseDir().getPath() + "/test";
final Module module = EclipseClasspathTest.setUpModule(path, project);
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
final String parentUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, model.getContentRoots()[0].getParent().getPath());
final Library library = model.getModuleLibraryTable().getLibraryByName("test.jar");
final Library.ModifiableModel libModifiableModel = library.getModifiableModel();
final String[] oldClsRoots = libModifiableModel.getUrls(OrderRootType.CLASSES);
for (String oldClsRoot : oldClsRoots) {
libModifiableModel.removeRoot(oldClsRoot, OrderRootType.CLASSES);
}
final String[] oldSrcRoots = libModifiableModel.getUrls(OrderRootType.SOURCES);
for (String oldSrcRoot : oldSrcRoots) {
libModifiableModel.removeRoot(oldSrcRoot, OrderRootType.SOURCES);
}
for (String classRoot : classRoots) {
libModifiableModel.addRoot(parentUrl + classRoot, OrderRootType.CLASSES);
}
for (String sourceRoot : sourceRoots) {
libModifiableModel.addRoot(parentUrl + sourceRoot, OrderRootType.SOURCES);
}
libModifiableModel.commit();
model.commit();
EclipseClasspathTest.checkModule(project.getBaseDir().getPath() + "/expected", module);
EclipseEmlTest.checkModule(project.getBaseDir().getPath() + "/expected", module);
}
@Override
protected String getRelativeTestPath() {
return "modification";
}
enum Bar{
ONE;
}
class Foo {
void foo(String each) {
Map map = new HashMap<String, Bar>();
map.put(new Foo(), Bar.ONE);
}
}
}