Author: bimargulies
Date: Mon Feb 20 16:30:18 2012
New Revision: 1291348

URL: http://svn.apache.org/viewvc?rev=1291348&view=rev
Log:
Considerable progress, but the scm provider refuses to process a list. Do I 
need to call it many times, or
what?

Added:
    maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/
    maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/
    
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/
    
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/apt/
    
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/apt/index.apt
   (with props)
    
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/site.xml
   (with props)
    
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/CommonSvnpubsubMojo.java
   (with props)
    
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/SvnpubsubPublishMojo.java
   (with props)
Modified:
    
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/SvnpubsubInventoryMojo.java

Added: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/apt/index.apt
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/apt/index.apt?rev=1291348&view=auto
==============================================================================
--- 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/apt/index.apt
 (added)
+++ 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/apt/index.apt
 Mon Feb 20 16:30:18 2012
@@ -0,0 +1,3 @@
+Index
+
+    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ultrices 
magna quis arcu venenatis varius. Donec pellentesque fringilla mauris, eget 
convallis quam gravida nec. Sed sapien urna, dapibus sed fringilla nec, 
adipiscing vitae dui. Sed at vestibulum diam. Integer mattis, eros in congue 
imperdiet, enim sapien eleifend mauris, sit amet blandit turpis nibh quis 
lorem. Donec consectetur hendrerit velit. Nulla luctus, felis eget luctus 
pharetra, sem lectus dapibus ante, eget sodales lorem felis laoreet tortor. Sed 
nisi orci, commodo in tempus id, semper sed tellus. Aenean tellus augue, 
dapibus vitae fermentum commodo, dapibus quis ante. Ut tempus nunc ut erat 
rutrum sit amet eleifend justo imperdiet. Suspendisse euismod nibh sit amet 
eros faucibus eget iaculis erat aliquet.
\ No newline at end of file

Propchange: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/apt/index.apt
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/apt/index.apt
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/site.xml
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/site.xml?rev=1291348&view=auto
==============================================================================
--- 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/site.xml
 (added)
+++ 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/site.xml
 Mon Feb 20 16:30:18 2012
@@ -0,0 +1,10 @@
+<project name="perform-002">
+  <publishDate position="right"/>
+  <version position="left"/>
+    <body>
+        <menu name="perform-002">
+            <item name="Home" href="index.html" />
+        </menu>
+        <menu ref="reports"/>
+    </body>
+</project>

Propchange: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/site.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/it/002-perform/src/site/site.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/CommonSvnpubsubMojo.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/CommonSvnpubsubMojo.java?rev=1291348&view=auto
==============================================================================
--- 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/CommonSvnpubsubMojo.java
 (added)
+++ 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/CommonSvnpubsubMojo.java
 Mon Feb 20 16:30:18 2012
