Browse Source

Interim solution for "strict" attribute. Change to an enum in a few hours.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@557229 13f79535-47bb-0310-9956-ffa450edef68
master
Jan Materne 18 years ago
parent
commit
154ef1be5c
4 changed files with 77 additions and 24 deletions
  1. +8
    -0
      docs/manual/CoreTasks/jar.html
  2. +6
    -1
      src/etc/testcases/taskdefs/jar.xml
  3. +55
    -19
      src/main/org/apache/tools/ant/taskdefs/Jar.java
  4. +8
    -4
      src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java

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

@@ -228,6 +228,14 @@ to a value other than its default, <code>"add"</code>.</b></p>
(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>


+ 6
- 1
src/etc/testcases/taskdefs/jar.xml View File

@@ -238,6 +238,11 @@
</target>
<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>
@@ -245,7 +250,7 @@
<!-- 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"/>


+ 55
- 19
src/main/org/apache/tools/ant/taskdefs/Jar.java View File

@@ -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 <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
@@ -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();
}

/**


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

@@ -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.") );


Loading…
Cancel
Save