Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case for PublishFeaturesAndBundlesMojo marking bundle unpacked #3538

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}

}
Loading