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"> | <target name="test1"> | ||||
| <jar file="mftest1.jar" manifest="manifests/test1.mf"/> | <jar file="mftest1.jar" manifest="manifests/test1.mf"/> | ||||
| <unjar src="mftest1.jar" dest="manifests"> | |||||
| <include name="META-INF/MANIFEST.MF"/> | |||||
| </unjar> | |||||
| </target> | </target> | ||||
| <target name="test2"> | <target name="test2"> | ||||
| <jar file="mftest2.jar" manifest="manifests/test2.mf"/> | <jar file="mftest2.jar" manifest="manifests/test2.mf"/> | ||||
| <unjar src="mftest2.jar" dest="manifests"> | |||||
| <include name="META-INF/MANIFEST.MF"/> | |||||
| </unjar> | |||||
| </target> | </target> | ||||
| <target name="test3"> | <target name="test3"> | ||||
| @@ -41,6 +47,9 @@ | |||||
| </section> | </section> | ||||
| </manifest> | </manifest> | ||||
| </jar> | </jar> | ||||
| <unjar src="mftest8.jar" dest="manifests"> | |||||
| <include name="META-INF/MANIFEST.MF"/> | |||||
| </unjar> | |||||
| </target> | </target> | ||||
| <target name="test9"> | <target name="test9"> | ||||
| @@ -98,12 +107,27 @@ | |||||
| <attribute name="class-Path" value="Test4"/> | <attribute name="class-Path" value="Test4"/> | ||||
| </manifest> | </manifest> | ||||
| </jar> | </jar> | ||||
| <unjar src="mftest14.jar" dest="manifests"> | |||||
| <include name="META-INF/MANIFEST.MF"/> | |||||
| </unjar> | |||||
| </target> | </target> | ||||
| <target name="testNoFile"> | <target name="testNoFile"> | ||||
| <manifest /> | <manifest /> | ||||
| </target> | </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"> | <target name="testReplace"> | ||||
| <copy file="manifests/test2.mf" toFile="mftest.mf" /> | <copy file="manifests/test2.mf" toFile="mftest.mf" /> | ||||
| <manifest file="mftest.mf" /> | <manifest file="mftest.mf" /> | ||||
| @@ -120,5 +144,6 @@ | |||||
| <delete> | <delete> | ||||
| <fileset dir="." includes="mftest*"/> | <fileset dir="." includes="mftest*"/> | ||||
| </delete> | </delete> | ||||
| <delete dir="manifests/META-INF"/> | |||||
| </target> | </target> | ||||
| </project> | </project> | ||||
| @@ -391,6 +391,18 @@ public class Manifest extends Task { | |||||
| writer.println(); | 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. | * 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();) { | for (Enumeration e = attributes.keys(); e.hasMoreElements();) { | ||||
| String attributeName = (String)e.nextElement(); | String attributeName = (String)e.nextElement(); | ||||
| Object attributeValue = attributes.get(attributeName); | 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; | return false; | ||||
| } | } | ||||
| } | } | ||||
| @@ -599,7 +611,7 @@ public class Manifest extends Task { | |||||
| if (section.getName() == null) { | if (section.getName() == null) { | ||||
| throw new BuildException("Sections must have a name"); | 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 { | public void addConfiguredAttribute(Attribute attribute) throws ManifestException { | ||||
| @@ -624,7 +636,7 @@ public class Manifest extends Task { | |||||
| Section ourSection = (Section)sections.get(sectionName); | Section ourSection = (Section)sections.get(sectionName); | ||||
| Section otherSection = (Section)other.sections.get(sectionName); | Section otherSection = (Section)other.sections.get(sectionName); | ||||
| if (ourSection == null) { | if (ourSection == null) { | ||||
| sections.put(sectionName.toLowerCase(), otherSection); | |||||
| sections.put(sectionName, otherSection); | |||||
| } | } | ||||
| else { | else { | ||||
| ourSection.merge(otherSection); | ourSection.merge(otherSection); | ||||
| @@ -725,7 +737,7 @@ public class Manifest extends Task { | |||||
| for (Enumeration e = sections.elements(); e.hasMoreElements();) { | for (Enumeration e = sections.elements(); e.hasMoreElements();) { | ||||
| Section section = (Section)e.nextElement(); | 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)) { | if (!section.equals(rhsSection)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| @@ -752,6 +764,44 @@ public class Manifest extends Task { | |||||
| mode = m; | 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. | * 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() { | protected File getProjectDir() { | ||||
| return project.getBaseDir(); | return project.getBaseDir(); | ||||
| } | } | ||||
| @@ -58,7 +58,9 @@ import java.io.File; | |||||
| import java.io.FileReader; | import java.io.FileReader; | ||||
| import java.io.IOException; | import java.io.IOException; | ||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.Vector; | |||||
| import org.apache.tools.ant.BuildFileTest; | import org.apache.tools.ant.BuildFileTest; | ||||
| import org.apache.tools.ant.Project; | |||||
| /** | /** | ||||
| * Testcase for the Manifest class used in the jar task. | * 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 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) { | public ManifestTest(String name) { | ||||
| super(name); | super(name); | ||||
| } | } | ||||
| @@ -78,19 +89,25 @@ public class ManifestTest extends BuildFileTest { | |||||
| public void tearDown() { | public void tearDown() { | ||||
| executeTarget("clean"); | executeTarget("clean"); | ||||
| } | } | ||||
| /** | /** | ||||
| * Empty manifest - is OK | * Empty manifest - is OK | ||||
| */ | */ | ||||
| public void test1() { | |||||
| public void test1() throws ManifestException, IOException { | |||||
| executeTarget("test1"); | 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 | * Simple Manifest with version 2.0 | ||||
| */ | */ | ||||
| public void test2() { | |||||
| public void test2() throws ManifestException, IOException { | |||||
| executeTarget("test2"); | 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 | * Inline manifest - OK | ||||
| */ | */ | ||||
| public void test8() { | |||||
| public void test8() throws IOException, ManifestException { | |||||
| executeTarget("test8"); | 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. | * Inline manifest - OK since classpath entries can be duplicated. | ||||
| */ | */ | ||||
| public void test14() { | |||||
| public void test14() throws IOException, ManifestException { | |||||
| executeTarget("test14"); | 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 { | public void testReplace() throws IOException, ManifestException { | ||||
| executeTarget("testReplace"); | executeTarget("testReplace"); | ||||
| Manifest mf = getManifest(); | |||||
| Manifest mf = getManifest("src/etc/testcases/taskdefs/mftest.mf"); | |||||
| assertNotNull(mf); | assertNotNull(mf); | ||||
| assertEquals(Manifest.getDefaultManifest(), mf); | assertEquals(Manifest.getDefaultManifest(), mf); | ||||
| } | } | ||||
| @@ -216,7 +263,7 @@ public class ManifestTest extends BuildFileTest { | |||||
| */ | */ | ||||
| public void testUpdate() throws IOException, ManifestException { | public void testUpdate() throws IOException, ManifestException { | ||||
| executeTarget("testUpdate"); | executeTarget("testUpdate"); | ||||
| Manifest mf = getManifest(); | |||||
| Manifest mf = getManifest("src/etc/testcases/taskdefs/mftest.mf"); | |||||
| assertNotNull(mf); | assertNotNull(mf); | ||||
| assertTrue(!Manifest.getDefaultManifest().equals(mf)); | assertTrue(!Manifest.getDefaultManifest().equals(mf)); | ||||
| String mfAsString = mf.toString(); | String mfAsString = mf.toString(); | ||||
| @@ -228,8 +275,8 @@ public class ManifestTest extends BuildFileTest { | |||||
| /** | /** | ||||
| * Reads mftest.mf. | * 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 { | try { | ||||
| return new Manifest(r); | return new Manifest(r); | ||||
| } finally { | } finally { | ||||