IDEA-CR-27841 fix IDEA-183742 Per-module bytecode versions aren't loaded when project is opened

This commit is contained in:
Vladimir Krivosheev
2017-12-13 15:17:52 +01:00
parent 7829b8b487
commit b8449330d6
4 changed files with 37 additions and 8 deletions
+1
View File
@@ -19,6 +19,7 @@
<orderEntry type="library" scope="TEST" name="Groovy" level="project" />
<orderEntry type="module" module-name="spellchecker" scope="RUNTIME" />
<orderEntry type="module" module-name="jps-model-impl" scope="TEST" />
<orderEntry type="module" module-name="testExtensions" scope="TEST" />
</component>
<component name="copyright">
<Base>
@@ -1,4 +1,6 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
/*
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package com.intellij.compiler;
import com.intellij.CommonBundle;
@@ -824,7 +826,7 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements
Element bytecodeTargetElement = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.BYTECODE_TARGET_LEVEL);
if (bytecodeTargetElement != null) {
myBytecodeTargetLevel = bytecodeTargetElement.getAttributeValue(JpsJavaCompilerConfigurationSerializer.TARGET_ATTRIBUTE);
readByteTargetLevel(parentNode);
readByteTargetLevel(parentNode, myModuleBytecodeTarget);
}
Map<String, String> externalState = myProject.getComponent(ExternalCompilerConfigurationStorage.class).getLoadedState();
@@ -1,4 +1,6 @@
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
/*
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package com.intellij.compiler
import com.intellij.openapi.components.PersistentStateComponent
@@ -36,7 +38,9 @@ internal class ExternalCompilerConfigurationStorage(private val project: Project
}
override fun loadState(state: Element) {
loadedState = readByteTargetLevel(state)
val result = THashMap<String, String>()
readByteTargetLevel(state, result)
loadedState = result
}
override fun getExternalSource(): ProjectModelExternalSource? {
@@ -73,13 +77,11 @@ internal fun writeBytecodeTarget(moduleNames: List<String>, map: Map<String, Str
}
}
internal fun readByteTargetLevel(parentNode: Element): Map<String, String> {
val result = THashMap<String, String>()
val bytecodeTargetElement = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.BYTECODE_TARGET_LEVEL) ?: return result
internal fun readByteTargetLevel(parentNode: Element, result: MutableMap<String, String>) {
val bytecodeTargetElement = parentNode.getChild(JpsJavaCompilerConfigurationSerializer.BYTECODE_TARGET_LEVEL) ?: return
for (element in bytecodeTargetElement.getChildren(JpsJavaCompilerConfigurationSerializer.MODULE)) {
val name = element.getAttributeValue(JpsJavaCompilerConfigurationSerializer.NAME) ?: continue
val target = element.getAttributeValue(JpsJavaCompilerConfigurationSerializer.TARGET_ATTRIBUTE) ?: continue
result.put(name, target)
}
return result
}
@@ -6,12 +6,17 @@ package com.intellij.compiler;
import com.intellij.module.ModuleGroupTestsKt;
import com.intellij.openapi.module.Module;
import com.intellij.testFramework.PlatformTestCase;
import org.jdom.JDOMException;
import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile;
import org.jetbrains.jps.model.java.impl.compiler.ProcessorConfigProfileImpl;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static com.intellij.testFramework.assertions.Assertions.assertThat;
import static com.intellij.util.JdomKt.loadElement;
public class CompilerConfigurationTest extends PlatformTestCase {
public void testUpdateTargetLevelOnModuleRename() {
Module module = createModule("foo");
@@ -22,6 +27,25 @@ public class CompilerConfigurationTest extends PlatformTestCase {
assertEquals("1.6", getConfiguration().getBytecodeTargetLevel(module));
}
public void testLoadState() throws IOException, JDOMException {
Module module = createModule("foo");
CompilerConfigurationImpl configuration = getConfiguration();
configuration.setBytecodeTargetLevel(module, "1.6");
assertThat(configuration.getState()).isEqualTo("<state>\n" +
" <bytecodeTargetLevel>\n" +
" <module name=\"foo\" target=\"1.6\" />\n" +
" </bytecodeTargetLevel>\n" +
"</state>");
configuration.loadState(loadElement("<state>\n" +
" <bytecodeTargetLevel>\n" +
" <module name=\"foo\" target=\"1.7\" />\n" +
" </bytecodeTargetLevel>\n" +
"</state>"));
assertThat(configuration.getBytecodeTargetLevel(module)).isEqualTo("1.7");
}
public void testUpdateOptionsOnModuleRename() {
Module module = createModule("foo");
List<String> options = Arrays.asList("-nowarn");