@@ -75,6 +75,9 @@ Other changes: | |||||
* added "javac10+" as new supported value for javac's compiler attribute. | * 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.10.0 TO Ant 1.10.1 | Changes from Ant 1.10.0 TO Ant 1.10.1 | ||||
===================================== | ===================================== | ||||
@@ -39,7 +39,8 @@ systems are used.</p> | |||||
generate the native header files with a single step.</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 | <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 | <p>It is possible to use different compilers. This can be selected | ||||
with the <code>implementation</code> attribute or a nested element. <a | with the <code>implementation</code> attribute or a nested element. <a | ||||
@@ -90,6 +90,11 @@ public class JavahAdapterFactory { | |||||
|| Gcjh.IMPLEMENTATION_NAME.equals(choice)) { | || Gcjh.IMPLEMENTATION_NAME.equals(choice)) { | ||||
return new Gcjh(); | return new Gcjh(); | ||||
} | } | ||||
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"); | |||||
} | |||||
if (ForkingJavah.IMPLEMENTATION_NAME.equals(choice)) { | if (ForkingJavah.IMPLEMENTATION_NAME.equals(choice)) { | ||||
return new ForkingJavah(); | return new ForkingJavah(); | ||||
} | } | ||||
@@ -187,8 +187,12 @@ public final class JavaEnvUtils { | |||||
javaVersionNumber = VERSION_9; | javaVersionNumber = VERSION_9; | ||||
// at least Java9 and this should properly support the purely numeric version property | // at least Java9 and this should properly support the purely numeric version property | ||||
String v = System.getProperty("java.specification.version"); | String v = System.getProperty("java.specification.version"); | ||||
javaVersionNumber = Integer.parseInt(v) * 10; | |||||
javaVersion = v; | |||||
DeweyDecimal pv = new DeweyDecimal(v); | |||||
javaVersionNumber = pv.get(0) * 10; | |||||
if (pv.getSize() > 1) { | |||||
javaVersionNumber += pv.get(1); | |||||
} | |||||
javaVersion = pv.toString(); | |||||
} catch (Throwable t) { | } catch (Throwable t) { | ||||
// swallow as we've hit the max class version that | // swallow as we've hit the max class version that | ||||
// we have | // we have | ||||
@@ -101,12 +101,12 @@ public class Foo { | |||||
</presetdef> | </presetdef> | ||||
</target> | </target> | ||||
<target name="testSimpleCompile" depends="-setupForRealJavahTests"> | |||||
<target name="testSimpleCompile" depends="-setupForRealJavahTests" unless="jdk10+"> | |||||
<javah-single/> | <javah-single/> | ||||
<au:assertFileExists file="${output}/org_example_Foo.h"/> | <au:assertFileExists file="${output}/org_example_Foo.h"/> | ||||
</target> | </target> | ||||
<target name="testCompileUsingFileset" depends="-setupForRealJavahTests"> | |||||
<target name="testCompileUsingFileset" depends="-setupForRealJavahTests" unless="jdk10+"> | |||||
<javah-fileset/> | <javah-fileset/> | ||||
<au:assertFileExists file="${output}/org_example_Foo.h"/> | <au:assertFileExists file="${output}/org_example_Foo.h"/> | ||||
</target> | </target> | ||||
@@ -123,13 +123,21 @@ public class Foo { | |||||
<au:assertFileExists file="${output}/org_example_Foo.h"/> | <au:assertFileExists file="${output}/org_example_Foo.h"/> | ||||
</target> | </target> | ||||
<target name="testSimpleCompileForking" depends="-setupForRealJavahTests"> | |||||
<target name="testSimpleCompileForking" depends="-setupForRealJavahTests" unless="jdk10+"> | |||||
<javah-single implementation="forking"/> | <javah-single implementation="forking"/> | ||||
<au:assertFileExists file="${output}/org_example_Foo.h"/> | <au:assertFileExists file="${output}/org_example_Foo.h"/> | ||||
</target> | </target> | ||||
<target name="testCompileUsingFilesetForking" depends="-setupForRealJavahTests"> | |||||
<target name="testCompileUsingFilesetForking" depends="-setupForRealJavahTests" unless="jdk10+"> | |||||
<javah-fileset implementation="forking"/> | <javah-fileset implementation="forking"/> | ||||
<au:assertFileExists file="${output}/org_example_Foo.h"/> | <au:assertFileExists file="${output}/org_example_Foo.h"/> | ||||
</target> | </target> | ||||
<target name="testSimpleCompileFailsOnJava10+" depends="-setupForRealJavahTests" | |||||
if="jdk10+"> | |||||
<au:expectfailure> | |||||
<javah-single/> | |||||
</au:expectfailure> | |||||
</target> | |||||
</project> | </project> |
@@ -18,6 +18,8 @@ | |||||
package org.apache.tools.ant.taskdefs.optional; | package org.apache.tools.ant.taskdefs.optional; | ||||
import org.apache.tools.ant.BuildFileRule; | import org.apache.tools.ant.BuildFileRule; | ||||
import org.apache.tools.ant.util.JavaEnvUtils; | |||||
import org.junit.Assume; | |||||
import org.junit.After; | import org.junit.After; | ||||
import org.junit.Before; | import org.junit.Before; | ||||
import org.junit.Rule; | import org.junit.Rule; | ||||
@@ -47,6 +49,7 @@ public class JavahTest { | |||||
@Test | @Test | ||||
public void testSimpleCompile() { | public void testSimpleCompile() { | ||||
Assume.assumeFalse(JavaEnvUtils.isAtLeastJavaVersion("10")); | |||||
buildRule.executeTarget("simple-compile"); | buildRule.executeTarget("simple-compile"); | ||||
assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h") | assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h") | ||||
.exists()); | .exists()); | ||||
@@ -54,6 +57,7 @@ public class JavahTest { | |||||
@Test | @Test | ||||
public void testCompileFileset() { | public void testCompileFileset() { | ||||
Assume.assumeFalse(JavaEnvUtils.isAtLeastJavaVersion("10")); | |||||
buildRule.executeTarget("test-fileset"); | buildRule.executeTarget("test-fileset"); | ||||
assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h").exists()); | assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h").exists()); | ||||
} | } | ||||
@@ -143,4 +143,15 @@ public class JavaEnvUtilsTest { | |||||
assertTrue("JAVA_1_9 is not considered equal to JAVA_9", | assertTrue("JAVA_1_9 is not considered equal to JAVA_9", | ||||
JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_9)); | JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_9)); | ||||
} | } | ||||
@Test | |||||
public void java10IsDetectedProperly() { | |||||
assumeTrue("10".equals(System.getProperty("java.specification.version"))); | |||||
assertEquals("10", JavaEnvUtils.getJavaVersion()); | |||||
assertEquals(100, JavaEnvUtils.getJavaVersionNumber()); | |||||
assertEquals(new DeweyDecimal("10"), JavaEnvUtils.getParsedJavaVersion()); | |||||
assertTrue(JavaEnvUtils.isJavaVersion("10")); | |||||
assertTrue(JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9)); | |||||
} | |||||
} | } |