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 11, 2024
1 parent 5a981ee commit 9eb705d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.nio.file.StandardCopyOption;
import java.util.List;
import java.util.Properties;
import java.util.stream.Stream;

import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.execution.MavenSession;
Expand All @@ -39,6 +40,35 @@

public class PublishFeaturesAndBundlesMojoTest extends AbstractTychoMojoTestCase {

public void testPublisherNoUnpack() throws Exception {
File basedir = getBasedir("publisher/testProjectNoUnpack");
List<MavenProject> projects = getSortedProjects(basedir);
MavenProject project = projects.get(0);

initLegacySupport(projects, project);

// simulate that content to be published has already been extracted to the target folder
Path sourceRepositoryDir = Path.of(project.getFile().getParent());
File publishedContentDir = new File(project.getFile().getParent(), "target/repository").getAbsoluteFile();

// call publisher mojo
Mojo publishMojo = lookupMojo("publish-features-and-bundles", project.getFile());
setVariableValueToObject(publishMojo, "sourceLocation", sourceRepositoryDir.toString());
setVariableValueToObject(publishMojo, "artifactRepositoryLocation", publishedContentDir.toString());
setVariableValueToObject(publishMojo, "metadataRepositoryLocation", publishedContentDir.toString());
setVariableValueToObject(publishMojo, "publishArtifacts", Boolean.TRUE);

publishMojo.execute();

assertPublishedIU(publishedContentDir, "test_plugin");
assertPublishedArtifact(publishedContentDir, "test_plugin", "1.0.0");
try (Stream<String> stream = Files.lines(publishedContentDir.toPath().resolve("content.xml"))) {
long numberOfZippedArtifacts = stream.filter(lines -> lines.contains("zipped")).count();
assertEquals("only the feature should be marked as zipped", 1, numberOfZippedArtifacts);
} catch (IOException e) {
}
}

public void testPublisher() throws Exception {
File basedir = getBasedir("publisher/testProject");
List<MavenProject> projects = getSortedProjects(basedir);
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?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-extras-tests</groupId>
<artifactId>publishedRepositoryUNPACK</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>

<pluginRepositories>
<pluginRepository>
<id>tycho-snapshots</id>
<url>https://repo.eclipse.org/content/repositories/tycho-snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>

<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>
<compress>false</compress>
<!-- additional arguments example
<additionalArgs>-configs win32.win32.x86</additionalArgs>
-->
</configuration>
</plugin>
</plugins>
</build>

</project>

0 comments on commit 9eb705d

Please sign in to comment.