Author: brett
Date: Tue May  9 07:32:36 2006
New Revision: 405443

URL: http://svn.apache.org/viewcvs?rev=405443&view=rev
Log:
if using a snapshot of the release plugin, prompt if it is ok to continue (fail 
is the default)

Added:
    
maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/check-dependencies/snapshot-release-plugin/
    
maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/check-dependencies/snapshot-release-plugin/pom.xml
   (with props)
Modified:
    
maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/CheckDependencySnapshotsPhase.java
    
maven/plugins/trunk/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml
    
maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/CheckDependencySnapshotsPhaseTest.java

Modified: 
maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/CheckDependencySnapshotsPhase.java
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/CheckDependencySnapshotsPhase.java?rev=405443&r1=405442&r2=405443&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/CheckDependencySnapshotsPhase.java
 (original)
+++ 
maven/plugins/trunk/maven-release-plugin/src/main/java/org/apache/maven/plugins/release/phase/CheckDependencySnapshotsPhase.java
 Tue May  9 07:32:36 2006
@@ -22,8 +22,11 @@
 import org.apache.maven.plugins.release.ReleaseFailureException;
 import org.apache.maven.plugins.release.config.ReleaseConfiguration;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.components.interactivity.Prompter;
+import org.codehaus.plexus.components.interactivity.PrompterException;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -41,6 +44,11 @@
 public class CheckDependencySnapshotsPhase
     extends AbstractReleasePhase
 {
+    /**
+     * Component used to prompt for input.
+     */
+    private Prompter prompter;
+
     public void execute( ReleaseConfiguration releaseConfiguration )
         throws ReleaseExecutionException, ReleaseFailureException
     {
@@ -53,12 +61,12 @@
         {
             MavenProject project = (MavenProject) i.next();
 
-            checkProject( project, originalVersions );
+            checkProject( project, originalVersions, releaseConfiguration );
         }
     }
 
-    private void checkProject( MavenProject project, Map originalVersions )
-        throws ReleaseExecutionException, ReleaseFailureException
+    private void checkProject( MavenProject project, Map originalVersions, 
ReleaseConfiguration releaseConfiguration )
+        throws ReleaseFailureException, ReleaseExecutionException
     {
         Set snapshotDependencies = new HashSet();
 
@@ -86,7 +94,37 @@
 
             if ( checkArtifact( artifact, originalVersions ) )
             {
-                snapshotDependencies.add( artifact );
+                boolean addToFailures = true;
+
+                if ( "org.apache.maven.plugins".equals( artifact.getGroupId() 
) &&
+                    "maven-release-plugin".equals( artifact.getArtifactId() ) )
+                {
+                    // It's a snapshot of the release plugin. Maybe just 
testing - ask
+                    // By default, we fail as for any ohter plugin
+                    if ( releaseConfiguration.isInteractive() )
+                    {
+                        try
+                        {
+                            prompter.showMessage(
+                                "This project relies on a SNAPSHOT of the 
release plugin. This may be necessary during testing." );
+                            String result = prompter.prompt( "Do you want to 
continue with the release?",
+                                                             Arrays.asList( 
new String[]{"yes", "no"} ), "no" );
+                            if ( result.toLowerCase().startsWith( "y" ) )
+                            {
+                                addToFailures = false;
+                            }
+                        }
+                        catch ( PrompterException e )
+                        {
+                            throw new ReleaseExecutionException( 
e.getMessage(), e );
+                        }
+                    }
+                }
+
+                if ( addToFailures )
+                {
+                    snapshotDependencies.add( artifact );
+                }
             }
         }
 
@@ -152,4 +190,8 @@
         execute( releaseConfiguration );
     }
 
+    public void setPrompter( Prompter prompter )
+    {
+        this.prompter = prompter;
+    }
 }

Modified: 
maven/plugins/trunk/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml?rev=405443&r1=405442&r2=405443&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml
 (original)
+++ 
maven/plugins/trunk/maven-release-plugin/src/main/resources/META-INF/plexus/components.xml
 Tue May  9 07:32:36 2006
