Browse Source

revert <javac>'s fork attribute to a true boolean and add executable

attribute to set the path to the compiler.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272016 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
fc7e3b1fd4
3 changed files with 36 additions and 34 deletions
  1. +9
    -4
      docs/manual/CoreTasks/javac.html
  2. +17
    -21
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  3. +10
    -9
      src/testcases/org/apache/tools/ant/taskdefs/JavacTest.java

+ 9
- 4
docs/manual/CoreTasks/javac.html View File

@@ -252,10 +252,15 @@ invoking the compiler.</p>
<tr> <tr>
<td valign="top">fork</td> <td valign="top">fork</td>
<td valign="top">Whether to execute <code>javac</code> using the <td valign="top">Whether to execute <code>javac</code> using the
JDK compiler externally; defaults to <code>no</code>. You can also
give a complete path to the <code>javac</code> executable to use
instead of <code>yes</code>, which would run the compiler of the Java
version that is currently running Ant.</td>
JDK compiler externally; defaults to <code>no</code>.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">executable</td>
<td valign="top">Complete path to the <code>javac</code>
executable to use in case of <code>fork=&quot;yes&quot;</code>.
Defaults to the compiler of the Java version that is currently
running Ant. Ignored if <code>fork=&quot;no&quot;</code></td>
<td align="center" valign="top">No</td> <td align="center" valign="top">No</td>
</tr> </tr>
<tr> <tr>


+ 17
- 21
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

@@ -128,7 +128,7 @@ public class Javac extends MatchingTask {
private Path extdirs; private Path extdirs;
private boolean includeAntRuntime = true; private boolean includeAntRuntime = true;
private boolean includeJavaRuntime = false; private boolean includeJavaRuntime = false;
private String fork = "false";
private boolean fork = false;
private String forkedExecutable = null; private String forkedExecutable = null;
private boolean nowarn = false; private boolean nowarn = false;
private String memoryInitialSize; private String memoryInitialSize;
@@ -547,31 +547,27 @@ public class Javac extends MatchingTask {
/** /**
* Sets whether to fork the javac compiler. * Sets whether to fork the javac compiler.
* *
* @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";
forkedExecutable = null;
} else {
fork = "true";
forkedExecutable = f;
}
* @param f "true|false|on|off|yes|no"
*/
public void setFork(boolean f) {
fork = f;
}

/**
* Sets the the name of the javac executable.
*
* <p>Ignored unless fork is true or extJavac has been specified
* as the compiler.</p>
*/
public void setExecutable(String forkExec) {
forkedExecutable = forkExec;
} }


/** /**
* Is this a forked invocation of JDK's javac? * Is this a forked invocation of JDK's javac?
*/ */
public boolean isForkedJavac() { public boolean isForkedJavac() {
return !"false".equals(fork) || "extJavac".equals(getCompiler());
return fork || "extJavac".equals(getCompiler());
} }


/** /**
@@ -753,7 +749,7 @@ public class Javac extends MatchingTask {
this.compiler != null ? this.compiler this.compiler != null ? this.compiler
: project.getProperty("build.compiler"); : project.getProperty("build.compiler");


if (!"false".equals(fork)) {
if (fork) {
if (compilerImpl != null) { if (compilerImpl != null) {
if (isJdkCompiler(compilerImpl)) { if (isJdkCompiler(compilerImpl)) {
log("Since fork is true, ignoring compiler setting.", log("Since fork is true, ignoring compiler setting.",


+ 10
- 9
src/testcases/org/apache/tools/ant/taskdefs/JavacTest.java View File

@@ -89,13 +89,13 @@ public class JavacTest extends TestCase {
project.setProperty("build.compiler", "modern"); project.setProperty("build.compiler", "modern");
assertNull("no fork means no executable", javac.getJavacExecutable()); assertNull("no fork means no executable", javac.getJavacExecutable());


javac.setFork("true");
javac.setFork(true);
assertNotNull("normal fork", javac.getJavacExecutable()); assertNotNull("normal fork", javac.getJavacExecutable());
assertTrue("name should contain \"javac\"", assertTrue("name should contain \"javac\"",
javac.getJavacExecutable().indexOf("javac") > -1); javac.getJavacExecutable().indexOf("javac") > -1);


project.setProperty("build.compiler", "extJavac"); project.setProperty("build.compiler", "extJavac");
javac.setFork("false");
javac.setFork(false);
assertNotNull("fork via property", javac.getJavacExecutable()); assertNotNull("fork via property", javac.getJavacExecutable());
assertTrue("name should contain \"javac\"", assertTrue("name should contain \"javac\"",
javac.getJavacExecutable().indexOf("javac") > -1); javac.getJavacExecutable().indexOf("javac") > -1);
@@ -105,7 +105,8 @@ public class JavacTest extends TestCase {
javac.getJavacExecutable()); javac.getJavacExecutable());


String myJavac = "Slartibartfast"; String myJavac = "Slartibartfast";
javac.setFork(myJavac);
javac.setFork(true);
javac.setExecutable(myJavac);
assertEquals(myJavac, javac.getJavacExecutable()); assertEquals(myJavac, javac.getJavacExecutable());
} }


@@ -161,7 +162,7 @@ public class JavacTest extends TestCase {
String testArg = ford + " " + prefect; String testArg = ford + " " + prefect;
arg.setValue(testArg); arg.setValue(testArg);
arg.setImplementation("extJavac"); arg.setImplementation("extJavac");
javac.setFork("true");
javac.setFork(true);
String[] args = javac.getCurrentCompilerArgs(); String[] args = javac.getCurrentCompilerArgs();
assertEquals("both are forked javac", 1, args.length); assertEquals("both are forked javac", 1, args.length);
assertEquals(testArg, args[0]); assertEquals(testArg, args[0]);
@@ -177,31 +178,31 @@ public class JavacTest extends TestCase {
assertTrue("default value", assertTrue("default value",
"modern".equals(compiler) || "classic".equals(compiler)); "modern".equals(compiler) || "classic".equals(compiler));


javac.setFork("true");
javac.setFork(true);
compiler = javac.getCompiler(); compiler = javac.getCompiler();
assertNotNull(compiler); assertNotNull(compiler);
assertEquals("extJavac", compiler); assertEquals("extJavac", compiler);


// check build.compiler provides defaults // check build.compiler provides defaults
javac.setFork("false");
javac.setFork(false);
project.setNewProperty("build.compiler", "jikes"); project.setNewProperty("build.compiler", "jikes");
compiler = javac.getCompiler(); compiler = javac.getCompiler();
assertNotNull(compiler); assertNotNull(compiler);
assertEquals("jikes", compiler); assertEquals("jikes", compiler);


javac.setFork("true");
javac.setFork(true);
compiler = javac.getCompiler(); compiler = javac.getCompiler();
assertNotNull(compiler); assertNotNull(compiler);
assertEquals("jikes", compiler); assertEquals("jikes", compiler);


// check attribute overrides build.compiler // check attribute overrides build.compiler
javac.setFork("false");
javac.setFork(false);
javac.setCompiler("jvc"); javac.setCompiler("jvc");
compiler = javac.getCompiler(); compiler = javac.getCompiler();
assertNotNull(compiler); assertNotNull(compiler);
assertEquals("jvc", compiler); assertEquals("jvc", compiler);


javac.setFork("true");
javac.setFork(true);
compiler = javac.getCompiler(); compiler = javac.getCompiler();
assertNotNull(compiler); assertNotNull(compiler);
assertEquals("jvc", compiler); assertEquals("jvc", compiler);


Loading…
Cancel
Save