git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278229 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -7,11 +7,23 @@ | |||||
| <h2><a name="Apt">Apt</a></h2> | <h2><a name="Apt">Apt</a></h2> | ||||
| <h3>Description</h3> | <h3>Description</h3> | ||||
| <p>Runs the annotation processor tool (apt), and then optionally compiles | <p>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.</p> | |||||
| 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.</p> | |||||
| <p>This task inherits from the <a href="javac.html">Javac Task</a>, and thus | <p>This task inherits from the <a href="javac.html">Javac Task</a>, 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 <tt>fork</tt> attribute, which is present | |||||
| but which can only be set to <tt>true</tt>. That is, apt only works as | |||||
| a forked process. | |||||
| </p> | |||||
| <p> | |||||
| In addition, it supports | |||||
| the following addition items:</p> | the following addition items:</p> | ||||
| <h3>Parameters</h3> | <h3>Parameters</h3> | ||||
| @@ -109,7 +121,7 @@ AnnotationProcessor instances.</p> | |||||
| <h3>Notes</h3> | <h3>Notes</h3> | ||||
| <p> | <p> | ||||
| 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. | |||||
| </p> | </p> | ||||
| <p> | <p> | ||||
| @@ -59,6 +59,18 @@ | |||||
| <assertAptExampleCompiled /> | <assertAptExampleCompiled /> | ||||
| </target> | </target> | ||||
| <target name="testAptForkFalse" depends="init"> | |||||
| <apt srcdir="${src}" | |||||
| destdir="${classes.dir}" | |||||
| debug="on" | |||||
| compile="true" | |||||
| fork="false" | |||||
| preprocessdir="${preprocess.dir}"> | |||||
| </apt> | |||||
| <assertAptExampleCompiled /> | |||||
| </target> | |||||
| <target name="testListAnnotationTypes" depends="init"> | <target name="testListAnnotationTypes" depends="init"> | ||||
| <apt srcdir="${src}" | <apt srcdir="${src}" | ||||
| destdir="${classes.dir}" | destdir="${classes.dir}" | ||||
| @@ -105,4 +117,5 @@ | |||||
| </project> | </project> | ||||
| @@ -51,6 +51,12 @@ public class Apt | |||||
| /** A warning message if used with java < 1.5. */ | /** A warning message if used with java < 1.5. */ | ||||
| public static final String ERROR_WRONG_JAVA_VERSION | public static final String ERROR_WRONG_JAVA_VERSION | ||||
| = "Apt task requires Java 1.5+"; | = "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. | * The nested option element. | ||||
| @@ -103,7 +109,7 @@ public class Apt | |||||
| */ | */ | ||||
| public Apt() { | public Apt() { | ||||
| super(); | super(); | ||||
| super.setCompiler(AptCompilerAdapter.class.getName()); | |||||
| super.setCompiler(AptExternalCompilerAdapter.class.getName()); | |||||
| setFork(true); | 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) { | 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)) { | if (!JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)) { | ||||
| throw new BuildException(ERROR_WRONG_JAVA_VERSION); | throw new BuildException(ERROR_WRONG_JAVA_VERSION); | ||||
| } | } | ||||
| super.execute(); | super.execute(); | ||||
| } | } | ||||
| } | } | ||||
| @@ -60,6 +60,12 @@ import java.util.Vector; | |||||
| * } | * } | ||||
| * </pre> | * </pre> | ||||
| * | * | ||||
| * 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 | * @since Ant 1.7 | ||||
| */ | */ | ||||
| public class AptCompilerAdapter extends DefaultCompilerAdapter { | public class AptCompilerAdapter extends DefaultCompilerAdapter { | ||||
| @@ -45,6 +45,11 @@ public class AptTest extends BuildFileTest { | |||||
| public void testAptFork() { | public void testAptFork() { | ||||
| executeTarget("testAptFork"); | executeTarget("testAptFork"); | ||||
| } | } | ||||
| public void testAptForkFalse() { | |||||
| executeTarget("testAptForkFalse"); | |||||
| assertLogContaining(Apt.WARNING_IGNORING_FORK); | |||||
| } | |||||
| public void testListAnnotationTypes() { | public void testListAnnotationTypes() { | ||||
| executeTarget("testListAnnotationTypes"); | executeTarget("testListAnnotationTypes"); | ||||