@@ -117,6 +117,11 @@
       <role>org.apache.maven.plugins.release.phase.ReleasePhase</role>
       <role-hint>check-dependency-snapshots</role-hint>
       
<implementation>org.apache.maven.plugins.release.phase.CheckDependencySnapshotsPhase</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.components.interactivity.Prompter</role>
+        </requirement>
+      </requirements>
     </component>
     <component>
       <role>org.apache.maven.plugins.release.phase.ReleasePhase</role>

Modified: 
maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/CheckDependencySnapshotsPhaseTest.java
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/CheckDependencySnapshotsPhaseTest.java?rev=405443&r1=405442&r2=405443&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/CheckDependencySnapshotsPhaseTest.java
 (original)
+++ 
maven/plugins/trunk/maven-release-plugin/src/test/java/org/apache/maven/plugins/release/phase/CheckDependencySnapshotsPhaseTest.java
 Tue May  9 07:32:36 2006
@@ -16,8 +16,15 @@
  * limitations under the License.
  */
 
+import org.apache.maven.plugins.release.ReleaseExecutionException;
 import org.apache.maven.plugins.release.ReleaseFailureException;
 import org.apache.maven.plugins.release.config.ReleaseConfiguration;
+import org.codehaus.plexus.components.interactivity.Prompter;
+import org.codehaus.plexus.components.interactivity.PrompterException;
+import org.jmock.cglib.Mock;
+import org.jmock.core.matcher.InvokeOnceMatcher;
+import org.jmock.core.stub.ReturnStub;
+import org.jmock.core.stub.ThrowStub;
 
 /**
  * Test the dependency snapshot check phase.
@@ -59,6 +66,181 @@
 
         // successful execution is verification enough
         assertTrue( true );
+    }
+
+    public void testSnapshotReleasePluginNonInteractive()
+        throws Exception
+    {
+        ReleaseConfiguration releaseConfiguration = 
createConfigurationFromProjects( "snapshot-release-plugin" );
+        releaseConfiguration.setInteractive( false );
+
+        try
+        {
+            phase.execute( releaseConfiguration );
+
+            fail( "Should have failed execution" );
+        }
+        catch ( ReleaseFailureException e )
+        {
+            assertTrue( true );
+        }
+
+        try
+        {
+            phase.simulate( releaseConfiguration );
+
+            fail( "Should have failed execution" );
+        }
+        catch ( ReleaseFailureException e )
+        {
+            assertTrue( true );
+        }
+    }
+
+    public void testSnapshotReleasePluginInteractiveDeclined()
+        throws Exception
+    {
+        CheckDependencySnapshotsPhase phase =
+            (CheckDependencySnapshotsPhase) lookup( ReleasePhase.ROLE, 
"check-dependency-snapshots" );
+
+        ReleaseConfiguration releaseConfiguration = 
createConfigurationFromProjects( "snapshot-release-plugin" );
+
+        Mock mockPrompter = new Mock( Prompter.class );
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "showMessage" 
);
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "prompt" 
).will( new ReturnStub( "no" ) );
+        phase.setPrompter( (Prompter) mockPrompter.proxy() );
+
+        try
+        {
+            phase.execute( releaseConfiguration );
+
+            fail( "Should have failed execution" );
+        }
+        catch ( ReleaseFailureException e )
+        {
+            assertTrue( true );
+        }
+
+        mockPrompter.reset();
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "showMessage" 
);
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "prompt" 
).will( new ReturnStub( "no" ) );
+
+        try
+        {
+            phase.simulate( releaseConfiguration );
+
+            fail( "Should have failed execution" );
+        }
+        catch ( ReleaseFailureException e )
+        {
+            assertTrue( true );
+        }
+    }
+
+    public void testSnapshotReleasePluginInteractiveAccepted()
+        throws Exception
+    {
+        CheckDependencySnapshotsPhase phase =
+            (CheckDependencySnapshotsPhase) lookup( ReleasePhase.ROLE, 
"check-dependency-snapshots" );
+
+        ReleaseConfiguration releaseConfiguration = 
createConfigurationFromProjects( "snapshot-release-plugin" );
+
+        Mock mockPrompter = new Mock( Prompter.class );
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "prompt" 
).will( new ReturnStub( "yes" ) );
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "showMessage" 
);
+        phase.setPrompter( (Prompter) mockPrompter.proxy() );
+
+        phase.execute( releaseConfiguration );
+
+        mockPrompter.reset();
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "prompt" 
).will( new ReturnStub( "yes" ) );
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "showMessage" 
);
+
+        phase.simulate( releaseConfiguration );
+
+        assertTrue( true );
+    }
+
+    public void testSnapshotReleasePluginInteractiveInvalid()
+        throws Exception
+    {
+        CheckDependencySnapshotsPhase phase =
+            (CheckDependencySnapshotsPhase) lookup( ReleasePhase.ROLE, 
"check-dependency-snapshots" );
+
+        ReleaseConfiguration releaseConfiguration = 
createConfigurationFromProjects( "snapshot-release-plugin" );
+
+        Mock mockPrompter = new Mock( Prompter.class );
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "showMessage" 
);
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "prompt" 
).will( new ReturnStub( "donkey" ) );
+        phase.setPrompter( (Prompter) mockPrompter.proxy() );
+
+        try
+        {
+            phase.execute( releaseConfiguration );
+
+            fail( "Should have failed execution" );
+        }
+        catch ( ReleaseFailureException e )
+        {
+            assertTrue( true );
+        }
+
+        mockPrompter.reset();
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "showMessage" 
);
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "prompt" 
).will( new ReturnStub( "donkey" ) );
+
+        try
+        {
+            phase.simulate( releaseConfiguration );
+
+            fail( "Should have failed execution" );
+        }
+        catch ( ReleaseFailureException e )
+        {
+            assertTrue( true );
+        }
+    }
+
+    public void testSnapshotReleasePluginInteractiveException()
+        throws Exception
+    {
+        CheckDependencySnapshotsPhase phase =
+            (CheckDependencySnapshotsPhase) lookup( ReleasePhase.ROLE, 
"check-dependency-snapshots" );
+
+        ReleaseConfiguration releaseConfiguration = 
createConfigurationFromProjects( "snapshot-release-plugin" );
+
+        Mock mockPrompter = new Mock( Prompter.class );
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "showMessage" 
);
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "prompt" 
).will(
+            new ThrowStub( new PrompterException( "..." ) ) );
+        phase.setPrompter( (Prompter) mockPrompter.proxy() );
+
+        try
+        {
+            phase.execute( releaseConfiguration );
+
+            fail( "Should have failed execution" );
+        }
+        catch ( ReleaseExecutionException e )
+        {
+            assertEquals( "Check cause", PrompterException.class, 
e.getCause().getClass() );
+        }
+
+        mockPrompter.reset();
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "showMessage" 
);
+        mockPrompter.expects( new InvokeOnceMatcher() ).method( "prompt" 
).will(
+            new ThrowStub( new PrompterException( "..." ) ) );
+
+        try
+        {
+            phase.simulate( releaseConfiguration );
+
+            fail( "Should have failed execution" );
+        }
+        catch ( ReleaseExecutionException e )
+        {
+            assertEquals( "Check cause", PrompterException.class, 
e.getCause().getClass() );
+        }
     }
 
     public void testSnapshotDependenciesInProjectOnlyMismatchedVersion()

Added: 
maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/check-dependencies/snapshot-release-plugin/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/check-dependencies/snapshot-release-plugin/pom.xml?rev=405443&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/check-dependencies/snapshot-release-plugin/pom.xml
 (added)
+++ 
maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/check-dependencies/snapshot-release-plugin/pom.xml
 Tue May  9 07:32:36 2006
@@ -0,0 +1,32 @@
+<!--
+  ~ Copyright 2005-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.
+  -->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>groupId</groupId>
+  <artifactId>artifactId</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-release-plugin</artifactId>
+        <version>1.1-SNAPSHOT</version>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: 
maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/check-dependencies/snapshot-release-plugin/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/plugins/trunk/maven-release-plugin/src/test/resources/projects/check-dependencies/snapshot-release-plugin/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision


Reply via email to