Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian W. Damus2016-03-05 11:36:57 -0500
committerChristian W. Damus2016-03-06 16:16:42 -0500
commitdf04211007a23bd537e424785841e4218e6ac124 (patch)
treed88b7bcf8cd1982a264f74e221ad09bce98292be /tests/junit/plugins/editor
parentc6734af6f9c1838204786417a9a4bb2a0d6013a8 (diff)
downloadorg.eclipse.papyrus-df04211007a23bd537e424785841e4218e6ac124.tar.gz
org.eclipse.papyrus-df04211007a23bd537e424785841e4218e6ac124.tar.xz
org.eclipse.papyrus-df04211007a23bd537e424785841e4218e6ac124.zip
Bug 489075: [DevTools] Manifest editor reorders main headers on save
https://bugs.eclipse.org/bugs/show_bug.cgi?id=489075 Ensure that the manifest file is rewritten with all headers in the original order, including additional sections beyond the main section. Also fix problems of empty sections being left after all their attributes are removed and new sections not being added when setting their initial attributes. Change-Id: I1aec074a15b61dc3048883aee8b748938e11f78c
Diffstat (limited to 'tests/junit/plugins/editor')
-rw-r--r--tests/junit/plugins/editor/org.eclipse.papyrus.eclipse.project.editors.tests/src/org/eclipse/papyrus/eclipse/project/editors/tests/ManifestEditorTest.java89
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/junit/plugins/editor/org.eclipse.papyrus.eclipse.project.editors.tests/src/org/eclipse/papyrus/eclipse/project/editors/tests/ManifestEditorTest.java b/tests/junit/plugins/editor/org.eclipse.papyrus.eclipse.project.editors.tests/src/org/eclipse/papyrus/eclipse/project/editors/tests/ManifestEditorTest.java
index abdc1281116..bbf4199d68b 100644
--- a/tests/junit/plugins/editor/org.eclipse.papyrus.eclipse.project.editors.tests/src/org/eclipse/papyrus/eclipse/project/editors/tests/ManifestEditorTest.java
+++ b/tests/junit/plugins/editor/org.eclipse.papyrus.eclipse.project.editors.tests/src/org/eclipse/papyrus/eclipse/project/editors/tests/ManifestEditorTest.java
@@ -23,7 +23,9 @@ import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
+import java.util.Arrays;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
@@ -471,6 +473,93 @@ public class ManifestEditorTest {
assertThat(fixture.slurp("META-INF/MANIFEST.MF"), hasItem(containsString("Manifest-Version:")));
}
+ @WithResource("manifest_project/META-INF/MANIFEST.MF")
+ @Test
+ public void headerOrderMaintained_bug489075() {
+ // Make a simple change
+ fixture.getEditor().addDependency("org.eclipse.jface", "3.10.0");
+
+ fixture.getEditor().save();
+
+ List<String> manifest = getManifest();
+ List<String> headerNames = manifest.stream()
+ .filter(l -> !l.startsWith(" "))
+ .filter(l -> !l.trim().isEmpty())
+ .map(l -> l.substring(0, l.indexOf(':')))
+ .collect(Collectors.toList());
+
+ assertThat(headerNames, is(Arrays.asList(
+ "Manifest-Version",
+ "Require-Bundle",
+ "Import-Package",
+ "Export-Package",
+ "Bundle-Vendor",
+ "Bundle-ActivationPolicy",
+ "Bundle-Version",
+ "Bundle-Name",
+ "Bundle-ManifestVersion",
+ "Bundle-SymbolicName",
+ "Bundle-Localization",
+ "Bundle-RequiredExecutionEnvironment",
+ "Name",
+ "Full-Name",
+ "Company",
+ "Committer")));
+ }
+
+ @WithResource("manifest_project/META-INF/MANIFEST.MF")
+ @Test
+ public void addNewCustomSection_bug489075() {
+ // Add a new manifest section with custom attributes
+ fixture.getEditor().setValue("test-section", "Attr1", "foo");
+ fixture.getEditor().setValue("test-section", "Other", "something else");
+ fixture.getEditor().setValue("test-section", "Favorite", "true");
+
+ fixture.getEditor().save();
+
+ List<String> manifest = getManifest();
+ List<String> headerNames = manifest.stream()
+ .filter(l -> !l.startsWith(" "))
+ .filter(l -> !l.trim().isEmpty())
+ .map(l -> l.substring(0, l.indexOf(':')))
+ .collect(Collectors.toList());
+
+ // Isolate the new headers (the last four, including the "Name: test-section")
+ headerNames = headerNames.subList(headerNames.size() - 4, headerNames.size());
+
+ // The first is the section name header
+ assertThat(headerNames.get(0), is("Name"));
+
+ // But the others aren't in any defined order
+ assertThat(new HashSet<>(headerNames), is(new HashSet<>(Arrays.asList(
+ "Name",
+ "Attr1",
+ "Other",
+ "Favorite"))));
+ }
+
+ @WithResource("manifest_project/META-INF/MANIFEST.MF")
+ @Test
+ public void removeCustomSection_bug489075() {
+ // Add a new manifest section with custom attributes
+ fixture.getEditor().removeValue("author-info", "Full-Name");
+ fixture.getEditor().removeValue("author-info", "Company");
+ fixture.getEditor().removeValue("author-info", "Committer");
+
+ fixture.getEditor().save();
+
+ List<String> manifest = getManifest();
+ List<String> headerNames = manifest.stream()
+ .filter(l -> !l.startsWith(" "))
+ .filter(l -> !l.trim().isEmpty())
+ .map(l -> l.substring(0, l.indexOf(':')))
+ .collect(Collectors.toList());
+
+ // The custom section does not appear at all. Not even the section name
+ assertThat(headerNames, not(either(hasItem("Name"))
+ .or(hasItem("Full-Name")).or(hasItem("Company")).or(hasItem("Committer"))));
+ }
+
//
// Test framework
//

Back to the top