git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271308 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -6,10 +6,16 @@ | |||
| <target name="test1"> | |||
| <jar file="mftest1.jar" manifest="manifests/test1.mf"/> | |||
| <unjar src="mftest1.jar" dest="manifests"> | |||
| <include name="META-INF/MANIFEST.MF"/> | |||
| </unjar> | |||
| </target> | |||
| <target name="test2"> | |||
| <jar file="mftest2.jar" manifest="manifests/test2.mf"/> | |||
| <unjar src="mftest2.jar" dest="manifests"> | |||
| <include name="META-INF/MANIFEST.MF"/> | |||
| </unjar> | |||
| </target> | |||
| <target name="test3"> | |||
| @@ -41,6 +47,9 @@ | |||
| </section> | |||
| </manifest> | |||
| </jar> | |||
| <unjar src="mftest8.jar" dest="manifests"> | |||
| <include name="META-INF/MANIFEST.MF"/> | |||
| </unjar> | |||
| </target> | |||
| <target name="test9"> | |||
| @@ -98,12 +107,27 @@ | |||
| <attribute name="class-Path" value="Test4"/> | |||
| </manifest> | |||
| </jar> | |||
| <unjar src="mftest14.jar" dest="manifests"> | |||
| <include name="META-INF/MANIFEST.MF"/> | |||
| </unjar> | |||
| </target> | |||
| <target name="testNoFile"> | |||
| <manifest /> | |||
| </target> | |||
| <target name="testLongLine"> | |||
| <jar file="mftestLongLine.jar"> | |||
| <manifest> | |||
| <attribute name="Class-path" | |||
| value="${test.longline}"/> | |||
| </manifest> | |||
| </jar> | |||
| <unjar src="mftestLongLine.jar" dest="manifests"> | |||
| <include name="META-INF/MANIFEST.MF"/> | |||
| </unjar> | |||
| </target> | |||
| <target name="testReplace"> | |||
| <copy file="manifests/test2.mf" toFile="mftest.mf" /> | |||
| <manifest file="mftest.mf" /> | |||
| @@ -120,5 +144,6 @@ | |||
| <delete> | |||
| <fileset dir="." includes="mftest*"/> | |||
| </delete> | |||
| <delete dir="manifests/META-INF"/> | |||
| </target> | |||
| </project> | |||
| @@ -391,6 +391,18 @@ public class Manifest extends Task { | |||
| writer.println(); | |||
| } | |||
| /** | |||
| * Get a attribute of the section | |||
| * | |||
| * @param attributeName the name of the attribute | |||
| * @return a Manifest.Attribute instance if the attribute is | |||
| * single-valued, otherwise a Vector of Manifest.Attribute | |||
| * instances. | |||
| */ | |||
| public Object getAttribute(String attributeName) { | |||
| return attributes.get(attributeName.toLowerCase()); | |||
| } | |||
| /** | |||
| * Get the value of the attribute with the name given. | |||
| * | |||
| @@ -497,8 +509,8 @@ public class Manifest extends Task { | |||
| for (Enumeration e = attributes.keys(); e.hasMoreElements();) { | |||
| String attributeName = (String)e.nextElement(); | |||
| Object attributeValue = attributes.get(attributeName); | |||
| Object rshAttributeValue = rhsSection.attributes.get(attributeName); | |||
| if (!attributeValue.equals(rshAttributeValue)) { | |||
| Object rhsAttributeValue = rhsSection.attributes.get(attributeName); | |||
| if (!attributeValue.equals(rhsAttributeValue)) { | |||
| return false; | |||
| } | |||
| } | |||
| @@ -599,7 +611,7 @@ public class Manifest extends Task { | |||
| if (section.getName() == null) { | |||
| throw new BuildException("Sections must have a name"); | |||
| } | |||
| sections.put(section.getName().toLowerCase(), section); | |||
| sections.put(section.getName(), section); | |||
| } | |||
| public void addConfiguredAttribute(Attribute attribute) throws ManifestException { | |||
| @@ -624,7 +636,7 @@ public class Manifest extends Task { | |||
| Section ourSection = (Section)sections.get(sectionName); | |||
| Section otherSection = (Section)other.sections.get(sectionName); | |||
| if (ourSection == null) { | |||
| sections.put(sectionName.toLowerCase(), otherSection); | |||
| sections.put(sectionName, otherSection); | |||
| } | |||
| else { | |||
| ourSection.merge(otherSection); | |||
| @@ -725,7 +737,7 @@ public class Manifest extends Task { | |||
| for (Enumeration e = sections.elements(); e.hasMoreElements();) { | |||
| Section section = (Section)e.nextElement(); | |||
| Section rhsSection = (Section)rhsManifest.sections.get(section.getName().toLowerCase()); | |||
| Section rhsSection = (Section)rhsManifest.sections.get(section.getName()); | |||
| if (!section.equals(rhsSection)) { | |||
| return false; | |||
| } | |||
| @@ -752,6 +764,44 @@ public class Manifest extends Task { | |||
| mode = m; | |||
| } | |||
| /** | |||
| * Get the version of the manifest | |||
| * | |||
| * @return the manifest's version string | |||
| */ | |||
| public String getManifestVersion() { | |||
| return manifestVersion; | |||
| } | |||
| /** | |||
| * Get the main section of the manifest | |||
| * | |||
| * @return the main section of the manifest | |||
| */ | |||
| public Section getMainSection() { | |||
| return mainSection; | |||
| } | |||
| /** | |||
| * Get a particular section from the manifest | |||
| * | |||
| * @param name the name of the section desired. | |||
| * @return the specified section or null if that section | |||
| * does not exist in the manifest | |||
| */ | |||
| public Section getSection(String name) { | |||
| return (Section)sections.get(name); | |||
| } | |||
| /** | |||
| * Get the section names in this manifest. | |||
| * | |||
| * @return an Enumeration of section names | |||
| */ | |||
| public Enumeration getSectionNames() { | |||
| return sections.keys(); | |||
| } | |||
| /** | |||
| * Create or update the Manifest when used as a task. | |||
| */ | |||
| @@ -243,6 +243,15 @@ public abstract class BuildFileTest extends TestCase { | |||
| } | |||
| /** | |||
| * Get the project which has been configured for a test. | |||
| * | |||
| * @return the Project instance for this test. | |||
| */ | |||
| protected Project getProject() { | |||
| return project; | |||
| } | |||
| protected File getProjectDir() { | |||
| return project.getBaseDir(); | |||
| } | |||
| @@ -58,7 +58,9 @@ import java.io.File; | |||
| import java.io.FileReader; | |||
| import java.io.IOException; | |||
| import java.util.Date; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.BuildFileTest; | |||
| import org.apache.tools.ant.Project; | |||
| /** | |||
| * Testcase for the Manifest class used in the jar task. | |||
| @@ -67,6 +69,15 @@ import org.apache.tools.ant.BuildFileTest; | |||
| */ | |||
| public class ManifestTest extends BuildFileTest { | |||
| public static final String EXPANDED_MANIFEST | |||
| = "src/etc/testcases/taskdefs/manifests/META-INF/MANIFEST.MF"; | |||
| public static final String LONG_LINE | |||
| = "AReallyLongLineToTestLineBreakingInManifests-ACapabilityWhich" + | |||
| "IsSureToLeadToHundredsOfQuestionsAboutWhyAntMungesManifests" + | |||
| "OfCourseTheAnswerIsThatIsWhatTheSpecRequiresAndIfAnythingHas" + | |||
| "AProblemWithThatItIsNotABugInAnt"; | |||
| public ManifestTest(String name) { | |||
| super(name); | |||
| } | |||
| @@ -78,19 +89,25 @@ public class ManifestTest extends BuildFileTest { | |||
| public void tearDown() { | |||
| executeTarget("clean"); | |||
| } | |||
| /** | |||
| * Empty manifest - is OK | |||
| */ | |||
| public void test1() { | |||
| public void test1() throws ManifestException, IOException { | |||
| executeTarget("test1"); | |||
| Manifest manifest = getManifest(EXPANDED_MANIFEST); | |||
| String version = manifest.getManifestVersion(); | |||
| assertEquals("Manifest was not created with correct version - ", "1.0", version); | |||
| } | |||
| /** | |||
| * Simple Manifest with version 2.0 | |||
| */ | |||
| public void test2() { | |||
| public void test2() throws ManifestException, IOException { | |||
| executeTarget("test2"); | |||
| Manifest manifest = getManifest(EXPANDED_MANIFEST); | |||
| String version = manifest.getManifestVersion(); | |||
| assertEquals("Manifest was not created with correct version - ", "2.0", version); | |||
| } | |||
| /** | |||
| @@ -143,8 +160,16 @@ public class ManifestTest extends BuildFileTest { | |||
| /** | |||
| * Inline manifest - OK | |||
| */ | |||
| public void test8() { | |||
| public void test8() throws IOException, ManifestException { | |||
| executeTarget("test8"); | |||
| Manifest manifest = getManifest(EXPANDED_MANIFEST); | |||
| Manifest.Section mainSection = manifest.getMainSection(); | |||
| String classpath = mainSection.getAttributeValue("class-path"); | |||
| assertEquals("Class-Path attribute was not set correctly - ", "fubar", classpath); | |||
| Manifest.Section testSection = manifest.getSection("Test"); | |||
| String testAttr = testSection.getAttributeValue("TestAttr"); | |||
| assertEquals("TestAttr attribute was not set correctly - ", "Test", testAttr); | |||
| } | |||
| /** | |||
| @@ -190,8 +215,30 @@ public class ManifestTest extends BuildFileTest { | |||
| /** | |||
| * Inline manifest - OK since classpath entries can be duplicated. | |||
| */ | |||
| public void test14() { | |||
| public void test14() throws IOException, ManifestException { | |||
| executeTarget("test14"); | |||
| Manifest manifest = getManifest(EXPANDED_MANIFEST); | |||
| Manifest.Section mainSection = manifest.getMainSection(); | |||
| String classpath = mainSection.getAttributeValue("class-path"); | |||
| assertEquals("Class-Path attribute was not set correctly - ", | |||
| "Test1 Test2 Test3 Test4", classpath); | |||
| Object classPathAttr = mainSection.getAttribute("class-PATH"); | |||
| assertTrue("Class path attribute should be a Vector", classPathAttr instanceof Vector); | |||
| } | |||
| /** | |||
| * Tets long line wrapping | |||
| */ | |||
| public void testLongLine() throws IOException, ManifestException { | |||
| Project project = getProject(); | |||
| project.setUserProperty("test.longline", LONG_LINE); | |||
| executeTarget("testLongLine"); | |||
| Manifest manifest = getManifest(EXPANDED_MANIFEST); | |||
| Manifest.Section mainSection = manifest.getMainSection(); | |||
| String classpath = mainSection.getAttributeValue("class-path"); | |||
| assertEquals("Class-Path attribute was not set correctly - ", | |||
| LONG_LINE, classpath); | |||
| } | |||
| /** | |||
| @@ -206,7 +253,7 @@ public class ManifestTest extends BuildFileTest { | |||
| */ | |||
| public void testReplace() throws IOException, ManifestException { | |||
| executeTarget("testReplace"); | |||
| Manifest mf = getManifest(); | |||
| Manifest mf = getManifest("src/etc/testcases/taskdefs/mftest.mf"); | |||
| assertNotNull(mf); | |||
| assertEquals(Manifest.getDefaultManifest(), mf); | |||
| } | |||
| @@ -216,7 +263,7 @@ public class ManifestTest extends BuildFileTest { | |||
| */ | |||
| public void testUpdate() throws IOException, ManifestException { | |||
| executeTarget("testUpdate"); | |||
| Manifest mf = getManifest(); | |||
| Manifest mf = getManifest("src/etc/testcases/taskdefs/mftest.mf"); | |||
| assertNotNull(mf); | |||
| assertTrue(!Manifest.getDefaultManifest().equals(mf)); | |||
| String mfAsString = mf.toString(); | |||
| @@ -228,8 +275,8 @@ public class ManifestTest extends BuildFileTest { | |||
| /** | |||
| * Reads mftest.mf. | |||
| */ | |||
| private Manifest getManifest() throws IOException, ManifestException { | |||
| FileReader r = new FileReader("src/etc/testcases/taskdefs/mftest.mf"); | |||
| private Manifest getManifest(String filename) throws IOException, ManifestException { | |||
| FileReader r = new FileReader(filename); | |||
| try { | |||
| return new Manifest(r); | |||
| } finally { | |||