From df04211007a23bd537e424785841e4218e6ac124 Mon Sep 17 00:00:00 2001 From: Christian W. Damus Date: Sat, 5 Mar 2016 11:36:57 -0500 Subject: 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 --- .../project/editors/tests/ManifestEditorTest.java | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) (limited to 'tests/junit') 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 manifest = getManifest(); + List 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 manifest = getManifest(); + List 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 manifest = getManifest(); + List 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 // -- cgit v1.2.3