remember inherit jdk state for nonexistent sdks (IDEA-70561)

This commit is contained in:
anna
2011-07-11 17:53:42 +04:00
parent 10f7e67653
commit 0e1ae3cb0b
7 changed files with 67 additions and 7 deletions
@@ -63,11 +63,20 @@ public class EclipseModuleManager implements PersistentStateComponent<Element>{
@NonNls private static final String LIBELEMENT = "libelement";
private int myExpectedModuleSourcePlace;
private Map<String, Integer> mySrcPlace = new LinkedHashMap<String, Integer>();
private String myInvalidJdk;
public EclipseModuleManager(Module module) {
myModule = module;
}
public void setInvalidJdk(String invalidJdk) {
myInvalidJdk = invalidJdk;
}
public String getInvalidJdk() {
return myInvalidJdk;
}
public static EclipseModuleManager getInstance(Module module) {
return ModuleServiceManager.getService(module, EclipseModuleManager.class);
}
@@ -244,6 +244,7 @@ public class EclipseClasspathReader {
}
else {
rootModel.setInvalidSdk(jdkName, IdeaXml.JAVA_SDK_TYPE);
eclipseModuleManager.setInvalidJdk(jdkName);
unknownJdks.add(jdkName);
}
}
@@ -43,6 +43,7 @@ import com.intellij.pom.java.LanguageLevel;
import org.jdom.Element;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.idea.eclipse.IdeaXml;
import org.jetbrains.idea.eclipse.config.EclipseModuleManager;
import java.io.File;
import java.io.IOException;
@@ -66,6 +67,7 @@ public class IdeaSpecificSettings {
@NonNls private static final String SRCROOT_BIND_ATTR = "bind";
private static final Logger LOG = Logger.getInstance("#" + IdeaSpecificSettings.class.getName());
@NonNls private static final String JAVADOCROOT_ATTR = "javadocroot_attr";
public static final String INHERIT_JDK = "inheritJdk";
private IdeaSpecificSettings() {
}
@@ -100,6 +102,10 @@ public class IdeaSpecificSettings {
}
}
final String inheritJdk = root.getAttributeValue(INHERIT_JDK);
if (inheritJdk != null && Boolean.parseBoolean(inheritJdk)) {
model.inheritSdk();
}
for (Object o : root.getChildren("lib")) {
Element libElement = (Element)o;
final String libName = libElement.getAttributeValue("name");
@@ -278,6 +284,10 @@ public class IdeaSpecificSettings {
isModified = true;
}
}
if (entry instanceof InheritedJdkOrderEntry && EclipseModuleManager.getInstance(entry.getOwnerModule()).getInvalidJdk() != null) {
root.setAttribute(INHERIT_JDK, "true");
isModified = true;
}
if (!(entry instanceof LibraryOrderEntry)) continue;
final Element element = new Element("lib");
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="output" path="bin"/>
</classpath>
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>preserveInheritedInvalidJdk</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>
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<component inheritJdk="true">
<contentEntry url="file://$MODULE_DIR$" />
</component>
@@ -28,10 +28,7 @@ import com.intellij.openapi.module.StdModuleTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModifiableRootModel;
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.*;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.IdeaTestCase;
@@ -65,6 +62,13 @@ public class EclipseEmlTest extends IdeaTestCase {
protected static void doTest(String relativePath, final Project project) throws Exception {
final String path = project.getBaseDir().getPath() + relativePath;
final Module module = doLoadModule(path, project);
checkModule(path, module);
}
private static Module doLoadModule(final String path, final Project project) throws IOException, JDOMException, InvalidDataException {
final Module module = ApplicationManager.getApplication().runWriteAction(new Computable<Module>() {
@Override
public Module compute() {
@@ -87,9 +91,7 @@ public class EclipseEmlTest extends IdeaTestCase {
rootModel.commit();
}
});
checkModule(path, module);
return module;
}
protected static void checkModule(String path, Module module) throws WriteExternalException, IOException, JDOMException {
@@ -119,4 +121,17 @@ public class EclipseEmlTest extends IdeaTestCase {
doTest("/test", getProject());
}
public void testPreserveInheritedInvalidJdk() throws Exception {
final Project project = getProject();
final String projectBasePath = project.getBaseDir().getPath();
final String path = projectBasePath + "/test";
final Module module = doLoadModule(path, project);
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
modifiableModel.inheritSdk();
modifiableModel.commit();
checkModule(projectBasePath + "/test/expected", module);
}
}