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 2011/09/22 15:16:22 UTC

svn commit: r1174113 - in /maven/wagon/trunk/wagon-providers/wagon-scm/src: main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java site/apt/usage.apt.vm

Author: olamy
Date: Thu Sep 22 13:16:22 2011
New Revision: 1174113

URL: http://svn.apache.org/viewvc?rev=1174113&view=rev
Log:
[WAGON-303] Make wagon-scm work better with git
Submitted by Kathryn Huxtable

Modified:
    maven/wagon/trunk/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
    maven/wagon/trunk/wagon-providers/wagon-scm/src/site/apt/usage.apt.vm

Modified: maven/wagon/trunk/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java?rev=1174113&r1=1174112&r2=1174113&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java (original)
+++ maven/wagon/trunk/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java Thu Sep 22 13:16:22 2011
@@ -19,19 +19,13 @@ package org.apache.maven.wagon.providers
  * under the License.
  */
 
-import java.io.File;
-import java.io.IOException;
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Random;
-import java.util.Stack;
-
+import org.apache.maven.scm.ScmBranch;
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.ScmFile;
 import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.ScmResult;
+import org.apache.maven.scm.ScmRevision;
+import org.apache.maven.scm.ScmTag;
 import org.apache.maven.scm.ScmVersion;
 import org.apache.maven.scm.command.add.AddScmResult;
 import org.apache.maven.scm.command.checkout.CheckOutScmResult;
@@ -50,10 +44,18 @@ import org.apache.maven.wagon.TransferFa
 import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.apache.maven.wagon.events.TransferEvent;
 import org.apache.maven.wagon.resource.Resource;
-
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
 
+import java.io.File;
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Random;
+import java.util.Stack;
+
 /**
  * Wagon provider to get and put files from and to SCM systems, using Maven-SCM as underlying transport.
  * <p/>
@@ -63,13 +65,12 @@ import org.codehaus.plexus.util.StringUt
  * possible, or the checkout directory needs to be a constant. Doing releases won't scale if you have to checkout the
  * whole repository structure in order to add 3 files.
  *
- * @plexus.component role="org.apache.maven.wagon.Wagon" role-hint="scm" instantiation-strategy="per-lookup"
- *
  * @author <a href="brett@apache.org">Brett Porter</a>
  * @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
  * @author <a href="carlos@apache.org">Carlos Sanchez</a>
  * @author Jason van Zyl
  * @version $Id$
+ * @plexus.component role="org.apache.maven.wagon.Wagon" role-hint="scm" instantiation-strategy="per-lookup"
  */
 public class ScmWagon
     extends AbstractWagon
@@ -79,6 +80,20 @@ public class ScmWagon
      */
     private ScmManager scmManager;
 
