Browse Source

compiler adapter as nested element in javac, rmic, native2ascii and javah. Document package-info.java stuff in javac manual page.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@811376 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
96932a3c78
13 changed files with 230 additions and 33 deletions
  1. +6
    -0
      WHATSNEW
  2. +39
    -24
      docs/manual/CoreTasks/javac.html
  3. +28
    -3
      docs/manual/CoreTasks/rmic.html
  4. +26
    -2
      docs/manual/OptionalTasks/javah.html
  5. +29
    -2
      docs/manual/OptionalTasks/native2ascii.html
  6. +14
    -0
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  7. +18
    -2
      src/main/org/apache/tools/ant/taskdefs/Rmic.java
  8. +14
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/Javah.java
  9. +14
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java
  10. +10
    -0
      src/tests/antunit/taskdefs/javac-test.xml
  11. +11
    -0
      src/tests/antunit/taskdefs/optional/javah-test.xml
  12. +11
    -0
      src/tests/antunit/taskdefs/optional/native2ascii-test.xml
  13. +10
    -0
      src/tests/antunit/taskdefs/rmic-test.xml

+ 6
- 0
WHATSNEW View File

@@ -860,6 +860,12 @@ Other changes:
task's (compiler) adapter class.
Bugzilla Report 11143.

* <javac>, <rmic>, <javah> and <native2ascii> 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


+ 39
- 24
docs/manual/CoreTasks/javac.html View File

@@ -59,9 +59,12 @@ for information on how the
inclusion/exclusion of files works, and how to write wildcard patterns.</p>
<p>It is possible to use different compilers. This can be specified by
either setting the global <code>build.compiler</code> property, which will
affect all <code>&lt;javac&gt;</code> tasks throughout the build, or by
affect all <code>&lt;javac&gt;</code> tasks throughout the build, by
setting the <code>compiler</code> attribute, specific to the current
<code>&lt;javac&gt;</code> task.
<code>&lt;javac&gt;</code> task or by using a nested element of any
<a href="typedef.html">typedef</a>fed or
<a href="componentdef.html">componentdef</a>fed type that implements
<code>org.apache.tools.ant.taskdefs.compilers.CompilerAdapter</code>.
<a name="compilervalues">Valid values for either the
<code>build.compiler</code> property or the <code>compiler</code>
attribute are:</a></p>
@@ -516,6 +519,12 @@ used.</p>
custom class has been specified. Doesn't have any effect when
using one of the built-in compilers.</p>

<h4>Any nested element of a type that implements CompilerAdapter
<em>since Ant 1.8.0</em></h4>

<p>If a defined type implements the <code>CompilerAdapter</code>
interface a nested element of that type can be used as an
alternative to the <code>compiler</code> attribute.</p>

<h3>Examples</h3>
<pre> &lt;javac srcdir=&quot;${src}&quot;
@@ -662,6 +671,25 @@ the <tt>&lt;compilerarg&gt;</tt> element:
&lt;/javac&gt; </pre>
</p>

<p>If you want to use a custom
CompilerAdapter <code>org.example.MyAdapter</code> you can either
use the compiler attribute:</p>
<pre>
&lt;javac srcdir="${src.dir}"
destdir="${classes.dir}"
compiler="org.example.MyAdapter"/&gt;
</pre>
<p>or a define a type and nest this into the task like in:</p>
<pre>
&lt;componentdef classname="org.example.MyAdapter"
name="myadapter"/&gt;
&lt;javac srcdir="${src.dir}"
destdir="${classes.dir}"&gt;
&lt;myadapter/&gt;
&lt;/javac&gt;
</pre>
<p>in which case your compiler adapter can support attributes and
nested elements of its own.</p>

<h3>Jikes Notes</h3>

@@ -800,27 +828,14 @@ while all others are <code>false</code>.</p>
task is run again, the
task will try to compile the package-info java files again.
</p>
<p>
In <b>Ant 1.7.1</b> the package-info.java will only be compiled if:
<ol>
<li>
If a <code>package-info.class</code> file exists and is older than
the <code>package-info.java</code> file.
</li>
<li>
If the directory for the
<code>package-info.class</code> file does not exist.
</li>
<li>
If the directory for the
<code>package-info.class</code> file exists, and has an older
modification time than the
the <code>package-info.java</code> file. In this case
&lt;javac&gt; will touch the corresponding .class directory
on successful compilation.
</li>
</ol>
</p>

<p>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 <code>package-info.java</code> in certain setup.</p>
<p>Starting with Ant 1.8.0 Ant will create
"empty" <code>package-info.class</code> files if it compiles
a <code>package-info.java</code> and
no <code>package-info.class</code> file has been created by the
compiler itself.</p>
</body>
</html>

