From d23230d9ea1c03e64184f3c69bfe69499e815ef8 Mon Sep 17 00:00:00 2001 From: Heiko Klare Date: Thu, 29 Feb 2024 10:36:34 +0100 Subject: [PATCH] Add test case for PublishFeaturesAndBundlesMojo marking bundle unpacked The PublishFeaturesAndBundlesMojo produces a p2 repository in which plugins are marked as "zipped" and will thus be unpacked upon installation when a feature including them does not include the plugin with "unpack=false". The added test demonstrates this behavior and ensures that only the feature will properly be marked as "zipped" but not the included plugin. --- .../test_feature_1.0.0.202402290953.jar | Bin 0 -> 366 bytes .../test_plugin_1.0.0.202402290953.jar | Bin 0 -> 417 bytes .../p2extra/publisherNoUnpack/pom.xml | 38 +++++++++++++++ .../eclipse/tycho/test/P2ExtrasPlugin.java | 45 ++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 tycho-its/projects/p2extra/publisherNoUnpack/features/test_feature_1.0.0.202402290953.jar create mode 100644 tycho-its/projects/p2extra/publisherNoUnpack/plugins/test_plugin_1.0.0.202402290953.jar create mode 100644 tycho-its/projects/p2extra/publisherNoUnpack/pom.xml diff --git a/tycho-its/projects/p2extra/publisherNoUnpack/features/test_feature_1.0.0.202402290953.jar b/tycho-its/projects/p2extra/publisherNoUnpack/features/test_feature_1.0.0.202402290953.jar new file mode 100644 index 0000000000000000000000000000000000000000..8c49c7a0eeca98b976329a130df8b3fe11e61134 GIT binary patch literal 366 zcmWIWW@Zs#;Nak3SmYNQ!GHv~f$X%@#FEmYRK1GaoZ5+d{SF(5w0^f~EiHdEL9BC; zifo3p;Wl9>4U6eVCOwYmb3S$Z`j+VlTBhI1&Yw4*lT(```rGODX}{+M^6Ccyy4OwG zb?)JY`*&>*?dsU%uX8uSFzLDaY8jbt@8+I!C=ab$a4PY=>bBqdtsMU^tHi2h?(z!b z=hj#x9~_pbzsBU;?HdWT{*UKWKB|#9F43QwEplv8cIAW57rp6-r25x>#`qw7TMoAXAw(C(1Le`V(#;@Z*aTjFVt{TSlkwsmBrz{ zo8!asGr5OrqmN}iSF&OZ@Mh=G5^-mE2K2lE69YqlHzSh>10sNshwlg9po-#;YJdu{nju<^_1ObBJ&C z@SF~G_DdiR!09ngWREce6|!>xMHrYs1P}yxGct)VAi@OMP*9kl0&F3KZURUL%yf|D a2yhd~gqslH&B_LnVgkZSAT7iQ;sF57P;OZO literal 0 HcmV?d00001 diff --git a/tycho-its/projects/p2extra/publisherNoUnpack/pom.xml b/tycho-its/projects/p2extra/publisherNoUnpack/pom.xml new file mode 100644 index 0000000000..e41dc9575a --- /dev/null +++ b/tycho-its/projects/p2extra/publisherNoUnpack/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + tycho-its-project.p2extra.publisherNoUnpack + parent + 1.0.0-SNAPSHOT + pom + + + + + + org.eclipse.tycho.extras + tycho-p2-extras-plugin + ${tycho-version} + + + prepare-package + + publish-features-and-bundles + + + + + . + target/repository + target/repository + true + false + + + + + + \ No newline at end of file diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/P2ExtrasPlugin.java b/tycho-its/src/test/java/org/eclipse/tycho/test/P2ExtrasPlugin.java index d4d53770a5..b83d4de6fa 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/P2ExtrasPlugin.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/P2ExtrasPlugin.java @@ -12,14 +12,25 @@ *******************************************************************************/ package org.eclipse.tycho.test; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.File; +import java.io.IOException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import org.apache.maven.it.VerificationException; import org.apache.maven.it.Verifier; import org.junit.Test; +import de.pdark.decentxml.Document; +import de.pdark.decentxml.Element; +import de.pdark.decentxml.XMLIOSource; +import de.pdark.decentxml.XMLParser; + public class P2ExtrasPlugin extends AbstractTychoIntegrationTest { @Test @@ -129,4 +140,38 @@ private void execute(Verifier verifier, boolean success, String project, String } } + @Test + public void testPublishFeaturesAndBundles_noUnpack() throws Exception { + final String pluginId = "test_plugin"; + final String featureId = "test_feature.feature.jar"; + + Verifier verifier = getVerifier("p2extra/publisherNoUnpack", false, true); + verifier.executeGoals(List.of("clean", "package")); + + Path contentXml = Path.of(verifier.getBasedir()).resolve("target/repository").resolve("content.xml"); + Element pluginUnitInContentXml = extractUnitFromContentXml(contentXml, pluginId); + assertFalse("test plugin should not be marked as zipped", hasChildWithZippedAttribute(pluginUnitInContentXml)); + Element featureUnitInContentXml = extractUnitFromContentXml(contentXml, featureId); + assertTrue("test feature should be marked as zipped", hasChildWithZippedAttribute(featureUnitInContentXml)); + } + + private static Element extractUnitFromContentXml(Path contentXml, String unitName) throws IOException { + XMLParser parser = new XMLParser(); + Document document = parser.parse(new XMLIOSource(contentXml.toFile())); + Element unitElement = document.getChild("repository/units"); + List units = unitElement.getChildren("unit"); + Optional extractedUnit = units.stream() + .filter(element -> unitName.equals(element.getAttribute("id").getValue())).findFirst(); + assertTrue(String.format("Unit with name '%s' not found in content.xml with units: %s", unitName, units), + extractedUnit.isPresent()); + return extractedUnit.get(); + } + + private static boolean hasChildWithZippedAttribute(Element element) { + if ("zipped".equals(element.getAttributeValue("key"))) { + return true; + } + return element.getChildren().stream().anyMatch(P2ExtrasPlugin::hasChildWithZippedAttribute); + } + }