diff --git a/WHATSNEW b/WHATSNEW
index e60ac6ccb..6037fe6ee 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -87,6 +87,10 @@ Other changes:
* a new implementation "forking" has been added to 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
===================================
diff --git a/manual/Tasks/javac.html b/manual/Tasks/javac.html
index a5fc56cfc..202215f70 100644
--- a/manual/Tasks/javac.html
+++ b/manual/Tasks/javac.html
@@ -125,6 +125,15 @@ classpath of the <javac>
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.
+If you are using Java 8 or above and your source contains native
+ methods or fields annotated with the @Native
annotation
+ you can set the nativeheaderdir
attribute in order to
+ use the -h
switch of javac
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 .class
is more recent than the
+ corresponding .java
file the file will not get compiled
+ even if a native header file generated for it would be outdated.
Parameters
@@ -505,6 +514,14 @@ invoking the compiler.
since Ant 1.9.7
No |
+
+ nativeheaderdir |
+
+ Specify where to place generated native header files. Ignored
+ when running on JDK < 8.
+ Since Ant 1.9.8.
+ | No |
+
Parameters specified as nested elements
diff --git a/manual/Tasks/javah.html b/manual/Tasks/javah.html
index 2958a2db6..bc49d77da 100644
--- a/manual/Tasks/javah.html
+++ b/manual/Tasks/javah.html
@@ -33,6 +33,14 @@ whether pre-JDK1.2
systems are used.
+If you are building with Java 8 or above consider
+ using javac
's nativeheaderdir
+ attribute instead which allows you to compile the classes and
+ generate the native header files with a single step.
+
+Note the javah
has been deprecated as of Java 9
+ and is scheduled to be removed with Java 10.
+
It is possible to use different compilers. This can be selected
with the implementation
attribute or a nested element. Here are the choices of the attribute:
diff --git a/manual/Tasks/rmic.html b/manual/Tasks/rmic.html
index 3c7a6d643..fa927bf8d 100644
--- a/manual/Tasks/rmic.html
+++ b/manual/Tasks/rmic.html
@@ -53,7 +53,7 @@ attribute. or a nested element.
Here are the choices:
- default -the default compiler (kaffe, sun or forking) for the platform.
-
- sun (the standard compiler of the JDK < JDK 9)
+ - sun (the standard compiler of the JDK < JDK 9)
- kaffe (the standard compiler of Kaffe)
- weblogic
- forking - the sun compiler forked into a separate process (since
diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java
index 1eef467d3..3c81e0d2b 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Javac.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java
@@ -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
diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
index db6cd8551..5f1f1f78d 100644
--- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
@@ -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;
}
diff --git a/src/tests/antunit/taskdefs/javac-test.xml b/src/tests/antunit/taskdefs/javac-test.xml
index a3ffc8247..60bc55287 100644
--- a/src/tests/antunit/taskdefs/javac-test.xml
+++ b/src/tests/antunit/taskdefs/javac-test.xml
@@ -18,10 +18,16 @@
-
-
+
+
+
+
+
+
+
-
+
@@ -54,7 +60,7 @@
-
+
@@ -67,7 +73,7 @@
-
+
@@ -80,7 +86,7 @@
-
+
@@ -151,7 +157,7 @@
-
+
@@ -198,16 +204,14 @@ public class Adapter implements CompilerAdapter {
-
+
public class A { }
-
-
-
@@ -235,16 +239,14 @@ public class Adapter implements CompilerAdapter {
-
+
public class A { }
-
-
-
@@ -264,4 +266,31 @@ public class Adapter implements CompilerAdapter {
+
+
+
+
+
+
+
+
+
+
+
+
+