+ 28
- 3
docs/manual/CoreTasks/rmic.html View File

@@ -48,8 +48,8 @@ supports most attributes of <code>&lt;fileset&gt;</code>
<code>&lt;include&gt;</code>, <code>&lt;exclude&gt;</code> and
<code>&lt;patternset&gt;</code> elements.</p>
<p>It is possible to use different compilers. This can be selected
with the &quot;build.rmic&quot; property or the <code>compiler</code>
attribute.
with the &quot;build.rmic&quot; property, the <code>compiler</code>
attribute. or a nested element.
<a name="compilervalues">Here are the choices</a>:</p>
<ul>
<li>default -the default compiler (kaffe or sun) for the platform.
@@ -311,6 +311,13 @@ used.</p>
custom class has been specified. Doesn't have any effect when
using one of the built-in compilers.</p>

<h4>Any nested element of a type that implements RmicAdapter
<em>since Ant 1.8.0</em></h4>

<p>If a defined type implements the <code>RmicAdapter</code>
interface a nested element of that type can be used as an
alternative to the <code>compiler</code> attribute.</p>

<h3>Examples</h3>
<pre> &lt;rmic classname=&quot;com.xyz.FooBar&quot; base=&quot;${build}/classes&quot;/&gt;</pre>
<p>runs the rmic compiler for the class <code>com.xyz.FooBar</code>. The
@@ -321,7 +328,25 @@ files below <code>${build}/classes</code> whose classname starts with
<i>Remote</i>. The compiled files will be stored in the directory
<code>${build}/classes</code>.</p>


<p>If you want to use a custom
RmicAdapter <code>org.example.MyAdapter</code> you can either
use the compiler attribute:</p>
<pre>
&lt;rmic classname=&quot;com.xyz.FooBar&quot;
base=&quot;${build}/classes&quot;
compiler="org.example.MyAdapter"/&gt;
</pre>
<p>or a define a type and nest this into the task like in:</p>
<pre>
&lt;componentdef classname="org.example.MyAdapter"
name="myadapter"/&gt;
&lt;rmic classname=&quot;com.xyz.FooBar&quot;
base=&quot;${build}/classes&quot;&gt;
&lt;myadapter/&gt;
&lt;/rmic&gt;
</pre>
<p>in which case your compiler adapter can support attributes and
nested elements of its own.</p>

</body>
</html>


+ 26
- 2
docs/manual/OptionalTasks/javah.html View File

@@ -34,8 +34,8 @@ whether <a href="http://java.sun.com/j2se/1.3/docs/tooldocs/win32/javah.html">JD
systems are used.</p>

<p>It is possible to use different compilers. This can be selected
with the <code>implementation</code> attribute. <a
name="implementationvalues">Here are the choices</a>:</p>
with the <code>implementation</code> attribute or a nested element. <a
name="implementationvalues">Here are the choices of the attribute</a>:</p>
<ul>
<li>default - the default compiler (kaffeh or sun) for the platform.</li>
<li>sun (the standard compiler of the JDK)</li>
@@ -177,6 +177,13 @@ only if a given compiler implementation will be used.</p>
custom class has been specified. Doesn't have any effect when
using one of the built-in compilers.</p>

<h4>Any nested element of a type that implements JavahAdapter
<em>since Ant 1.8.0</em></h4>

<p>If a defined type implements the <code>JavahAdapter</code>
interface a nested element of that type can be used as an
alternative to the <code>implementation</code> attribute.</p>

<h3>Examples</h3>
<pre> &lt;javah destdir=&quot;c&quot; class=&quot;org.foo.bar.Wibble&quot;/&gt;</pre>
<p>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.</p>
writes the corresponding .c stubs. The verbose option will cause Javah to
describe its progress.</p>

<p>If you want to use a custom
JavahAdapter <code>org.example.MyAdapter</code> you can either
use the implementation attribute:</p>
<pre>
&lt;javah destdir="c" class="org.foo.bar.Wibble"
implementation="org.example.MyAdapter"/&gt;
</pre>
<p>or a define a type and nest this into the task like in:</p>
<pre>
&lt;componentdef classname="org.example.MyAdapter"
name="myadapter"/&gt;
&lt;javah destdir="c" class="org.foo.bar.Wibble"&gt;
&lt;myadapter/&gt;
&lt;/javah&gt;
</pre>
<p>in which case your javah adapter can support attributes and
nested elements of its own.</p>

</body>



+ 29
- 2
docs/manual/OptionalTasks/native2ascii.html View File

@@ -58,8 +58,8 @@
</p>

