Author: hboutemy
Date: Wed Oct 10 15:09:24 2012
New Revision: 1396634

URL: http://svn.apache.org/viewvc?rev=1396634&view=rev
Log:
[MSCMPUB-1] removed obsolete prepare and publish goals

Removed:
    maven/plugins/trunk/maven-scm-publish-plugin/src/it/001-prepare/
    maven/plugins/trunk/maven-scm-publish-plugin/src/it/002-perform/
    
maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishInventory.java
    
maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishInventoryMojo.java
    
maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishMojo.java
Modified:
    
maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java
    
maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishScmMojo.java
    maven/plugins/trunk/maven-scm-publish-plugin/src/site/apt/index.apt

Modified: 
maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java?rev=1396634&r1=1396633&r2=1396634&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java
 Wed Oct 10 15:09:24 2012
@@ -20,6 +20,7 @@ package org.apache.maven.plugins.scmpubl
  */
 
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -32,6 +33,9 @@ import org.apache.maven.scm.ScmBranch;
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.command.add.AddScmResult;
+import org.apache.maven.scm.command.checkin.CheckInScmResult;
+import org.apache.maven.scm.command.remove.RemoveScmResult;
 import org.apache.maven.scm.manager.NoSuchScmProviderException;
 import org.apache.maven.scm.manager.ScmManager;
 import org.apache.maven.scm.provider.ScmProvider;
@@ -45,7 +49,14 @@ import org.apache.maven.shared.release.s
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 
 /**
  * Base class for the scm-publish mojos.
@@ -53,14 +64,6 @@ import java.util.Map;
 public abstract class AbstractScmPublishMojo
     extends AbstractMojo
 {
-
-    /**
-     * Location of the inventory file.
-     */
-    @Parameter ( property = "scmpublish.inventoryFile",
-                 defaultValue = 
"${project.build.directory}/scmpublish-inventory.js" )
-    protected File inventoryFile;
-
     /**
      * Location of the scm publication tree.
      */
@@ -76,6 +79,24 @@ public abstract class AbstractScmPublish
     protected File checkoutDirectory;
 
     /**
+     * Display list of added, deleted, and changed files, but do not do any 
actual SCM operations.
+     */
+    @Parameter ( property = "scmpublish.dryRun" )
+    private boolean dryRun;
+
+    /**
+     * Run add and delete commands, but leave the actually checkin for the 
user to run manually.
+     */
+    @Parameter ( property = "scmpublish.skipCheckin" )
+    private boolean skipCheckin;
+
+    /**
+     * SCM log/checkin comment for this publication.
+     */
+    @Parameter ( property = "scmpublish.checkinComment", defaultValue = "Site 
checkin for project ${project.name}" )
+    private String checkinComment;
+
+    /**
      * Patterns to exclude from the scm tree.
      */
     @Parameter
@@ -120,7 +141,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!
+     * various SCM providers provided via Modello!
      */
     @Parameter ( property = "localCheckout", defaultValue = "false" )
     protected boolean localCheckout;
@@ -179,6 +200,17 @@ public abstract class AbstractScmPublish
     @Parameter ( property = "scmpublish.automaticRemotePathCreation", 
defaultValue = "true" )
     protected boolean automaticRemotePathCreation;
 
+    /**
+     * Filename extensions of files which need new line normalization.
+     */
+    private final static String[] NORMALIZE_EXTENSIONS = { "html", "css", "js" 
};
+
+    /**
+     * extra file extensions to normalize line ending (will be added to list 
html,css,js)
+     */
+    @Parameter
+    protected String[] extraNormalizeExtensions;
+
     protected ScmProvider scmProvider;
 
     protected ScmRepository scmRepository;
@@ -198,6 +230,23 @@ public abstract class AbstractScmPublish
         getLog().error( String.format( format, params ) );
     }
 
+    private File relativize( File base, File file )
+    {
+        return new File( base.toURI().relativize( file.toURI() ).getPath() );
+    }
+
+    protected boolean requireNormalizeNewlines( File f )
+        throws IOException
+    {
+        List<String> extensions = Arrays.asList( NORMALIZE_EXTENSIONS );
+        if ( extraNormalizeExtensions != null )
+        {
+            extensions.addAll( Arrays.asList( extraNormalizeExtensions ) );
+        }
+
+        return FilenameUtils.isExtension( f.getName(), extensions );
+    }
+
     protected ReleaseDescriptor setupScm()
         throws ScmRepositoryException, NoSuchScmProviderException
     {
@@ -450,6 +499,158 @@ public abstract class AbstractScmPublish
         }
     }
 
