git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@553857 13f79535-47bb-0310-9956-ffa450edef68master
@@ -1547,6 +1547,22 @@ | |||||
<!-- Used by AntlibTest.testAntlibResource: --> | <!-- Used by AntlibTest.testAntlibResource: --> | ||||
<jar jarfile="${build.tests}/org/apache/tools/ant/taskdefs/test2-antlib.jar"> | <jar jarfile="${build.tests}/org/apache/tools/ant/taskdefs/test2-antlib.jar"> | ||||
<manifest> | |||||
<attribute name="Extension-name" | |||||
value="org.apache.tools.ant"/> | |||||
<attribute name="Specification-Title" | |||||
value="Apache Ant"/> | |||||
<attribute name="Specification-Version" | |||||
value="${manifest-version}"/> | |||||
<attribute name="Specification-Vendor" | |||||
value="Apache Software Foundation"/> | |||||
<attribute name="Implementation-Title" | |||||
value="org.apache.tools.ant"/> | |||||
<attribute name="Implementation-Version" | |||||
value="${manifest-version}"/> | |||||
<attribute name="Implementation-Vendor" | |||||
value="Apache Software Foundation"/> | |||||
</manifest> | |||||
<zipfileset dir="${tests.etc.dir}" fullpath="taskdefs/test.antlib.xml"> | <zipfileset dir="${tests.etc.dir}" fullpath="taskdefs/test.antlib.xml"> | ||||
<include name="taskdefs/test2.antlib.xml"/> | <include name="taskdefs/test2.antlib.xml"/> | ||||
</zipfileset> | </zipfileset> | ||||
@@ -73,14 +73,17 @@ attribute of a zipfileset in a Zip task. The one difference is that if the | |||||
include an empty one for you.)</p> | include an empty one for you.)</p> | ||||
<p>Manifests are processed by the Jar task according to the | <p>Manifests are processed by the Jar task according to the | ||||
<a href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html">Jar file specification.</a> | |||||
<a target="_blank" href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html">Jar file specification.</a> | |||||
Note in particular that this may result in manifest lines greater than 72 bytes | Note in particular that this may result in manifest lines greater than 72 bytes | ||||
being wrapped and continued on the next line. | |||||
</p> | |||||
being wrapped and continued on the next line.</p> | |||||
<p>The Jar task checks whether you specified package information according to the | |||||
<a target="_blank" href="http://java.sun.com/j2se/1.3/docs/guide/versioning/spec/VersioningSpecification.html#PackageVersioning"> | |||||
versioning specification</a>.</p> | |||||
<p><b>Please note that the zip format allows multiple files of the same | <p><b>Please note that the zip format allows multiple files of the same | ||||
fully-qualified name to exist within a single archive. This has been | |||||
documented as causing various problems for unsuspecting users. If you wish | |||||
fully-qualified name to exist within a single archive. This has been | |||||
documented as causing various problems for unsuspecting users. If you wish | |||||
to avoid this behavior you must set the <code>duplicate</code> attribute | to avoid this behavior you must set the <code>duplicate</code> attribute | ||||
to a value other than its default, <code>"add"</code>.</b></p> | to a value other than its default, <code>"add"</code>.</b></p> | ||||
@@ -236,5 +236,23 @@ | |||||
</indexjars> | </indexjars> | ||||
</jar> | </jar> | ||||
</target> | </target> | ||||
<target name="testNoVersionInfo"> | |||||
<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}"> | |||||
<manifest> | |||||
<attribute name="Implementation-Title" value="Packaging Version Test"/> | |||||
<attribute name="Implementation-Version" value="1.0"/> | |||||
<attribute name="Implementation-Vendor" value="Apache Software Foundation"/> | |||||
</manifest> | |||||
</jar> | |||||
</target> | |||||
</project> | </project> |
@@ -45,6 +45,7 @@ import java.util.zip.ZipFile; | |||||
import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.taskdefs.Manifest.Section; | |||||
import org.apache.tools.ant.types.EnumeratedAttribute; | import org.apache.tools.ant.types.EnumeratedAttribute; | ||||
import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
import org.apache.tools.ant.types.ResourceCollection; | import org.apache.tools.ant.types.ResourceCollection; | ||||
@@ -76,6 +77,7 @@ public class Jar extends Zip { | |||||
/** merged manifests added through addConfiguredManifest */ | /** merged manifests added through addConfiguredManifest */ | ||||
private Manifest configuredManifest; | private Manifest configuredManifest; | ||||
/** shadow of the above if upToDate check alters the value */ | /** shadow of the above if upToDate check alters the value */ | ||||
private Manifest savedConfiguredManifest; | private Manifest savedConfiguredManifest; | ||||
@@ -158,7 +160,7 @@ public class Jar extends Zip { | |||||
setEncoding("UTF8"); | setEncoding("UTF8"); | ||||
rootEntries = new Vector(); | rootEntries = new Vector(); | ||||
} | } | ||||
/** | /** | ||||
* Not used for jar files. | * Not used for jar files. | ||||
* @param we not used | * @param we not used | ||||
@@ -773,6 +775,25 @@ public class Jar extends Zip { | |||||
*/ | */ | ||||
protected void cleanUp() { | protected void cleanUp() { | ||||
super.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() + ")"); | |||||
} else { | |||||
if (mainSection.getAttribute("Implementation-Title") == null) { | |||||
log("No Implementation-Title set. (" + getLocation() + ")"); | |||||
} | |||||
if (mainSection.getAttribute("Implementation-Version") == null) { | |||||
log("No Implementation-Version set. (" + getLocation() + ")"); | |||||
} | |||||
if (mainSection.getAttribute("Implementation-Vendor") == null) { | |||||
log("No Implementation-Vendor set. (" + getLocation() + ")"); | |||||
} | |||||
} | |||||
// we want to save this info if we are going to make another pass | // we want to save this info if we are going to make another pass | ||||
if (!doubleFilePass || !skipWriting) { | if (!doubleFilePass || !skipWriting) { | ||||
@@ -267,4 +267,19 @@ public class JarTest extends BuildFileTest { | |||||
public void testIndexJarsPlusJarMarker() { | public void testIndexJarsPlusJarMarker() { | ||||
executeTarget("testIndexJarsPlusJarMarker"); | executeTarget("testIndexJarsPlusJarMarker"); | ||||
} | } | ||||
public void testNoVersionInfo() { | |||||
executeTarget("testNoVersionInfo"); | |||||
assertLogContaining("No Implementation-Title set."); | |||||
assertLogContaining("No Implementation-Version set."); | |||||
assertLogContaining("No Implementation-Vendor set."); | |||||
} | |||||
public void testHasVersionInfo() { | |||||
executeTarget("testHasVersionInfo"); | |||||
assertFalse( getLog().contains("No Implementation-Title set.") ); | |||||
assertFalse( getLog().contains("No Implementation-Version set.") ); | |||||
assertFalse( getLog().contains("No Implementation-Vendor set.") ); | |||||
} | |||||
} | } |