PR: 4119 git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269868 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -191,8 +191,11 @@ files/directories from the CLASSPATH it passes to the compiler.</p> | |||
| </tr> | |||
| <tr> | |||
| <td valign="top">fork</td> | |||
| <td valign="top">whether to execute Javac using the JDK compiler externally; | |||
| defaults to <code>no</code>.</td> | |||
| <td valign="top">whether to execute Javac using the JDK compiler | |||
| externally; defaults to <code>no</code>. You can also give a | |||
| complete path to the javac executable to use instead of | |||
| <code>yes</code>, which would run the compiler of the Java | |||
| vesrion that is currently running Ant.</td> | |||
| <td align="center" valign="top">No</td> | |||
| </tr> | |||
| <tr> | |||
| @@ -251,6 +254,26 @@ href="../using.html#path">path-like structures</a> and can also be set via neste | |||
| directory, and stores | |||
| the <code>.class</code> files in the <code>${build}</code> directory. | |||
| The classpath used contains <code>xyz.jar</code>, and debug information is on.</p> | |||
| <pre> <javac srcdir="${src}" | |||
| destdir="${build}" | |||
| fork="true" | |||
| /></pre> | |||
| <p>compiles all <code>.java</code> files under the <code>${src}</code> | |||
| directory, and stores the <code>.class</code> files in the | |||
| <code>${build}</code> directory. This will fork off the javac | |||
| compiler using the default javac executable.</p> | |||
| <pre> <javac srcdir="${src}" | |||
| destdir="${build}" | |||
| fork="java$$javac.exe" | |||
| /></pre> | |||
| <p>compiles all <code>.java</code> files under the <code>${src}</code> | |||
| directory, and stores the <code>.class</code> files in the | |||
| <code>${build}</code> directory. This will fork off the javac | |||
| compiler using the executable named <code>java$javac.exe</code>. Note | |||
| that the <code>$</code> sign needs to be escaped by a second one.</p> | |||
| <pre> <javac srcdir="${src}" | |||
| destdir="${build}" | |||
| includes="mypackage/p1/**,mypackage/p2/**" | |||
| @@ -63,6 +63,7 @@ import org.apache.tools.ant.util.GlobPatternMapper; | |||
| import org.apache.tools.ant.util.SourceFileScanner; | |||
| import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter; | |||
| import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory; | |||
| import org.apache.tools.ant.taskdefs.condition.Os; | |||
| import java.io.File; | |||
| @@ -118,7 +119,8 @@ public class Javac extends MatchingTask { | |||
| private Path extdirs; | |||
| private boolean includeAntRuntime = true; | |||
| private boolean includeJavaRuntime = false; | |||
| private boolean fork = false; | |||
| private String fork = "false"; | |||
| private String forkedExecutable = null; | |||
| private boolean nowarn = false; | |||
| private String memoryInitialSize; | |||
| private String memoryMaximumSize; | |||
| @@ -452,20 +454,40 @@ public class Javac extends MatchingTask { | |||
| /** | |||
| * Sets whether to fork the javac compiler. | |||
| */ | |||
| public void setFork(boolean fork) | |||
| { | |||
| this.fork = fork; | |||
| * | |||
| * @param f "true|false|on|off|yes|no" or the name of the javac | |||
| * executable. | |||
| */ | |||
| public void setFork(String f) { | |||
| if (f.equalsIgnoreCase("on") | |||
| || f.equalsIgnoreCase("true") | |||
| || f.equalsIgnoreCase("yes")) { | |||
| fork = "true"; | |||
| forkedExecutable = getSystemJavac(); | |||
| } else if (f.equalsIgnoreCase("off") | |||
| || f.equalsIgnoreCase("false") | |||
| || f.equalsIgnoreCase("no")) { | |||
| fork = "false"; | |||
| } else { | |||
| fork = "true"; | |||
| forkedExecutable = f; | |||
| } | |||
| } | |||
| /** | |||
| * Is this a forked invocation of JDK's javac? | |||
| */ | |||
| public boolean isForkedJavac() { | |||
| return fork || | |||
| return !"false".equals(fork) || | |||
| "extJavac".equals(project.getProperty("build.compiler")); | |||
| } | |||
| /** | |||
| * The name of the javac executable to use in fork-mode. | |||
| */ | |||
| public String getJavacExecutable() { | |||
| return forkedExecutable; | |||
| } | |||
| /** | |||
| * Sets whether the -nowarn option should be used. | |||
| @@ -519,7 +541,7 @@ public class Javac extends MatchingTask { | |||
| String compiler = project.getProperty("build.compiler"); | |||
| if (fork) { | |||
| if (!"false".equals(fork)) { | |||
| if (compiler != null) { | |||
| if (isJdkCompiler(compiler)) { | |||
| log("Since fork is true, ignoring build.compiler setting.", | |||
| @@ -611,4 +633,24 @@ public class Javac extends MatchingTask { | |||
| "javac1.4".equals(compiler); | |||
| } | |||
| protected String getSystemJavac() { | |||
| // 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"; | |||
| } | |||
| } | |||
| } | |||
| @@ -56,7 +56,6 @@ package org.apache.tools.ant.taskdefs.compilers; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.taskdefs.condition.Os; | |||
| import org.apache.tools.ant.types.Commandline; | |||
| /** | |||
| @@ -73,7 +72,7 @@ public class JavacExternal extends DefaultCompilerAdapter { | |||
| attributes.log("Using external javac compiler", Project.MSG_VERBOSE); | |||
| Commandline cmd = new Commandline(); | |||
| cmd.setExecutable(getJavacExecutableName()); | |||
| cmd.setExecutable(getJavac().getJavacExecutable()); | |||
| setupModernJavacCommandlineSwitches(cmd); | |||
| int firstFileName = cmd.size(); | |||
| logAndAddFilesToCompile(cmd); | |||
| @@ -81,25 +80,5 @@ public class JavacExternal extends DefaultCompilerAdapter { | |||
| 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"; | |||
| } | |||
| } | |||
| } | |||