You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2012/05/01 00:45:12 UTC

svn commit: r1332454 - in /maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish: AbstractScmPublishMojo.java ScmPublishInventory.java ScmPublishInventoryMojo.java ScmPublishPublishMojo.java

Author: hboutemy
Date: Mon Apr 30 22:45:11 2012
New Revision: 1332454

URL: http://svn.apache.org/viewvc?rev=1332454&view=rev
Log:
extracted inventory methods into ScmPublishInventory

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

Modified: maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java?rev=1332454&r1=1332453&r2=1332454&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java (original)
+++ maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/AbstractScmPublishMojo.java Mon Apr 30 22:45:11 2012
@@ -20,19 +20,11 @@ package org.apache.maven.plugins.scmpubl
  */
 
 import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.filefilter.IOFileFilter;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.scm.manager.NoSuchScmProviderException;
 import org.apache.maven.scm.manager.ScmManager;
@@ -44,11 +36,6 @@ import org.apache.maven.shared.release.R
 import org.apache.maven.shared.release.config.ReleaseDescriptor;
 import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
 import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
-import org.codehaus.jackson.JsonEncoding;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.JsonParser;
-import org.codehaus.jackson.JsonProcessingException;
-import org.codehaus.jackson.map.MappingJsonFactory;
 
 /**
  * Base class for the site-scm-publish mojos.
@@ -186,22 +173,6 @@ public abstract class AbstractScmPublish
     protected ScmProvider scmProvider;
     protected ScmRepository scmRepository;
 
-    protected static class DotFilter
-        implements IOFileFilter
-    {
-
-        public boolean accept( File file )
-        {
-            return !file.getName().startsWith( "." );
-        }
-
-        public boolean accept( File dir, String name )
-        {
-            return !name.startsWith( "." );
-        }
-
-    }
-
     protected AbstractScmPublishMojo()
     {
         super();
@@ -217,79 +188,6 @@ public abstract class AbstractScmPublish
         getLog().error( String.format( format, params ) );
     }
 
-    /**
-     * Create a list of all the files in the checkout (which we will presently remove). For now, duck anything that
-     * starts with a ., since the site plugin won't make any and it will dodge metadata I'm familiar with. None if this
-     * is really good enough for safe usage with exotics like clearcase. Perhaps protest if anything other than svn or
-     * git? Or use http://plexus.codehaus.org/plexus-utils/apidocs/org/codehaus/plexus/util/AbstractScanner.html#DEFAULTEXCLUDES?
-     * @throws MojoFailureException 
-     */
-    protected List<File> writeInventory()
-        throws MojoFailureException
-    {
-        List<File> inventory = new ArrayList<File>();
-        inventory.addAll( FileUtils.listFiles( checkoutDirectory, new DotFilter(), new DotFilter() ) );
-        Collections.sort( inventory );
-
-        ScmPublishInventory initialInventory = new ScmPublishInventory();
-        Set<String> paths = new HashSet<String>();
-
-        /*
-         * It might be cleverer to store paths relative to the checkoutDirectory, but this really should work.
-         */
-        for ( File f : inventory )
-        {
-            // See below. We only bother about files.
-            if ( f.isFile() )
-            {
-                paths.add( f.getAbsolutePath() );
-            }
-        }
-        initialInventory.setPaths( paths );
-        try
-        {
-            MappingJsonFactory factory = new MappingJsonFactory();
-            JsonGenerator gen = factory.createJsonGenerator( inventoryFile, JsonEncoding.UTF8 );
-            gen.writeObject( initialInventory );
-            gen.close();
-            return inventory;
-        }
-        catch ( JsonProcessingException e )
-        {
-            throw new MojoFailureException( "Failed to write inventory to " + inventoryFile.getAbsolutePath(), e );
-        }
-        catch ( IOException e )
-        {
-            throw new MojoFailureException( "Failed to write inventory to " + inventoryFile.getAbsolutePath(), e );
-        }
-    }
-
-    protected List<File> readInventory()
-        throws MojoFailureException
-    {
-        try
-        {
-            MappingJsonFactory factory = new MappingJsonFactory();
-            JsonParser parser = factory.createJsonParser( inventoryFile );
-            ScmPublishInventory storedInventory = parser.readValueAs( ScmPublishInventory.class );
-            List<File> inventory = new ArrayList<File>();
-            for ( String p : storedInventory.getPaths() )
-            {
-                inventory.add( new File( p ) );
-            }
-            parser.close();
-            return inventory;
-        }
-        catch ( JsonProcessingException e )
-        {
-            throw new MojoFailureException( "Failed to write inventory to " + inventoryFile.getAbsolutePath(), e );
-        }
-        catch ( IOException e )
-        {
-            throw new MojoFailureException( "Failed to write inventory to " + inventoryFile.getAbsolutePath(), e );
-        }  
-    }
-
     protected ReleaseDescriptor setupScm()
         throws ReleaseScmRepositoryException, ReleaseExecutionException
     {

Modified: maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishInventory.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishInventory.java?rev=1332454&r1=1332453&r2=1332454&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishInventory.java (original)
+++ maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishInventory.java Mon Apr 30 22:45:11 2012
@@ -19,29 +19,117 @@ package org.apache.maven.plugins.scmpubl
  * under the License.
  */
 
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.filefilter.IOFileFilter;
+import org.apache.maven.plugin.MojoFailureException;
+import org.codehaus.jackson.JsonEncoding;
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.MappingJsonFactory;
+
 /**
  * A class designed for json serialization to store the existing inventory, if any. In this version, there's no attempt
  * to account for directories as managed items.
  */
 public class ScmPublishInventory
 {
-    private Set<String> paths;
+    private static class DotFilter
+        implements IOFileFilter
+    {
+
+        public boolean accept( File file )
+        {
+            return !file.getName().startsWith( "." );
+        }
+
+        public boolean accept( File dir, String name )
+        {
+            return !name.startsWith( "." );
+        }
 
-    public ScmPublishInventory() 
+    }
+
+    public static List<File> listInventoryFiles( File basedir )
     {
-        paths = new HashSet<String>(); 
+        List<File> inventory = new ArrayList<File>();
+        inventory.addAll( FileUtils.listFiles( basedir, new DotFilter(), new DotFilter() ) );
+        Collections.sort( inventory );
+        return inventory;
     }
 
-    public Set<String> getPaths()
+    /**
+     * Create a list of all the files in the checkout (which we will presently remove). For now, duck anything that
+     * starts with a ., since the site plugin won't make any and it will dodge metadata I'm familiar with. None if this
+     * is really good enough for safe usage with exotics like clearcase. Perhaps protest if anything other than svn or
+     * git? Or use http://plexus.codehaus.org/plexus-utils/apidocs/org/codehaus/plexus/util/AbstractScanner.html#DEFAULTEXCLUDES?
+     * @throws MojoFailureException 
+     */
+    public static List<File> writeInventory( List<File> inventory, File inventoryFile )
+        throws MojoFailureException
     {
-        return paths;
+        Set<String> paths = new HashSet<String>();
+
+        /*
+         * It might be cleverer to store paths relative to the checkoutDirectory, but this really should work.
+         */
+        for ( File f : inventory )
+        {
+            // See below. We only bother about files.
+            if ( f.isFile() )
+            {
+                paths.add( f.getAbsolutePath() );
+            }
+        }
+        try
+        {
+            MappingJsonFactory factory = new MappingJsonFactory();
+            JsonGenerator gen = factory.createJsonGenerator( inventoryFile, JsonEncoding.UTF8 );
+            gen.writeObject( paths );
+            gen.close();
+            return inventory;
+        }
+        catch ( JsonProcessingException e )
+        {
+            throw new MojoFailureException( "Failed to write inventory to " + inventoryFile.getAbsolutePath(), e );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoFailureException( "Failed to write inventory to " + inventoryFile.getAbsolutePath(), e );
+        }
     }
 
-    public void setPaths( Set<String> paths )
+    public static List<File> readInventory( File inventoryFile )
+        throws MojoFailureException
     {
-        this.paths = paths;
+        try
+        {
+            MappingJsonFactory factory = new MappingJsonFactory();
+            JsonParser parser = factory.createJsonParser( inventoryFile );
+            Set<String> storedInventory = parser.readValueAs( HashSet.class );
+            List<File> inventory = new ArrayList<File>();
+            for ( String p : storedInventory )
+            {
+                inventory.add( new File( p ) );
+            }
+            parser.close();
+            return inventory;
+        }
+        catch ( JsonProcessingException e )
+        {
+            throw new MojoFailureException( "Failed to write inventory to " + inventoryFile.getAbsolutePath(), e );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoFailureException( "Failed to write inventory to " + inventoryFile.getAbsolutePath(), e );
+        }  
     }
 }

Modified: maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishInventoryMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishInventoryMojo.java?rev=1332454&r1=1332453&r2=1332454&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishInventoryMojo.java (original)
+++ maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishInventoryMojo.java Mon Apr 30 22:45:11 2012
@@ -172,7 +172,9 @@ public class ScmPublishInventoryMojo
         {
             checkoutExisting();
 
-            List<File> inventory = writeInventory();
+            List<File> inventory = ScmPublishInventory.listInventoryFiles( checkoutDirectory );
+
+            ScmPublishInventory.writeInventory( inventory, inventoryFile );
 
             deleteInventory( inventory );
         }

Modified: maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishMojo.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishMojo.java?rev=1332454&r1=1332453&r2=1332454&view=diff
==============================================================================
--- maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishMojo.java (original)
+++ maven/sandbox/trunk/plugins/maven-site-scm-publish-plugin/src/main/java/org/apache/maven/plugins/scmpublish/ScmPublishPublishMojo.java Mon Apr 30 22:45:11 2012
@@ -160,7 +160,7 @@ public class ScmPublishPublishMojo
         }
 
         // read in the list left behind by prepare; fail if it's not there.