+    /**
+     * Check-in content from scm checkout.
+     *
+     * @throws MojoExecutionException
+     */
+    protected void checkinFiles()
+        throws MojoExecutionException
+    {
+        if ( skipCheckin )
+        {
+            return;
+        }
+
+        ScmFileSet updatedFileSet = new ScmFileSet( checkoutDirectory );
+        try
+        {
+            logInfo( "Checkin to the scm" );
+
+            CheckInScmResult checkinResult =
+                scmProvider.checkIn( scmRepository, updatedFileSet, new 
ScmBranch( scmBranch ), checkinComment );
+            if ( !checkinResult.isSuccess() )
+            {
+                logError( "checkin operation failed: %s",
+                          checkinResult.getProviderMessage() + " " + 
checkinResult.getCommandOutput() );
+                throw new MojoExecutionException( "Failed to checkin files: " 
+ checkinResult.getProviderMessage() + " "
+                                                      + 
checkinResult.getCommandOutput() );
+            }
+            logInfo( "Checkin %d file(s) to revision: %s", 
checkinResult.getCheckedInFiles().size(),
+                     checkinResult.getScmRevision() );
+        }
+        catch ( ScmException e )
+        {
+            throw new MojoExecutionException( "Failed to perform checkin SCM", 
e );
+        }
+    }
+
+    protected void deleteFiles( Collection<File> deleted )
+        throws MojoExecutionException
+    {
+        if ( skipDeletedFiles )
+        {
+            logInfo( "deleting files is skipped" );
+            return;
+        }
+        List<File> deletedList = new ArrayList<File>();
+        for ( File f : deleted )
+        {
+            deletedList.add( relativize( checkoutDirectory, f ) );
+        }
+        ScmFileSet deletedFileSet = new ScmFileSet( checkoutDirectory, 
deletedList );
+        try
+        {
+            getLog().debug( "deleting files: " + deletedList );
+
+            RemoveScmResult deleteResult =
+                scmProvider.remove( scmRepository, deletedFileSet, "Deleting 
obsolete site files." );
+            if ( !deleteResult.isSuccess() )
+            {
+                logError( "delete operation failed: %s",
+                          deleteResult.getProviderMessage() + " " + 
deleteResult.getCommandOutput() );
+                throw new MojoExecutionException( "Failed to delete files: " + 
deleteResult.getProviderMessage() + " "
+                                                      + 
deleteResult.getCommandOutput() );
+            }
+        }
+        catch ( ScmException e )
+        {
+            throw new MojoExecutionException( "Failed to delete removed files 
to SCM", e );
+        }
+    }
+
+    /**
+     * Add files to scm.
+     *
+     * @param added files to be added
+     * @throws MojoFailureException
+     * @throws MojoExecutionException
+     */
+    protected void addFiles( Collection<File> added )
+        throws MojoFailureException, MojoExecutionException
+    {
+        List<File> addedList = new ArrayList<File>();
+        Set<File> createdDirs = new HashSet<File>();
+        Set<File> dirsToAdd = new TreeSet<File>();
+
+        createdDirs.add( relativize( checkoutDirectory, checkoutDirectory ) );
+
+        for ( File f : added )
+        {
+            for ( File dir = f.getParentFile(); !dir.equals( checkoutDirectory 
); dir = dir.getParentFile() )
+            {
+                File relativized = relativize( checkoutDirectory, dir );
+                //  we do the best we can with the directories
+                if ( createdDirs.add( relativized ) )
+                {
+                    dirsToAdd.add( relativized );
+                }
+                else
+                {
+                    break;
+                }
+            }
+            addedList.add( relativize( checkoutDirectory, f ) );
+        }
+
+        for ( File relativized : dirsToAdd )
+        {
+            try
+            {
+                ScmFileSet fileSet = new ScmFileSet( checkoutDirectory, 
relativized );
+                getLog().debug( "scm add directory: " + relativized );
+                AddScmResult addDirResult = scmProvider.add( scmRepository, 
fileSet, "Adding directory" );
+                if ( !addDirResult.isSuccess() )
+                {
+                    getLog().debug( " Error adding directory " + relativized + 
": " + addDirResult.getCommandOutput() );
+                }
+            }
+            catch ( ScmException e )
+            {
+                //
+            }
+        }
+
+        // remove directories already added !
+        addedList.removeAll( dirsToAdd );
+
+        ScmFileSet addedFileSet = new ScmFileSet( checkoutDirectory, addedList 
);
+        getLog().debug( "scm add files: " + addedList );
+        try
+        {
+            CommandParameters commandParameters = new CommandParameters();
+            commandParameters.setString( CommandParameter.MESSAGE, "Adding new 
site files." );
+            commandParameters.setString( CommandParameter.FORCE_ADD, 
Boolean.TRUE.toString() );
+            AddScmResult addResult = scmProvider.add( scmRepository, 
addedFileSet, commandParameters );
+            if ( !addResult.isSuccess() )
+            {
+                logError( "add operation failed: %s",
+                          addResult.getProviderMessage() + " " + 
addResult.getCommandOutput() );
+                throw new MojoExecutionException(
+                    "Failed to add new files: " + 
addResult.getProviderMessage() + " " + addResult.getCommandOutput() );
+            }
+        }
+        catch ( ScmException e )
+        {
+            throw new MojoExecutionException( "Failed to add new files to 
SCM", e );
+        }
+    }
+
+    public boolean isDryRun()
+    {
+        return dryRun;
+    }
+
     public abstract void scmPublishExecute()
         throws MojoExecutionException, MojoFailureException;
 }
\ No newline at end of file

Modified: 
maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishScmMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishScmMojo.java?rev=1396634&r1=1396633&r2=1396634&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishScmMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishScmMojo.java
 Wed Oct 10 15:09:24 2012
@@ -47,13 +47,13 @@ import java.util.List;
 import java.util.Set;
 
 /**
- * Publish a content to scm in one step. By default, content is taken from 
default site staging directory
+ * Publish a content to scm. By default, content is taken from default site 
staging directory
  * <code>${project.build.directory}/staging</code>.
  * Can be used without project, so usable to update any SCM with any content.
  */
 @Mojo ( name = "publish-scm", aggregator = true, requiresProject = false )
 public class ScmPublishPublishScmMojo
-    extends ScmPublishPublishMojo
+    extends AbstractScmPublishMojo
 {
     /**
      * The content to be published.

Modified: maven/plugins/trunk/maven-scm-publish-plugin/src/site/apt/index.apt
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-scm-publish-plugin/src/site/apt/index.apt?rev=1396634&r1=1396633&r2=1396634&view=diff
==============================================================================
--- maven/plugins/trunk/maven-scm-publish-plugin/src/site/apt/index.apt 
(original)
+++ maven/plugins/trunk/maven-scm-publish-plugin/src/site/apt/index.apt Wed Oct 
10 15:09:24 2012
@@ -41,18 +41,13 @@ Maven SCM Publish Plugin
 
 Implementation
 
-    The plugin proceed to publish your website using the following steps.
+    The plugin works from staged website.
 
-    The prepare phase checks out the contents of a directory from
-    the SCM into (by default) <<<target/scmpublish-checkout>>>. It 
-    then lists the files known to the SCM and stores them
-    in (by default) <<<target/scmpublish-inventory.js>>>. This provides
-    the point of reference for an eventual SCM checkin. Then it deletes every
-    files to let a clean place for site generation.
-
-    Finally, the publish phase compares the output of the generated site
-    with the inventory from the prepare phase, and issues
-    appropriate SCM commands to add and delete, followed by a
+    It first checks out the contents of a directory from
+    the SCM into (by default) <<<target/scmpublish-checkout>>>.
+
+    Then locally staged content is applied to the check-out, issuing
+    appropriate SCM commands to add and delete entries, followed by a
     checkin.
 
     The <<scmpublish.dryRun>> parameter to the plugin avoids all
@@ -110,4 +105,4 @@ Future Dreams
 
     []
 
-    Then this plugin will be outdated, replaced by natural 
<<<maven-site-plugin>>>.
+    Then this plugin will be outdated, replaced by natural 
<<<maven-site-plugin:deploy>>>.


Reply via email to