diff --git a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java index 1ae478adfae8..5c57b8383f66 100644 --- a/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java +++ b/java/compiler/impl/src/com/intellij/compiler/CompilerConfigurationImpl.java @@ -763,7 +763,8 @@ public class CompilerConfigurationImpl extends CompilerConfiguration implements final Element moduleElement = new Element("module"); bytecodeTarget.addContent(moduleElement); moduleElement.setAttribute("name", name); - moduleElement.setAttribute("target", myModuleBytecodeTarget.get(name)); + final String value = myModuleBytecodeTarget.get(name); + moduleElement.setAttribute("target", value != null? value : ""); } } } diff --git a/java/compiler/impl/src/com/intellij/compiler/options/TargetOptionsComponent.java b/java/compiler/impl/src/com/intellij/compiler/options/TargetOptionsComponent.java index 7abb35489a92..da8f5bb839e4 100644 --- a/java/compiler/impl/src/com/intellij/compiler/options/TargetOptionsComponent.java +++ b/java/compiler/impl/src/com/intellij/compiler/options/TargetOptionsComponent.java @@ -44,7 +44,7 @@ import java.util.List; */ public class TargetOptionsComponent extends JPanel { private static final String[] KNOWN_TARGETS = new String[] {"1.1", "1.2", "1.3","1.4","1.5", "1.6", "1.7", "1.8"}; - private static final String COMPILER_DEFAULT = "compiler default"; + private static final String COMPILER_DEFAULT = "JDK default"; private ComboBox myCbProjectTargetLevel; private JBTable myTable; @@ -74,7 +74,7 @@ public class TargetOptionsComponent extends JPanel { targetLevelColumn.setMinWidth(width); targetLevelColumn.setMaxWidth(width); - add(new JLabel("Project bytecode version (leave blank for compiler default): "), + add(new JLabel("Project bytecode version (leave blank for jdk default): "), constraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NONE)); add(myCbProjectTargetLevel, constraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NONE)); add(new JLabel("Per-module bytecode version:"), constraints(0, 1, 2, 1, 1.0, 0.0, GridBagConstraints.NONE)); diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java index 80786ed78a48..8d8ed4338457 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java @@ -591,15 +591,45 @@ public class JavaBuilder extends ModuleLevelBuilder { cached = JAVAC_OPTIONS.get(context); } final List options = new ArrayList(cached); - final Module module = chunk.getModules().iterator().next(); - final String langlevel = module.getLanguageLevel(); + final String langlevel = chunk.getModules().iterator().next().getLanguageLevel(); if (!StringUtil.isEmpty(langlevel)) { options.add("-source"); options.add(langlevel); } + + final BytecodeTargetConfiguration targetConfig = context.getProject().getCompilerConfiguration().getBytecodeTarget(); + String bytecodeTarget = null; + for (Module module : chunk.getModules()) { + final String moduleTarget = getModuleTarget(targetConfig, module); + if (moduleTarget == null) { + continue; + } + if (bytecodeTarget == null) { + bytecodeTarget = moduleTarget; + } + else { + if (moduleTarget.compareTo(bytecodeTarget) < 0) { + bytecodeTarget = moduleTarget; // use the lower possible target among modules that form the chunk + } + } + } + if (bytecodeTarget != null) { + options.add("-target"); + options.add(bytecodeTarget); + } + return options; } + @Nullable + private static String getModuleTarget(BytecodeTargetConfiguration config, Module module) { + final String level = config.getModulesBytecodeTarget().get(module.getName()); + if (level != null) { + return level.isEmpty()? null : level; + } + return config.getProjectBytecodeTarget(); + } + private static void loadJavacOptions(CompileContext context) { final List options = new ArrayList(); final List vmOptions = new ArrayList(); diff --git a/jps/model/src/org/jetbrains/jps/CompilerConfiguration.groovy b/jps/model/src/org/jetbrains/jps/CompilerConfiguration.groovy index 3049ff44c0ce..826087af3ada 100644 --- a/jps/model/src/org/jetbrains/jps/CompilerConfiguration.groovy +++ b/jps/model/src/org/jetbrains/jps/CompilerConfiguration.groovy @@ -11,6 +11,7 @@ class CompilerConfiguration { boolean clearOutputDirectoryOnRebuild = true boolean addNotNullAssertions = true AnnotationProcessingConfiguration annotationProcessing = new AnnotationProcessingConfiguration() + BytecodeTargetConfiguration bytecodeTarget = new BytecodeTargetConfiguration() CompilerExcludes excludes = new CompilerExcludes() } @@ -20,4 +21,9 @@ class AnnotationProcessingConfiguration { String processorsPath Map processorsOptions = [:] Map processModule = [:] +} + +class BytecodeTargetConfiguration { + String projectBytecodeTarget + Map modulesBytecodeTarget = [:] } \ No newline at end of file diff --git a/jps/model/src/org/jetbrains/jps/idea/IdeaProjectLoader.groovy b/jps/model/src/org/jetbrains/jps/idea/IdeaProjectLoader.groovy index 231de9ede3e2..a500b889211d 100644 --- a/jps/model/src/org/jetbrains/jps/idea/IdeaProjectLoader.groovy +++ b/jps/model/src/org/jetbrains/jps/idea/IdeaProjectLoader.groovy @@ -266,6 +266,15 @@ public class IdeaProjectLoader { } } + def targetLevels = componentTag?.bytecodeTargetLevel + if (!targetLevels.isEmpty()) { + def targetLevelTag = targetLevels.first() + configuration.bytecodeTarget.projectBytecodeTarget = targetLevelTag."@target" ?: null; + targetLevelTag.module?.each { + configuration.bytecodeTarget.modulesBytecodeTarget[it."@name"] = it."@target" ?: "" + } + } + def addNotNullTag = componentTag?.addNotNullAssertions if (addNotNullTag != null) { project.compilerConfiguration.addNotNullAssertions = parseBoolean(addNotNullTag."@enabled", true);