bodewig 02/02/15 05:42:53
Modified: . WHATSNEW
docs/manual/CoreTasks javac.html
src/main/org/apache/tools/ant/taskdefs Javac.java
src/testcases/org/apache/tools/ant/taskdefs JavacTest.java
Log:
Add compiler attribute to <javac> that allows users to override
build.compiler on a task by task basis.
Revision Changes Path
1.210 +4 -0 jakarta-ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
retrieving revision 1.209
retrieving revision 1.210
diff -u -r1.209 -r1.210
--- WHATSNEW 14 Feb 2002 17:34:19 -0000 1.209
+++ WHATSNEW 15 Feb 2002 13:42:53 -0000 1.210
@@ -163,6 +163,10 @@
* you can now specify the -sourcepath for <javac> explicitly.
+* The compiler implementation for javac can now be chosen on a task by
+ task basis. Use the new compiler attribute of <javac> to override
+ the build.compiler property.
+
Changes from Ant 1.4 to Ant 1.4.1
===========================================
1.26 +7 -1 jakarta-ant/docs/manual/CoreTasks/javac.html
Index: javac.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/javac.html,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- javac.html 15 Feb 2002 07:22:01 -0000 1.25
+++ javac.html 15 Feb 2002 13:42:53 -0000 1.26
@@ -29,7 +29,7 @@
href="../dirtasks.html#directorybasedtasks">directory based tasks</a>, on
how the
inclusion/exclusion of files works, and how to write patterns.</p>
<p>It is possible to use different compilers. This can be selected with the
-"build.compiler" property. Here are the choices:-</p>
+"build.compiler" property or the compiler attribute. Here are the
choices:-</p>
<ul>
<li>classic (the standard compiler of JDK 1.1/1.2) - javac1.1 and
javac1.2 can be used as aliases</li>
@@ -257,6 +257,12 @@
appended to <code>-g</code>. If debug is not turned on, this attribute
will be
ignored.
</td>
+ <td align="center" valign="top">No</td>
+ </tr>
+ <tr>
+ <td valign="top">compiler</td>
+ <td valign="top">The compiler implementation to use.
+ Defaults to the value of the <code>build.compiler</code> property.</td>
<td align="center" valign="top">No</td>
</tr>
</table>
1.84 +50 -22
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java
Index: Javac.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- Javac.java 14 Feb 2002 17:34:19 -0000 1.83
+++ Javac.java 15 Feb 2002 13:42:53 -0000 1.84
@@ -90,6 +90,7 @@
* <li>includeantruntime
* <li>includejavaruntime
* <li>source
+ * <li>compiler
* </ul>
* Of these arguments, the <b>sourcedir</b> and <b>destdir</b> are required.
* <p>
@@ -137,6 +138,15 @@
private String debugLevel;
/**
+ * The compiler set via the compiler attribute.
+ *
+ * <p>default is null</p>
+ *
+ * @since 1.84, Ant 1.5
+ */
+ private String compiler = null;
+
+ /**
* Get the value of debugLevel.
* @return value of debugLevel.
*/
@@ -544,8 +554,7 @@
* Is this a forked invocation of JDK's javac?
*/
public boolean isForkedJavac() {
- return !"false".equals(fork) ||
- "extJavac".equals(project.getProperty("build.compiler"));
+ return !"false".equals(fork) || "extJavac".equals(getCompiler());
}
/**
@@ -665,13 +674,13 @@
return compileList;
}
- protected boolean isJdkCompiler(String compiler) {
- return "modern".equals(compiler) ||
- "classic".equals(compiler) ||
- "javac1.1".equals(compiler) ||
- "javac1.2".equals(compiler) ||
- "javac1.3".equals(compiler) ||
- "javac1.4".equals(compiler);
+ protected boolean isJdkCompiler(String compilerImpl) {
+ return "modern".equals(compilerImpl) ||
+ "classic".equals(compilerImpl) ||
+ "javac1.1".equals(compilerImpl) ||
+ "javac1.2".equals(compilerImpl) ||
+ "javac1.3".equals(compilerImpl) ||
+ "javac1.4".equals(compilerImpl);
}
protected String getSystemJavac() {
@@ -705,34 +714,53 @@
}
}
- private String determineCompiler() {
- String compiler = project.getProperty("build.compiler");
+ /**
+ * Chose the implementation for this particular task.
+ *
+ * @since 1.84, Ant 1.5
+ */
+ public void setCompiler(String compiler) {
+ this.compiler = compiler;
+ }
+
+ /**
+ * The implementation for this particular task.
+ *
+ * <p>Defaults to the build.compiler property but can be overriden
+ * via the compiler and for attributes.</p>
+ *
+ * @since 1.84, Ant 1.5
+ */
+ public String getCompiler() {
+ String compilerImpl =
+ this.compiler != null ? this.compiler
+ : project.getProperty("build.compiler");
if (!"false".equals(fork)) {
- if (compiler != null) {
- if (isJdkCompiler(compiler)) {
+ if (compilerImpl != null) {
+ if (isJdkCompiler(compilerImpl)) {
log("Since fork is true, ignoring build.compiler
setting.",
Project.MSG_WARN);
- compiler = "extJavac";
+ compilerImpl = "extJavac";
}
else {
log("Since build.compiler setting isn't classic or
modern, ignoring fork setting.", Project.MSG_WARN);
}
}
else {
- compiler = "extJavac";
+ compilerImpl = "extJavac";
}
}
- if (compiler == null) {
+ if (compilerImpl == null) {
if (Project.getJavaVersion() != Project.JAVA_1_1 &&
Project.getJavaVersion() != Project.JAVA_1_2) {
- compiler = "modern";
+ compilerImpl = "modern";
} else {
- compiler = "classic";
+ compilerImpl = "classic";
}
}
- return compiler;
+ return compilerImpl;
}
/**
@@ -765,7 +793,7 @@
* @since 1.82, Ant 1.5
*/
protected void compile() {
- String compiler = determineCompiler();
+ String compilerImpl = getCompiler();
if (compileList.length > 0) {
log("Compiling " + compileList.length +
@@ -774,7 +802,7 @@
+ (destDir != null ? " to " + destDir : ""));
CompilerAdapter adapter =
- CompilerAdapterFactory.getCompiler(compiler, this);
+ CompilerAdapterFactory.getCompiler(compilerImpl, this);
// now we need to populate the compiler adapter
adapter.setJavac(this);
@@ -805,7 +833,7 @@
}
public String[] getParts() {
- if (impl == null || impl.equals(determineCompiler())) {
+ if (impl == null || impl.equals(getCompiler())) {
return super.getParts();
} else {
return new String[0];
1.3 +42 -2
jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/JavacTest.java
Index: JavacTest.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/JavacTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- JavacTest.java 29 Nov 2001 08:31:01 -0000 1.2
+++ JavacTest.java 15 Feb 2002 13:42:53 -0000 1.3
@@ -1,7 +1,7 @@
/*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -62,7 +62,7 @@
* Testcase for <javac>.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Stefan Bodewig</a>
- * @version $Revision: 1.2 $ $Date: 2001/11/29 08:31:01 $
+ * @version $Revision: 1.3 $ $Date: 2002/02/15 13:42:53 $
*/
public class JavacTest extends TestCase {
@@ -165,6 +165,46 @@
String[] args = javac.getCurrentCompilerArgs();
assertEquals("both are forked javac", 1, args.length);
assertEquals(testArg, args[0]);
+ }
+
+ /**
+ * Test compiler attribute.
+ */
+ public void testCompilerAttribute() {
+ // check defaults
+ String compiler = javac.getCompiler();
+ assertNotNull(compiler);
+ assertTrue("default value",
+ "modern".equals(compiler) || "classic".equals(compiler));
+
+ javac.setFork("true");
+ compiler = javac.getCompiler();
+ assertNotNull(compiler);
+ assertEquals("extJavac", compiler);
+
+ // check build.compiler provides defaults
+ javac.setFork("false");
+ project.setNewProperty("build.compiler", "jikes");
+ compiler = javac.getCompiler();
+ assertNotNull(compiler);
+ assertEquals("jikes", compiler);
+
+ javac.setFork("true");
+ compiler = javac.getCompiler();
+ assertNotNull(compiler);
+ assertEquals("jikes", compiler);
+
+ // check attribute overrides build.compiler
+ javac.setFork("false");
+ javac.setCompiler("jvc");
+ compiler = javac.getCompiler();
+ assertNotNull(compiler);
+ assertEquals("jvc", compiler);
+
+ javac.setFork("true");
+ compiler = javac.getCompiler();
+ assertNotNull(compiler);
+ assertEquals("jvc", compiler);
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>