continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From epunza...@apache.org
Subject svn commit: r441469 - in /maven/continuum/branches/release-integration/maven/maven-release-plugin/src: main/java/org/apache/maven/plugins/release/ main/resources/META-INF/plexus/ test/resources/org/apache/maven/plugins/release/
Date Fri, 08 Sep 2006 10:50:10 GMT
Author: epunzalan
Date: Fri Sep  8 03:50:09 2006
New Revision: 441469

URL: http://svn.apache.org/viewvc?view=rev&rev=441469
Log:
PR: CONTINUUM-727

added support for listeners
added todo for release:perform phases

Added:
    maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/ReleaseManagerListener.java
  (with props)
Modified:
    maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/DefaultReleaseManager.java
    maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/ReleaseManager.java
    maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml
    maven/continuum/branches/release-integration/maven/maven-release-plugin/src/test/resources/org/apache/maven/plugins/release/DefaultReleaseManagerTest.xml

Modified: maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/DefaultReleaseManager.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/DefaultReleaseManager.java?view=diff&rev=441469&r1=441468&r2=441469
==============================================================================
--- maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/DefaultReleaseManager.java
(original)
+++ maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/DefaultReleaseManager.java
Fri Sep  8 03:50:09 2006
@@ -42,6 +42,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.ArrayList;
 
 /**
  * Implementation of the release manager.
@@ -55,7 +56,10 @@
     /**
      * The phases of release to run, and in what order.
      */
-    private List phases;
+    private List preparePhases;
+
+    //todo implement
+    private List performPhases;
 
     /**
      * The available phases.
@@ -77,6 +81,11 @@
      */
     private MavenExecutor mavenExecutor;
 
