Skip to content

Commit

Permalink
Merge pull request #204 from olamy/assemble-maven-repository-respect-…
Browse files Browse the repository at this point in the history
…skip-from-maven-deploy-plugin

Issue #201 assemble-maven-repository respect skip from maven-deploy-plugin
  • Loading branch information
laeubi committed Aug 16, 2021
2 parents e3fb31d + 2a1080a commit 66bcbff
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -3,3 +3,5 @@ bin/
.project
.classpath
.settings/
*.iml
.idea/
@@ -0,0 +1,8 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test-mvn-updatesite-reactor-deployme
Bundle-SymbolicName: test.mvn.updatesite.reactor.deployme
Bundle-Version: 1.0.0
Automatic-Module-Name: test.mvn.updatesite.reactor.deployme
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.jetty.http
22 changes: 22 additions & 0 deletions tycho-its/projects/p2mavensite.reactor/deployme/pom.xml
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>

<parent>
<groupId>org.eclipse.tycho.it</groupId>
<artifactId>issue-201-parent</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>deployme</artifactId>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.2</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,8 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test-mvn-updatesite-reactor-ignoreme-property
Bundle-SymbolicName: test.mvn.updatesite.reactor.ignoreme.property
Bundle-Version: 1.0.0
Automatic-Module-Name: test.mvn.updatesite.reactor.ignoreme.property
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.jetty.http
25 changes: 25 additions & 0 deletions tycho-its/projects/p2mavensite.reactor/ignoreme-property/pom.xml
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>

<parent>
<groupId>org.eclipse.tycho.it</groupId>
<artifactId>issue-201-parent</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ignoreme-property</artifactId>
<packaging>bundle</packaging>
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.2</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,8 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test-mvn-updatesite-reactor-ignoreme
Bundle-SymbolicName: test.mvn.updatesite.reactor.ignoreme
Bundle-Version: 1.0.0
Automatic-Module-Name: test.mvn.updatesite.reactor.ignoreme
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.jetty.http
35 changes: 35 additions & 0 deletions tycho-its/projects/p2mavensite.reactor/ignoreme/pom.xml
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>

<parent>
<groupId>org.eclipse.tycho.it</groupId>
<artifactId>issue-201-parent</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ignoreme</artifactId>
<packaging>bundle</packaging>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>5.1.2</version>
<extensions>true</extensions>
</plugin>
</plugins>
<!-- TODO configure deploy plugin with SKIP = true -->
</build>
</project>
17 changes: 17 additions & 0 deletions tycho-its/projects/p2mavensite.reactor/pom.xml
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.tycho.it</groupId>
<artifactId>issue-201-parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<properties>
<tycho-version>2.5.0-SNAPSHOT</tycho-version>
</properties>
<modules>
<module>site</module>
<module>deployme</module>
<module>ignoreme</module>
<module>ignoreme-property</module>
</modules>
</project>
55 changes: 55 additions & 0 deletions tycho-its/projects/p2mavensite.reactor/site/pom.xml
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>

<parent>
<groupId>org.eclipse.tycho.it</groupId>
<artifactId>issue-201-parent</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>update-site</artifactId>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<executions>
<execution>
<configuration>
<categoryName>Reactor Bundles</categoryName>
<includeManaged>false</includeManaged>
<includeDependencies>false</includeDependencies>
<includeReactor>true</includeReactor>
<includeTransitiveDependencies>false</includeTransitiveDependencies>
</configuration>
<id>maven-p2-site</id>
<phase>package</phase>
<goals>
<goal>assemble-maven-repository</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.tycho.it</groupId>
<artifactId>deployme</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.tycho.it</groupId>
<artifactId>ignoreme</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.tycho.it</groupId>
<artifactId>ignoreme-property</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

</project>
Expand Up @@ -10,10 +10,12 @@
package org.eclipse.tycho.test.p2Repository;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.io.File;

import org.apache.commons.io.FileUtils;
import org.apache.maven.it.Verifier;
import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
import org.junit.Test;
Expand Down Expand Up @@ -41,4 +43,16 @@ public void testProduceConsume() throws Exception {
verifier.verifyErrorFreeLog();
}
}

