Browse Source

Spec breaks now can 'fail' the build or just be reported on 'warn' or verbose ('ignore') level.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@557270 13f79535-47bb-0310-9956-ffa450edef68
master
Jan Materne 18 years ago
parent
commit
05d6dded01
4 changed files with 71 additions and 18 deletions
  1. +8
    -5
      docs/manual/CoreTasks/jar.html
  2. +15
    -5
      src/etc/testcases/taskdefs/jar.xml
  3. +32
    -6
      src/main/org/apache/tools/ant/taskdefs/Jar.java
  4. +16
    -2
      src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java

+ 8
- 5
docs/manual/CoreTasks/jar.html View File

@@ -230,11 +230,14 @@ to a value other than its default, <code>"add"</code>.</b></p>
</tr> </tr>
<tr> <tr>
<td valign="top">strict</td> <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>
<td valign="top">Configures how to handle breaks of the packaging version
specification: <ul>
<li><b>fail</b> = throws a BuildException</li>
<li><b>warn</b> = logs a message on warn level</li>
<li><b>ignore</b> = logs a message on verbose level (default)</li>
</ul>
<em>Since Ant 1.7.1</em></td>
<td valign="top" align="center">No, defaults to <tt>ignore</tt>. </td>
</tr> </tr>
</table> </table>




+ 15
- 5
src/etc/testcases/taskdefs/jar.xml View File

@@ -237,20 +237,30 @@
</jar> </jar>
</target> </target>
<target name="testNoVersionInfo">
<target name="testNoVersionInfoNoStrict">
<mkdir dir="${tmp.dir}"/> <mkdir dir="${tmp.dir}"/>
<jar destfile="${tmp.jar}" basedir="${tmp.dir}" strict="true"/>
<jar destfile="${tmp.jar}" basedir="${tmp.dir}"/>
</target> </target>


<target name="testNoVersionInfoNoStrict">
<target name="testNoVersionInfoFail">
<mkdir dir="${tmp.dir}"/> <mkdir dir="${tmp.dir}"/>
<jar destfile="${tmp.jar}" basedir="${tmp.dir}"/>
<jar destfile="${tmp.jar}" basedir="${tmp.dir}" strict="fail"/>
</target>

<target name="testNoVersionInfoIgnore">
<mkdir dir="${tmp.dir}"/>
<jar destfile="${tmp.jar}" basedir="${tmp.dir}" strict="ignore"/>
</target> </target>


<target name="testNoVersionInfoWarn">
<mkdir dir="${tmp.dir}"/>
<jar destfile="${tmp.jar}" basedir="${tmp.dir}" strict="warn"/>
</target>
<!-- see http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning --> <!-- see http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning -->
<target name="testHasVersionInfo"> <target name="testHasVersionInfo">
<mkdir dir="${tmp.dir}"/> <mkdir dir="${tmp.dir}"/>
<jar destfile="${tmp.jar}" basedir="${tmp.dir}" strict="true">
<jar destfile="${tmp.jar}" basedir="${tmp.dir}" strict="fail">
<manifest> <manifest>
<attribute name="Implementation-Title" value="Packaging Version Test"/> <attribute name="Implementation-Title" value="Packaging Version Test"/>
<attribute name="Implementation-Version" value="1.0"/> <attribute name="Implementation-Version" value="1.0"/>


+ 32
- 6
src/main/org/apache/tools/ant/taskdefs/Jar.java View File

@@ -143,11 +143,13 @@ public class Jar extends Zip {
*/ */
private Path indexJars; private Path indexJars;


// CheckStyle:LineLength OFF - Link is too long.
/** /**
* Strict mode for checking rules of the JAR-Specification. * Strict mode for checking rules of the JAR-Specification.
* @see http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning * @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. * Extra fields needed to make Solaris recognize the archive as a jar file.
@@ -165,6 +167,7 @@ public class Jar extends Zip {
emptyBehavior = "create"; emptyBehavior = "create";
setEncoding("UTF8"); setEncoding("UTF8");
rootEntries = new Vector(); 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. * will be thrown if the Jar-Packaging specification was broken.
* @param strict New value of the strict mode. * @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(); rootEntries.removeAllElements();
} }


// CheckStyle:LineLength OFF - Link is too long.
/** /**
* Check against packaging spec * Check against packaging spec
* @see http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning * @see http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning
*/ */
// CheckStyle:LineLength ON
private void checkJarSpec() { private void checkJarSpec() {
String br = System.getProperty("line.separator"); String br = System.getProperty("line.separator");
StringBuffer message = new StringBuffer(); StringBuffer message = new StringBuffer();
Section mainSection = (configuredManifest == null) Section mainSection = (configuredManifest == null)
? null
? null
: configuredManifest.getMainSection(); : configuredManifest.getMainSection();


if (mainSection == null) { if (mainSection == null) {
@@ -833,10 +838,10 @@ public class Jar extends Zip {
message.append(br); message.append(br);
message.append("Location: ").append(getLocation()); message.append("Location: ").append(getLocation());
message.append(br); message.append(br);
if (strict) {
if (strict.getValue().equalsIgnoreCase("fail")) {
throw new BuildException(message.toString(), getLocation()); throw new BuildException(message.toString(), getLocation());
} else { } 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
} }

+ 16
- 2
src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java View File

@@ -268,8 +268,22 @@ public class JarTest extends BuildFileTest {
executeTarget("testIndexJarsPlusJarMarker"); 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() { public void testNoVersionInfoNoStrict() {


Loading…
Cancel
Save