+    /**
+     * The SCM version, if any.
+     *
+     * @parameter
+     */
+    private String scmVersion;
+
+    /**
+     * The SCM version type, if any. Defaults to "branch".
+     *
+     * @parameter
+     */
+    private String scmVersionType;
+
     private File checkoutDirectory;
 
     /**
@@ -102,6 +117,46 @@ public class ScmWagon
     }
 
     /**
+     * Get the scmVersion used in this Wagon
+     *
+     * @return the scmVersion
+     */
+    public String getScmVersion()
+    {
+        return scmVersion;
+    }
+
+    /**
+     * Set the scmVersion
+     *
+     * @param scmVersion the scmVersion to set
+     */
+    public void setScmVersion( String scmVersion )
+    {
+        this.scmVersion = scmVersion;
+    }
+
+    /**
+     * Get the scmVersionType used in this Wagon
+     *
+     * @return the scmVersionType
+     */
+    public String getScmVersionType()
+    {
+        return scmVersionType;
+    }
+
+    /**
+     * Set the scmVersionType
+     *
+     * @param scmVersionType the scmVersionType to set
+     */
+    public void setScmVersionType( String scmVersionType )
+    {
+        this.scmVersionType = scmVersionType;
+    }
+
+    /**
      * Get the directory where Wagon will checkout files from SCM. This directory will be deleted!
      *
      * @return directory
@@ -193,6 +248,37 @@ public class ScmWagon
         }
     }
 
+    /**
+     * Construct the ScmVersion to use for operations.
+     * <p/>
+     * <p>If scmVersion is supplied, scmVersionType must also be supplied to
+     * take effect.</p>
+     */
+    private ScmVersion makeScmVersion()
+    {
+        if ( StringUtils.isBlank( scmVersion ) )
+        {
+            return null;
+        }
+        if ( scmVersion.length() > 0 )
+        {
+            if ( "revision".equals( scmVersionType ) )
+            {
+                return new ScmRevision( scmVersion );
+            }
+            else if ( "tag".equals( scmVersionType ) )
+            {
+                return new ScmTag( scmVersion );
+            }
+            else if ( "branch".equals( scmVersionType ) )
+            {
+                return new ScmBranch( scmVersion );
+            }
+        }
+
+        return null;
+    }
+
     private ScmRepository getScmRepository( String url )
         throws ScmRepositoryException, NoSuchScmProviderException
     {
@@ -277,7 +363,7 @@ public class ScmWagon
 
             target.setContentLength( source.length() );
             target.setLastModified( source.lastModified() );
-            
+
             firePutStarted( target, source );
 
             String msg = "Wagon: Adding " + source.getName() + " to repository";
@@ -289,8 +375,7 @@ public class ScmWagon
 
             File newCheckoutDirectory = new File( checkoutDirectory, relPath );
 
-            File scmFile =
-                new File( newCheckoutDirectory, source.isDirectory() ? "" : getFilename( targetName ) );
+            File scmFile = new File( newCheckoutDirectory, source.isDirectory() ? "" : getFilename( targetName ) );
 
             boolean fileAlreadyInScm = scmFile.exists();
 
@@ -318,21 +403,21 @@ public class ScmWagon
                 }
             }
 
-            ScmResult result = scmProvider.checkIn( scmRepository, new ScmFileSet( checkoutDirectory ),
-                                                    (ScmVersion) null, msg );
+            ScmResult result =
+                scmProvider.checkIn( scmRepository, new ScmFileSet( checkoutDirectory ), makeScmVersion(), msg );
 
             checkScmResult( result );
         }
         catch ( ScmException e )
         {
             fireTransferError( target, e, TransferEvent.REQUEST_GET );
-            
+
             throw new TransferFailedException( "Error interacting with SCM: " + e.getMessage(), e );
         }
         catch ( IOException e )
         {
             fireTransferError( target, e, TransferEvent.REQUEST_GET );
-            
+
             throw new TransferFailedException( "Error interacting with SCM: " + e.getMessage(), e );
         }
 
