per-module bytecode target option supported for out-of-process make

This commit is contained in:
Eugene Zhuravlev
2012-05-11 17:20:49 +02:00
parent b72bdae38c
commit f43a3e6ac2
5 changed files with 51 additions and 5 deletions
@@ -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 : "");
}
}
}
@@ -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));
@@ -591,15 +591,45 @@ public class JavaBuilder extends ModuleLevelBuilder {
cached = JAVAC_OPTIONS.get(context);
}
final List<String> options = new ArrayList<String>(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<String> options = new ArrayList<String>();
final List<String> vmOptions = new ArrayList<String>();
@@ -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<String, String> processorsOptions = [:]
Map<String, String> processModule = [:]
}
class BytecodeTargetConfiguration {
String projectBytecodeTarget
Map<String, String> modulesBytecodeTarget = [:]
}
@@ -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);