diff --git a/WHATSNEW b/WHATSNEW index 2bcb7e727..27843c5bd 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -860,6 +860,12 @@ Other changes: task's (compiler) adapter class. Bugzilla Report 11143. + * , , and now provide a nested + element to specify the task's (compiler) adapter as an instance of + a class that has been defined via typedef/componentdef. This + allows more control over the classpath and allows adapters to be + defined in Antlibs easily. + * A new subclass org.apache.tools.ant.loader.AntClassLoader5 of AntClassLoader has been added which overrides getResources which became non-final in ClassLoader with Java5+ so diff --git a/docs/manual/CoreTasks/javac.html b/docs/manual/CoreTasks/javac.html index 6c3736a1b..56b0b39f4 100644 --- a/docs/manual/CoreTasks/javac.html +++ b/docs/manual/CoreTasks/javac.html @@ -59,9 +59,12 @@ for information on how the inclusion/exclusion of files works, and how to write wildcard patterns.

It is possible to use different compilers. This can be specified by either setting the global build.compiler property, which will -affect all <javac> tasks throughout the build, or by +affect all <javac> tasks throughout the build, by setting the compiler attribute, specific to the current -<javac> task. +<javac> task or by using a nested element of any +typedeffed or +componentdeffed type that implements +org.apache.tools.ant.taskdefs.compilers.CompilerAdapter. Valid values for either the build.compiler property or the compiler attribute are:

@@ -516,6 +519,12 @@ used.

custom class has been specified. Doesn't have any effect when using one of the built-in compilers.

+

Any nested element of a type that implements CompilerAdapter + since Ant 1.8.0

+ +

If a defined type implements the CompilerAdapter + interface a nested element of that type can be used as an + alternative to the compiler attribute.

Examples

  <javac srcdir="${src}"
@@ -662,6 +671,25 @@ the <compilerarg> element:
   </javac> 

+

If you want to use a custom + CompilerAdapter org.example.MyAdapter you can either + use the compiler attribute:

+
+<javac srcdir="${src.dir}"
+       destdir="${classes.dir}"
+       compiler="org.example.MyAdapter"/>
+
+

or a define a type and nest this into the task like in:

+
+<componentdef classname="org.example.MyAdapter"
+              name="myadapter"/>
+<javac srcdir="${src.dir}"
+       destdir="${classes.dir}">
+  <myadapter/>
+</javac>
+
+

in which case your compiler adapter can support attributes and + nested elements of its own.

Jikes Notes

@@ -800,27 +828,14 @@ while all others are false.

task is run again, the task will try to compile the package-info java files again.

-

- In Ant 1.7.1 the package-info.java will only be compiled if: -

    -
  1. - If a package-info.class file exists and is older than - the package-info.java file. -
  2. -
  3. - If the directory for the - package-info.class file does not exist. -
  4. -
  5. - If the directory for the - package-info.class file exists, and has an older - modification time than the - the package-info.java file. In this case - <javac> will touch the corresponding .class directory - on successful compilation. -
  6. -
-

- +

With Ant 1.7.1 a different kind of logic was introduced that + involved the timestamp of the directory that would normally + contain the .class file. This logic turned out to lead to Ant not + recompiling package-info.java in certain setup.

+

Starting with Ant 1.8.0 Ant will create + "empty" package-info.class files if it compiles + a package-info.java and + no package-info.class file has been created by the + compiler itself.

diff --git a/docs/manual/CoreTasks/rmic.html b/docs/manual/CoreTasks/rmic.html index f2148aab1..e3ebf1c3b 100644 --- a/docs/manual/CoreTasks/rmic.html +++ b/docs/manual/CoreTasks/rmic.html @@ -48,8 +48,8 @@ supports most attributes of <fileset> <include>, <exclude> and <patternset> elements.