@@ -371,9 +456,9 @@ public class ScmWagon
 
         try
         {
-            while ( target.length() > 0 && !scmProvider
-                .list( scmRepository, new ScmFileSet( new File( "." ), new File( target ) ), false, (ScmVersion) null )
-                .isSuccess() )
+            while ( target.length() > 0 && !scmProvider.list( scmRepository,
+                                                              new ScmFileSet( new File( "." ), new File( target ) ),
+                                                              false, makeScmVersion() ).isSuccess() )
             {
                 stack.push( getFilename( target ) );
                 target = getDirname( target );
@@ -382,7 +467,7 @@ public class ScmWagon
         catch ( ScmException e )
         {
             fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
-            
+
             throw new TransferFailedException( "Error listing repository: " + e.getMessage(), e );
         }
 
@@ -393,18 +478,24 @@ public class ScmWagon
 
         try
         {
-            scmRepository = getScmRepository( getRepository().getUrl() + "/" + target.replace( '\\', '/' ) );
-
-            CheckOutScmResult ret = scmProvider.checkOut( scmRepository,
-                                                          new ScmFileSet( new File( checkoutDirectory, "" ) ),
-                                                          (ScmVersion) null, false );
+            String repoUrl = getRepository().getUrl();
+            if ( "svn".equals( scmProvider.getScmType() ) )
+            {
+                // Subversion is the only SCM that adds path structure to represent tags and branches.
+                // The rest use scmVersion and scmVersionType.
+                repoUrl += "/" + target.replace( '\\', '/' );
+            }
+            scmRepository = getScmRepository( repoUrl );
+            CheckOutScmResult ret =
+                scmProvider.checkOut( scmRepository, new ScmFileSet( new File( checkoutDirectory, "" ) ),
+                                      makeScmVersion(), false );
 
             checkScmResult( ret );
         }
         catch ( ScmException e )
         {
             fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
-            
+
             throw new TransferFailedException( "Error checking out: " + e.getMessage(), e );
         }
 
@@ -420,8 +511,9 @@ public class ScmWagon
             File newDir = new File( checkoutDirectory, relPath );
             if ( !newDir.mkdirs() )
             {
-                throw new TransferFailedException( "Failed to create directory " + newDir.getAbsolutePath()
-                    + "; parent should exist: " + checkoutDirectory );
+                throw new TransferFailedException(
+                    "Failed to create directory " + newDir.getAbsolutePath() + "; parent should exist: "
+                        + checkoutDirectory );
             }
 
             try
@@ -431,7 +523,7 @@ public class ScmWagon
             catch ( ScmException e )
             {
                 fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
-                
+
                 throw new TransferFailedException( "Failed to add directory " + newDir + " to working copy", e );
             }
         }
@@ -485,8 +577,9 @@ public class ScmWagon
             {
                 if ( reservedScmFile != null && !reservedScmFile.equals( files[i].getName() ) )
                 {
-                    addedFiles += addFiles( scmProvider, scmRepository, basedir, ( scmFilePath.length() == 0 ? ""
-                        : scmFilePath + "/" ) + files[i].getName() );
+                    addedFiles += addFiles( scmProvider, scmRepository, basedir,
+                                            ( scmFilePath.length() == 0 ? "" : scmFilePath + "/" )
+                                                + files[i].getName() );
                 }
             }
         }
@@ -518,15 +611,17 @@ public class ScmWagon
      *
      * @param result
      * @throws TransferFailedException if result was not a successful operation
-     * @throws ScmException 
+     * @throws ScmException
      */
     private void checkScmResult( ScmResult result )
         throws ScmException
     {
         if ( !result.isSuccess() )
         {
-            throw new ScmException( "Unable to commit file. " + result.getProviderMessage() + " "
-                + ( result.getCommandOutput() == null ? "" : result.getCommandOutput() ) );
+            throw new ScmException(
+                "Unable to commit file. " + result.getProviderMessage() + " " + ( result.getCommandOutput() == null
+                    ? ""
+                    : result.getCommandOutput() ) );
         }
     }
 
@@ -582,14 +677,14 @@ public class ScmWagon
 
             if ( reservedScmFile != null && new File( basedir, reservedScmFile ).exists() )
             {
-                scmProvider.update( scmRepository, new ScmFileSet( basedir ), (ScmVersion) null );
+                scmProvider.update( scmRepository, new ScmFileSet( basedir ), makeScmVersion() );
             }
             else
             {
                 // TODO: this should be checking out a full hierarchy (requires the -d equiv)
                 basedir.mkdirs();
 
-                scmProvider.checkOut( scmRepository, new ScmFileSet( basedir ), (ScmVersion) null );
+                scmProvider.checkOut( scmRepository, new ScmFileSet( basedir ), makeScmVersion() );
             }
 
             if ( !scmFile.exists() )
