You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2020/06/27 19:37:06 UTC
[maven-artifact-plugin] branch master updated: extract PluginUtil
This is an automated email from the ASF dual-hosted git repository.
hboutemy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-artifact-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new f193f87 extract PluginUtil
f193f87 is described below
commit f193f875cc80fa4baba57e69a29e1ac56c653ddf
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Sat Jun 27 21:36:57 2020 +0200
extract PluginUtil
---
.../plugins/artifact/buildinfo/BuildinfoMojo.java | 56 +--------------
.../plugins/artifact/buildinfo/PluginUtil.java | 80 ++++++++++++++++++++++
2 files changed, 83 insertions(+), 53 deletions(-)
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildinfoMojo.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildinfoMojo.java
index 9d0a671..81ddb02 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildinfoMojo.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildinfoMojo.java
@@ -22,7 +22,6 @@ package org.apache.maven.plugins.artifact.buildinfo;
import org.apache.commons.codec.Charsets;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -34,7 +33,6 @@ import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectHelper;
import org.apache.maven.shared.utils.logging.MessageUtils;
import org.codehaus.plexus.util.StringUtils;
-import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.eclipse.aether.RepositorySystem;
import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
@@ -148,7 +146,7 @@ public class BuildinfoMojo
if ( !mono )
{
// if module skips install and/or deploy
- if ( isSkip( project ) )
+ if ( PluginUtil.isSkip( project ) )
{
getLog().info( "Skipping buildinfo for module that skips install and/or deploy" );
return;
@@ -215,7 +213,7 @@ public class BuildinfoMojo
{
for ( MavenProject project : reactorProjects )
{
- if ( !isSkip( project ) )
+ if ( !PluginUtil.isSkip( project ) )
{
bi.printArtifacts( project );
}
@@ -427,59 +425,11 @@ public class BuildinfoMojo
while ( i > 0 )
{
MavenProject project = reactorProjects.get( --i );
- if ( !isSkip( project ) )
+ if ( !PluginUtil.isSkip( project ) )
{
return project;
}
}
return null;
}
-
- private static boolean isSkip( MavenProject project )
- {
- return isSkip( project, "install" ) || isSkip( project, "deploy" );
- }
-
- private static boolean isSkip( MavenProject project, String id )
- {
- Plugin plugin = getPlugin( project, "org.apache.maven.plugins:maven-" + id + "-plugin" );
- String skip = getPluginParameter( plugin, "skip" );
- if ( skip == null )
- {
- skip = project.getProperties().getProperty( "maven." + id + ".skip" );
- }
- return Boolean.valueOf( skip );
- }
-
- private static Plugin getPlugin( MavenProject project, String plugin )
- {
- Map<String, Plugin> pluginsAsMap = project.getBuild().getPluginsAsMap();
- Plugin result = pluginsAsMap.get( plugin );
- if ( result == null )
- {
- pluginsAsMap = project.getPluginManagement().getPluginsAsMap();
- result = pluginsAsMap.get( plugin );
- }
- return result;
- }
-
- private static String getPluginParameter( Plugin plugin, String parameter )
- {
- if ( plugin != null )
- {
- Xpp3Dom pluginConf = (Xpp3Dom) plugin.getConfiguration();
-
- if ( pluginConf != null )
- {
- Xpp3Dom target = pluginConf.getChild( parameter );
-
- if ( target != null )
- {
- return target.getValue();
- }
- }
- }
-
- return null;
- }
}
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/PluginUtil.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/PluginUtil.java
new file mode 100644
index 0000000..369dd8d
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/PluginUtil.java
@@ -0,0 +1,80 @@
+package org.apache.maven.plugins.artifact.buildinfo;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.Map;
+
+import org.apache.maven.model.Plugin;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+/**
+ * Plugin utility to detect if install or deploy is skipped in a build.
+ */
+public class PluginUtil
+{
+ public static boolean isSkip( MavenProject project )
+ {
+ return isSkip( project, "install" ) || isSkip( project, "deploy" );
+ }
+
+ private static boolean isSkip( MavenProject project, String id )
+ {
+ Plugin plugin = getPlugin( project, "org.apache.maven.plugins:maven-" + id + "-plugin" );
+ String skip = getPluginParameter( plugin, "skip" );
+ if ( skip == null )
+ {
+ skip = project.getProperties().getProperty( "maven." + id + ".skip" );
+ }
+ return Boolean.valueOf( skip );
+ }
+
+ private static Plugin getPlugin( MavenProject project, String plugin )
+ {
+ Map<String, Plugin> pluginsAsMap = project.getBuild().getPluginsAsMap();
+ Plugin result = pluginsAsMap.get( plugin );
+ if ( result == null )
+ {
+ pluginsAsMap = project.getPluginManagement().getPluginsAsMap();
+ result = pluginsAsMap.get( plugin );
+ }
+ return result;
+ }
+
+ private static String getPluginParameter( Plugin plugin, String parameter )
+ {
+ if ( plugin != null )
+ {
+ Xpp3Dom pluginConf = (Xpp3Dom) plugin.getConfiguration();
+
+ if ( pluginConf != null )
+ {
+ Xpp3Dom target = pluginConf.getChild( parameter );
+
+ if ( target != null )
+ {
+ return target.getValue();
+ }
+ }
+ }
+
+ return null;
+ }
+}