diff --git a/docs/manual/CoreTasks/apt.html b/docs/manual/CoreTasks/apt.html index af7e99082..d36db3bbc 100644 --- a/docs/manual/CoreTasks/apt.html +++ b/docs/manual/CoreTasks/apt.html @@ -7,11 +7,23 @@

Apt

Description

Runs the annotation processor tool (apt), and then optionally compiles - the original code, and any generated source code. This task requires Java1.5 or later.

+ the original code, and any generated source code. This task requires Java 1.5. + It may work on later versions, but this cannot be confirmed until those + versions ship. Be advised that the Apt tool does appear to be an unstable + part of the JDK framework, so may change radically in future versions. + If the <apt> task does break when upgrading JVM, please + check to see if there is a more recent version of Ant that tracks + any changes.

This task inherits from the Javac Task, and thus - supports all of the same attributes, and subelements. In addition, it supports + supports nearly all of the same attributes, and subelements. + There is one special case, the fork attribute, which is present + but which can only be set to true. That is, apt only works as + a forked process. +

+

+ In addition, it supports the following addition items:

Parameters

@@ -109,7 +121,7 @@ AnnotationProcessor instances.

Notes

-The inherited "fork" attribute is set to true by default. +The inherited "fork" attribute is set to true by default; please do not change it.

diff --git a/src/etc/testcases/taskdefs/apt.xml b/src/etc/testcases/taskdefs/apt.xml index 6c6af32c4..3281cd982 100644 --- a/src/etc/testcases/taskdefs/apt.xml +++ b/src/etc/testcases/taskdefs/apt.xml @@ -59,6 +59,18 @@ + + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/Apt.java b/src/main/org/apache/tools/ant/taskdefs/Apt.java index a0093e1dd..7c68cb1a7 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Apt.java +++ b/src/main/org/apache/tools/ant/taskdefs/Apt.java @@ -51,6 +51,12 @@ public class Apt /** A warning message if used with java < 1.5. */ public static final String ERROR_WRONG_JAVA_VERSION = "Apt task requires Java 1.5+"; + + /** + * exposed for debug messages + */ + public static final String WARNING_IGNORING_FORK = + "Apt only runs in its own JVM; fork=false option ignored"; /** * The nested option element. @@ -103,7 +109,7 @@ public class Apt */ public Apt() { super(); - super.setCompiler(AptCompilerAdapter.class.getName()); + super.setCompiler(AptExternalCompilerAdapter.class.getName()); setFork(true); } @@ -126,16 +132,15 @@ public class Apt } /** - * Set the fork attribute (optional, default=true). - * If fork is true run the external apt command. - * If fork is false run the apt compiler in the same jvm as the task. - * @param fork if true use the external command. + * Set the fork attribute. + * Non-forking APT is highly classpath dependent and appears to be too + * brittle to work. The sole reason this attribute is retained + * is the superclass does it + * @param fork if false; warn the option is ignored. */ public void setFork(boolean fork) { - if (fork) { - super.setCompiler(AptExternalCompilerAdapter.class.getName()); - } else { - super.setCompiler(AptCompilerAdapter.class.getName()); + if (!fork) { + log(WARNING_IGNORING_FORK,Project.MSG_WARN); } } @@ -258,7 +263,6 @@ public class Apt if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)) { throw new BuildException(ERROR_WRONG_JAVA_VERSION); } - super.execute(); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/AptCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/AptCompilerAdapter.java index e8c145a5f..c196f128a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/compilers/AptCompilerAdapter.java +++ b/src/main/org/apache/tools/ant/taskdefs/compilers/AptCompilerAdapter.java @@ -60,6 +60,12 @@ import java.util.Vector; * } * * + * This Adapter is designed to run Apt in-JVM, an option that is not actually + * exposed to end-users, because it was too brittle during beta testing; classpath + * problems being the core issue. + * + * + * * @since Ant 1.7 */ public class AptCompilerAdapter extends DefaultCompilerAdapter { diff --git a/src/testcases/org/apache/tools/ant/taskdefs/AptTest.java b/src/testcases/org/apache/tools/ant/taskdefs/AptTest.java index d94cb427c..dd7f20f72 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/AptTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/AptTest.java @@ -45,6 +45,11 @@ public class AptTest extends BuildFileTest { public void testAptFork() { executeTarget("testAptFork"); } + + public void testAptForkFalse() { + executeTarget("testAptForkFalse"); + assertLogContaining(Apt.WARNING_IGNORING_FORK); + } public void testListAnnotationTypes() { executeTarget("testListAnnotationTypes");