Stefan Bodewig 8 years ago
parent
commit
ee85859ea0
6 changed files with 104 additions and 15 deletions
  1. +4
    -0
      WHATSNEW
  2. +17
    -0
      manual/Tasks/javac.html
  3. +8
    -0
      manual/Tasks/javah.html
  4. +21
    -0
      src/main/org/apache/tools/ant/taskdefs/Javac.java
  5. +10
    -0
      src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
  6. +44
    -15
      src/tests/antunit/taskdefs/javac-test.xml

+ 4
- 0
WHATSNEW View File

@@ -67,6 +67,10 @@ Other changes:
* a new implementation "forking" has been added to <javah> and is
used as default when running on JDK9.

* support for javac's -h switch has been added with the
nativeheaderdir attribute.
Bugzilla Report 59905

Changes from Ant 1.9.6 TO Ant 1.9.7
===================================



+ 17
- 0
manual/Tasks/javac.html View File

@@ -125,6 +125,15 @@ classpath of the <code>&lt;javac&gt;</code> task, and does not release them.
The side effect of this is that you will not be able to delete or move
those files later on in the build. The workaround is to fork when
invoking the compiler.</p>
<p>If you are using Java 8 or above and your source contains native
methods or fields annotated with the <code>@Native</code> annotation
you can set the <code>nativeheaderdir</code> attribute in order to
use the <code>-h</code> switch of <code>javac</code> to generate the
native header files. Note that the logic Ant uses to determine which
files to compile does not take native headers into account, i.e. if
the <code>.class</code> is more recent than the
corresponding <code>.java</code> file the file will not get compiled
even if a native header file generated for it would be outdated.</p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
@@ -505,6 +514,14 @@ invoking the compiler.</p>
<em>since Ant 1.9.7</em></td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">nativeheaderdir</td>
<td valign="top">
Specify where to place generated native header files. Ignored
when running on JDK &lt; 8.
<em>Since Ant 1.9.8</em>.
<td align="center" valign="top">No</td>
</tr>
</table>

<h3>Parameters specified as nested elements</h3>


+ 8
- 0
manual/Tasks/javah.html View File

@@ -33,6 +33,14 @@ whether <a href="http://docs.oracle.com/javase/7/docs/technotes/tools/windows/ja
or <a href="http://java.sun.com/products/jdk/1.1/docs/tooldocs/win32/javah.html">pre-JDK1.2</a>
systems are used.</p>

<p>If you are building with Java 8 or above consider
using <a href="javac.html"><code>javac</code></a>'s <code>nativeheaderdir</code>
attribute instead which allows you to compile the classes and
generate the native header files with a single step.</p>

<p><b>Note</b> the <code>javah</code> has been deprecated as of Java 9
and is scheduled to be removed with Java 10.</p>

<p>It is possible to use different compilers. This can be selected
with the <code>implementation</code> attribute or a nested element. <a
name="implementationvalues">Here are the choices of the attribute</a>:</p>


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

