Browse Source

Updated the Jar task to have an whenmanifestonly attribute,

creating the possibility to skip jar files that would 
otherwise only contain a jar file. Also started to use this
for the optional tasks in the build.xml

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@293157 13f79535-47bb-0310-9956-ffa450edef68
master
Jacobus Martinus Kruithof 19 years ago
parent
commit
01967f4543
3 changed files with 49 additions and 6 deletions
  1. +12
    -6
      build.xml
  2. +12
    -0
      docs/manual/CoreTasks/jar.html
  3. +25
    -0
      src/main/org/apache/tools/ant/taskdefs/Jar.java

+ 12
- 6
build.xml View File

@@ -777,7 +777,8 @@
</manifest>

<jar destfile="${build.lib}/${name}-launcher.jar"
basedir="${build.classes}">
basedir="${build.classes}"
whenmanifestonly="fail">
<selector refid="ant.launcher"/>
<manifest>
<attribute name="Main-Class" value="org.apache.tools.ant.launch.Launcher"/>
@@ -786,7 +787,8 @@

<jar destfile="${build.lib}/${name}.jar"
basedir="${build.classes}"
manifest="${manifest}">
manifest="${manifest}"
whenmanifestonly="fail">
<not>
<selector id="non-core">
<or>
@@ -835,7 +837,8 @@

<jar destfile="${build.lib}/${bootstrap.jar}"
basedir="${build.classes}"
manifest="${manifest}">
manifest="${manifest}"
whenmanifestonly="fail">
<include name="${ant.package}/Main.class"/>
<metainf dir="${build.dir}">
<include name="LICENSE.txt"/>
@@ -849,7 +852,8 @@

<jar destfile="${build.lib}/ant-nodeps.jar"
basedir="${build.classes}"
manifest="${manifest.tmp}">
manifest="${manifest.tmp}"
whenmanifestonly="skip">
<and>
<selector refid="non-core"/>
<not>
@@ -895,7 +899,8 @@
<sequential>
<jar destfile="${build.lib}/${optional.jars.prefix}-@{dep}.jar"
basedir="${build.classes}"
manifest="${manifest.tmp}">
manifest="${manifest.tmp}"
whenmanifestonly="skip">
<selector refid="needs.@{dep}"/>
</jar>
</sequential>
@@ -928,7 +933,8 @@

<jar destfile="${build.lib}/${optional.jars.prefix}-weblogic.jar"
basedir="${build.classes}"
manifest="${manifest.tmp}">
manifest="${manifest.tmp}"
whenmanifestonly="skip">
<or>
<selector refid="needs.weblogic.ejbc"/>
<selector refid="needs.weblogic.ddcreator"/>


+ 12
- 0
docs/manual/CoreTasks/jar.html View File

@@ -43,6 +43,13 @@ note that ZIP files store file modification times with a granularity
of two seconds. If a file is less than two seconds newer than the
entry in the archive, Ant will not consider it newer.</p>

<p>The <code>whenmanifestonly</code> parameter controls what happens when no
files, apart from the manifest file, match.
If <code>skip</code>, the JAR is not created and a warning is issued.
If <code>fail</code>, the JAR is not created and the build is halted with an error.
If <code>create</code>, (default) an empty JAR file (only containing a manifest)
is created.</p>

<p>(The Jar task is a shortcut for specifying the manifest file of a JAR file.
The same thing can be accomplished by using the <i>fullpath</i>
attribute of a zipfileset in a Zip task. The one difference is that if the
@@ -155,6 +162,11 @@ to a value other than its default, <code>&quot;add&quot;</code>.</b></p>
the destination file if it already exists. Default is &quot;false&quot;.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">whenmanifestonly</td>
<td valign="top">behavior when no files match. Valid values are &quot;fail&quot;, &quot;skip&quot;, and &quot;create&quot;. Default is &quot;create&quot;.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">duplicate</td>
<td valign="top">behavior when a duplicate file is found. Valid values are &quot;add&quot;, &quot;preserve&quot;, and &quot;fail&quot;. The default value is &quot;add&quot;. </td>


+ 25
- 0
src/main/org/apache/tools/ant/taskdefs/Jar.java View File

@@ -140,6 +140,8 @@ public class Jar extends Zip {
private ZipExtraField[] JAR_MARKER = new ZipExtraField[] {
JarMarker.getInstance()
};
protected String emptyBehavior = "create";

/** constructor */
public Jar() {
@@ -160,6 +162,16 @@ public class Jar extends Zip {
Project.MSG_WARN);
}

/**
* Not used for jar files.
* @param we not used
* @ant.attribute ignore="true"
*/
public void setWhenmanifestonly(WhenEmpty we) {
emptyBehavior = we.getValue();
}

/**
* Set the destination file.
* @param jarFile the destination file
@@ -677,6 +689,18 @@ public class Jar extends Zip {
return true;
}

if (emptyBehavior.equals("skip")) {
log("Warning: skipping " + archiveType + " archive "
+ zipFile + " because no files were included.",
Project.MSG_WARN);
return true;
} else if (emptyBehavior.equals("fail")) {
throw new BuildException("Cannot create " + archiveType
+ " archive " + zipFile
+ ": no files were included.",
getLocation());
}
ZipOutputStream zOut = null;
try {
log("Building MANIFEST-only jar: "
@@ -737,6 +761,7 @@ public class Jar extends Zip {
*/
public void reset() {
super.reset();
emptyBehavior = "create";
configuredManifest = null;
filesetManifestConfig = null;
mergeManifestsMain = false;


Loading…
Cancel
Save