@@ -0,0 +1,302 @@
+package org.apache.maven.plugins.svnpubsub;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.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.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.provider.ScmProvider;
+import org.apache.maven.scm.repository.ScmRepository;
+import org.apache.maven.scm.repository.ScmRepositoryException;
+import org.apache.maven.settings.Settings;
+import org.apache.maven.shared.release.ReleaseExecutionException;
+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 svnpubsub mojos.
+ */
+public abstract class CommonSvnpubsubMojo
+    extends AbstractMojo
+{
+
+    /**
+     * Location of the inventory file.
+     * 
+     * @parameter expression="${svnpubsub.inventoryFile}"
+     *            
default-value="${project.build.directory}/svnpubsub-inventory.js"
+     */
+    protected File inventoryFile;
+    /**
+     * Location of the svn publication tree.
+     * 
+     * @parameter expression="${svnpubsub.pubScmUrl}"
+     * @required
+     */
+    protected String pubScmUrl;
+    /**
+     * Location of the svn publication tree.
+     * 
+     * @parameter expression="${svnpubsub.checkoutDirectory}"
+     *            default-value="${project.build.directory}/svnpubsub-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;
+    /**
+     * 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;
+    /**
+     * @parameter expression="${settings}"
+     * @required
+     * @readonly
+     */
+    protected Settings settings;
+    /**
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    protected MavenProject project;
+    /**
+     * @parameter expression="${reactorProjects}"
+     * @required
+     * @readonly
+     */
+    protected List<MavenProject> reactorProjects;
+    /**
+     * 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
+     */
+    protected boolean localCheckout;
+    /**
+     * @parameter expression="${basedir}"
+     * @required
+     * @readonly
+     */
+    protected File basedir;
+    /**
+     * @parameter expression="${session}"
+     * @readonly
+     * @required
+     */
+    protected MavenSession session;
+    protected ScmProvider scmProvider;
+    protected ScmRepository scmRepository;
+    // a list (ordered) to maintain sort for ease of comparison.
+    protected List<File> inventory;
+
+    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 CommonSvnpubsubMojo()
+    {
+        super();
+    }
+
+    protected void logInfo( String format, Object... params )
+    {
+        getLog().info( String.format( format, params ) );
+    }
+
+    protected void logError( String format, Object... params )
+    {
+        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?
+     * @throws MojoFailureException 
+     */
+    protected void writeInventory()
+        throws MojoFailureException
+    {
+        inventory = new ArrayList<File>();
+        inventory.addAll(FileUtils.listFiles( checkoutDirectory, new 
DotFilter(), new DotFilter()));
+        Collections.sort(inventory);
+        SvnpubsubInventory initialInventory = new SvnpubsubInventory();
+        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();
+        }
+        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 void readInventory() throws MojoFailureException 
+    {
+        try
+        {
+            MappingJsonFactory factory = new MappingJsonFactory();
+            JsonParser parser = factory.createJsonParser( inventoryFile );
+            SvnpubsubInventory storedInventory = parser.readValueAs( 
SvnpubsubInventory.class );
+            inventory = new ArrayList<File>();
+            for (String p : storedInventory.getPaths()) {
+                inventory.add( new File( p ) );
+            }
+            parser.close();
+        }
+        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
+    {
+        String scmUrl;
+        if ( localCheckout )
+        {
+            // in the release phase we have to change the checkout URL
+            // to do a local checkout instead of going over the network.
+    
+            // the first step is a bit tricky, we need to know which provider! 
like e.g. "scm:jgit:http://";
+            // the offset of 4 is because 'scm:' has 4 characters...
+            String providerPart = pubScmUrl.substring( 0, pubScmUrl.indexOf( 
':', 4 ) );
+    
+            // X TODO: also check the information from 
releaseDescriptor.getScmRelativePathProjectDirectory()
+            // X TODO: in case our toplevel git directory has no pom.
+            // X TODO: fix pathname once I understand this.
+            scmUrl = providerPart + ":file://" + "target/localCheckout";
+            logInfo( "Performing a LOCAL checkout from " + scmUrl );
+        }
+    
+        ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
+        releaseDescriptor.setInteractive( settings.isInteractiveMode() );
+    
+        releaseDescriptor.setScmPassword( password );
+        releaseDescriptor.setScmUsername( username );
+    
+        releaseDescriptor.setWorkingDirectory( basedir.getAbsolutePath() );
+        releaseDescriptor.setLocalCheckout( localCheckout );
+        releaseDescriptor.setScmSourceUrl( pubScmUrl );
+    
+        try
+        {
+            scmRepository = scmRepositoryConfigurator.getConfiguredRepository( 
releaseDescriptor, settings );
+    
+            scmProvider = scmRepositoryConfigurator.getRepositoryProvider( 
scmRepository );
+        }
+        catch ( ScmRepositoryException e )
+        {
+            // TODO: rethink this error pattern.
+            logError( e.getMessage() );
+    
+            throw new ReleaseScmRepositoryException( e.getMessage(), 
e.getValidationMessages() );
+        }
+        catch ( NoSuchScmProviderException e )
+        {
+            logError( e.getMessage() );
+    
+            throw new ReleaseExecutionException( "Unable to configure SCM 
repository: " + e.getMessage(), e );
+        }
+        return releaseDescriptor;
+    }
+
+
+}
\ No newline at end of file

Propchange: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/CommonSvnpubsubMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/CommonSvnpubsubMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/SvnpubsubInventoryMojo.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/SvnpubsubInventoryMojo.java?rev=1291348&r1=1291347&r2=1291348&view=diff
==============================================================================
--- 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/SvnpubsubInventoryMojo.java
 (original)
+++ 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/SvnpubsubInventoryMojo.java
 Mon Feb 20 16:30:18 2012
@@ -21,225 +21,49 @@ package org.apache.maven.plugins.svnpubs
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Collection;
-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.execution.MavenSession;
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 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.manager.NoSuchScmProviderException;
-import org.apache.maven.scm.provider.ScmProvider;
-import org.apache.maven.scm.repository.ScmRepository;
-import org.apache.maven.scm.repository.ScmRepositoryException;
-import org.apache.maven.settings.Settings;
 import org.apache.maven.shared.release.ReleaseExecutionException;
 import org.apache.maven.shared.release.ReleaseFailureException;
 import org.apache.maven.shared.release.config.ReleaseDescriptor;
 import org.apache.maven.shared.release.scm.ReleaseScmCommandException;
-import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
-import org.apache.maven.shared.release.scm.ScmRepositoryConfigurator;
 import org.apache.maven.shared.release.util.ReleaseUtil;
-import org.codehaus.jackson.JsonEncoding;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.JsonProcessingException;
-import org.codehaus.jackson.map.MappingJsonFactory;
 import org.codehaus.plexus.util.StringUtils;
 
 /**
  * Prepare a directory for version-managed site generation. This checks out 
the specified directory from the SCM and
  * then takes inventory of all the resulting files. This inventory then allows 
the 'checkin' target to tee up deletions
  * as well as modifications and additions. There's an assumption here that an 
entire directory in svn is dedicated to
- * the publication process for this project. In the aggregate case, this is 
going to take some doing. TODO: we want
+ * the publication process for this project. In the aggregate case, this is 
going to take some doing. 
+ * 
+ * If we allow this to be non-aggregate, then each module has to configure 
pathnames, which would be a pain. So
+ * we assume that in an aggregate project this runs once, at the top -- then 
all of the projects site-deploy
+ * into the file: url this creates. 
+ * 
+ * 
+ * TODO: we want
  * multiple includes/excludes, but the scm API doesn't go there.
  * 
  * @goal prepare
  * @phase pre-site
+ * @aggregate
  */
 public class SvnpubsubInventoryMojo
-    extends AbstractMojo
+    extends CommonSvnpubsubMojo
 {
-    /**
-     * Location of the inventory file.
-     * 
-     * @parameter expression="${svnpubsub.inventoryFile}"
-     *            
default-value="${project.build.directory}/svnpubsub-inventory.js"
-     */
-    private File inventoryFile;
-
-    /**
-     * Location of the svn publication tree.
-     * 
-     * @parameter expression="${svnpubsub.pubScmUrl}"
-     * @required
-     */
-    private String pubScmUrl;
-
-    /**
-     * Location of the svn publication tree.
-     * 
-     * @parameter expression="${svnpubsub.checkoutDirectory}"
-     *            default-value="${project.build.directory}/svnpubsub-checkout"
-     */
-    private File checkoutDirectory;
-
-    /**
-     * Patterns to exclude from the scm tree.
-     * 
-     * @parameter
-     */
-    private String excludes;
-
-    /**
-     * Patterns to include in the scm tree.
-     * 
-     * @parameter
-     */
-    private String includes;
-
-    /**
-     * Tool that gets a configured SCM repository from release configuration.
-     * 
-     * @component
-     */
-    private ScmRepositoryConfigurator scmRepositoryConfigurator;
-
-    /**
-     * The SCM username to use.
-     * 
-     * @parameter expression="${username}"
-     */
-    private String username;
-
-    /**
-     * The SCM password to use.
-     * 
-     * @parameter expression="${password}"
-     */
-    private String password;
-
-    /**
-     * @parameter expression="${settings}"
-     * @required
-     * @readonly
-     */
-    protected Settings settings;
-
-    /**
-     * @parameter expression="${project}"
-     * @required
-     * @readonly
-     */
-    protected MavenProject project;
-
-    /**
-     * @parameter expression="${reactorProjects}"
-     * @required
-     * @readonly
-     */
-    protected List<MavenProject> reactorProjects;
-
-    /**
-     * 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
-     */
-    private boolean localCheckout;
-
-    /**
-     * @parameter expression="${basedir}"
-     * @required
-     * @readonly
-     */
-    protected File basedir;
-
-    /**
-     * @parameter expression="${session}"
-     * @readonly
-     * @required
-     */
-    protected MavenSession session;
-
-    private ScmProvider scmProvider;
-
-    private ScmRepository scmRepository;
-
-    private Collection<File> inventory;
-
-    private void logInfo( String format, Object... params )
-    {
-        getLog().info( String.format( format, params ) );
-    }
-
-    private void logError( String format, Object... params )
-    {
-        getLog().error( String.format( format, params ) );
-    }
-
     private void checkoutExisting()
         throws ReleaseExecutionException, ReleaseFailureException
     {
 
         logInfo( "Checking out the pub tree ..." );
 
-        String scmUrl = pubScmUrl;
-
-        if ( localCheckout )
-        {
-            // in the release phase we have to change the checkout URL
-            // to do a local checkout instead of going over the network.
-
-            // the first step is a bit tricky, we need to know which provider! 
like e.g. "scm:jgit:http://";
-            // the offset of 4 is because 'scm:' has 4 characters...
-            String providerPart = pubScmUrl.substring( 0, pubScmUrl.indexOf( 
':', 4 ) );
-
-            // X TODO: also check the information from 
releaseDescriptor.getScmRelativePathProjectDirectory()
-            // X TODO: in case our toplevel git directory has no pom.
-            // X TODO: fix pathname once I understand this.
-            scmUrl = providerPart + ":file://" + "target/localCheckout";
-            logInfo( "Performing a LOCAL checkout from " + scmUrl );
-        }
-
-        ReleaseDescriptor releaseDescriptor = new ReleaseDescriptor();
-        releaseDescriptor.setInteractive( settings.isInteractiveMode() );
-
-        releaseDescriptor.setScmPassword( password );
-        releaseDescriptor.setScmUsername( username );
-
-        releaseDescriptor.setWorkingDirectory( basedir.getAbsolutePath() );
-        releaseDescriptor.setLocalCheckout( localCheckout );
-        releaseDescriptor.setScmSourceUrl( pubScmUrl );
-
-        try
-        {
-            scmRepository = scmRepositoryConfigurator.getConfiguredRepository( 
releaseDescriptor, settings );
-
-            scmProvider = scmRepositoryConfigurator.getRepositoryProvider( 
scmRepository );
-        }
-        catch ( ScmRepositoryException e )
-        {
-            // TODO: rethink this error pattern.
-            logError( e.getMessage() );
-
-            throw new ReleaseScmRepositoryException( e.getMessage(), 
e.getValidationMessages() );
-        }
-        catch ( NoSuchScmProviderException e )
-        {
-            logError( e.getMessage() );
-
-            throw new ReleaseExecutionException( "Unable to configure SCM 
repository: " + e.getMessage(), e );
-        }
+        ReleaseDescriptor releaseDescriptor = setupScm();
 
         MavenProject rootProject = ReleaseUtil.getRootProject( reactorProjects 
);
         if ( checkoutDirectory.exists() )
@@ -309,6 +133,8 @@ public class SvnpubsubInventoryMojo
                 scmRelativePathProjectDirectory = 
rootProjectBasedir.substring( basedir.length() + 1 );
             }
         }
+        
+        // I don't seem to be using this. 
         releaseDescriptor.setScmRelativePathProjectDirectory( 
scmRelativePathProjectDirectory );
 
         if ( !scmResult.isSuccess() )
@@ -318,62 +144,7 @@ public class SvnpubsubInventoryMojo
             throw new ReleaseScmCommandException( "Unable to checkout from 
SCM", scmResult );
         }
     }
-    
-    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( "." );
-        }
-        
-    }
-
-    /**
-     * 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?
-     * @throws MojoFailureException 
-     */
-    private void writeInventory() throws MojoFailureException
-    {
-        inventory = FileUtils.listFiles( checkoutDirectory, new DotFilter(), 
new DotFilter());
-        SvnpubsubInventory initialInventory = new SvnpubsubInventory();
-        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();
-        }
-        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 );
-        }
-    }
-    
     /**
      * Clear out the data, so we can tell what's left after the run of the 
site plugin.
      * For now, don't bother with deleting empty directories. They are fairly 
harmless,

Added: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/SvnpubsubPublishMojo.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/SvnpubsubPublishMojo.java?rev=1291348&view=auto
==============================================================================
--- 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/SvnpubsubPublishMojo.java
 (added)
+++ 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/SvnpubsubPublishMojo.java
 Mon Feb 20 16:30:18 2012
@@ -0,0 +1,164 @@
+package org.apache.maven.plugins.svnpubsub;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
+import org.apache.maven.shared.release.ReleaseExecutionException;
+import org.apache.maven.shared.release.scm.ReleaseScmRepositoryException;
+
+/**
+ * Compare the list of files now on disk to the original inventory. Fire off 
scm adds and deletes as needed.
+ * 
+ * @goal publish
+ * @phase post-site
+ * @aggregate
+ */
+public class SvnpubsubPublishMojo
+    extends CommonSvnpubsubMojo
+{
+
+    /**
+     * Display list of added, deleted, and changed files, but do not do any 
actual SCM operations.
+     * 
+     * @parameter expression="${svnpubsub.dryRun}"
+     */
+    private boolean dryRun;
+
+    /**
+     * Run add and delete commands, but leave the actually checkin for the 
user to run manually.
+     * 
+     * @parameter expression="${svnpubsub.skipCheckin}"
+     */
+    private boolean skipCheckin;
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.maven.plugin.Mojo#execute()
+     */
+    public void execute()
+        throws MojoExecutionException, MojoFailureException
+    {
+        // read in the list left behind by prepare; fail if it's not there.
+        readInventory();
+        // setup the scm plugin with help from release plugin utilities
+        try
+        {
+            setupScm();
+        }
+        catch ( ReleaseScmRepositoryException e )
+        {
+            throw new MojoExecutionException( e.getMessage() );
+        }
+        catch ( ReleaseExecutionException e )
+        {
+            throw new MojoExecutionException( e.getMessage() );
+        }
+
+        // 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 );
+
+        /*
+         * I originally thought that this was a 'Diff' problem, but I don't 
think so now. I think this is most easily
+         * managed with set membership.
+         */
+        Set<File> deleted = new HashSet<File>();
+        deleted.addAll( inventory );
+        deleted.removeAll( added ); // old - new = deleted. (Added is the 
complete new inventory at this point.)
+        added.removeAll( inventory ); // new - old = added.
+
+        Set<File> updated = new HashSet<File>();
+        updated.addAll( newInventory );
+        updated.retainAll( inventory ); // set intersection
+
+        if ( dryRun )
+        {
+            for ( File addedFile : added )
+            {
+                logInfo( "Added %s", addedFile.getAbsolutePath() );
+            }
+            for ( File deletedFile : deleted )
+            {
+                logInfo( "Deleted %s", deletedFile.getAbsolutePath() );
+            }
+            for ( File updatedFile : updated )
+            {
+                logInfo( "Updated %s", updatedFile.getAbsolutePath() );
+            }
+            return;
+        }
+
+        if ( !added.isEmpty() )
+        {
+            List<File> addedList = new ArrayList<File>();
+            addedList.addAll( added );
+            ScmFileSet addedFileSet = new ScmFileSet( checkoutDirectory, 
addedList );
+            try
+            {
+                scmProvider.add( scmRepository, addedFileSet, "Adding new site 
files." );
+            }
+            catch ( ScmException e )
+            {
+                throw new MojoExecutionException( "Failed to add new files to 
SCM", e );
+            }
+        }
+
+        if ( !deleted.isEmpty() )
+        {
+            List<File> deletedList = new ArrayList<File>();
+            deletedList.addAll( deleted );
+            ScmFileSet deletedFileSet = new ScmFileSet( checkoutDirectory, 
deletedList );
+            try
+            {
+                scmProvider.remove( scmRepository, deletedFileSet, "Deleting 
obsolete site files." );
+            }
+            catch ( ScmException e )
+            {
+                throw new MojoExecutionException( "Failed to delete removed 
files to SCM", e );
+            }
+        }
+
+        if ( !skipCheckin )
+        {
+            ScmFileSet updatedFileSet = new ScmFileSet( checkoutDirectory );
+            try
+            {
+                scmProvider.checkIn( scmRepository, updatedFileSet, "Checking 
in site." );
+            }
+            catch ( ScmException e )
+            {
+                throw new MojoExecutionException( "Failed to perform checkin 
SCM", e );
+            }
+        }
+    }
+
+}

Propchange: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/SvnpubsubPublishMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/sandbox/trunk/plugins/asf-svnpubsub-plugin/src/main/java/org/apache/maven/plugins/svnpubsub/SvnpubsubPublishMojo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to