@@ -108,6 +108,7 @@ public class Javac extends MatchingTask {

private Path src;
private File destDir;
private File nativeHeaderDir;
private Path compileClasspath;
private Path modulepath;
private Path upgrademodulepath;
@@ -285,6 +286,26 @@ public class Javac extends MatchingTask {
return destDir;
}

/**
* Set the destination directory into which the generated native
* header files should be placed.
* @param nhDir where to place generated native header files
* @since Ant 1.9.8
*/
public void setNativeHeaderDir(final File nhDir) {
this.nativeHeaderDir = nhDir;
}

/**
* Gets the destination directory into which the generated native
* header files should be placed.
* @return where to place generated native header files
* @since Ant 1.9.8
*/
public File getNativeHeaderDir() {
return nativeHeaderDir;
}

/**
* Set the sourcepath to be used for this compilation.
* @param sourcepath the source path


+ 10
- 0
src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java View File

@@ -414,6 +414,16 @@ public abstract class DefaultCompilerAdapter
cmd.createArgument().setValue("-upgrademodulepath");
cmd.createArgument().setPath(ump);
}
if (attributes.getNativeHeaderDir() != null) {
if (assumeJava13() || assumeJava14() || assumeJava15()
|| assumeJava16() || assumeJava17()) {
attributes.log("Support for javac -h has been added in Java8,"
+ " ignoring it");
} else {
cmd.createArgument().setValue("-h");
cmd.createArgument().setFile(attributes.getNativeHeaderDir());
}
}
return cmd;
}



+ 44
- 15
src/tests/antunit/taskdefs/javac-test.xml View File

@@ -18,10 +18,16 @@
<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit">
<import file="../antunit-base.xml" />

<property name="javac-dir" location="${output}/javac-dir" />
<property name="build-dir" location="${javac-dir}/build" />
<target name="setup">
<property name="javac-dir" location="${output}/javac-dir" />
<property name="build-dir" location="${javac-dir}/build" />
<presetdef name="testJavac">
<javac srcdir="${javac-dir}/src" destdir="${javac-dir}/classes"
includeantruntime="false"/>
</presetdef>
</target>

<target name="test-includeDestClasses">
<target name="test-includeDestClasses" depends="setup">
<property name="DATE" value="09/10/1999 4:30 pm" />
<delete dir="${javac-dir}/src" />
<mkdir dir="${javac-dir}/src" />
@@ -54,7 +60,7 @@
</au:assertFalse>
</target>

<target name="test-updated-property">
<target name="test-updated-property" depends="setup">
<delete quiet="yes" dir="${build-dir}" />
<mkdir dir="${build-dir}" />
<javac srcdir="javac-dir/good-src" destdir="${build-dir}" updatedProperty="classes-updated" />
@@ -67,7 +73,7 @@
</au:assertFalse>
</target>

<target name="test-error-property">
<target name="test-error-property" depends="setup">
<delete quiet="yes" dir="${build-dir}" />
<mkdir dir="${build-dir}" />
<javac srcdir="javac-dir/good-src" destdir="${build-dir}" failOnError="false" errorProperty="compile-failed" />
@@ -80,7 +86,7 @@
</au:assertTrue>
</target>

<target name="setUpForPackageInfoJava">
<target name="setUpForPackageInfoJava" depends="setup">
<mkdir dir="${javac-dir}/src/a" />
<mkdir dir="${build-dir}" />
<echo file="${javac-dir}/src/a/package-info.java">
@@ -151,7 +157,7 @@
<au:assertFileDoesntExist file="${build-dir}/a/package-info.class"/>
</target>

<target name="-create-javac-adapter">
<target name="-create-javac-adapter" depends="setup">
<property name="adapter.dir" location="${output}/adapter" />
<mkdir dir="${input}/org/example" />
<echo file="${input}/org/example/Adapter.java">
@@ -198,16 +204,14 @@ public class Adapter implements CompilerAdapter {
<au:assertLogContains text="adapter called" />
</target>

<target name="testSourceAttributes" xmlns:if="ant:if" xmlns:unless="ant:unless">
<target name="testSourceAttributes" depends="setup"
xmlns:if="ant:if" xmlns:unless="ant:unless">
<delete dir="${javac-dir}/src" />
<mkdir dir="${javac-dir}/src" />
<mkdir dir="${javac-dir}/classes" />
<echo file="${javac-dir}/src/A.java">
public class A { }
</echo>
<presetdef name="testJavac">
<javac srcdir="${javac-dir}/src" destdir="${javac-dir}/classes" includeantruntime="false"/>
</presetdef>

<au:expectfailure>
<testJavac source="notValid"/>
@@ -256,16 +260,14 @@ public class Adapter implements CompilerAdapter {
</sequential>
</target>
<target name="testTargetAttributes" xmlns:if="ant:if" xmlns:unless="ant:unless">
<target name="testTargetAttributes" depends="setup"
xmlns:if="ant:if" xmlns:unless="ant:unless">
<delete dir="${javac-dir}/src" />
<mkdir dir="${javac-dir}/src" />
<mkdir dir="${javac-dir}/classes" />
<echo file="${javac-dir}/src/A.java">
public class A { }
</echo>
<presetdef name="testJavac">
<javac srcdir="${javac-dir}/src" destdir="${javac-dir}/classes" includeantruntime="false"/>
</presetdef>

<au:expectfailure>
<testJavac target="notValid"/>
@@ -313,4 +315,31 @@ public class Adapter implements CompilerAdapter {
<mkdir dir="${javac-dir}/classes"/>
</sequential>
</target>

<target name="testJavacWithNativeHeaderGeneration" if="jdk1.8+" depends="setup">
<mkdir dir="${javac-dir}/src/org/example" />
<mkdir dir="${javac-dir}/classes"/>
<mkdir dir="${javac-dir}/headers"/>
<echo file="${javac-dir}/src/org/example/Foo.java">
<![CDATA[
package org.example;
public class Foo {
public Foo() {}
public native String bar(Object baz);
}
]]></echo>
<echo file="${javac-dir}/src/org/example/Bar.java">
<![CDATA[
package org.example;
public class Bar {
public Bar() {}
public String xyzzy(Object baz) {
return new Foo().bar(baz);
}
}
]]></echo>
<testJavac nativeheaderdir="${javac-dir}/headers"/>
<au:assertFileExists file="${javac-dir}/headers/org_example_Foo.h"/>
<au:assertFileDoesntExist file="${javac-dir}/headers/org_example_Bar.h"/>
</target>
</project>

Loading…
Cancel
Save