maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r165259 - /maven/wagon/trunk/wagon-providers/wagon-scm /maven/wagon/trunk/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm /maven/wagon/trunk/wagon-providers/wagon-scm/src/main/resources/META-INF/plexus /maven/wagon/trunk/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm /maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext
Date Fri, 29 Apr 2005 04:49:08 GMT
Author: brett
Date: Thu Apr 28 21:49:06 2005
New Revision: 165259

URL: http://svn.apache.org/viewcvs?rev=165259&view=rev
Log:
complete implementation of SCM based wagon

Modified:
    maven/wagon/trunk/wagon-providers/wagon-scm/pom.xml
    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/main/resources/META-INF/plexus/components.xml
    maven/wagon/trunk/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmWagonTest.java
    maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java

Modified: maven/wagon/trunk/wagon-providers/wagon-scm/pom.xml
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-scm/pom.xml?rev=165259&r1=165258&r2=165259&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-scm/pom.xml (original)
+++ maven/wagon/trunk/wagon-providers/wagon-scm/pom.xml Thu Apr 28 21:49:06 2005
@@ -28,5 +28,11 @@
       <version>1.0-alpha-1-SNAPSHOT</version>
       <!-- temporarily required at compile time -->
     </dependency>
+    <dependency>
+      <groupId>org.apache.maven.scm</groupId>
+      <artifactId>maven-scm-test</artifactId>
+      <version>1.0-alpha-1-SNAPSHOT</version>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>

Modified: maven/wagon/trunk/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-scm/src/main/java/org/apache/maven/wagon/providers/scm/ScmWagon.java?rev=165259&r1=165258&r2=165259&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 Apr 28 21:49:06 2005
@@ -16,35 +16,24 @@
  * limitations under the License.
  */
 
-import org.apache.commons.httpclient.Credentials;
-import org.apache.commons.httpclient.Header;
-import org.apache.commons.httpclient.HostConfiguration;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpRecoverableException;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
-import org.apache.commons.httpclient.NTCredentials;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.commons.httpclient.methods.GetMethod;
-import org.apache.commons.httpclient.methods.PutMethod;
-import org.apache.commons.httpclient.util.DateParseException;
-import org.apache.commons.httpclient.util.DateParser;
-import org.apache.commons.lang.StringUtils;
+import org.apache.maven.scm.ScmException;
+import org.apache.maven.scm.ScmFileSet;
 import org.apache.maven.scm.manager.NoSuchScmProviderException;
 import org.apache.maven.scm.manager.ScmManager;
 import org.apache.maven.scm.provider.svn.repository.SvnScmProviderRepository;
 import org.apache.maven.scm.repository.ScmRepository;
 import org.apache.maven.scm.repository.ScmRepositoryException;
-import org.apache.maven.scm.ScmFileSet;
-import org.apache.maven.scm.ScmException;
 import org.apache.maven.wagon.AbstractWagon;
 import org.apache.maven.wagon.ConnectionException;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.events.TransferEvent;
 import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.apache.maven.wagon.resource.Resource;
+import org.apache.maven.wagon.util.FileUtils;
 
 import java.io.File;
