diff --git a/docs/manual/CoreTasks/jar.html b/docs/manual/CoreTasks/jar.html
index c4f88c1df..f37786b41 100644
--- a/docs/manual/CoreTasks/jar.html
+++ b/docs/manual/CoreTasks/jar.html
@@ -228,6 +228,14 @@ to a value other than its default, "add"
.
(maximum compression/slowest). Since Ant 1.7
No |
+
+ strict |
+ When this attribut is set to true, a BuildException
+ will be thrown if the packaging version specification was broken. If set to
+ false (default) only a message is logged (verbose).
+ Defaults to false. Since Ant 1.7.1 |
+ No |
+
Nested elements
diff --git a/src/etc/testcases/taskdefs/jar.xml b/src/etc/testcases/taskdefs/jar.xml
index 1f12bcc56..6b232e4d0 100644
--- a/src/etc/testcases/taskdefs/jar.xml
+++ b/src/etc/testcases/taskdefs/jar.xml
@@ -238,6 +238,11 @@
+
+
+
+
+
@@ -245,7 +250,7 @@
-
+
diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java
index e3c6e3d29..de218d51f 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Jar.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java
@@ -143,6 +143,12 @@ public class Jar extends Zip {
*/
private Path indexJars;
+ /**
+ * Strict mode for checking rules of the JAR-Specification.
+ * @see http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning
+ */
+ private boolean strict = false;
+
/**
* Extra fields needed to make Solaris recognize the archive as a jar file.
*
@@ -160,7 +166,7 @@ public class Jar extends Zip {
setEncoding("UTF8");
rootEntries = new Vector();
}
-
+
/**
* Not used for jar files.
* @param we not used
@@ -185,6 +191,15 @@ public class Jar extends Zip {
emptyBehavior = we.getValue();
}
+ /**
+ * Activate the strict mode. When set to true a BuildException
+ * will be thrown if the Jar-Packaging specification was broken.
+ * @param strict New value of the strict mode.
+ */
+ public void setStrict(boolean strict) {
+ this.strict = strict;
+ }
+
/**
* Set the destination file.
* @param jarFile the destination file
@@ -775,34 +790,55 @@ public class Jar extends Zip {
*/
protected void cleanUp() {
super.cleanUp();
-
- // check against packaging spec
- // http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning
- Section mainSection = (configuredManifest==null) ? null : configuredManifest.getMainSection();
- if (mainSection==null) {
- log("No Implementation-Title set. (" + getLocation() + ")");
- log("No Implementation-Version set. (" + getLocation() + ")");
- log("No Implementation-Vendor set. (" + getLocation() + ")");
+ checkJarSpec();
+
+ // we want to save this info if we are going to make another pass
+ if (!doubleFilePass || !skipWriting) {
+ manifest = null;
+ configuredManifest = savedConfiguredManifest;
+ filesetManifest = null;
+ originalManifest = null;
+ }
+ rootEntries.removeAllElements();
+ }
+
+ /**
+ * Check against packaging spec
+ * @see http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning
+ */
+ private void checkJarSpec() {
+ String br = System.getProperty("line.separator");
+ StringBuffer message = new StringBuffer();
+ Section mainSection = (configuredManifest == null)
+ ? null
+ : configuredManifest.getMainSection();
+
+ if (mainSection == null) {
+ message.append("No Implementation-Title set.");
+ message.append("No Implementation-Version set.");
+ message.append("No Implementation-Vendor set.");
} else {
if (mainSection.getAttribute("Implementation-Title") == null) {
- log("No Implementation-Title set. (" + getLocation() + ")");
+ message.append("No Implementation-Title set.");
}
if (mainSection.getAttribute("Implementation-Version") == null) {
- log("No Implementation-Version set. (" + getLocation() + ")");
+ message.append("No Implementation-Version set.");
}
if (mainSection.getAttribute("Implementation-Vendor") == null) {
- log("No Implementation-Vendor set. (" + getLocation() + ")");
+ message.append("No Implementation-Vendor set.");
}
}
- // we want to save this info if we are going to make another pass
- if (!doubleFilePass || !skipWriting) {
- manifest = null;
- configuredManifest = savedConfiguredManifest;
- filesetManifest = null;
- originalManifest = null;
+ if (message.length() > 0) {
+ message.append(br);
+ message.append("Location: ").append(getLocation());
+ message.append(br);
+ if (strict) {
+ throw new BuildException(message.toString(), getLocation());
+ } else {
+ log(message.toString(), Project.MSG_VERBOSE);
+ }
}
- rootEntries.removeAllElements();
}
/**
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java
index f5ad7092c..11766387a 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java
@@ -269,12 +269,16 @@ public class JarTest extends BuildFileTest {
}
public void testNoVersionInfo() {
- executeTarget("testNoVersionInfo");
- assertLogContaining("No Implementation-Title set.");
- assertLogContaining("No Implementation-Version set.");
- assertLogContaining("No Implementation-Vendor set.");
+ expectBuildExceptionContaining("testNoVersionInfo", "Manifest Implemention information missing.", "No Implementation-Title set.");
}
+ public void testNoVersionInfoNoStrict() {
+ executeTarget("testNoVersionInfoNoStrict");
+ assertFalse( getLog().contains("No Implementation-Title set.") );
+ assertFalse( getLog().contains("No Implementation-Version set.") );
+ assertFalse( getLog().contains("No Implementation-Vendor set.") );
+ }
+
public void testHasVersionInfo() {
executeTarget("testHasVersionInfo");
assertFalse( getLog().contains("No Implementation-Title set.") );