Browse Source

<manifest> could miss situations in which an update was necessary.

PR: 12440
Submitted by:	Thomas Zimber <tzimber at e2e.ch>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273405 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 22 years ago
parent
commit
4e687594a1
4 changed files with 42 additions and 2 deletions
  1. +3
    -0
      WHATSNEW
  2. +12
    -0
      src/etc/testcases/taskdefs/manifest.xml
  3. +20
    -2
      src/main/org/apache/tools/ant/taskdefs/Manifest.java
  4. +7
    -0
      src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java

+ 3
- 0
WHATSNEW View File

@@ -19,6 +19,9 @@ Fixed bugs:

* <property environment=... /> now works on OS/400.

* <manifest> wouldn't update an existing manifest if only an attribute
of an existing section changed.

Other changes:
--------------



+ 12
- 0
src/etc/testcases/taskdefs/manifest.xml View File

@@ -188,6 +188,18 @@
<manifest file="mftest.mf" mode="update">
<attribute name="Foo" value="Bar" />
</manifest>

<copy file="manifests/test2.mf" toFile="mftest2.mf" />
<manifest file="mftest2.mf" mode="update">
<section name="Test">
<attribute name="Foo" value="Bar" />
</section>
</manifest>
<manifest file="mftest2.mf" mode="update">
<section name="Test">
<attribute name="Foo" value="Baz" />
</section>
</manifest>
</target>

<target name="clean">


+ 20
- 2
src/main/org/apache/tools/ant/taskdefs/Manifest.java View File

@@ -625,6 +625,24 @@ public class Manifest {
return null;
}

/**
* Clone this section
*
* @since Ant 1.5.2
*/
public Object clone() {
Section cloned = new Section();
cloned.setName(name);
Enumeration e = getAttributeKeys();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
Attribute attribute = getAttribute(key);
cloned.storeAttribute(new Attribute(attribute.getName(),
attribute.getValue()));
}
return cloned;
}

/**
* Store an attribute and update the index.
*
@@ -841,7 +859,7 @@ public class Manifest {
throws ManifestException {
if (other != null) {
if (overwriteMain) {
mainSection = other.mainSection;
mainSection = (Section) other.mainSection.clone();
} else {
mainSection.merge(other.mainSection);
}
@@ -858,7 +876,7 @@ public class Manifest {
= (Section) other.sections.get(sectionName);
if (ourSection == null) {
if (otherSection != null) {
addConfiguredSection(otherSection);
addConfiguredSection((Section) otherSection.clone());
}
} else {
ourSection.merge(otherSection);


+ 7
- 0
src/testcases/org/apache/tools/ant/taskdefs/ManifestTest.java View File

@@ -315,6 +315,13 @@ public class ManifestTest extends BuildFileTest {
assertNotNull(mfAsString);
assertTrue(mfAsString.startsWith("Manifest-Version: 2.0"));
assertTrue(mfAsString.indexOf("Foo: Bar") > -1);

mf = getManifest("src/etc/testcases/taskdefs/mftest2.mf");
assertNotNull(mf);
mfAsString = mf.toString();
assertNotNull(mfAsString);
assertEquals(-1, mfAsString.indexOf("Foo: Bar"));
assertTrue(mfAsString.indexOf("Foo: Baz") > -1);
}

/**


Loading…
Cancel
Save