Author: jhm Date: Wed Jul 18 04:23:40 2007 New Revision: 557229 URL: http://svn.apache.org/viewvc?view=rev&rev=557229 Log: Interim solution for "strict" attribute. Change to an enum in a few hours.
Modified: ant/core/trunk/docs/manual/CoreTasks/jar.html ant/core/trunk/src/etc/testcases/taskdefs/jar.xml ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java Modified: ant/core/trunk/docs/manual/CoreTasks/jar.html URL: http://svn.apache.org/viewvc/ant/core/trunk/docs/manual/CoreTasks/jar.html?view=diff&rev=557229&r1=557228&r2=557229 ============================================================================== --- ant/core/trunk/docs/manual/CoreTasks/jar.html (original) +++ ant/core/trunk/docs/manual/CoreTasks/jar.html Wed Jul 18 04:23:40 2007 @@ -228,6 +228,14 @@ (maximum compression/slowest). <em>Since Ant 1.7</em></td> <td valign="top" align="center">No</td> </tr> + <tr> + <td valign="top">strict</td> + <td valign="top">When this attribut is set to <tt>true</tt>, a BuildException + will be thrown if the packaging version specification was broken. If set to + <tt>false</tt> (default) only a message is logged (verbose). + <br>Defaults to false. <em>Since Ant 1.7.1</em></td> + <td valign="top" align="center">No</td> + </tr> </table> <h3>Nested elements</h3> Modified: ant/core/trunk/src/etc/testcases/taskdefs/jar.xml URL: http://svn.apache.org/viewvc/ant/core/trunk/src/etc/testcases/taskdefs/jar.xml?view=diff&rev=557229&r1=557228&r2=557229 ============================================================================== --- ant/core/trunk/src/etc/testcases/taskdefs/jar.xml (original) +++ ant/core/trunk/src/etc/testcases/taskdefs/jar.xml Wed Jul 18 04:23:40 2007 @@ -239,13 +239,18 @@ <target name="testNoVersionInfo"> <mkdir dir="${tmp.dir}"/> + <jar destfile="${tmp.jar}" basedir="${tmp.dir}" strict="true"/> + </target> + + <target name="testNoVersionInfoNoStrict"> + <mkdir dir="${tmp.dir}"/> <jar destfile="${tmp.jar}" basedir="${tmp.dir}"/> </target> <!-- see http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning --> <target name="testHasVersionInfo"> <mkdir dir="${tmp.dir}"/> - <jar destfile="${tmp.jar}" basedir="${tmp.dir}"> + <jar destfile="${tmp.jar}" basedir="${tmp.dir}" strict="true"> <manifest> <attribute name="Implementation-Title" value="Packaging Version Test"/> <attribute name="Implementation-Version" value="1.0"/> Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java?view=diff&rev=557229&r1=557228&r2=557229 ============================================================================== --- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java (original) +++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Jar.java Wed Jul 18 04:23:40 2007 @@ -144,6 +144,12 @@ 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. * * @since Ant 1.6.3 @@ -160,7 +166,7 @@ setEncoding("UTF8"); rootEntries = new Vector(); } - + /** * Not used for jar files. * @param we not used @@ -186,6 +192,15 @@ } /** + * Activate the strict mode. When set to <i>true</i> 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 * @deprecated since 1.5.x. @@ -775,34 +790,55 @@ */ 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(); } /** Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java?view=diff&rev=557229&r1=557228&r2=557229 ============================================================================== --- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java (original) +++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java Wed Jul 18 04:23:40 2007 @@ -269,12 +269,16 @@ } 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.") ); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]