Author: jdcasey
Date: Tue Sep 18 06:21:21 2007
New Revision: 576898

URL: http://svn.apache.org/viewvc?rev=576898&view=rev
Log:
Adding a mojo to display the phases in a given lifecycle, whether 'build' (also 
called 'default'), 'site', or 'clean'.

Added:
    
maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/ShowLifecyclePhasesMojo.java
   (with props)
Modified:
    maven/sandbox/trunk/plugins/maven-lifecycle-plugin/pom.xml

Modified: maven/sandbox/trunk/plugins/maven-lifecycle-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-lifecycle-plugin/pom.xml?rev=576898&r1=576897&r2=576898&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-lifecycle-plugin/pom.xml (original)
+++ maven/sandbox/trunk/plugins/maven-lifecycle-plugin/pom.xml Tue Sep 18 
06:21:21 2007
@@ -40,17 +40,17 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-container-default</artifactId>
-      <version>1.0-alpha-24</version>
+      <version>1.0-alpha-30</version>
     </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-component-api</artifactId>
-      <version>1.0-alpha-24</version>
+      <version>1.0-alpha-30</version>
     </dependency>
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-utils</artifactId>
-      <version>1.4.1</version>
+      <version>1.4.5</version>
     </dependency>
     <dependency>
       <groupId>org.apache.maven</groupId>

Added: 
maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/ShowLifecyclePhasesMojo.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/ShowLifecyclePhasesMojo.java?rev=576898&view=auto
==============================================================================
--- 
maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/ShowLifecyclePhasesMojo.java
 (added)
+++ 
maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/ShowLifecyclePhasesMojo.java
 Tue Sep 18 06:21:21 2007
@@ -0,0 +1,83 @@
+package org.apache.maven.plugin.lifecycle;
+
+import org.apache.maven.lifecycle.model.LifecycleBinding;
+import org.apache.maven.lifecycle.model.LifecycleBindings;
+import org.apache.maven.plugin.Mojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Displays the phases of the lifecycle in order of execution.
+ *
+ * @goal show-lifecycle-phases
+ * @author jdcasey
+ *
+ */
+public class ShowLifecyclePhasesMojo
+    implements Mojo
+{
+
+    /**
+     * @parameter default-value="build"
+     */
+    private String lifecycle;
+
+    private Log log;
+
+    public void execute()
+        throws MojoExecutionException, MojoFailureException
+    {
+        LifecycleBindings bindings = new LifecycleBindings();
+        List bindingList = bindings.getBindingList();
+
+        LifecycleBinding referencedBinding = null;
+        for ( Iterator it = bindingList.iterator(); it.hasNext(); )
+        {
+            LifecycleBinding binding = (LifecycleBinding) it.next();
+            if ( lifecycle.equals( binding.getId() ) )
+            {
+                referencedBinding = binding;
+                break;
+            }
+            else if ( "default".equals( lifecycle ) && "build".equals( 
binding.getId() ) )
+            {
+                referencedBinding = binding;
+                break;
+            }
+        }
+
+        if ( referencedBinding == null )
+        {
+            throw new MojoFailureException( "Cannot find lifecycle with name: 
" + lifecycle, "Try \'build\' (also known as \'default\'), \'clean\', or 
\'site\'.", lifecycle );
+        }
+        else
+        {
+            StringBuffer sb = new StringBuffer( "Phases for lifecycle: " + 
referencedBinding.getId() + "(in order of execution):\n\n" );
+
+            int idx = 1;
+            for ( Iterator it = 
referencedBinding.getPhaseNamesInOrder().iterator(); it.hasNext(); )
+            {
+                String name = (String) it.next();
+                sb.append( idx ).append( ". " ).append( ( idx < 10 ? " " : "" 
) ).append( name ).append( '\n' );
+                idx++;
+            }
+
+            getLog().info( sb.toString() );
+        }
+    }
+
+    public Log getLog()
+    {
+        return log;
+    }
+
+    public void setLog( Log log )
+    {
+        this.log = log;
+    }
+
+}

Propchange: 
maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/ShowLifecyclePhasesMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/sandbox/trunk/plugins/maven-lifecycle-plugin/src/main/java/org/apache/maven/plugin/lifecycle/ShowLifecyclePhasesMojo.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"


Reply via email to