Repository: maven
Updated Branches:
  refs/heads/master d8ae13fd7 -> 1d148be82


MNG-5805: Custom packaging types: configuring DefaultLifecycleMapping mojo 
executions

Signed-off-by: Jason van Zyl <ja...@tesla.io>


Project: http://git-wip-us.apache.org/repos/asf/maven/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/1d148be8
Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/1d148be8
Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/1d148be8

Branch: refs/heads/master
Commit: 1d148be82bcf3e16c01477d412f4f9206445a7aa
Parents: d8ae13f
Author: Anton Tanasenko <atg.sleepl...@gmail.com>
Authored: Sat Apr 18 22:01:16 2015 +0300
Committer: Jason van Zyl <ja...@tesla.io>
Committed: Mon Apr 27 17:28:37 2015 -0400

----------------------------------------------------------------------
 .../org/apache/maven/lifecycle/Lifecycle.java   |  8 +-
 .../DefaultLifecyclePluginAnalyzer.java         | 89 +++++++++++---------
 .../mapping/DefaultLifecycleMapping.java        |  6 +-
 .../maven/lifecycle/mapping/Lifecycle.java      |  6 +-
 .../lifecycle/mapping/LifecycleMapping.java     |  2 +-
 .../maven/lifecycle/mapping/LifecycleMojo.java  | 63 ++++++++++++++
 .../maven/lifecycle/mapping/LifecyclePhase.java | 64 ++++++++++++++
 7 files changed, 186 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven/blob/1d148be8/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java
----------------------------------------------------------------------
diff --git a/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java 
b/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java
index fcfde95..54aefc4 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/Lifecycle.java
@@ -22,6 +22,8 @@ package org.apache.maven.lifecycle;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.maven.lifecycle.mapping.LifecyclePhase;
+
 /**
  * Class Lifecycle.
  */
@@ -31,7 +33,7 @@ public class Lifecycle
     {
     }
 
