Skip to content

Commit 1f0bb2a

Browse files
HeikoKlareeclipse-tycho-bot
authored andcommittedMar 25, 2024
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. (cherry picked from commit d23230d)
1 parent 8fa411b commit 1f0bb2a

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>tycho-its-project.p2extra.publisherNoUnpack</groupId>
8+
<artifactId>parent</artifactId>
9+
<version>1.0.0-SNAPSHOT</version>
10+
<packaging>pom</packaging>
11+
12+
<build>
13+
<plugins>
14+
<!-- Configuration for the PublishFeaturesAndBundlesMojoTest -->
15+
<plugin>
16+
<groupId>org.eclipse.tycho.extras</groupId>
17+
<artifactId>tycho-p2-extras-plugin</artifactId>
18+
<version>${tycho-version}</version>
19+
<executions>
20+
<execution>
21+
<phase>prepare-package</phase>
22+
<goals>
23+
<goal>publish-features-and-bundles</goal>
24+
</goals>
25+
</execution>
26+
</executions>
27+
<configuration>
28+
<sourceLocation>.</sourceLocation>
29+
<artifactRepositoryLocation>target/repository</artifactRepositoryLocation>
30+
<metadataRepositoryLocation>target/repository</metadataRepositoryLocation>
31+
<publishArtifacts>true</publishArtifacts>
32+
<compress>false</compress>
33+
</configuration>
34+
</plugin>
35+
</plugins>
36+
</build>
37+
38+
</project>

‎tycho-its/src/test/java/org/eclipse/tycho/test/P2ExtrasPlugin.java

+45
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,25 @@
1212
*******************************************************************************/
1313
package org.eclipse.tycho.test;
1414

15+
import static org.junit.Assert.assertFalse;
16+
import static org.junit.Assert.assertTrue;
17+
1518
import java.io.File;
19+
import java.io.IOException;
20+
import java.nio.file.Path;
1621
import java.util.ArrayList;
1722
import java.util.List;
23+
import java.util.Optional;
1824

1925
import org.apache.maven.it.VerificationException;
2026
import org.apache.maven.it.Verifier;
2127
import org.junit.Test;
2228

29+
import de.pdark.decentxml.Document;
30+
import de.pdark.decentxml.Element;
31+
import de.pdark.decentxml.XMLIOSource;
32+
import de.pdark.decentxml.XMLParser;
33+
2334
public class P2ExtrasPlugin extends AbstractTychoIntegrationTest {
2435

2536
@Test
@@ -129,4 +140,38 @@ private void execute(Verifier verifier, boolean success, String project, String
129140
}
130141
}
131142

143+
@Test
144+
public void testPublishFeaturesAndBundles_noUnpack() throws Exception {
145+
final String pluginId = "test_plugin";
146+
final String featureId = "test_feature.feature.jar";
147+
148+
Verifier verifier = getVerifier("p2extra/publisherNoUnpack", false, true);
149+
verifier.executeGoals(List.of("clean", "package"));
150+
151+
Path contentXml = Path.of(verifier.getBasedir()).resolve("target/repository").resolve("content.xml");
152+
Element pluginUnitInContentXml = extractUnitFromContentXml(contentXml, pluginId);
153+
assertFalse("test plugin should not be marked as zipped", hasChildWithZippedAttribute(pluginUnitInContentXml));
154+
Element featureUnitInContentXml = extractUnitFromContentXml(contentXml, featureId);
155+
assertTrue("test feature should be marked as zipped", hasChildWithZippedAttribute(featureUnitInContentXml));
156+
}
157+
158+
private static Element extractUnitFromContentXml(Path contentXml, String unitName) throws IOException {
159+
XMLParser parser = new XMLParser();
160+
Document document = parser.parse(new XMLIOSource(contentXml.toFile()));
161+
Element unitElement = document.getChild("repository/units");
162+
List<Element> units = unitElement.getChildren("unit");
163+
Optional<Element> extractedUnit = units.stream()
164+
.filter(element -> unitName.equals(element.getAttribute("id").getValue())).findFirst();
165+
assertTrue(String.format("Unit with name '%s' not found in content.xml with units: %s", unitName, units),
166+
extractedUnit.isPresent());
167+
return extractedUnit.get();
168+
}
169+
170+
private static boolean hasChildWithZippedAttribute(Element element) {
171+
if ("zipped".equals(element.getAttributeValue("key"))) {
172+
return true;
173+
}
174+
return element.getChildren().stream().anyMatch(P2ExtrasPlugin::hasChildWithZippedAttribute);
175+
}
176+
132177
}

0 commit comments

Comments
 (0)