Skip to content

Commit

Permalink
Add test case for PublishFeaturesAndBundlesMojo marking bundle unpacked
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
HeikoKlare authored and laeubi committed Mar 25, 2024
1 parent 27398a5 commit d23230d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
38 changes: 38 additions & 0 deletions tycho-its/projects/p2extra/publisherNoUnpack/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>tycho-its-project.p2extra.publisherNoUnpack</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<build>
<plugins>
<!-- Configuration for the PublishFeaturesAndBundlesMojoTest -->
<plugin>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-p2-extras-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>publish-features-and-bundles</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceLocation>.</sourceLocation>
<artifactRepositoryLocation>target/repository</artifactRepositoryLocation>
<metadataRepositoryLocation>target/repository</metadataRepositoryLocation>
<publishArtifacts>true</publishArtifacts>
<compress>false</compress>
</configuration>
</plugin>
</plugins>
</build>

</project>
45 changes: 45 additions & 0 deletions tycho-its/src/test/java/org/eclipse/tycho/test/P2ExtrasPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Element> units = unitElement.getChildren("unit");
Optional<Element> 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);
}

}

0 comments on commit d23230d

Please sign in to comment.