From 2a1080a57ca91cfd56bb41f851f0e4b3ae8fd99a Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 29 Jul 2021 09:23:50 +1000 Subject: [PATCH] Issue #201 assemble-maven-repository respect skip from maven-deploy-plugin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Olivier Lamy Signed-off-by: Christoph Läubrich --- .gitignore | 2 + .../deployme/META-INF/MANIFEST.MF | 8 ++ .../p2mavensite.reactor/deployme/pom.xml | 22 ++++ .../ignoreme-property/META-INF/MANIFEST.MF | 8 ++ .../ignoreme-property/pom.xml | 25 +++++ .../ignoreme/META-INF/MANIFEST.MF | 8 ++ .../p2mavensite.reactor/ignoreme/pom.xml | 35 ++++++ .../projects/p2mavensite.reactor/pom.xml | 17 +++ .../projects/p2mavensite.reactor/site/pom.xml | 55 +++++++++ .../test/p2Repository/MavenP2SiteTest.java | 14 +++ .../p2/repository/MavenP2SiteMojo.java | 106 ++++++++++++++++-- 11 files changed, 292 insertions(+), 8 deletions(-) create mode 100644 tycho-its/projects/p2mavensite.reactor/deployme/META-INF/MANIFEST.MF create mode 100644 tycho-its/projects/p2mavensite.reactor/deployme/pom.xml create mode 100644 tycho-its/projects/p2mavensite.reactor/ignoreme-property/META-INF/MANIFEST.MF create mode 100644 tycho-its/projects/p2mavensite.reactor/ignoreme-property/pom.xml create mode 100644 tycho-its/projects/p2mavensite.reactor/ignoreme/META-INF/MANIFEST.MF create mode 100644 tycho-its/projects/p2mavensite.reactor/ignoreme/pom.xml create mode 100644 tycho-its/projects/p2mavensite.reactor/pom.xml create mode 100644 tycho-its/projects/p2mavensite.reactor/site/pom.xml diff --git a/.gitignore b/.gitignore index 936ec28c96..8f7ab3af96 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ bin/ .project .classpath .settings/ +*.iml +.idea/ diff --git a/tycho-its/projects/p2mavensite.reactor/deployme/META-INF/MANIFEST.MF b/tycho-its/projects/p2mavensite.reactor/deployme/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..dcab379873 --- /dev/null +++ b/tycho-its/projects/p2mavensite.reactor/deployme/META-INF/MANIFEST.MF @@ -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 diff --git a/tycho-its/projects/p2mavensite.reactor/deployme/pom.xml b/tycho-its/projects/p2mavensite.reactor/deployme/pom.xml new file mode 100644 index 0000000000..40078d7da9 --- /dev/null +++ b/tycho-its/projects/p2mavensite.reactor/deployme/pom.xml @@ -0,0 +1,22 @@ + + + + + org.eclipse.tycho.it + issue-201-parent + 1.0.0 + + 4.0.0 + deployme + bundle + + + + org.apache.felix + maven-bundle-plugin + 5.1.2 + true + + + + diff --git a/tycho-its/projects/p2mavensite.reactor/ignoreme-property/META-INF/MANIFEST.MF b/tycho-its/projects/p2mavensite.reactor/ignoreme-property/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..a79068b680 --- /dev/null +++ b/tycho-its/projects/p2mavensite.reactor/ignoreme-property/META-INF/MANIFEST.MF @@ -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 diff --git a/tycho-its/projects/p2mavensite.reactor/ignoreme-property/pom.xml b/tycho-its/projects/p2mavensite.reactor/ignoreme-property/pom.xml new file mode 100644 index 0000000000..a97b9a3a88 --- /dev/null +++ b/tycho-its/projects/p2mavensite.reactor/ignoreme-property/pom.xml @@ -0,0 +1,25 @@ + + + + + org.eclipse.tycho.it + issue-201-parent + 1.0.0 + + 4.0.0 + ignoreme-property + bundle + + true + + + + + org.apache.felix + maven-bundle-plugin + 5.1.2 + true + + + + diff --git a/tycho-its/projects/p2mavensite.reactor/ignoreme/META-INF/MANIFEST.MF b/tycho-its/projects/p2mavensite.reactor/ignoreme/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..e960eea13b --- /dev/null +++ b/tycho-its/projects/p2mavensite.reactor/ignoreme/META-INF/MANIFEST.MF @@ -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 diff --git a/tycho-its/projects/p2mavensite.reactor/ignoreme/pom.xml b/tycho-its/projects/p2mavensite.reactor/ignoreme/pom.xml new file mode 100644 index 0000000000..c6ba268d15 --- /dev/null +++ b/tycho-its/projects/p2mavensite.reactor/ignoreme/pom.xml @@ -0,0 +1,35 @@ + + + + + org.eclipse.tycho.it + issue-201-parent + 1.0.0 + + 4.0.0 + ignoreme + bundle + + + + + org.apache.maven.plugins + maven-deploy-plugin + 3.0.0-M1 + + true + + + + + + + org.apache.felix + maven-bundle-plugin + 5.1.2 + true + + + + + diff --git a/tycho-its/projects/p2mavensite.reactor/pom.xml b/tycho-its/projects/p2mavensite.reactor/pom.xml new file mode 100644 index 0000000000..a384c7f95e --- /dev/null +++ b/tycho-its/projects/p2mavensite.reactor/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + org.eclipse.tycho.it + issue-201-parent + 1.0.0 + pom + + 2.5.0-SNAPSHOT + + + site + deployme + ignoreme + ignoreme-property + + diff --git a/tycho-its/projects/p2mavensite.reactor/site/pom.xml b/tycho-its/projects/p2mavensite.reactor/site/pom.xml new file mode 100644 index 0000000000..b9cdc97a3d --- /dev/null +++ b/tycho-its/projects/p2mavensite.reactor/site/pom.xml @@ -0,0 +1,55 @@ + + + + + org.eclipse.tycho.it + issue-201-parent + 1.0.0 + + 4.0.0 + update-site + pom + + + + org.eclipse.tycho + tycho-p2-repository-plugin + ${tycho-version} + + + + Reactor Bundles + false + false + true + false + + maven-p2-site + package + + assemble-maven-repository + + + + + + + + + org.eclipse.tycho.it + deployme + ${project.version} + + + org.eclipse.tycho.it + ignoreme + ${project.version} + + + org.eclipse.tycho.it + ignoreme-property + ${project.version} + + + + diff --git a/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/MavenP2SiteTest.java b/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/MavenP2SiteTest.java index 995dc6b009..0eeb5b6f1c 100644 --- a/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/MavenP2SiteTest.java +++ b/tycho-its/src/test/java/org/eclipse/tycho/test/p2Repository/MavenP2SiteTest.java @@ -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; @@ -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'")); + } } diff --git a/tycho-p2/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/MavenP2SiteMojo.java b/tycho-p2/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/MavenP2SiteMojo.java index 914995ed78..b3283f6b90 100644 --- a/tycho-p2/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/MavenP2SiteMojo.java +++ b/tycho-p2/tycho-p2-repository-plugin/src/main/java/org/eclipse/tycho/plugins/p2/repository/MavenP2SiteMojo.java @@ -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; @@ -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; @@ -188,18 +192,11 @@ public void execute() throws MojoExecutionException, MojoFailureException { if (includeReactor) { List 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)); } @@ -407,4 +404,97 @@ public String getClassifier() { return null; } + /** + * + * @return true 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 true 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 param key + * or null 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 ${project.build.plugins} or in + * ${project.build.pluginManagement}, or null 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; + } + }