<p>It is possible to use different converters. This can be selected
with the <code>implementation</code> attribute.
<a name="implementationvalues">Here are the choices</a>:</p>
with the <code>implementation</code> attribute or a nested element.
<a name="implementationvalues">Here are the choices of the attribute</a>:</p>
<ul>
<li>default - the default converter (kaffe or sun) for the platform.</li>
<li>sun (the standard converter of the JDK)</li>
@@ -190,6 +190,13 @@ only if a given converter implementation will be used.</p>
custom class has been specified. Doesn't have any effect when
using one of the built-in converters.</p>

<h4>Any nested element of a type that implements Native2AsciiAdapter
<em>since Ant 1.8.0</em></h4>

<p>If a defined type implements the <code>Native2AsciiAdapter</code>
interface a nested element of that type can be used as an
alternative to the <code>implementation</code> attribute.</p>

<h3>Examples</h3>

<pre>
@@ -214,6 +221,26 @@ only if a given converter implementation will be used.</p>
placing the results in the directory <em>src</em>.
The names of the files remain the same.
</p>

<p>If you want to use a custom
Native2AsciiAdapter <code>org.example.MyAdapter</code> you can either
use the implementation attribute:</p>
<pre>
&lt;native2ascii encoding="EUCJIS" src="srcdir" dest="srcdir"
includes="**/*.eucjis" ext=".java"
implementation="org.example.MyAdapter"/&gt;
</pre>
<p>or a define a type and nest this into the task like in:</p>
<pre>
&lt;componentdef classname="org.example.MyAdapter"
name="myadapter"/&gt;
&lt;native2ascii encoding="EUCJIS" src="srcdir" dest="srcdir"
includes="**/*.eucjis" ext=".java"&gt;
&lt;myadapter/&gt;
&lt;/native2ascii&gt;
</pre>
<p>in which case your native2ascii adapter can support attributes and
nested elements of its own.</p>
</body>

</html>

+ 14
- 0
src/main/org/apache/tools/ant/taskdefs/Javac.java View File

@@ -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());



+ 18
- 2
src/main/org/apache/tools/ant/taskdefs/Rmic.java View File

@@ -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);


+ 14
- 0
src/main/org/apache/tools/ant/taskdefs/optional/Javah.java View File

@@ -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());


+ 14
- 0
src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java View File

@@ -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());


+ 10
- 0
src/tests/antunit/taskdefs/javac-test.xml View File

@@ -155,4 +155,14 @@ public class Adapter implements CompilerAdapter {
</javac>
<au:assertLogContains text="adapter called"/>
</target>

<target name="testCompilerAsNestedElement" depends="-create-javac-adapter">
<componentdef classname="org.example.Adapter" name="myjavac">
<classpath location="${adapter.dir}"/>
</componentdef>
<javac srcdir="${input}" destdir="${output}">
<myjavac/>
</javac>
<au:assertLogContains text="adapter called"/>
</target>
</project>

+ 11
- 0
src/tests/antunit/taskdefs/optional/javah-test.xml View File

@@ -52,4 +52,15 @@ public class Adapter implements JavahAdapter {
</javah>
<au:assertLogContains text="adapter called"/>
</target>

<target name="testImplementationAsNestedElement"
depends="-create-javah-adapter">
<componentdef classname="org.example.Adapter" name="myjavac">
<classpath location="${adapter.dir}"/>
</componentdef>
<javah class="org.example.Adapter" destdir="${output}">
<myjavac/>
</javah>
<au:assertLogContains text="adapter called"/>
</target>
</project>

+ 11
- 0
src/tests/antunit/taskdefs/optional/native2ascii-test.xml View File

@@ -53,4 +53,15 @@ public class Adapter implements Native2AsciiAdapter {
</native2ascii>
<au:assertLogContains text="adapter called"/>
</target>

<target name="testImplementationAsNestedElement"
depends="-create-native2ascii-adapter">
<componentdef classname="org.example.Adapter" name="myjavac">
<classpath location="${adapter.dir}"/>
</componentdef>
<native2ascii src="${input}" dest="${output}" includes="**/*.java">
<myjavac/>
</native2ascii>
<au:assertLogContains text="adapter called"/>
</target>
</project>

+ 10
- 0
src/tests/antunit/taskdefs/rmic-test.xml View File

@@ -66,4 +66,14 @@ public class Adapter implements RmicAdapter {
</rmic>
<au:assertLogContains text="adapter called"/>
</target>

<target name="testCompilerAsNestedElement" depends="-create-rmic-adapter">
<componentdef classname="org.example.Adapter" name="myjavac">
<classpath location="${adapter.dir}"/>
</componentdef>
<rmic base="${adapter.dir}" includes="**/*.class">
<myjavac/>
</rmic>
<au:assertLogContains text="adapter called"/>
</target>
</project>

Loading…
Cancel
Save