@@ -605,13 +700,13 @@ public class ScmWagon
         catch ( ScmException e )
         {
             fireTransferError( resource, e, TransferEvent.REQUEST_GET );
-            
+
             throw new TransferFailedException( "Error getting file from SCM", e );
         }
         catch ( IOException e )
         {
             fireTransferError( resource, e, TransferEvent.REQUEST_GET );
-            
+
             throw new TransferFailedException( "Error getting file from SCM", e );
         }
 
@@ -633,9 +728,9 @@ public class ScmWagon
 
             ScmProvider provider = getScmProvider( repository.getProvider() );
 
-            ListScmResult result = provider.list( repository,
-                                                  new ScmFileSet( new File( "." ), new File( resourcePath ) ), false,
-                                                  (ScmVersion) null );
+            ListScmResult result =
+                provider.list( repository, new ScmFileSet( new File( "." ), new File( resourcePath ) ), false,
+                               makeScmVersion() );
 
             if ( !result.isSuccess() )
             {

Modified: maven/wagon/trunk/wagon-providers/wagon-scm/src/site/apt/usage.apt.vm
URL: http://svn.apache.org/viewvc/maven/wagon/trunk/wagon-providers/wagon-scm/src/site/apt/usage.apt.vm?rev=1174113&r1=1174112&r2=1174113&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-scm/src/site/apt/usage.apt.vm (original)
+++ maven/wagon/trunk/wagon-providers/wagon-scm/src/site/apt/usage.apt.vm Thu Sep 22 13:16:22 2011
@@ -3,7 +3,7 @@
  ------
  Carlos Sanchez
  ------
- 2006-03-07
+ 2011-09-22
  ------
 
  ~~ Licensed to the Apache Software Foundation (ASF) under one
@@ -32,6 +32,11 @@ Maven Wagon SCM Usage
  (wagon-scm, maven-scm-manager-plexus and the maven-scm-provider for your SCM system, see examples below)
  to your pom and use URLs in the
  {{{http://maven.apache.org/scm/scm-url-format.html}SCM format}}.
+ 
+ For non-subversion SCM, in your settings.xml file you can include the elements <<<scmVersionType>>> and <<<scmVersion>>> to
+ specify a branch or tag to use. The value of <<<scmVersionType>>> must be one of <<<branch>>> or <<<tag>>>.
+ There is no default value for <<<scmVersionType>>> so you <MUST> specify it with <<<scmVersion>>> in order
+ to have any effect.
 
 
 Deploying your Maven site to Subversion
@@ -100,6 +105,50 @@ Deploying your Maven site to CVS
 ------
 
 
+Deploying your Maven site to GitHub's gh-pages
+
+ Same as before, but changing svnexe to gitexe and using a Git svn url.
+
+------
+  <build>
+    <extensions>
+      <extension>
+        <groupId>org.apache.maven.wagon</groupId>
+        <artifactId>wagon-scm</artifactId>
+        <version>${project.version}</version>
+      </extension>
+      <extension>
+        <groupId>org.apache.maven.scm</groupId>
+        <artifactId>maven-scm-manager-plexus</artifactId>
+        <version>${project.version}</version>
+      </extension>
+      <extension>
+        <groupId>org.apache.maven.scm</groupId>
+        <artifactId>maven-scm-provider-gitexe</artifactId>
+        <version>${project.version}</version>
+      </extension>
+    </extensions>
+  </build>
+  <distributionManagement>
+    <site>
+      <id>my.git.server</id>
+      <url>scm:git:ssh://git@github.com/myuser/myproject.git</url>
+    </site>
+  </distributionManagement>
+------
+
+ And in your settings.xml file:
+
+------
+  <server>
+    <id>my.git.server</id>
+    <username>git</username>
+    <scmVersionType>branch</scmVersionType>
+    <scmVersion>gh-pages</scmVersion>
+  </server>
+------
+
+
 
 Using a Subversion based remote repository in Maven 2