+import java.io.IOException;
 
 /**
  * @author <a href="brett@apache.org">Brett Porter</a>
@@ -55,6 +44,8 @@
 {
     private ScmManager scmManager;
 
+    private File checkoutDirectory;
+
     public ScmManager getScmManager()
     {
         return scmManager;
@@ -65,9 +56,23 @@
         this.scmManager = scmManager;
     }
 
+    public File getCheckoutDirectory()
+    {
+        return checkoutDirectory;
+    }
+
+    public void setCheckoutDirectory( File checkoutDirectory )
+    {
+        this.checkoutDirectory = checkoutDirectory;
+    }
+
     public void openConnection()
         throws ConnectionException
     {
+        if ( !checkoutDirectory.exists() )
+        {
+            checkoutDirectory.mkdirs();
+        }
     }
 
     private ScmRepository getScmRepository( String url )
@@ -87,7 +92,7 @@
         ScmRepository scmRepository;
         try
         {
-            scmRepository = scmManager.makeScmRepository( getRepository().getUrl() );
+            scmRepository = scmManager.makeScmRepository( url );
         }
         catch ( ScmRepositoryException e )
         {
@@ -119,17 +124,51 @@
     public void put( File source, String resourceName )
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
     {
-        String url = getRepository().getUrl() + "/" + resourceName;
-
         Resource resource = new Resource( resourceName );
 
         firePutInitiated( resource, source );
 
+        String url = getRepository().getUrl() + "/" + resourceName;
+
+        ScmRepository scmRepository = getScmRepository( url );
+
         firePutStarted( resource, source );
 
-        // TODO: if not exists, checkout
-        // TODO: put file in place
-        // TODO: commit
+        try
+        {
+            File scmFile = new File( checkoutDirectory, resourceName );
+            scmFile.getParentFile().mkdirs();
+
+            boolean alreadyExists = scmFile.exists();
+
+            if ( !scmFile.equals( source ) )
+            {
+                FileUtils.copyFile( source, scmFile );
+            }
+
+            if ( alreadyExists )
+            {
+                scmManager.update( scmRepository, new ScmFileSet( checkoutDirectory, resourceName,
null ), null );
+            }
+            else
+            {
+                scmManager.checkOut( scmRepository, new ScmFileSet( scmFile.getParentFile()
), null );
+                scmManager.add( scmRepository, new ScmFileSet( scmFile.getParentFile(), scmFile
) );
+            }
+
+            String msg = "Adding " + resourceName + " to repository";
+            scmManager.checkIn( scmRepository, new ScmFileSet( scmFile.getParentFile(), scmFile
), null, msg );
+        }
+        catch ( ScmException e )
+        {
+            throw new TransferFailedException( "Error interacting with SCM", e );
+        }
+        catch ( IOException e )
+        {
+            throw new TransferFailedException( "Error interacting with SCM", e );
+        }
+
+        postProcessListeners( resource, source, TransferEvent.REQUEST_PUT );
 
         firePutCompleted( resource, source );
     }
@@ -165,19 +204,33 @@
 
         try
         {
-            if ( destination.exists() )
+            File scmFile = new File( checkoutDirectory, resourceName );
+            scmFile.getParentFile().mkdirs();
+
+            if ( scmFile.exists() )
             {
-                scmManager.update( scmRepository, new ScmFileSet( destination.getParentFile(),
destination ), null );
+                scmManager.update( scmRepository, new ScmFileSet( checkoutDirectory, resourceName,
null ), null );
             }
             else
             {
-                scmManager.checkOut( scmRepository, new ScmFileSet( destination.getParentFile()
), null );
+                scmManager.checkOut( scmRepository, new ScmFileSet( scmFile.getParentFile()
), null );
+            }
+
+            if ( !scmFile.equals( destination ) )
+            {
+                FileUtils.copyFile( scmFile, destination );
             }
         }
         catch ( ScmException e )
         {
             throw new TransferFailedException( "Error getting file from SCM", e );
         }
+        catch ( IOException e )
+        {
+            throw new TransferFailedException( "Error getting file from SCM", e );
+        }
+
+        postProcessListeners( resource, destination, TransferEvent.REQUEST_GET );
 
         fireGetCompleted( resource, destination );
     }

Modified: maven/wagon/trunk/wagon-providers/wagon-scm/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-scm/src/main/resources/META-INF/plexus/components.xml?rev=165259&r1=165258&r2=165259&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-scm/src/main/resources/META-INF/plexus/components.xml
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-scm/src/main/resources/META-INF/plexus/components.xml
Thu Apr 28 21:49:06 2005
@@ -10,6 +10,9 @@
           <role>org.apache.maven.scm.manager.ScmManager</role>
         </requirement>
       </requirements>
+      <configuration>
+        <checkoutDirectory>${user.home}/.m2/repository</checkoutDirectory>
+      </configuration>
     </component>
   </components>
 </component-set>

Modified: maven/wagon/trunk/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmWagonTest.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmWagonTest.java?rev=165259&r1=165258&r2=165259&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmWagonTest.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-scm/src/test/java/org/apache/maven/wagon/providers/scm/ScmWagonTest.java
Thu Apr 28 21:49:06 2005
@@ -17,8 +17,9 @@
  */
 
 
-import org.apache.maven.wagon.FileTestUtils;
 import org.apache.maven.wagon.WagonTestCase;
+import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.util.FileUtils;
 
 import java.io.File;
 import java.io.IOException;
@@ -30,16 +31,46 @@
 public class ScmWagonTest
     extends WagonTestCase
 {
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        FileUtils.deleteDirectory( getCheckoutDirectory() );
+    }
+
+    protected Wagon getWagon()
+        throws Exception
+    {
+        ScmWagon wagon = (ScmWagon) super.getWagon();
+
+        wagon.setCheckoutDirectory( getCheckoutDirectory() );
+
+        return wagon;
+    }
+
+    private File getCheckoutDirectory()
+    {
+        return getTestFile( "target/test-output/checkout" );
+    }
+
     protected String getProtocol()
     {
-        return "file";
+        return "scm";
     }
 
     protected String getTestRepositoryUrl()
         throws IOException
     {
-        File file = FileTestUtils.createUniqueDir( getName() + ".file-repository." );
+        String repository = getTestFile( "target/test-classes/test-repo" ).getAbsolutePath();
+
+        // TODO: this is a hack for windows
+        if ( repository.indexOf( ":" ) >= 0 )
+        {
+            repository = repository.substring( repository.indexOf( ":" ) + 1 );
+        }
+        repository = repository.replace( '\\', '/' );
 
-        return "file://" + file.getPath();
+        return "scm:cvs:local:" + repository + ":repository";
     }
 }

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java?rev=165259&r1=165258&r2=165259&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java
Thu Apr 28 21:49:06 2005
@@ -274,35 +274,6 @@
         firePutCompleted( resource, source );
     }
 
-    private void postProcessListeners( Resource resource, File source, int requestType )
-        throws TransferFailedException
-    {
-        byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
-
-        TransferEvent transferEvent = new TransferEvent( this, resource, TransferEvent.TRANSFER_PROGRESS,
requestType );
-
-        try
-        {
-            InputStream input = new FileInputStream( source );
-
-            while ( true )
-            {
-                int n = input.read( buffer );
-
-                if ( n == -1 )
-                {
-                    break;
-                }
-
-                fireTransferProgress( transferEvent, buffer, n );
-            }
-        }
-        catch ( IOException e )
-        {
-            throw new TransferFailedException( "Failed to post-process the source file",
e );
-        }
-    }
-
     public void get( String resourceName, File destination )
         throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
     {



---------------------------------------------------------------------
To unsubscribe, e-mail: wagon-cvs-unsubscribe@maven.apache.org
For additional commands, e-mail: wagon-cvs-help@maven.apache.org


Mime
View raw message