-    public Lifecycle( String id, List<String> phases, Map<String, String> 
defaultPhases )
+    public Lifecycle( String id, List<String> phases, Map<String, 
LifecyclePhase> defaultPhases )
     {
         this.id = id;
         this.phases = phases;
@@ -54,7 +56,7 @@ public class Lifecycle
 
     private List<String> phases;
 
-    private Map<String, String> defaultPhases;
+    private Map<String, LifecyclePhase> defaultPhases;
 
     public String getId()
     {
@@ -66,7 +68,7 @@ public class Lifecycle
         return this.phases;
     }
 
-    public Map<String, String> getDefaultPhases()
+    public Map<String, LifecyclePhase> getDefaultPhases()
     {
         return defaultPhases;
     }

http://git-wip-us.apache.org/repos/asf/maven/blob/1d148be8/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java
 
b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java
index a5e6a34..52f3e85 100644
--- 
a/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java
+++ 
b/maven-core/src/main/java/org/apache/maven/lifecycle/internal/DefaultLifecyclePluginAnalyzer.java
@@ -23,6 +23,8 @@ import org.apache.maven.lifecycle.DefaultLifecycles;
 import org.apache.maven.lifecycle.LifeCyclePluginAnalyzer;
 import org.apache.maven.lifecycle.Lifecycle;
 import org.apache.maven.lifecycle.mapping.LifecycleMapping;
+import org.apache.maven.lifecycle.mapping.LifecycleMojo;
+import org.apache.maven.lifecycle.mapping.LifecyclePhase;
 import org.apache.maven.model.Plugin;
 import org.apache.maven.model.PluginExecution;
 import org.codehaus.plexus.component.annotations.Component;
@@ -98,7 +100,7 @@ public class DefaultLifecyclePluginAnalyzer
             org.apache.maven.lifecycle.mapping.Lifecycle 
lifecycleConfiguration =
                 lifecycleMappingForPackaging.getLifecycles().get( 
lifecycle.getId() );
 
-            Map<String, String> phaseToGoalMapping = null;
+            Map<String, LifecyclePhase> phaseToGoalMapping = null;
 
             if ( lifecycleConfiguration != null )
             {
@@ -111,14 +113,10 @@ public class DefaultLifecyclePluginAnalyzer
 
             if ( phaseToGoalMapping != null )
             {
-                // These are of the form:
-                //
-                // compile -> 
org.apache.maven.plugins:maven-compiler-plugin:compile[,gid:aid:goal,...]
-                //
-                for ( Map.Entry<String, String> goalsForLifecyclePhase : 
phaseToGoalMapping.entrySet() )
+                for ( Map.Entry<String, LifecyclePhase> goalsForLifecyclePhase 
: phaseToGoalMapping.entrySet() )
                 {
                     String phase = goalsForLifecyclePhase.getKey();
-                    String goals = goalsForLifecyclePhase.getValue();
+                    LifecyclePhase goals = goalsForLifecyclePhase.getValue();
                     if ( goals != null )
                     {
                         parseLifecyclePhaseDefinitions( plugins, phase, goals 
);
@@ -149,47 +147,54 @@ public class DefaultLifecyclePluginAnalyzer
         return lifecycles;
     }
 
-    private void parseLifecyclePhaseDefinitions( Map<Plugin, Plugin> plugins, 
String phase, String goals )
+    private void parseLifecyclePhaseDefinitions( Map<Plugin, Plugin> plugins, 
String phase, LifecyclePhase goals )
     {
-        String[] mojos = StringUtils.split( goals, "," );
-
-        for ( int i = 0; i < mojos.length; i++ )
+        List<LifecycleMojo> mojos = goals.getMojos();
+        if ( mojos != null )
         {
-            GoalSpec gs = parseGoalSpec( mojos[i].trim() );
-
-            if ( gs == null )
-            {
-                logger.warn( "Ignored invalid goal specification '" + mojos[i] 
+ "' from lifecycle mapping for phase "
-                    + phase );
-                continue;
-            }
-
-            Plugin plugin = new Plugin();
-            plugin.setGroupId( gs.groupId );
-            plugin.setArtifactId( gs.artifactId );
-            plugin.setVersion( gs.version );
-
-            Plugin existing = plugins.get( plugin );
-            if ( existing != null )
+            
+            for ( int i = 0; i < mojos.size(); i++ )
             {
-                if ( existing.getVersion() == null )
+                LifecycleMojo mojo = mojos.get( i );
+                
+                GoalSpec gs = parseGoalSpec( mojo.getGoal() );
+    
+                if ( gs == null )
                 {
-                    existing.setVersion( plugin.getVersion() );
+                    logger.warn( "Ignored invalid goal specification '" + 
mojo.getGoal()
+                            + "' from lifecycle mapping for phase " + phase );
+                    continue;
                 }
-                plugin = existing;
-            }
-            else
-            {
-                plugins.put( plugin, plugin );
+    
+                Plugin plugin = new Plugin();
+                plugin.setGroupId( gs.groupId );
+                plugin.setArtifactId( gs.artifactId );
+                plugin.setVersion( gs.version );
+    
+                Plugin existing = plugins.get( plugin );
+                if ( existing != null )
+                {
+                    if ( existing.getVersion() == null )
+                    {
+                        existing.setVersion( plugin.getVersion() );
+                    }
+                    plugin = existing;
+                }
+                else
+                {
+                    plugins.put( plugin, plugin );
+                }
+    
+                PluginExecution execution = new PluginExecution();
+                execution.setId( getExecutionId( plugin, gs.goal ) );
+                execution.setPhase( phase );
+                execution.setPriority( i - mojos.size() );
+                execution.getGoals().add( gs.goal );
+                execution.setConfiguration( mojo.getConfiguration() );
+                
+                plugin.setDependencies( mojo.getDependencies() );
+                plugin.getExecutions().add( execution );
             }
-
-            PluginExecution execution = new PluginExecution();
-            execution.setId( getExecutionId( plugin, gs.goal ) );
-            execution.setPhase( phase );
-            execution.setPriority( i - mojos.length );
-            execution.getGoals().add( gs.goal );
-
-            plugin.getExecutions().add( execution );
         }
     }
 

http://git-wip-us.apache.org/repos/asf/maven/blob/1d148be8/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java
 
b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java
index 9947e2f..d3e11fd 100644
--- 
a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java
+++ 
b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/DefaultLifecycleMapping.java
@@ -32,7 +32,7 @@ public class DefaultLifecycleMapping
     private Map<String, Lifecycle> lifecycleMap;
 
     /** @deprecated use lifecycles instead */
-    private Map<String, String> phases;
+    private Map<String, LifecyclePhase> phases;
 
     /**
      * Populates the lifecycle map from the injected list of lifecycle 
mappings (if not already done).
@@ -61,7 +61,7 @@ public class DefaultLifecycleMapping
 
                 for ( String lifecycleId : lifecycleIds )
                 {
-                    Map<String, String> phases = getPhases( lifecycleId );
+                    Map<String, LifecyclePhase> phases = getPhases( 
lifecycleId );
                     if ( phases != null )
                     {
                         Lifecycle lifecycle = new Lifecycle();
@@ -88,7 +88,7 @@ public class DefaultLifecycleMapping
         return null;
     }
 
-    public Map<String, String> getPhases( String lifecycle )
+    public Map<String, LifecyclePhase> getPhases( String lifecycle )
     {
         initLifecycleMap();
 

http://git-wip-us.apache.org/repos/asf/maven/blob/1d148be8/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java 
b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java
index 6adf4f3..c80ed2f 100644
--- a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java
+++ b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/Lifecycle.java
@@ -35,7 +35,7 @@ public class Lifecycle
     /**
      * Field phases
      */
-    private Map<String, String> phases;
+    private Map<String, LifecyclePhase> phases;
 
     /*
      * NOTE: This exists merely for backward-compat with legacy-style 
lifecycle definitions and allows configuration
@@ -55,7 +55,7 @@ public class Lifecycle
     /**
      * Method getPhases
      */
-    public Map<String, String> getPhases()
+    public Map<String, LifecyclePhase> getPhases()
     {
         return this.phases;
     }
@@ -75,7 +75,7 @@ public class Lifecycle
      *
      * @param phases
      */
-    public void setPhases( Map<String, String> phases )
+    public void setPhases( Map<String, LifecyclePhase> phases )
     {
         this.phases = phases;
     } //-- void setPhases(java.util.List)

http://git-wip-us.apache.org/repos/asf/maven/blob/1d148be8/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java
 
b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java
index e656cc9..3248f70 100644
--- 
a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java
+++ 
b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMapping.java
@@ -34,6 +34,6 @@ public interface LifecycleMapping
     List<String> getOptionalMojos( String lifecycle );
 
     @Deprecated
-    Map<String, String> getPhases( String lifecycle );
+    Map<String, LifecyclePhase> getPhases( String lifecycle );
 
 }

http://git-wip-us.apache.org/repos/asf/maven/blob/1d148be8/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMojo.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMojo.java
 
b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMojo.java
new file mode 100644
index 0000000..f2af879
--- /dev/null
+++ 
b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecycleMojo.java
@@ -0,0 +1,63 @@
+package org.apache.maven.lifecycle.mapping;
+
+/*
+ * 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.List;
+
+import org.apache.maven.model.Dependency;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+public class LifecycleMojo
+{
+    
+    private String goal;
+    private Xpp3Dom configuration;
+    private List<Dependency> dependencies;
+    
+    public String getGoal()
+    {
+        return goal;
+    }
+    
+    public Xpp3Dom getConfiguration()
+    {
+        return configuration;
+    }
+    
+    public List<Dependency> getDependencies()
+    {
+        return dependencies;
+    }
+    
+    public void setGoal( String goal )
+    {
+        this.goal = goal;
+    }
+    
+    public void setConfiguration( Xpp3Dom configuration )
+    {
+        this.configuration = configuration;
+    }
+    
+    public void setDependencies( List<Dependency> dependencies )
+    {
+        this.dependencies = dependencies;
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven/blob/1d148be8/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java
----------------------------------------------------------------------
diff --git 
a/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java
 
b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java
new file mode 100644
index 0000000..a68a71c
--- /dev/null
+++ 
b/maven-core/src/main/java/org/apache/maven/lifecycle/mapping/LifecyclePhase.java
@@ -0,0 +1,64 @@
+package org.apache.maven.lifecycle.mapping;
+
+/*
+ * 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.ArrayList;
+import java.util.List;
+
+import org.codehaus.plexus.util.StringUtils;
+
+public class LifecyclePhase
+{
+    
+    private List<LifecycleMojo> mojos;
+    
+    public LifecyclePhase()
+    {
+    }
+    
+    public LifecyclePhase( String goals )
+    {
+        set( goals );
+    }
+    
+    public List<LifecycleMojo> getMojos()
+    {
+        return mojos;
+    }
+    
+    public void setMojos( List<LifecycleMojo> mojos )
+    {
+        this.mojos = mojos;
+    }
+    
+    public void set( String goals )
+    {
+        mojos = new ArrayList<LifecycleMojo>();
+        
+        String[] mojoGoals = StringUtils.split( goals, "," );
+        
+        for ( String mojoGoal: mojoGoals )
+        {
+            LifecycleMojo lifecycleMojo = new LifecycleMojo();
+            lifecycleMojo.setGoal( mojoGoal.trim() );
+            mojos.add( lifecycleMojo );
+        }
+    }
+}

Reply via email to