@Test
public void testDeployIgnore() throws Exception {
Verifier verifier = getVerifier("p2mavensite.reactor", false);
verifier.executeGoals(asList("install"));
verifier.verifyErrorFreeLog();
String artifacts = FileUtils
.readFileToString(new File(verifier.getBasedir(), "site/target/repository/artifacts.xml"), "UTF-8");
assertTrue("artifact to deploy is missing", artifacts.contains("id='org.eclipse.tycho.it.deployme'"));
assertFalse("artifact is deployed but should't", artifacts.contains("id='org.eclipse.tycho.it.ignoreme'"));
assertFalse("artifact is deployed but should't", artifacts.contains("id='org.eclipse.tycho.it.ignoreme-property'"));
}
}
Expand Up @@ -26,12 +26,15 @@
import java.util.stream.Collectors;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
Expand All @@ -45,6 +48,7 @@
import org.codehaus.plexus.archiver.util.DefaultFileSet;
import org.codehaus.plexus.archiver.zip.ZipArchiver;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.eclipse.sisu.equinox.EquinoxServiceFactory;
import org.eclipse.sisu.equinox.launching.internal.P2ApplicationLauncher;
import org.eclipse.tycho.p2.repository.RepositoryLayoutHelper;
Expand Down Expand Up @@ -188,18 +192,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
if (includeReactor) {
List<MavenProject> allProjects = session.getAllProjects();
for (MavenProject mavenProject : allProjects) {
String packaging = mavenProject.getPackaging();
if (packaging.equalsIgnoreCase("pom")) {
if (skipProject(mavenProject)) {
continue;
}
Artifact artifact = mavenProject.getArtifact();
if (artifact == null) {
continue;
}
File file = artifact.getFile();
if (file == null || !file.isFile()) {
continue;
}
bundles.add(file);
advices.add(createMavenAdvice(artifact));
}
Expand Down Expand Up @@ -407,4 +404,97 @@ public String getClassifier() {
return null;
}

/**
*
* @return <code>true</code> if this project should not be packaged in the p2 site
*/
protected boolean skipProject(MavenProject mavenProject) {
String packaging = mavenProject.getPackaging();
if (packaging.equalsIgnoreCase("pom")) {
return true;
}
Artifact artifact = mavenProject.getArtifact();
if (artifact == null) {
return true;
}
File file = artifact.getFile();
if (file == null || !file.isFile()) {
return true;
}
if (isSkippedDeploy(mavenProject)){
return true;
}
return false;
}

/**
*
* @return <code>true</code> if the pom configuration skip deploy for the project
*/
protected boolean isSkippedDeploy(MavenProject mavenProject) {
String property = mavenProject.getProperties().getProperty("maven.deploy.skip");
if (property != null) {
boolean skip = BooleanUtils.toBoolean(property);
getLog().debug("deploy is " + (skip?"":"not") + " skipped in MavenProject "
+ mavenProject.getName() + " because of property 'maven.deploy.skip'");
return skip;
}
String pluginId = "org.apache.maven.plugins:maven-deploy-plugin";
property = getPluginParameter(mavenProject, pluginId, "skip");
if (property != null) {
boolean skip = BooleanUtils.toBoolean(property);
getLog().debug("deploy is " + (skip?"":"not") + " skipped in MavenProject "
+ mavenProject.getName() + " because of configuration of the plugin 'org.apache.maven.plugins:maven-deploy-plugin'");
return skip;
}
if (mavenProject.getParent() != null) {
return isSkippedDeploy(mavenProject.getParent());
}
getLog().debug("not skipping deploy of MavenProject '" + mavenProject.getName() + "'");
return false;
}

/**
* @param p not null
* @param pluginId not null
* @param param not null
* @return the simple parameter as String defined in the plugin configuration by <code>param</code> key
* or <code>null</code> if not found.
* @since 2.6
*/
private static String getPluginParameter(MavenProject p, String pluginId, String param) {
Plugin plugin = getPlugin(p, pluginId);
if (plugin != null) {
Xpp3Dom xpp3Dom = (Xpp3Dom) plugin.getConfiguration();
if (xpp3Dom != null && xpp3Dom.getChild(param) != null
&& StringUtils.isNotEmpty(xpp3Dom.getChild( param ).getValue())) {
return xpp3Dom.getChild(param).getValue();
}
}

return null;
}

/**
* @param p not null
* @param pluginId not null key of the plugin defined in {@link org.apache.maven.model.Build#getPluginsAsMap()}
* or in {@link org.apache.maven.model.PluginManagement#getPluginsAsMap()}
* @return the Maven plugin defined in <code>${project.build.plugins}</code> or in
* <code>${project.build.pluginManagement}</code>, or <code>null</code> if not defined.
*/
private static Plugin getPlugin(MavenProject p, String pluginId) {
if ((p.getBuild() == null) || (p.getBuild().getPluginsAsMap() == null)) {
return null;
}

Plugin plugin = p.getBuild().getPluginsAsMap().get(pluginId);

if ((plugin == null) && (p.getBuild().getPluginManagement() != null) &&
(p.getBuild().getPluginManagement().getPluginsAsMap() != null)) {
plugin = p.getBuild().getPluginManagement().getPluginsAsMap().get(pluginId);
}

return plugin;
}

}

0 comments on commit 66bcbff

Please sign in to comment.