}
}
protected Commandline setupJavacCommand() throws BuildException {
Commandline cmd = new Commandline();
this.customDefaultOptions = new CompilerOptions().getMap();
Class javacClass = Javac.class;
/*
* Read in the compiler arguments first since we might need to modify
* the classpath if any access rules were specified
*/
String [] compilerArgs = processCompilerArguments(javacClass);
/*
* This option is used to never exit at the end of the ant task.
*/
cmd.createArgument().setValue("-noExit"); //$NON-NLS-1$
if (this.bootclasspath != null) {
cmd.createArgument().setValue("-bootclasspath"); //$NON-NLS-1$
if (this.bootclasspath.size() != 0) {
/*
* Set the bootclasspath for the Eclipse compiler.
*/
cmd.createArgument().setPath(this.bootclasspath);
} else {
cmd.createArgument().setValue(Util.EMPTY_STRING);
}
}
Path classpath = new Path(this.project);
/*
* Eclipse compiler doesn't support -extdirs.
* It is emulated using the classpath. We add extdirs entries after the
* bootclasspath.
*/
if (this.extdirs != null) {
cmd.createArgument().setValue("-extdirs"); //$NON-NLS-1$
cmd.createArgument().setPath(this.extdirs);
}
/*
* The java runtime is already handled, so we simply want to retrieve the
* ant runtime and the compile classpath.
*/
classpath.append(getCompileClasspath());
// For -sourcepath, use the "sourcepath" value if present.
// Otherwise default to the "srcdir" value.
Path sourcepath = null;
// retrieve the method getSourcepath() using reflect
// This is done to improve the compatibility to ant 1.5
Method getSourcepathMethod = null;
try {
getSourcepathMethod = javacClass.getMethod("getSourcepath", null); //$NON-NLS-1$
} catch(NoSuchMethodException e) {
// if not found, then we cannot use this method (ant 1.5)
}
Path compileSourcePath = null;
if (getSourcepathMethod != null) {
try {
compileSourcePath = (Path) getSourcepathMethod.invoke(this.attributes, null);
} catch (IllegalAccessException e) {
// should never happen
} catch (InvocationTargetException e) {
// should never happen
}
}
if (compileSourcePath != null) {
sourcepath = compileSourcePath;
} else {
sourcepath = this.src;
}
classpath.append(sourcepath);
/*
* Set the classpath for the Eclipse compiler.
*/
cmd.createArgument().setValue("-classpath"); //$NON-NLS-1$
createClasspathArgument(cmd, classpath);
final String javaVersion = JavaEnvUtils.getJavaVersion();
String memoryParameterPrefix = javaVersion.equals(JavaEnvUtils.JAVA_1_1) ? "-J-" : "-J-X";//$NON-NLS-1$//$NON-NLS-2$
if (this.memoryInitialSize != null) {
if (!this.attributes.isForkedJavac()) {
this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.info.ignoringMemoryInitialSize"), Project.MSG_WARN); //$NON-NLS-1$
} else {
cmd.createArgument().setValue(memoryParameterPrefix
+ "ms" + this.memoryInitialSize); //$NON-NLS-1$
}
}
if (this.memoryMaximumSize != null) {
if (!this.attributes.isForkedJavac()) {
this.attributes.log(AntAdapterMessages.getString("ant.jdtadapter.info.ignoringMemoryMaximumSize"), Project.MSG_WARN); //$NON-NLS-1$
} else {
cmd.createArgument().setValue(memoryParameterPrefix
+ "mx" + this.memoryMaximumSize); //$NON-NLS-1$
}
}
if (this.debug) {
// retrieve the method getSourcepath() using reflect
// This is done to improve the compatibility to ant 1.5
Method getDebugLevelMethod = null;
try {
getDebugLevelMethod = javacClass.getMethod("getDebugLevel", null); //$NON-NLS-1$
} catch(NoSuchMethodException e) {
// if not found, then we cannot use this method (ant 1.5)
// debug level is only available with ant 1.5.x
}
String debugLevel = null;
if (getDebugLevelMethod != null) {
try {
debugLevel = (String) getDebugLevelMethod.invoke(this.attributes, null);
} catch (IllegalAccessException e) {
// should never happen
} catch (InvocationTargetException e) {
// should never happen
}
}
if (debugLevel != null) {
this.customDefaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE);
this.customDefaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE);
this.customDefaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute , CompilerOptions.DO_NOT_GENERATE);
if (debugLevel.length() != 0) {
if (debugLevel.indexOf("vars") != -1) {//$NON-NLS-1$
this.customDefaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
}
if (debugLevel.indexOf("lines") != -1) {//$NON-NLS-1$
this.customDefaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
}
if (debugLevel.indexOf("source") != -1) {//$NON-NLS-1$
this.customDefaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute , CompilerOptions.GENERATE);
}
}
} else {
this.customDefaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE);
this.customDefaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.GENERATE);
this.customDefaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute , CompilerOptions.GENERATE);
}
} else {
this.customDefaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.DO_NOT_GENERATE);
this.customDefaultOptions.put(CompilerOptions.OPTION_LineNumberAttribute, CompilerOptions.DO_NOT_GENERATE);
this.customDefaultOptions.put(CompilerOptions.OPTION_SourceFileAttribute , CompilerOptions.DO_NOT_GENERATE);
}
/*
* Handle the nowarn option. If none, then we generate all warnings.
*/
if (this.attributes.getNowarn()) {
// disable all warnings
Object[] entries = this.customDefaultOptions.entrySet().toArray();
for (int i = 0, max = entries.length; i < max; i++) {
Map.Entry entry = (Map.Entry) entries[i];
if (!(entry.getKey() instanceof String))
continue;
if (!(entry.getValue() instanceof String))
continue;
if (((String) entry.getValue()).equals(CompilerOptions.WARNING)) {
this.customDefaultOptions.put(entry.getKey(), CompilerOptions.IGNORE);
}
}
this.customDefaultOptions.put(CompilerOptions.OPTION_TaskTags, Util.EMPTY_STRING);
if (this.deprecation) {
this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING);
this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.ENABLED);
this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.ENABLED);
}
} else if (this.deprecation) {
this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.WARNING);
this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.ENABLED);
this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.ENABLED);
} else {
this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationInDeprecatedCode, CompilerOptions.DISABLED);
this.customDefaultOptions.put(CompilerOptions.OPTION_ReportDeprecationWhenOverridingDeprecatedMethod, CompilerOptions.DISABLED);
}
/*
* destDir option.
*/
if (this.destDir != null) {
cmd.createArgument().setValue("-d"); //$NON-NLS-1$
cmd.createArgument().setFile(this.destDir.getAbsoluteFile());
}
/*
* verbose option
*/
if (this.verbose) {
cmd.createArgument().setValue("-verbose"); //$NON-NLS-1$
}
/*
* failnoerror option
*/
if (!this.attributes.getFailonerror()) {
cmd.createArgument().setValue("-proceedOnError"); //$NON-NLS-1$
}
/*
* target option.
*/
if (this.target != null) {
this.customDefaultOptions.put(CompilerOptions.OPTION_TargetPlatform, this.target);
}
/*
* source option
*/
String source = this.attributes.getSource();
if (source != null) {
this.customDefaultOptions.put(CompilerOptions.OPTION_Source, source);
}
/*
* encoding option
*/
if (this.encoding != null) {
cmd.createArgument().setValue("-encoding"); //$NON-NLS-1$
cmd.createArgument().setValue(this.encoding);
}
if (compilerArgs != null) {
/*
* Add extra argument on the command line
*/
final int length = compilerArgs.length;
if (length != 0) {
for (int i = 0, max = length; i < max; i++) {
String arg = compilerArgs[i];
if (this.logFileName == null && "-log".equals(arg) && ((i + 1) < max)) { //$NON-NLS-1$
this.logFileName = compilerArgs[i + 1];
}
cmd.createArgument().setValue(arg);
}
}
}
/*
* Eclipse compiler doesn't have a -sourcepath option. This is