+    //todo tests
+    private List listenerList = new ArrayList();
+
+    private final int phaseSkip = 0, phaseStart = 1, phaseEnd = 2, goalStart = 11, goalEnd
= 12, error = 99;
+
     public void prepare( ReleaseDescriptor releaseDescriptor, Settings settings, List reactorProjects
)
         throws ReleaseExecutionException, ReleaseFailureException
     {
@@ -87,6 +96,8 @@
                          boolean dryRun )
         throws ReleaseExecutionException, ReleaseFailureException
     {
+        reportToListeners( "prepare", goalStart );
+
         ReleaseDescriptor config;
         if ( resume )
         {
@@ -96,6 +107,8 @@
             }
             catch ( ReleaseDescriptorStoreException e )
             {
+                reportToListeners( e.getMessage(), error );
+
                 throw new ReleaseExecutionException( "Error reading stored configuration:
" + e.getMessage(), e );
             }
         }
@@ -108,30 +121,41 @@
         // more flexible set of steps.
 
         String completedPhase = config.getCompletedPhase();
-        int index = phases.indexOf( completedPhase );
+        int index = preparePhases.indexOf( completedPhase );
+
+        for ( int idx = 0; idx < preparePhases.size(); idx++ )
+        {
+            reportToListeners( preparePhases.get( idx ).toString(), phaseSkip );
+        }
 
-        if ( index == phases.size() - 1 )
+        if ( index == preparePhases.size() - 1 )
         {
             getLogger().info(
                 "Release preparation already completed. You can now continue with release:perform,
or start again using the -Dresume=false flag" );
         }
         else if ( index >= 0 )
         {
-            getLogger().info( "Resuming release from phase '" + phases.get( index + 1 ) +
"'" );
+            getLogger().info( "Resuming release from phase '" + preparePhases.get( index
+ 1 ) + "'" );
         }
 
         // start from next phase
-        for ( int i = index + 1; i < phases.size(); i++ )
+        for ( int i = index + 1; i < preparePhases.size(); i++ )
         {
-            String name = (String) phases.get( i );
+            String name = (String) preparePhases.get( i );
 
             ReleasePhase phase = (ReleasePhase) releasePhases.get( name );
 
             if ( phase == null )
             {
-                throw new ReleaseExecutionException( "Unable to find phase '" + name + "'
to execute" );
+                String message = "Unable to find phase '" + name + "' to execute";
+
+                reportToListeners( message, error );
+
+                throw new ReleaseExecutionException( message );
             }
 
+            reportToListeners( name, phaseStart );
+
             if ( dryRun )
             {
                 phase.simulate( config, settings, reactorProjects );
@@ -148,9 +172,15 @@
             }
             catch ( ReleaseDescriptorStoreException e )
             {
+                reportToListeners( e.getMessage(), error );
+
                 // TODO: rollback?
                 throw new ReleaseExecutionException( "Error writing release properties after
completing phase", e );
             }
+
+            reportToListeners( name, phaseEnd );
+
+            reportToListeners( "prepare", goalEnd );
         }
     }
 
@@ -158,8 +188,12 @@
                          File checkoutDirectory, String goals, boolean useReleaseProfile
)
         throws ReleaseExecutionException, ReleaseFailureException
     {
+        reportToListeners( "perform", goalStart );
+
         getLogger().info( "Checking out the project to perform the release ..." );
 
+        reportToListeners( "verify-release-configuration", phaseStart );
+
         ReleaseDescriptor config;
         try
         {
@@ -167,21 +201,37 @@
         }
         catch ( ReleaseDescriptorStoreException e )
         {
+            reportToListeners( e.getMessage(), error );
+
             throw new ReleaseExecutionException( "Error reading stored configuration: " +
e.getMessage(), e );
         }
 
+        reportToListeners( "verify-release-configuration", phaseEnd );
+        reportToListeners( "verify-completed-prepare-phases", phaseStart );
+
         // if we stopped mid-way through preparation - don't perform
         if ( config.getCompletedPhase() != null && !"end-release".equals( config.getCompletedPhase()
) )
         {
-            throw new ReleaseFailureException(
-                "Cannot perform release - the preparation step was stopped mid-way. Please
re-run release:prepare to continue, or perform the release from an SCM tag." );
+            String message = "Cannot perform release - the preparation step was stopped mid-way.
Please re-run " +
+                "release:prepare to continue, or perform the release from an SCM tag.";
+
+            reportToListeners( message, error );
+
+            throw new ReleaseFailureException( message );
         }
 
         if ( config.getScmSourceUrl() == null )
         {
-            throw new ReleaseFailureException( "No SCM URL was provided to perform the release
from" );
+            String message = "No SCM URL was provided to perform the release from";
+
+            reportToListeners( message, error );
+
+            throw new ReleaseFailureException( message );
         }
 
+        reportToListeners( "verify-completed-prepare-phases", phaseEnd );
+        reportToListeners( "configure-repositories", phaseStart );
+
         ScmRepository repository;
         ScmProvider provider;
         try
@@ -192,15 +242,22 @@
         }
         catch ( ScmRepositoryException e )
         {
+            reportToListeners( e.getMessage(), error );
+
             throw new ReleaseScmRepositoryException( e.getMessage(), e.getValidationMessages()
);
         }
         catch ( NoSuchScmProviderException e )
         {
+            reportToListeners( e.getMessage(), error );
+
             throw new ReleaseExecutionException( "Unable to configure SCM repository: " +
e.getMessage(), e );
         }
 
         // TODO: sanity check that it is not . or .. or lower
 
+        reportToListeners( "configure-repositories", phaseEnd );
+        reportToListeners( "checkout-project-from-scm", phaseStart );
+
         if ( checkoutDirectory.exists() )
         {
             try
@@ -209,6 +266,8 @@
             }
             catch ( IOException e )
             {
+                reportToListeners( e.getMessage(), error );
+
                 throw new ReleaseExecutionException( "Unable to remove old checkout directory:
" + e.getMessage(), e );
             }
         }
@@ -221,13 +280,20 @@
         }
         catch ( ScmException e )
         {
+            reportToListeners( e.getMessage(), error );
+
             throw new ReleaseExecutionException( "An error is occurred in the checkout process:
" + e.getMessage(), e );
         }
         if ( !result.isSuccess() )
         {
+            reportToListeners( result.getProviderMessage(), error );
+
             throw new ReleaseScmCommandException( "Unable to checkout from SCM", result );
         }
 
+        reportToListeners( "checkout-project-from-scm", phaseEnd );
+        reportToListeners( "build-project", phaseStart );
+
         String additionalArguments = config.getAdditionalArguments();
 
         if ( useReleaseProfile )
@@ -249,10 +315,18 @@
         }
         catch ( MavenExecutorException e )
         {
+            reportToListeners( e.getMessage(), error );
+
             throw new ReleaseExecutionException( "Error executing Maven: " + e.getMessage(),
e );
         }
 
+        reportToListeners( "build-project", phaseEnd );
+        reportToListeners( "cleanup", phaseStart );
+
         clean( config, reactorProjects );
+
+        reportToListeners( "cleanup", phaseEnd );
+        reportToListeners( "perform", goalEnd );
     }
 
     public void clean( ReleaseDescriptor releaseDescriptor, List reactorProjects )
@@ -261,7 +335,7 @@
 
         configStore.delete( releaseDescriptor );
 
-        for ( Iterator i = phases.iterator(); i.hasNext(); )
+        for ( Iterator i = preparePhases.iterator(); i.hasNext(); )
         {
             String name = (String) i.next();
 
@@ -279,5 +353,68 @@
     void setMavenExecutor( MavenExecutor mavenExecutor )
     {
         this.mavenExecutor = mavenExecutor;
+    }
+
+    void reportToListeners( String name, int state )
+    {
+        for( Iterator listeners = listenerList.iterator(); listeners.hasNext(); )
+        {
+            ReleaseManagerListener listener = (ReleaseManagerListener) listeners.next();
+
+            switch( state )
+            {
+                case goalStart:
+                    listener.goalStart( name, getGoalPhases( name ) );
+                    break;
+                case goalEnd:
+                    listener.goalEnd();
+                    break;
+                case phaseSkip:
+                    listener.phaseSkip( name );
+                    break;
+                case phaseStart:
+                    listener.phaseStart( name );
+                    break;
+                case phaseEnd:
+                    listener.phaseEnd();
+                    break;
+                default:
+                    listener.error( name );
+            }
+        }
+    }
+
+    private List getGoalPhases( String name )
+    {
+        List phases = new ArrayList();
+
+        if ( "prepare".equals( name ) )
+        {
+            phases.addAll( this.preparePhases );
+        }
+        else if ( "perform".equals( name ) )
+        {
+            phases.addAll( this.performPhases );
+        }
+
+        return phases;
+    }
+
+    public void addListener( ReleaseManagerListener listener )
+    {
+        listenerList.add( listener );
+    }
+
+    public void removeListener( ReleaseManagerListener listener )
+    {
+        if ( listenerList.contains( listener ) )
+        {
+            listenerList.remove( listener );
+        }
+    }
+
+    List getListeners()
+    {
+        return listenerList;
     }
 }

Modified: maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/ReleaseManager.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/ReleaseManager.java?view=diff&rev=441469&r1=441468&r2=441469
==============================================================================
--- maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/ReleaseManager.java
(original)
+++ maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/ReleaseManager.java
Fri Sep  8 03:50:09 2006
@@ -83,4 +83,18 @@
      * @param reactorProjects   the reactor projects
      */
     void clean( ReleaseDescriptor releaseDescriptor, List reactorProjects );
+
+    /**
+     * Add a progress listener
+     *
+     * @param listener
+     */
+    void addListener( ReleaseManagerListener listener );
+
+    /**
+     * Remove a progress listener
+     *
+     * @param listener
+     */
+    void removeListener( ReleaseManagerListener listener );
 }

Added: maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/ReleaseManagerListener.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/ReleaseManagerListener.java?view=auto&rev=441469
==============================================================================
--- maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/ReleaseManagerListener.java
(added)
+++ maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/ReleaseManagerListener.java
Fri Sep  8 03:50:09 2006
@@ -0,0 +1,37 @@
+package org.apache.maven.plugins.release;
+
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+/**
+ * @author Edwin Punzalan
+ */
+public interface ReleaseManagerListener
+{
+    void goalStart( String goal, List phases );
+
+    void phaseStart( String name );
+
+    void phaseEnd();
+
+    void phaseSkip( String name );
+
+    void goalEnd();
+
+    void error( String reason );
+}

Propchange: maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/ReleaseManagerListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml?view=diff&rev=441469&r1=441468&r2=441469
==============================================================================
--- maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml
(original)
+++ maven/continuum/branches/release-integration/maven/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml
Fri Sep  8 03:50:09 2006
@@ -38,7 +38,7 @@
         </requirement>
       </requirements>
       <configuration>
-        <phases>
+        <preparePhases>
           <phase>check-poms</phase>
           <phase>scm-check-modifications</phase>
           <phase>check-dependency-snapshots</phase>
@@ -54,7 +54,15 @@
           <phase>remove-release-poms</phase>
           <phase>scm-commit-development</phase>
           <phase>end-release</phase>
-        </phases>
+        </preparePhases>
+        <performPhases>
+          <phase>verify-release-configuration</phase>
+          <phase>verify-completed-prepare-phases</phase>
+          <phase>configure-repositories</phase>
+          <phase>checkout-project-from-scm</phase>
+          <phase>build-project</phase>
+          <phase>cleanup</phase>
+        </performPhases>
       </configuration>
     </component>
     <component>

Modified: maven/continuum/branches/release-integration/maven/maven-release-plugin/src/test/resources/org/apache/maven/plugins/release/DefaultReleaseManagerTest.xml
URL: http://svn.apache.org/viewvc/maven/continuum/branches/release-integration/maven/maven-release-plugin/src/test/resources/org/apache/maven/plugins/release/DefaultReleaseManagerTest.xml?view=diff&rev=441469&r1=441468&r2=441469
==============================================================================
--- maven/continuum/branches/release-integration/maven/maven-release-plugin/src/test/resources/org/apache/maven/plugins/release/DefaultReleaseManagerTest.xml
(original)
+++ maven/continuum/branches/release-integration/maven/maven-release-plugin/src/test/resources/org/apache/maven/plugins/release/DefaultReleaseManagerTest.xml
Fri Sep  8 03:50:09 2006
@@ -38,11 +38,11 @@
         </requirement>
       </requirements>
       <configuration>
-        <phases>
+        <preparePhases>
           <phase>step1</phase>
           <phase>step2</phase>
           <phase>step3</phase>
-        </phases>
+        </preparePhases>
       </configuration>
     </component>
     <component>
@@ -61,9 +61,9 @@
         </requirement>
       </requirements>
       <configuration>
-        <phases>
+        <preparePhases>
           <phase>foo</phase>
-        </phases>
+        </preparePhases>
       </configuration>
     </component>
     <component>



Mime
View raw message