diff --git a/docs/manual/CoreTasks/jar.html b/docs/manual/CoreTasks/jar.html index f37786b41..9402a4bdf 100644 --- a/docs/manual/CoreTasks/jar.html +++ b/docs/manual/CoreTasks/jar.html @@ -230,11 +230,14 @@ to a value other than its default, "add".

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 + Configures how to handle breaks of the packaging version + specification: + Since Ant 1.7.1 + No, defaults to ignore. diff --git a/src/etc/testcases/taskdefs/jar.xml b/src/etc/testcases/taskdefs/jar.xml index 6b232e4d0..bfabf8e05 100644 --- a/src/etc/testcases/taskdefs/jar.xml +++ b/src/etc/testcases/taskdefs/jar.xml @@ -237,20 +237,30 @@ - + - + - + - + + + + + + + + + + + - + diff --git a/src/main/org/apache/tools/ant/taskdefs/Jar.java b/src/main/org/apache/tools/ant/taskdefs/Jar.java index de218d51f..e727efc98 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Jar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Jar.java @@ -143,11 +143,13 @@ public class Jar extends Zip { */ private Path indexJars; + // CheckStyle:LineLength OFF - Link is too long. /** * 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; + private StrictMode strict; + // CheckStyle:LineLength ON /** * Extra fields needed to make Solaris recognize the archive as a jar file. @@ -165,6 +167,7 @@ public class Jar extends Zip { emptyBehavior = "create"; setEncoding("UTF8"); rootEntries = new Vector(); + strict = new StrictMode("ignore"); } /** @@ -196,8 +199,8 @@ public class Jar extends Zip { * 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; + public void setStrict(String strict) { + this.strict = new StrictMode(strict); } /** @@ -802,15 +805,17 @@ public class Jar extends Zip { rootEntries.removeAllElements(); } + // CheckStyle:LineLength OFF - Link is too long. /** * Check against packaging spec * @see http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning */ + // CheckStyle:LineLength ON private void checkJarSpec() { String br = System.getProperty("line.separator"); StringBuffer message = new StringBuffer(); Section mainSection = (configuredManifest == null) - ? null + ? null : configuredManifest.getMainSection(); if (mainSection == null) { @@ -833,10 +838,10 @@ public class Jar extends Zip { message.append(br); message.append("Location: ").append(getLocation()); message.append(br); - if (strict) { + if (strict.getValue().equalsIgnoreCase("fail")) { throw new BuildException(message.toString(), getLocation()); } else { - log(message.toString(), Project.MSG_VERBOSE); + log(message.toString(), strict.getLogLevel()); } } } @@ -1025,4 +1030,25 @@ public class Jar extends Zip { } } } + + // CheckStyle:JavadocType OFF - simple enum + public class StrictMode extends EnumeratedAttribute { + // CheckStyle:JavadocMethod OFF - simple enum + public StrictMode() { + } + public StrictMode(String value) { + setValue(value); + } + public String[] getValues() { + return new String[]{"fail", "warn", "ignore"}; + } + /** + * @return The log level according to the strict mode. + */ + public int getLogLevel() { + return (getValue().equals("ignore")) ? Project.MSG_VERBOSE : Project.MSG_WARN; + } + // CheckStyle:JavadocMethod ON + } + // CheckStyle:JavadocType ON } 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 11766387a..977767ecf 100644 --- a/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java +++ b/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java @@ -268,8 +268,22 @@ public class JarTest extends BuildFileTest { executeTarget("testIndexJarsPlusJarMarker"); } - public void testNoVersionInfo() { - expectBuildExceptionContaining("testNoVersionInfo", "Manifest Implemention information missing.", "No Implementation-Title set."); + public void testNoVersionInfoFail() { + expectBuildExceptionContaining("testNoVersionInfoFail", "Manifest Implemention information missing.", "No Implementation-Title set."); + } + + public void testNoVersionInfoIgnore() { + executeTarget("testNoVersionInfoIgnore"); + assertTrue( getFullLog().contains("No Implementation-Title set.") ); + assertTrue( getFullLog().contains("No Implementation-Version set.") ); + assertTrue( getFullLog().contains("No Implementation-Vendor set.") ); + } + + public void testNoVersionInfoWarn() { + executeTarget("testNoVersionInfoWarn"); + assertTrue( getLog().contains("No Implementation-Title set.") ); + assertTrue( getLog().contains("No Implementation-Version set.") ); + assertTrue( getLog().contains("No Implementation-Vendor set.") ); } public void testNoVersionInfoNoStrict() {