You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2012/08/22 17:54:49 UTC

svn commit: r1376106 - /maven/sandbox/trunk/plugins/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java

Author: olamy
Date: Wed Aug 22 15:54:49 2012
New Revision: 1376106

URL: http://svn.apache.org/viewvc?rev=1376106&view=rev
Log:
add an option to use update rather than delete then checkout all the time

Modified:
    maven/sandbox/trunk/plugins/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java

Modified: maven/sandbox/trunk/plugins/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java?rev=1376106&r1=1376105&r2=1376106&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java (original)
+++ maven/sandbox/trunk/plugins/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java Wed Aug 22 15:54:49 2012
@@ -19,10 +19,6 @@ package org.apache.maven.plugins.scmpubl
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.util.Map;
-
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
@@ -30,7 +26,7 @@ import org.apache.maven.plugin.MojoExecu
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFileSet;
-import org.apache.maven.scm.command.checkout.CheckOutScmResult;
+import org.apache.maven.scm.ScmResult;
 import org.apache.maven.scm.manager.NoSuchScmProviderException;
 import org.apache.maven.scm.manager.ScmManager;
 import org.apache.maven.scm.provider.ScmProvider;
@@ -40,6 +36,10 @@ import org.apache.maven.settings.Setting
 import org.apache.maven.shared.release.config.ReleaseDescriptor;
 import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
 /**
  * Base class for the scm-publish mojos.
  */
@@ -49,15 +49,15 @@ public abstract class AbstractScmPublish
 
     /**
      * Location of the inventory file.
-     * 
+     *
      * @parameter expression="${scmpublish.inventoryFile}"
-     *            default-value="${project.build.directory}/scmpublish-inventory.js"
+     * default-value="${project.build.directory}/scmpublish-inventory.js"
      */
     protected File inventoryFile;
 
     /**
      * Location of the scm publication tree.
-     * 
+     *
      * @parameter expression="${scmpublish.pubScmUrl}" default-value="${project.distributionManagement.site.url}"
      * @required
      */
@@ -65,33 +65,33 @@ public abstract class AbstractScmPublish
 
     /**
      * Location where the scm check-out is done.
-     * 
+     *
      * @parameter expression="${scmpublish.checkoutDirectory}"
-     *            default-value="${project.build.directory}/scmpublish-checkout"
+     * default-value="${project.build.directory}/scmpublish-checkout"
      */
     protected File checkoutDirectory;
 
     /**
      * Patterns to exclude from the scm tree.
-     * 
+     *
      * @parameter
      */
     protected String excludes;
 
     /**
      * Patterns to include in the scm tree.
-     * 
+     *
      * @parameter
      */
     protected String includes;
-    
+
     /**
      * List of provider implementations.
      *
      * @parameter
      */
     private Map<String, String> providerImplementations;
-    
+
     /**
      * The SCM manager.
      *
@@ -101,21 +101,21 @@ public abstract class AbstractScmPublish
 
     /**
      * Tool that gets a configured SCM repository from release configuration.
-     * 
+     *
      * @component
      */
     protected ScmRepositoryConfigurator scmRepositoryConfigurator;
 
     /**
      * The SCM username to use.
-     * 
+     *
      * @parameter expression="${username}"
      */
     protected String username;
 
     /**
      * The SCM password to use.
-     * 
+     *
      * @parameter expression="${password}"
      */
     protected String password;
@@ -131,7 +131,7 @@ public abstract class AbstractScmPublish
      * Use a local checkout instead of doing a checkout from the upstream repository. ATTENTION: This will only work
      * with distributed SCMs which support the file:// protocol TODO: we should think about having the defaults for the
      * various SCM providers provided via modello!
-     * 
+     *
      * @parameter expression="${localCheckout}" default-value="false"
      * @since 2.0
      */
@@ -154,12 +154,21 @@ public abstract class AbstractScmPublish
     /**
      * The outputEncoding parameter of the site plugin. This plugin will corrupt your site
      * if this does not match the value used by the site plugin.
-     * 
+     *
      * @parameter expression="${outputEncoding}" default-value="${project.reporting.outputEncoding}"
      */
     protected String siteOutputEncoding;
 
+    /**
+     * if the checkout directory exists and this flag is activated the plugin will try an update rather
+     * than delete then checkout
+     *
+     * @parameter expression="${scmpublish.tryUpdate}" default-value="false"
+     */
+    protected boolean tryUpdate;
+
     protected ScmProvider scmProvider;
+
     protected ScmRepository scmRepository;
 
     protected AbstractScmPublishMojo()
@@ -212,7 +221,7 @@ public abstract class AbstractScmPublish
             for ( Map.Entry<String, String> providerEntry : providerImplementations.entrySet() )
             {
                 getLog().info( "Change the default '" + providerEntry.getKey() + "' provider implementation to '"
-                    + providerEntry.getValue() + "'." );
+                                   + providerEntry.getValue() + "'." );
                 scmManager.setScmProviderImplementation( providerEntry.getKey(), providerEntry.getValue() );
             }
         }
@@ -227,9 +236,9 @@ public abstract class AbstractScmPublish
     protected void checkoutExisting()
         throws MojoExecutionException
     {
-        logInfo( "Checking out the pub tree ..." );
+        logInfo( ( tryUpdate ? "Updating" : "Checking" ) + " out the pub tree ..." );
 
-        if ( checkoutDirectory.exists() )
+        if ( checkoutDirectory.exists() && !tryUpdate )
         {
             try
             {
@@ -245,12 +254,19 @@ public abstract class AbstractScmPublish
 
         checkoutDirectory.mkdirs();
 
-        CheckOutScmResult scmResult;
+        ScmResult scmResult;
 
         try
         {
             ScmFileSet fileSet = new ScmFileSet( checkoutDirectory, includes, excludes );
-            scmResult = scmProvider.checkOut( scmRepository, fileSet );
+            if ( tryUpdate )
+            {
+                scmResult = scmProvider.update( scmRepository, fileSet );
+            }
+            else
+            {
+                scmResult = scmProvider.checkOut( scmRepository, fileSet );
+            }
         }
         catch ( ScmException e )
         {
@@ -269,8 +285,9 @@ public abstract class AbstractScmPublish
         {
             logError( scmResult.getProviderMessage() );
 
-            throw new MojoExecutionException( "Unable to checkout from SCM" + "\nProvider message:\n"
-                + scmResult.getProviderMessage() + "\nCommand output:\n" + scmResult.getCommandOutput() );
+            throw new MojoExecutionException(
+                "Unable to checkout from SCM" + "\nProvider message:\n" + scmResult.getProviderMessage()
+                    + "\nCommand output:\n" + scmResult.getCommandOutput() );
         }
     }
 
@@ -321,7 +338,7 @@ public abstract class AbstractScmPublish
         }
     }
 
-    
+
     public abstract void scmPublishExecute()
         throws MojoExecutionException, MojoFailureException;
 }
\ No newline at end of file