Skip to content
GitLab
Explore
Sign in
Register
Commits on Source (3)
Mark binary packages as M-A: foreign. Closes: #925467.
· 785221e2
Matthias Klose
authored
Mar 28, 2019
785221e2
Bump standards version
· b4948c24
Matthias Klose
authored
Mar 28, 2019
b4948c24
Enable multi release jar support. LP: #1808383
· b36d108d
Tiago Stürmer Daitx
authored
Mar 28, 2019
and
Matthias Klose
committed
Mar 28, 2019
b36d108d
Hide whitespace changes
Inline
Side-by-side
debian/changelog
View file @
b36d108d
ant (1.10.5-3) unstable; urgency=medium
[ Matthias Klose ]
* Mark binary packages as M-A: foreign. Closes: #925467.
* Bump standards version.
[ Tiago Stürmer Daitx ]
* Enable multi release jar support. LP: #1808383.
- debian/patches/0016-multirelease-jar-support.patch: apply 2 upstream
patches to provide mrjar support.
-- Matthias Klose <doko@debian.org> Thu, 28 Mar 2019 09:36:55 +0100
ant (1.10.5-2) unstable; urgency=medium
* Team upload.
...
...
debian/control
View file @
b36d108d
...
...
@@ -25,13 +25,14 @@ Build-Depends: antlr,
libxml-commons-resolver1.1-java (>= 1.2-7~),
libxz-java,
maven-repo-helper (>> 1.0)
Standards-Version: 4.
2.1
Standards-Version: 4.
3.0
Vcs-Git: https://salsa.debian.org/java-team/ant.git
Vcs-Browser: https://salsa.debian.org/java-team/ant
Homepage: http://ant.apache.org
Package: ant
Architecture: all
Multi-Arch: foreign
Depends: default-jre-headless (>= 2:1.8) | java8-runtime-headless,
${misc:Depends}
Recommends: ant-optional
...
...
@@ -50,6 +51,7 @@ Description: Java based build tool like make
Package: ant-optional
Architecture: all
Multi-Arch: foreign
Depends: ant (= ${source:Version}), ${misc:Depends}
Suggests: antlr,
javacc,
...
...
@@ -85,6 +87,7 @@ Description: Java based build tool like make - optional libraries
Package: ant-doc
Architecture: all
Multi-Arch: foreign
Section: doc
Depends: ${misc:Depends}
Suggests: ant
...
...
debian/patches/0016-multirelease-jar-support.patch
0 → 100644
View file @
b36d108d
Description: Enable multi release jar support
Merge 2 upstream patches to enable support for multi release jar files to ant.
This new feature functionally only modifies behavior when jar file is a
'multi-release jarfile' containing different byte-code targeting different
Java versions at runtime.
The following 2 upstream patches are merged in this fix:
From: Jaikiran Pai <jaikiran@apache.org>
Date: Wed, 5 Dec 2018 12:56:14 +0000 (+0530)
Subject: bz-62952 Make AntClassLoader multi-release jar aware when it deals
with java.util...
X-Git-Url: https://gitbox.apache.org/repos/asf?p=ant.git;a=commitdiff_plain;h=593aff2d2ea52a025cfe7da32155216719029a7d;hp=ac46ff190ed158bcb5ec5764b583ef82f1ecaa80
bz-62952 Make AntClassLoader multi-release jar aware when it deals with
java.util.jar.JarFile
From: Jaikiran Pai <jaikiran@apache.org>
Date: Wed, 5 Dec 2018 14:06:53 +0000 (+0530)
Subject: bz-62952 Fix the jar-test.xml#testMultiReleaseJar antunit test case
X-Git-Url: https://gitbox.apache.org/repos/asf?p=ant.git;a=commitdiff_plain;h=69269adced56238dc80297b9ae881442cd56259c
bz-62952 Fix the jar-test.xml#testMultiReleaseJar antunit test case
Origin: upstream, https://gitbox.apache.org/repos/asf?p=ant.git;a=commit;h=593aff2d2ea52a025cfe7da32155216719029a7d, https://gitbox.apache.org/repos/asf?p=ant.git;a=commit;h=69269adced56238dc80297b9ae881442cd56259c
Bug-Ubuntu: https://launchpad.net/bugs/1808383
Forwarded: not-needed
Applied-Upstream: https://gitbox.apache.org/repos/asf?p=ant.git;a=commit;h=593aff2d2ea52a025cfe7da32155216719029a7d, https://gitbox.apache.org/repos/asf?p=ant.git;a=commit;h=69269adced56238dc80297b9ae881442cd56259c
Reviewed-by: Tiago Sturmer Daitx <tiago.daitx@ubuntu.com>
Last-Update: 2019-03-14
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
---
--- a/src/etc/testcases/core/antclassloader.xml
+++ b/src/etc/testcases/core/antclassloader.xml
@@ -73,4 +73,52 @@
public class Foo {}
<target name="createNonJar">
<touch file="${tmp.dir}/foo.jar"/>
</target>
+
+ <target name="testMRJar" description="tests AntClassLoader support for multi-release jars.
+ see https://bz.apache.org/bugzilla/show_bug.cgi?id=62952">
+ <mkdir dir="${tmp.dir}/mrjar/org/example"/>
+ <mkdir dir="${tmp.dir}/mrjar-9/org/example"/>
+ <!-- default version of the class -->
+ <echo file="${tmp.dir}/mrjar/org/example/MRJarTest.java"><![CDATA[
+ package org.example;
+ public class MRJarTest {
+ public static void main(String[] args) {
+ System.out.println("mrjar test result = default");
+ }
+ }
+ ]]>
+ </echo>
+ <!-- Java runtime version 9 of the class -->
+ <echo file="${tmp.dir}/mrjar-9/org/example/MRJarTest.java"><![CDATA[
+ package org.example;
+ public class MRJarTest {
+ public static void main(String[] args) {
+ System.out.println("mrjar test result = 9");
+ }
+ }
+ ]]>
+ </echo>
+ <!-- compile these classes -->
+ <javac srcdir="${tmp.dir}/mrjar" destdir="${tmp.dir}/mrjar"/>
+ <javac srcdir="${tmp.dir}/mrjar-9" destdir="${tmp.dir}/mrjar-9"/>
+
+ <!-- create multi-release jar file -->
+ <jar destfile="${tmp.dir}/mrjar.jar">
+ <manifest>
+ <attribute name="Multi-Release" value="true"/>
+ </manifest>
+ <!-- default classes -->
+ <fileset dir="${tmp.dir}/mrjar" includes="**/*.class"/>
+ <!-- Java 9 specific classes -->
+ <zipfileset prefix="META-INF/versions/9/" dir="${tmp.dir}/mrjar-9" includes="**/*.class"/>
+ </jar>
+
+ <!-- now run the class present in the multi-release jar -->
+ <java classname="org.example.MRJarTest" failonerror="true">
+ <classpath>
+ <pathelement location="${tmp.dir}/mrjar.jar"/>
+ </classpath>
+ </java>
+
+ </target>
</project>
--- a/src/main/org/apache/tools/ant/AntClassLoader.java
+++ b/src/main/org/apache/tools/ant/AntClassLoader.java
@@ -45,12 +45,14 @@
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.stream.Collectors;
import java.util.stream.Stream;
+import java.util.zip.ZipFile;
import org.apache.tools.ant.launch.Locator;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JavaEnvUtils;
import org.apache.tools.ant.util.LoaderUtils;
+import org.apache.tools.ant.util.ReflectUtil;
import org.apache.tools.ant.util.StringUtils;
import org.apache.tools.ant.util.VectorSet;
import org.apache.tools.zip.ZipLong;
@@ -76,8 +78,29 @@
public class AntClassLoader extends Clas
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+ private static final boolean IS_ATLEAST_JAVA9 = JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9);
+ // constructs needed to create (via reflection) a java.util.jar.JarFile instance when Java runtime version is >= 9
+ private static final Class[] MR_JARFILE_CTOR_ARGS;
+ private static final Object MR_JARFILE_CTOR_RUNTIME_VERSION_VAL;
+
static {
registerAsParallelCapable();
+ if (IS_ATLEAST_JAVA9) {
+ Class[] ctorArgs = null;
+ Object runtimeVersionVal = null;
+ try {
+ final Class<?> runtimeVersionClass = Class.forName("java.lang.Runtime$Version");
+ ctorArgs = new Class[] {File.class, boolean.class, int.class, runtimeVersionClass};
+ runtimeVersionVal = Runtime.class.getDeclaredMethod("version").invoke(null);
+ } catch (Exception e) {
+ // ignore - we consider this as multi-release jar unsupported
+ }
+ MR_JARFILE_CTOR_ARGS = ctorArgs;
+ MR_JARFILE_CTOR_RUNTIME_VERSION_VAL = runtimeVersionVal;
+ } else {
+ MR_JARFILE_CTOR_ARGS = null;
+ MR_JARFILE_CTOR_RUNTIME_VERSION_VAL = null;
+ }
}
/**
@@ -498,7 +521,7 @@
public class AntClassLoader extends Clas
+ pathComponent.lastModified() + "-" + pathComponent.length();
String classpath = pathMap.get(absPathPlusTimeAndLength);
if (classpath == null) {
- try (JarFile jarFile = new JarFile(pathComponent)) {
+ try (JarFile jarFile = newJarFile(pathComponent)) {
final Manifest manifest = jarFile.getManifest();
if (manifest == null) {
return;
@@ -783,7 +806,7 @@
public class AntClassLoader extends Clas
} else {
if (jarFile == null) {
if (file.exists()) {
- jarFile = new JarFile(file);
+ jarFile = newJarFile(file);
jarFiles.put(file, jarFile);
} else {
return null;
@@ -1003,7 +1026,7 @@
public class AntClassLoader extends Clas
log(msg, Project.MSG_WARN);
return null;
}
- jarFile = new JarFile(file);
+ jarFile = newJarFile(file);
jarFiles.put(file, jarFile);
} else {
return null;
@@ -1572,4 +1595,19 @@
public class AntClassLoader extends Clas
}
}
+ /**
+ *
+ * @param file The file representing the jar
+ * @return Returns a {@link JarFile} instance, which is constructed based upon the Java runtime version.
+ * Depending on the Java runtime version, the returned instance may or may not be {@code multi-release}
+ * aware (a feature introduced in Java 9)
+ * @throws IOException
+ */
+ private static JarFile newJarFile(final File file) throws IOException {
+ if (!IS_ATLEAST_JAVA9 || MR_JARFILE_CTOR_ARGS == null || MR_JARFILE_CTOR_RUNTIME_VERSION_VAL == null) {
+ return new JarFile(file);
+ }
+ return ReflectUtil.newInstance(JarFile.class, MR_JARFILE_CTOR_ARGS,
+ new Object[] {file, true, ZipFile.OPEN_READ, MR_JARFILE_CTOR_RUNTIME_VERSION_VAL});
+ }
}
--- a/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java
+++ b/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java
@@ -33,7 +33,9 @@
import java.util.Enumeration;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.FileUtils;
+import org.apache.tools.ant.util.JavaEnvUtils;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -233,6 +235,26 @@
public class AntClassLoaderTest {
assertFalse(acl.getResources("META-INF/MANIFEST.MF").hasMoreElements());
}
+ /**
+ * Tests that {@link AntClassLoader} supports multi-release jar files while dealing with
+ * runtime resources in Java 9+ runtime environments.
+ *
+ * @see <a href="bz-62952">https://bz.apache.org/bugzilla/show_bug.cgi?id=62952</a>
+ */
+ @Test
+ public void testMultiReleaseJar() {
+ buildRule.executeTarget("testMRJar");
+ final boolean atleastJava9 = JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_9);
+ final String targetOutput = buildRule.getOutput();
+ Assert.assertNotNull("Multi-release jar test did not generate any output", targetOutput);
+ if (atleastJava9) {
+ Assert.assertTrue("Unexpected output from multi-release jar test for Java runtime >= 9",
+ targetOutput.contains("mrjar test result = 9"));
+ } else {
+ Assert.assertTrue("Unexpected output from multi-release jar test", targetOutput.contains("mrjar test result = default"));
+ }
+ }
+
private static class EmptyLoader extends ClassLoader {
public URL getResource(String n) {
return null;
--- a/src/tests/antunit/taskdefs/jar-test.xml
+++ b/src/tests/antunit/taskdefs/jar-test.xml
@@ -314,9 +314,22 @@
Main-Class: MyClass
</loadresource>
<au:assertTrue>
<or>
- <equals arg1="Java8" arg2="${valueFrom8}"/>
- <!-- maybe we are running on an early version of Java9 -->
- <equals arg1="Java9" arg2="${valueFrom8}"/>
+ <and>
+ <not>
+ <javaversion atleast="9"/>
+ </not>
+ <equals arg1="Java8" arg2="${valueFrom8}"/>
+ </and>
+
+ <and>
+ <javaversion exactly="9"/>
+ <equals arg1="Java9" arg2="${valueFrom8}"/>
+ </and>
+
+ <and>
+ <javaversion atleast="10"/>
+ <equals arg1="Java10" arg2="${valueFrom8}"/>
+ </and>
</or>
</au:assertTrue>
</target>
debian/patches/series
View file @
b36d108d
...
...
@@ -4,3 +4,4 @@
0013-auto-adjust-target.patch
0015-javadoc-ignore-source-errors.patch
0014-remove-java-activation-module.patch
0016-multirelease-jar-support.patch