You are viewing a plain text version of this content. The canonical link for it is here.
Posted to npanday-commits@incubator.apache.org by lc...@apache.org on 2011/02/28 12:43:16 UTC

svn commit: r1075315 - in /incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main: groovy/npanday/plugin/customlifecycle/ java/ java/npanday/ java/npanday/plugin/ java/npanday/plugin/customLifecycle/

Author: lcorneliussen
Date: Mon Feb 28 12:43:15 2011
New Revision: 1075315

URL: http://svn.apache.org/viewvc?rev=1075315&view=rev
Log:
[NPANDAY-373] now by default binding (finalName) + (packaging extension) in target dir - if it exists

Added:
    incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/java/
    incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/java/npanday/
    incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/java/npanday/plugin/
    incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/java/npanday/plugin/customLifecycle/
    incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/java/npanday/plugin/customLifecycle/SetArtifactMojo.java
Modified:
    incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/groovy/npanday/plugin/customlifecycle/CustomLifecycleMap.groovy

Modified: incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/groovy/npanday/plugin/customlifecycle/CustomLifecycleMap.groovy
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/groovy/npanday/plugin/customlifecycle/CustomLifecycleMap.groovy?rev=1075315&r1=1075314&r2=1075315&view=diff
==============================================================================
--- incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/groovy/npanday/plugin/customlifecycle/CustomLifecycleMap.groovy (original)
+++ incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/groovy/npanday/plugin/customlifecycle/CustomLifecycleMap.groovy Mon Feb 28 12:43:15 2011
@@ -36,12 +36,14 @@ import static LifecycleMappingBuilder.bu
  */
 class CustomLifecycleMap extends LifecycleMap
 {
+    def self_setArtifact = 'npanday.plugin:custom-lifecycle-maven-plugin:set-artifact'
 	def mv_install = 'org.apache.maven.plugins:maven-install-plugin:install'
 	def mv_deploy = 'org.apache.maven.plugins:maven-deploy-plugin:deploy'
 	
 	void defineMappings() {
-	    def phases = {LifecycleMappingBuilder b -> 
-			b.install( mv_install )
+	    def phases = {LifecycleMappingBuilder b ->
+            b._package( self_setArtifact )
+            b.install( mv_install )
 			b.deploy( mv_deploy )
 		}
 		

Added: incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/java/npanday/plugin/customLifecycle/SetArtifactMojo.java
URL: http://svn.apache.org/viewvc/incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/java/npanday/plugin/customLifecycle/SetArtifactMojo.java?rev=1075315&view=auto
==============================================================================
--- incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/java/npanday/plugin/customLifecycle/SetArtifactMojo.java (added)
+++ incubator/npanday/trunk/plugins/custom-lifecycle-maven-plugin/src/main/java/npanday/plugin/customLifecycle/SetArtifactMojo.java Mon Feb 28 12:43:15 2011
@@ -0,0 +1,63 @@
+package npanday.plugin.customLifecycle;
+
+import npanday.ArtifactType;
+import npanday.ArtifactTypeHelper;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+
+import java.io.File;
+
+/**
+ * If an artifact with final name is found, it is added.
+ *
+ * @author Lars Corneliussen
+ * @goal set-artifact
+ * @phase package
+ */
+public class SetArtifactMojo
+        extends AbstractMojo
+{
+
+    /**
+     * The maven project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     */
+    protected MavenProject project;
+
+    /** @parameter default-value="false" */
+    protected boolean skip;
+
+    public void execute() throws MojoExecutionException, MojoFailureException {
+
+        if (skip)  {
+            return;
+        }
+
+        if (project.getArtifact().getFile() != null) {
+            getLog().debug("NPANDAY-105-004: Execution skipped, because the artifact file is already set: "
+                    + project.getArtifact().getFile().getAbsolutePath() );
+            return;
+        }
+
+        String outputDirectory = project.getBuild().getDirectory();
+        String finalName = project.getBuild().getFinalName();
+        ArtifactType type = ArtifactType.getArtifactTypeForPackagingName(project.getPackaging());
+
+        if (type == ArtifactType.NULL) {
+            throw new MojoFailureException("NPANDAY-105-000: Packaging " + project.getPackaging() + " is not supported by this Mojo!");
+        }
+
+        File artifact = new File(outputDirectory, finalName + "." + type.getExtension());
+        if (!artifact.exists()) {
+            getLog().warn("NPANDAY-105-001: Could not set expected artifact to '" + artifact.getAbsolutePath() + "', because it does not exist");
+            return;
+        }
+
+        getLog().debug("NPANDAY-105-003: Set the artifact file to '" + artifact.getAbsolutePath() + "'.");
+        project.getArtifact().setFile(artifact);
+    }
+}