-        List<File> inventory = readInventory();
+        List<File> inventory = ScmPublishInventory.readInventory( inventoryFile );
 
         // setup the scm plugin with help from release plugin utilities
         try
@@ -177,17 +177,15 @@ public class ScmPublishPublishMojo
         }
 
         // what files are in stock now?
-        Set<File> added = new HashSet<File>();
-        Collection<File> newInventory = FileUtils.listFiles( checkoutDirectory, new DotFilter(), new DotFilter() );
-        added.addAll( newInventory );
-
-        Set<File> deleted = new HashSet<File>();
-        deleted.addAll( inventory );
-        deleted.removeAll( added ); // old - new = deleted. (Added is the complete new inventory at this point.)
+        Collection<File> newInventory = ScmPublishInventory.listInventoryFiles( checkoutDirectory );
+
+        Set<File> deleted = new HashSet<File>( inventory );
+        deleted.removeAll( newInventory ); // old - new = deleted. (Added is the complete new inventory at this point.)
+
+        Set<File> added = new HashSet<File>( newInventory );
         added.removeAll( inventory ); // new - old = added.
 
-        Set<File> updated = new HashSet<File>();
-        updated.addAll( newInventory );
+        Set<File> updated = new HashSet<File>( newInventory );
         updated.retainAll( inventory ); // set intersection
 
         logInfo( "Publish files: %d addition(s), %d update(s), %d delete(s)", added.size(), updated.size(),