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