It is possible to use different compilers. This can be selected -with the "build.rmic" property or the compiler -attribute. +with the "build.rmic" property, the compiler +attribute. or a nested element. Here are the choices:

  • default -the default compiler (kaffe or sun) for the platform. @@ -311,6 +311,13 @@ used.

    custom class has been specified. Doesn't have any effect when using one of the built-in compilers.

    +

    Any nested element of a type that implements RmicAdapter + since Ant 1.8.0

    + +

    If a defined type implements the RmicAdapter + interface a nested element of that type can be used as an + alternative to the compiler attribute.

    +

    Examples

      <rmic classname="com.xyz.FooBar" base="${build}/classes"/>

    runs the rmic compiler for the class com.xyz.FooBar. The @@ -321,7 +328,25 @@ files below ${build}/classes whose classname starts with Remote. The compiled files will be stored in the directory ${build}/classes.

    - +

    If you want to use a custom + RmicAdapter org.example.MyAdapter you can either + use the compiler attribute:

    +
    +<rmic classname="com.xyz.FooBar"
    +      base="${build}/classes"
    +      compiler="org.example.MyAdapter"/>
    +
    +

    or a define a type and nest this into the task like in:

    +
    +<componentdef classname="org.example.MyAdapter"
    +              name="myadapter"/>
    +<rmic classname="com.xyz.FooBar"
    +      base="${build}/classes">
    +  <myadapter/>
    +</rmic>
    +
    +

    in which case your compiler adapter can support attributes and + nested elements of its own.

    diff --git a/docs/manual/OptionalTasks/javah.html b/docs/manual/OptionalTasks/javah.html index 7e2f3729f..f84d54e32 100644 --- a/docs/manual/OptionalTasks/javah.html +++ b/docs/manual/OptionalTasks/javah.html @@ -34,8 +34,8 @@ whether JD systems are used.

    It is possible to use different compilers. This can be selected -with the implementation attribute. Here are the choices:

    +with the implementation attribute or a nested element. Here are the choices of the attribute:

    • default - the default compiler (kaffeh or sun) for the platform.
    • sun (the standard compiler of the JDK)
    • @@ -177,6 +177,13 @@ only if a given compiler implementation will be used.

      custom class has been specified. Doesn't have any effect when using one of the built-in compilers.

      +

      Any nested element of a type that implements JavahAdapter + since Ant 1.8.0

      + +

      If a defined type implements the JavahAdapter + interface a nested element of that type can be used as an + alternative to the implementation attribute.

      +

      Examples

        <javah destdir="c" class="org.foo.bar.Wibble"/>

      makes a JNI header of the named class, using the JDK1.2 JNI model. Assuming @@ -210,6 +217,23 @@ is invoked, even if they already exist.

      writes the corresponding .c stubs. The verbose option will cause Javah to describe its progress.

      +

      If you want to use a custom + JavahAdapter org.example.MyAdapter you can either + use the implementation attribute:

      +
      +<javah destdir="c" class="org.foo.bar.Wibble"
      +       implementation="org.example.MyAdapter"/>
      +
      +

      or a define a type and nest this into the task like in:

      +
      +<componentdef classname="org.example.MyAdapter"
      +              name="myadapter"/>
      +<javah destdir="c" class="org.foo.bar.Wibble">
      +  <myadapter/>
      +</javah>
      +
      +

      in which case your javah adapter can support attributes and + nested elements of its own.

      diff --git a/docs/manual/OptionalTasks/native2ascii.html b/docs/manual/OptionalTasks/native2ascii.html index 3b3ce5c61..230b8d204 100644 --- a/docs/manual/OptionalTasks/native2ascii.html +++ b/docs/manual/OptionalTasks/native2ascii.html @@ -58,8 +58,8 @@

      It is possible to use different converters. This can be selected - with the implementation attribute. - Here are the choices:

      + with the implementation attribute or a nested element. + Here are the choices of the attribute:

      • default - the default converter (kaffe or sun) for the platform.
      • sun (the standard converter of the JDK)
      • @@ -190,6 +190,13 @@ only if a given converter implementation will be used.

        custom class has been specified. Doesn't have any effect when using one of the built-in converters.

        +

        Any nested element of a type that implements Native2AsciiAdapter + since Ant 1.8.0

        + +

        If a defined type implements the Native2AsciiAdapter + interface a nested element of that type can be used as an + alternative to the implementation attribute.

        +

        Examples

        @@ -214,6 +221,26 @@ only if a given converter implementation will be used.

        placing the results in the directory src. The names of the files remain the same.

        + +

        If you want to use a custom + Native2AsciiAdapter org.example.MyAdapter you can either + use the implementation attribute:

        +
        +<native2ascii encoding="EUCJIS" src="srcdir" dest="srcdir"
        +       includes="**/*.eucjis" ext=".java"
        +       implementation="org.example.MyAdapter"/>
        +
        +

        or a define a type and nest this into the task like in:

        +
        +<componentdef classname="org.example.MyAdapter"
        +              name="myadapter"/>
        +<native2ascii encoding="EUCJIS" src="srcdir" dest="srcdir"
        +       includes="**/*.eucjis" ext=".java">
        +  <myadapter/>
        +</native2ascii>
        +
        +

        in which case your native2ascii adapter can support attributes and + nested elements of its own.

        diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java index b7b8d27af..912526eb1 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javac.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java @@ -127,6 +127,7 @@ public class Javac extends MatchingTask { private String errorProperty; private boolean taskSuccess = true; // assume the best private boolean includeDestClasses = true; + private CompilerAdapter nestedAdapter = null; /** * Javac task for compilation of Java files. @@ -865,6 +866,18 @@ public class Javac extends MatchingTask { return facade.getImplementationClasspath(getProject()); } + /** + * Set the compiler adapter explicitly. + * @since Ant 1.8.0 + */ + public void add(CompilerAdapter adapter) { + if (nestedAdapter != null) { + throw new BuildException("Can't have more than one compiler" + + " adapter"); + } + nestedAdapter = adapter; + } + /** * Executes the task. * @exception BuildException if an error occurs @@ -1073,6 +1086,7 @@ public class Javac extends MatchingTask { } CompilerAdapter adapter = + nestedAdapter != null ? nestedAdapter : CompilerAdapterFactory.getCompiler(compilerImpl, this, createCompilerClasspath()); diff --git a/src/main/org/apache/tools/ant/taskdefs/Rmic.java b/src/main/org/apache/tools/ant/taskdefs/Rmic.java index 23bb79584..edac71518 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Rmic.java +++ b/src/main/org/apache/tools/ant/taskdefs/Rmic.java @@ -128,6 +128,8 @@ public class Rmic extends MatchingTask { private boolean listFiles = false; + private RmicAdapter nestedAdapter = null; + /** * Constructor for Rmic. */ @@ -560,6 +562,18 @@ public class Rmic extends MatchingTask { public void setListfiles(boolean list) { listFiles = list; } + + /** + * Set the compiler adapter explicitly. + * @since Ant 1.8.0 + */ + public void add(RmicAdapter adapter) { + if (nestedAdapter != null) { + throw new BuildException("Can't have more than one rmic adapter"); + } + nestedAdapter = adapter; + } + /** * execute by creating an instance of an implementation * class and getting to do the work @@ -582,8 +596,10 @@ public class Rmic extends MatchingTask { if (verify) { log("Verify has been turned on.", Project.MSG_VERBOSE); } - RmicAdapter adapter = RmicAdapterFactory.getRmic(getCompiler(), this, - createCompilerClasspath()); + RmicAdapter adapter = + nestedAdapter != null ? nestedAdapter : + RmicAdapterFactory.getRmic(getCompiler(), this, + createCompilerClasspath()); // now we need to populate the compiler adapter adapter.setRmic(this); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java b/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java index 704636c42..1908682c6 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Javah.java @@ -83,6 +83,7 @@ public class Javah extends Task { //private Path extdirs; private FacadeTaskHelper facade = null; private Vector files = new Vector(); + private JavahAdapter nestedAdapter = null; /** * No arg constructor. @@ -416,6 +417,18 @@ public class Javah extends Task { return facade.getImplementationClasspath(getProject()); } + /** + * Set the adapter explicitly. + * @since Ant 1.8.0 + */ + public void add(JavahAdapter adapter) { + if (nestedAdapter != null) { + throw new BuildException("Can't have more than one javah" + + " adapter"); + } + nestedAdapter = adapter; + } + /** * Execute the task * @@ -452,6 +465,7 @@ public class Javah extends Task { } JavahAdapter ad = + nestedAdapter != null ? nestedAdapter : JavahAdapterFactory.getAdapter(facade.getImplementation(), this, createImplementationClasspath()); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java b/src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java index e2eb06be2..a40e6a331 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java @@ -48,6 +48,7 @@ public class Native2Ascii extends MatchingTask { private Mapper mapper; private FacadeTaskHelper facade = null; + private Native2AsciiAdapter nestedAdapter = null; /** No args constructor */ public Native2Ascii() { @@ -184,6 +185,18 @@ public class Native2Ascii extends MatchingTask { return facade.getImplementationClasspath(getProject()); } + /** + * Set the adapter explicitly. + * @since Ant 1.8.0 + */ + public void add(Native2AsciiAdapter adapter) { + if (nestedAdapter != null) { + throw new BuildException("Can't have more than one native2ascii" + + " adapter"); + } + nestedAdapter = adapter; + } + /** * Execute the task * @@ -274,6 +287,7 @@ public class Native2Ascii extends MatchingTask { log("converting " + srcName, Project.MSG_VERBOSE); Native2AsciiAdapter ad = + nestedAdapter != null ? nestedAdapter : Native2AsciiAdapterFactory.getAdapter(facade.getImplementation(), this, createImplementationClasspath()); diff --git a/src/tests/antunit/taskdefs/javac-test.xml b/src/tests/antunit/taskdefs/javac-test.xml index 55e794be6..6b3712152 100644 --- a/src/tests/antunit/taskdefs/javac-test.xml +++ b/src/tests/antunit/taskdefs/javac-test.xml @@ -155,4 +155,14 @@ public class Adapter implements CompilerAdapter { + + + + + + + + + + diff --git a/src/tests/antunit/taskdefs/optional/javah-test.xml b/src/tests/antunit/taskdefs/optional/javah-test.xml index 9779ea4bc..d222cb31d 100644 --- a/src/tests/antunit/taskdefs/optional/javah-test.xml +++ b/src/tests/antunit/taskdefs/optional/javah-test.xml @@ -52,4 +52,15 @@ public class Adapter implements JavahAdapter { + + + + + + + + + + diff --git a/src/tests/antunit/taskdefs/optional/native2ascii-test.xml b/src/tests/antunit/taskdefs/optional/native2ascii-test.xml index 1bd192169..3c9b3c441 100644 --- a/src/tests/antunit/taskdefs/optional/native2ascii-test.xml +++ b/src/tests/antunit/taskdefs/optional/native2ascii-test.xml @@ -53,4 +53,15 @@ public class Adapter implements Native2AsciiAdapter { + + + + + + + + + + diff --git a/src/tests/antunit/taskdefs/rmic-test.xml b/src/tests/antunit/taskdefs/rmic-test.xml index f0cc36440..65688de7e 100644 --- a/src/tests/antunit/taskdefs/rmic-test.xml +++ b/src/tests/antunit/taskdefs/rmic-test.xml @@ -66,4 +66,14 @@ public class Adapter implements RmicAdapter { + + + + + + + + + +