Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions WHATSNEW
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ Fixed bugs:
actual address could potentially be unreachable. This is now fixed
and the resolved address is actually checked for reachability.

* Added version and mainClass attributes for modular jar files.
Bugzilla Report 62772
Bugzilla Report 62789

Other changes:
--------------
Expand Down
6 changes: 5 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<property name="apache.resolver.type.package" value="${type.package}/resolver"/>
<property name="util.package" value="${ant.package}/util"/>
<property name="regexp.package" value="${util.package}/regexp"/>
<property name="jarattr.package" value="${util.package}/jarattr"/>

<property name="optional.jars.prefix" value="ant"/>
<property name="optional.jars.whenmanifestonly" value="skip"/>
Expand Down Expand Up @@ -180,7 +181,10 @@
-->

<selector id="needs.jdk9+">
<filename name="${modules.package}/"/>
<or>
<filename name="${modules.package}/"/>
<filename name="${jarattr.package}/"/>
</or>
</selector>

<!-- Kaffe has some JDK 1.5 features including java.lang.Readable,
Expand Down
51 changes: 51 additions & 0 deletions manual/Tasks/jar.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ <h3>Parameters</h3>
include <samp>META-INF</samp> unless explicitly asked to. <em>Since Ant 1.8.0</em></td>
<td>No; defaults to <q>false</q></td>
</tr>
<tr>
<td>version</td>
<td>The <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/module/ModuleDescriptor.Version.html">module version</a>
to embed into the jar file's module descriptor, if it has one. Not used in Java versions
older than Java 9.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used in Java versions older than Java 9.

I think this wording is confusing. Rephrasing it to "Not used in Java versions below Java 9", might be better.

<td>No</td>
</tr>
<tr>
<td>mainClass</td>
<td>Fully qualified name of main class of a modular jar file. Modular jar files, introduced
with Java 9, use this instead of their manifest's Main-Class attribute to determine their
execution entry point. Setting this does not affect the manifest in any way, and specifying
a Main-Class in the manifest will not cause this attribute to be set.
<strong>Note:</strong> If this is set to a class which isn't in the jar file, Java will
refuse to load the module at runtime.</td>
<td>No</td>
</tr>
<tr>
<td>manifestencoding</td>
<td>The encoding used to read the JAR manifest, when a manifest file is specified. The task
Expand Down Expand Up @@ -385,6 +402,40 @@ <h4 id="service">service</h4>
a JAR file has more that one implementation of the service, a number of
nested <code>&lt;provider&gt;</code> elements may be used.</p>

<h4 id="version">version</h4>

<p><em>Since Ant 1.10.6</em></p>

<p>Specifies a <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/module/ModuleDescriptor.Version.html">module version</a>
as individual components. Either this or the <code>version</code> attribute may be specified,
but not both.</p>

<table class="attr">
<caption>Attributes:</caption>
<tr>
<th scope="col">Attribute</th>
<th scope="col">Description</th>
<th scope="col">Required</th>
</tr>
<tr>
<td>number</td>
<td>Primary version number. Can contain any characters except
"<code>-</code>" (ASCII hyphen) and "<code>+</code>" (ASCII plus).</td>
<td>Yes</td>
</tr>
<tr>
<td>preRelease</td>
<td>Optional release status, such as <code>ea</code> (early access), <code>internal</code>,
<code>beta</code>, etc. Can contain any characters except "<code>+</code>" (ASCII plus).</td>
<td>No</td>
</tr>
<tr>
<td>build</td>
<td>Optional build number. Can contain any text.</td>
<td>No</td>
</tr>
</table>

<h3>Examples</h3>

<h4>Simple</h4>
Expand Down
105 changes: 104 additions & 1 deletion src/etc/testcases/taskdefs/jar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,5 +281,108 @@
</jar>
</target>


<target name="-modularTestProgram">
<property name="package.name" value="org.apache.tools.ant.test"/>
<property name="package.path" value="org/apache/tools/ant/test"/>
<property name="test-module.name" value="org.apache.tools.ant.test"/>
<property name="test-module.src" value="${tmp.dir}/src"/>
<property name="test-module.classes" value="${tmp.dir}/classes"/>

<mkdir dir="${test-module.src}/${package.path}"/>
<echo file="${test-module.src}/${package.path}/Test.java"><!--
-->package ${package.name};

public class Test {
public static void main(String[] args) {
System.out.println("Successful.");
}
}
<!-- --></echo>
<echo file="${test-module.src}/module-info.java"><!--
-->module ${test-module.name} {
exports ${package.name};
}
<!-- --></echo>

<mkdir dir="${test-module.classes}"/>
<javac srcdir="${test-module.src}" destdir="${test-module.classes}"
debug="true" includeAntRuntime="false">
<compilerarg value="-Xlint"/>
</javac>
<jar destfile="${tmp.jar}" basedir="${test-module.classes}"/>
</target>

<target name="testModularJar" depends="-modularTestProgram">
<jar destfile="${tmp.jar}" basedir="${test-module.classes}"/>
</target>

<target name="testModuleVersion" depends="-modularTestProgram">
<jar destfile="${tmp.jar}" basedir="${test-module.classes}"
index="true"
version="1.0-test+0001"/>
</target>

<target name="testNestedVersion" depends="-modularTestProgram">
<jar destfile="${tmp.jar}" basedir="${test-module.classes}">
<version number="1.0" preRelease="test" build="0001"/>
</jar>
</target>

<target name="testNestedVersionNumberOnly" depends="-modularTestProgram">
<jar destfile="${tmp.jar}" basedir="${test-module.classes}">
<version number="1.0"/>
</jar>
</target>

<target name="testNestedVersionNumberAndPreReleaseOnly"
depends="-modularTestProgram">
<jar destfile="${tmp.jar}" basedir="${test-module.classes}">
<version number="1.0" preRelease="test"/>
</jar>
</target>

<target name="testNestedVersionNumberAndBuildOnly"
depends="-modularTestProgram">
<jar destfile="${tmp.jar}" basedir="${test-module.classes}">
<version number="1.0" build="0001"/>
</jar>
</target>

<target name="testNestedVersionMissingNumber" depends="-modularTestProgram">
<jar destfile="${tmp.jar}" basedir="${test-module.classes}">
<version preRelease="test" build="0001"/>
</jar>
</target>

<target name="testNestedVersionInvalidNumber" depends="-modularTestProgram">
<jar destfile="${tmp.jar}" basedir="${test-module.classes}">
<version number="1-0" preRelease="test" build="0001"/>
</jar>
</target>

<target name="testNestedVersionInvalidPreRelease"
depends="-modularTestProgram">
<jar destfile="${tmp.jar}" basedir="${test-module.classes}">
<version number="1.0" preRelease="ant+test" build="0001"/>
</jar>
</target>

<target name="testNestedVersionAndAttribute"
depends="-modularTestProgram">
<jar destfile="${tmp.jar}" basedir="${test-module.classes}"
version="1.0-test+0001">
<version number="2.0" preRelease="test" build="0002"/>
</jar>
</target>

<target name="testMainClass" depends="-modularTestProgram">
<jar destfile="${tmp.jar}" basedir="${test-module.classes}"
mainClass="${package.name}.Test"/>
</target>

<target name="testModuleVersionAndMainClass" depends="-modularTestProgram">
<jar destfile="${tmp.jar}" basedir="${test-module.classes}"
version="1.0-test+0001" mainClass="${package.name}.Test"/>
</target>

</project>
Loading