Browse Source

fail early if javah is used with java 10+

master
Stefan Bodewig 7 years ago
parent
commit
79e9d10435
5 changed files with 25 additions and 5 deletions
  1. +3
    -0
      WHATSNEW
  2. +2
    -1
      manual/Tasks/javah.html
  3. +4
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/javah/JavahAdapterFactory.java
  4. +12
    -4
      src/tests/antunit/taskdefs/optional/javah-test.xml
  5. +4
    -0
      src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java

+ 3
- 0
WHATSNEW View File

@@ -52,6 +52,9 @@ Other changes:

* added "javac10+" as new supported value for javac's compiler attribute.

* javah has been removed from Java 10. The task will now throw an
exception if you try to use it while running Java 10 or newer.

Changes from Ant 1.9.8 TO Ant 1.9.9
===================================



+ 2
- 1
manual/Tasks/javah.html View File

@@ -39,7 +39,8 @@ systems are used.</p>
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>
and removed as of Java 10. Trying to use it with Java10 will
fail.</p>

<p>It is possible to use different compilers. This can be selected
with the <code>implementation</code> attribute or a nested element. <a


+ 4
- 0
src/main/org/apache/tools/ant/taskdefs/optional/javah/JavahAdapterFactory.java View File

@@ -89,6 +89,10 @@ public class JavahAdapterFactory {
} else if ((JavaEnvUtils.isGij() && choice == null)
|| Gcjh.IMPLEMENTATION_NAME.equals(choice)) {
return new Gcjh();
} else if (JavaEnvUtils.isAtLeastJavaVersion("10") &&
(choice == null || ForkingJavah.IMPLEMENTATION_NAME.equals(choice))) {
throw new BuildException("javah does not exist under Java 10 and higher,"
+ " use the javac task with nativeHeaderDir instead");
} else if ((JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)
&& choice == null)
|| ForkingJavah.IMPLEMENTATION_NAME.equals(choice)) {


+ 12
- 4
src/tests/antunit/taskdefs/optional/javah-test.xml View File

@@ -101,12 +101,12 @@ public class Foo {
</presetdef>
</target>

<target name="testSimpleCompile" depends="-setupForRealJavahTests">
<target name="testSimpleCompile" depends="-setupForRealJavahTests" unless="jdk10+">
<javah-single/>
<au:assertFileExists file="${output}/org_example_Foo.h"/>
</target>

<target name="testCompileUsingFileset" depends="-setupForRealJavahTests">
<target name="testCompileUsingFileset" depends="-setupForRealJavahTests" unless="jdk10+">
<javah-fileset/>
<au:assertFileExists file="${output}/org_example_Foo.h"/>
</target>
@@ -123,13 +123,21 @@ public class Foo {
<au:assertFileExists file="${output}/org_example_Foo.h"/>
</target>

<target name="testSimpleCompileForking" depends="-setupForRealJavahTests">
<target name="testSimpleCompileForking" depends="-setupForRealJavahTests" unless="jdk10+">
<javah-single implementation="forking"/>
<au:assertFileExists file="${output}/org_example_Foo.h"/>
</target>

<target name="testCompileUsingFilesetForking" depends="-setupForRealJavahTests">
<target name="testCompileUsingFilesetForking" depends="-setupForRealJavahTests" unless="jdk10+">
<javah-fileset implementation="forking"/>
<au:assertFileExists file="${output}/org_example_Foo.h"/>
</target>

<target name="testSimpleCompileFailsOnJava10+" depends="-setupForRealJavahTests"
if="jdk10+">
<au:expectfailure>
<javah-single/>
</au:expectfailure>
</target>

</project>

+ 4
- 0
src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java View File

@@ -18,6 +18,8 @@
package org.apache.tools.ant.taskdefs.optional;

import org.apache.tools.ant.BuildFileRule;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.junit.Assume;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@@ -47,6 +49,7 @@ public class JavahTest {

@Test
public void testSimpleCompile() {
Assume.assumeFalse(JavaEnvUtils.isAtLeastJavaVersion("10"));
buildRule.executeTarget("simple-compile");
assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h")
.exists());
@@ -54,6 +57,7 @@ public class JavahTest {

@Test
public void testCompileFileset() {
Assume.assumeFalse(JavaEnvUtils.isAtLeastJavaVersion("10"));
buildRule.executeTarget("test-fileset");
assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h").exists());
}


Loading…
Cancel
Save