PR: 3045 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269858 13f79535-47bb-0310-9956-ffa450edef68master
@@ -282,25 +282,33 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter { | |||||
} | } | ||||
/** | /** | ||||
* Does the command line argument processing common to classic and | |||||
* modern and adds the files to compile as well. | |||||
* Does the command line argument processing for modern. Doesn't | |||||
* add the files to compile. | |||||
*/ | */ | ||||
protected Commandline setupModernJavacCommand() { | |||||
Commandline cmd = new Commandline(); | |||||
protected Commandline setupModernJavacCommandlineSwitches(Commandline cmd) { | |||||
setupJavacCommandlineSwitches(cmd); | setupJavacCommandlineSwitches(cmd); | ||||
if (attributes.getSource() != null) { | if (attributes.getSource() != null) { | ||||
cmd.createArgument().setValue("-source"); | cmd.createArgument().setValue("-source"); | ||||
cmd.createArgument().setValue(attributes.getSource()); | cmd.createArgument().setValue(attributes.getSource()); | ||||
} | } | ||||
return cmd; | |||||
} | |||||
/** | |||||
* Does the command line argument processing for modern and adds | |||||
* the files to compile as well. | |||||
*/ | |||||
protected Commandline setupModernJavacCommand() { | |||||
Commandline cmd = new Commandline(); | |||||
setupModernJavacCommandlineSwitches(cmd); | |||||
logAndAddFilesToCompile(cmd); | logAndAddFilesToCompile(cmd); | ||||
return cmd; | return cmd; | ||||
} | } | ||||
/** | /** | ||||
* Does the command line argument processing common to classic and | |||||
* modern and adds the files to compile as well. | |||||
* Does the command line argument processing for classic and adds | |||||
* the files to compile as well. | |||||
*/ | */ | ||||
protected Commandline setupJavacCommand() { | protected Commandline setupJavacCommand() { | ||||
Commandline cmd = new Commandline(); | Commandline cmd = new Commandline(); | ||||
@@ -56,6 +56,7 @@ package org.apache.tools.ant.taskdefs.compilers; | |||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.taskdefs.condition.Os; | |||||
import org.apache.tools.ant.types.Commandline; | import org.apache.tools.ant.types.Commandline; | ||||
/** | /** | ||||
@@ -72,12 +73,33 @@ public class JavacExternal extends DefaultCompilerAdapter { | |||||
attributes.log("Using external javac compiler", Project.MSG_VERBOSE); | attributes.log("Using external javac compiler", Project.MSG_VERBOSE); | ||||
Commandline cmd = new Commandline(); | Commandline cmd = new Commandline(); | ||||
cmd.setExecutable("javac"); | |||||
setupJavacCommandlineSwitches(cmd); | |||||
cmd.setExecutable(getJavacExecutableName()); | |||||
setupModernJavacCommandlineSwitches(cmd); | |||||
int firstFileName = cmd.size(); | int firstFileName = cmd.size(); | ||||
logAndAddFilesToCompile(cmd); | logAndAddFilesToCompile(cmd); | ||||
return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0; | return executeExternalCompile(cmd.getCommandline(), firstFileName) == 0; | ||||
} | } | ||||
private String getJavacExecutableName() { | |||||
// This is the most common extension case - exe for windows and OS/2, | |||||
// nothing for *nix. | |||||
String extension = Os.isFamily("dos") ? ".exe" : ""; | |||||
// Look for java in the java.home/../bin directory. Unfortunately | |||||
// on Windows java.home doesn't always refer to the correct location, | |||||
// so we need to fall back to assuming java is somewhere on the | |||||
// PATH. | |||||
java.io.File jExecutable = | |||||
new java.io.File(System.getProperty("java.home") + | |||||
"/../bin/javac" + extension ); | |||||
if (jExecutable.exists() && !Os.isFamily("netware")) { | |||||
return jExecutable.getAbsolutePath(); | |||||
} else { | |||||
return "javac"; | |||||
} | |||||
} | |||||
} | } | ||||