maven-wagon-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r312781 - in /maven/wagon/trunk: wagon-provider-api/src/main/java/org/apache/maven/wagon/ wagon-provider-api/src/test/java/org/apache/maven/wagon/ wagon-provider-test/src/main/java/org/apache/maven/wagon/ wagon-providers/wagon-ssh-external/...
Date Tue, 11 Oct 2005 02:05:02 GMT
Author: brett
Date: Mon Oct 10 19:04:28 2005
New Revision: 312781

URL: http://svn.apache.org/viewcvs?rev=312781&view=rev
Log:
share command executor, make scpexe capable of directory copy

Added:
    maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutionException.java
  (contents, props changed)
      - copied, changed from r312585, maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/CommandExecutionException.java
    maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutor.java
  (contents, props changed)
      - copied, changed from r312585, maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/SshCommandExecutor.java
    maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PermissionModeUtils.java
  (contents, props changed)
      - copied, changed from r312585, maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java
    maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PermissionModeUtilsTest.java
  (contents, props changed)
      - copied, changed from r312585, maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java
    maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/CommandExecutorTestCase.java
  (with props)
    maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/test/java/org/apache/maven/wagon/providers/sshext/SshCommandExecutorTest.java
  (with props)
Removed:
    maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/SshCommandExecutor.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/CommandExecutionException.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/SshCommandExecutor.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java
Modified:
    maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
    maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/ScpExternalWagon.java
    maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/resources/META-INF/plexus/components.xml
    maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/test/java/org/apache/maven/wagon/providers/sshext/TestData.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/resources/META-INF/plexus/components.xml
    maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/SshCommandExecutorTest.java

Modified: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java?rev=312781&r1=312780&r2=312781&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
(original)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
Mon Oct 10 19:04:28 2005
@@ -36,6 +36,10 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.FileOutputStream;
+import java.util.List;
+import java.util.zip.ZipOutputStream;
+import java.util.zip.ZipEntry;
 
 /**
  * Implementation of common facilties for Wagon providers.
@@ -585,5 +589,66 @@
     public boolean supportsDirectoryCopy()
     {
         return false;
+    }
+
+    public void createZip( List files, File zipName, File basedir )
+        throws IOException
+    {
+        ZipOutputStream zos = new ZipOutputStream( new FileOutputStream( zipName ) );
+
+        try
+        {
+            for ( int i = 0; i < files.size(); i++ )
+            {
+                String file = (String) files.get( i );
+
+                file = file.replace( '\\', '/' );
+
+                writeZipEntry( zos, new File( basedir, file ), file );
+            }
+        }
+        finally
+        {
+            IOUtil.close( zos );
+        }
+    }
+
+    private void writeZipEntry( ZipOutputStream jar, File source, String entryName )
+        throws IOException
+    {
+        byte[] buffer = new byte[1024];
+
+        int bytesRead;
+
+        FileInputStream is = new FileInputStream( source );
+
+        try
+        {
+            ZipEntry entry = new ZipEntry( entryName );
+
+            jar.putNextEntry( entry );
+
+            while ( ( bytesRead = is.read( buffer ) ) != -1 )
+            {
+                jar.write( buffer, 0, bytesRead );
+            }
+        }
+
+        finally
+        {
+            is.close();
+        }
+    }
+
+    protected static String getPath( String basedir, String dir )
+    {
+        String path;
+        path = basedir;
+        if ( !basedir.endsWith( "/" ) && !dir.startsWith( "/" ) )
+        {
+            path += "/";
+        }
+        path += dir;
+        return path;
     }
 }

Copied: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutionException.java
(from r312585, maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/CommandExecutionException.java)
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutionException.java?p2=maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutionException.java&p1=maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/CommandExecutionException.java&r1=312585&r2=312781&rev=312781&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/CommandExecutionException.java
(original)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutionException.java
Mon Oct 10 19:04:28 2005
@@ -1,4 +1,4 @@
-package org.apache.maven.wagon.providers.ssh;
+package org.apache.maven.wagon;
 
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
@@ -15,8 +15,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
-import org.apache.maven.wagon.WagonException;
 
 /**
  * Exception which should be thrown when a command fails to execute on the repository.

Propchange: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutionException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutionException.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Copied: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutor.java
(from r312585, maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/SshCommandExecutor.java)
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutor.java?p2=maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutor.java&p1=maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/SshCommandExecutor.java&r1=312585&r2=312781&rev=312781&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/java/org/apache/maven/wagon/providers/sshext/SshCommandExecutor.java
(original)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutor.java
Mon Oct 10 19:04:28 2005
@@ -1,4 +1,4 @@
-package org.apache.maven.wagon.providers.sshext;
+package org.apache.maven.wagon;
 
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
@@ -16,16 +16,18 @@
  * limitations under the License.
  */
 
-import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.Wagon;
+import org.apache.maven.wagon.CommandExecutionException;
 
 /**
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
  * @version $Id$
  */
-public interface SshCommandExecutor
+public interface CommandExecutor
     extends Wagon
 {
+    String ROLE = CommandExecutor.class.getName();
+
     void executeCommand( String command )
-        throws TransferFailedException;
+        throws CommandExecutionException;
 }

Propchange: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutor.java
------------------------------------------------------------------------------
    cvs2svn:cvs-rev = 1.2

Propchange: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/CommandExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PermissionModeUtils.java
(from r312585, maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java)
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PermissionModeUtils.java?p2=maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PermissionModeUtils.java&p1=maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java&r1=312585&r2=312781&rev=312781&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtils.java
(original)
+++ maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PermissionModeUtils.java
Mon Oct 10 19:04:28 2005
@@ -1,4 +1,4 @@
-package org.apache.maven.wagon.providers.ssh;
+package org.apache.maven.wagon;
 
 /*
  * Copyright 2001-2005 The Apache Software Foundation.

Propchange: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PermissionModeUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/wagon/trunk/wagon-provider-api/src/main/java/org/apache/maven/wagon/PermissionModeUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id

Copied: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PermissionModeUtilsTest.java
(from r312585, maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java)
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PermissionModeUtilsTest.java?p2=maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PermissionModeUtilsTest.java&p1=maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java&r1=312585&r2=312781&rev=312781&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/PermissionModeUtilsTest.java
(original)
+++ maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PermissionModeUtilsTest.java
Mon Oct 10 19:04:28 2005
@@ -1,4 +1,4 @@
-package org.apache.maven.wagon.providers.ssh;
+package org.apache.maven.wagon;
 
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
@@ -17,6 +17,7 @@
  */
 
 import junit.framework.TestCase;
+import org.apache.maven.wagon.PermissionModeUtils;
 
 /**
  * Unit test for PermissionModeUtils class

Propchange: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PermissionModeUtilsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/wagon/trunk/wagon-provider-api/src/test/java/org/apache/maven/wagon/PermissionModeUtilsTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/CommandExecutorTestCase.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/CommandExecutorTestCase.java?rev=312781&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/CommandExecutorTestCase.java
(added)
+++ maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/CommandExecutorTestCase.java
Mon Oct 10 19:04:28 2005
@@ -0,0 +1,82 @@
+package org.apache.maven.wagon;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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 org.codehaus.plexus.PlexusTestCase;
+import org.apache.maven.wagon.repository.Repository;
+import org.apache.maven.wagon.authentication.AuthenticationInfo;
+
+/**
+ * Base class for command executor tests.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @version $Id$
+ */
+public abstract class CommandExecutorTestCase
+    extends PlexusTestCase
+{
+    public void testErrorInCommandExecuted()
+        throws Exception
+    {
+        CommandExecutor exec = (CommandExecutor) lookup( CommandExecutor.ROLE );
+
+        Repository repository = getTestRepository();
+
+        AuthenticationInfo authenticationInfo = new AuthenticationInfo();
+        authenticationInfo.setUserName( System.getProperty( "user.name" ) );
+
+        exec.connect( repository, authenticationInfo );
+
+        try
+        {
+            exec.executeCommand( "fail" );
+            fail( "Command should have failed" );
+        }
+        catch ( CommandExecutionException e )
+        {
+            assertTrue( e.getMessage().trim().endsWith( "fail: command not found" ) );
+        }
+        finally
+        {
+            exec.disconnect();
+        }
+    }
+
+    public void testExecuteSuccessfulCommand()
+        throws Exception
+    {
+        CommandExecutor exec = (CommandExecutor) lookup( CommandExecutor.ROLE );
+
+        Repository repository = getTestRepository();
+
+        AuthenticationInfo authenticationInfo = new AuthenticationInfo();
+        authenticationInfo.setUserName( System.getProperty( "user.name" ) );
+
+        exec.connect( repository, authenticationInfo );
+
+        try
+        {
+            exec.executeCommand( "ls" );
+        }
+        finally
+        {
+            exec.disconnect();
+        }
+    }
+
+    protected abstract Repository getTestRepository();
+}

Propchange: maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/CommandExecutorTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/wagon/trunk/wagon-provider-test/src/main/java/org/apache/maven/wagon/CommandExecutorTestCase.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

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=312781&r1=312780&r2=312781&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
Mon Oct 10 19:04:28 2005
@@ -21,17 +21,23 @@
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.WagonConstants;
+import org.apache.maven.wagon.CommandExecutor;
+import org.apache.maven.wagon.CommandExecutionException;
+import org.apache.maven.wagon.PermissionModeUtils;
 import org.apache.maven.wagon.authentication.AuthenticationException;
 import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.apache.maven.wagon.events.TransferEvent;
 import org.apache.maven.wagon.repository.RepositoryPermissions;
 import org.apache.maven.wagon.resource.Resource;
 import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.cli.CommandLineException;
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.cli.Commandline;
 
 import java.io.File;
+import java.io.IOException;
+import java.util.List;
 
 /**
  * SCP deployer using "external" scp program.  To allow for
@@ -43,7 +49,7 @@
  */
 public class ScpExternalWagon
     extends AbstractWagon
-    implements SshCommandExecutor
+    implements CommandExecutor
 {
     /**
      * The external SCP command to use - default is <code>scp</code>.
@@ -154,7 +160,7 @@
     }
 
     public void executeCommand( String command )
-        throws TransferFailedException
+        throws CommandExecutionException
     {
         Commandline cl = new Commandline();
 
@@ -190,11 +196,16 @@
 
         try
         {
-            CommandLineUtils.executeCommandLine( cl, null, null );
+            CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
+            int exitCode = CommandLineUtils.executeCommandLine( cl, null, err );
+            if ( exitCode != 0 )
+            {
+                throw new CommandExecutionException( "Exit code " + exitCode + " - " + err.getOutput()
);
+            }
         }
         catch ( CommandLineException e )
         {
-            throw new TransferFailedException( "Error executing command line", e );
+            throw new CommandExecutionException( "Error executing command line", e );
         }
     }
 
@@ -279,7 +290,14 @@
 
         String mkdirCmd = "mkdir -p " + basedir + "/" + dir + "\n";
 
-        executeCommand( mkdirCmd );
+        try
+        {
+            executeCommand( mkdirCmd );
+        }
+        catch ( CommandExecutionException e )
+        {
+            throw new TransferFailedException( "Error executing command for transfer", e
);
+        }
 
         firePutStarted( resource, source );
 
@@ -287,16 +305,23 @@
 
         postProcessListeners( resource, source, TransferEvent.REQUEST_PUT );
 
-        RepositoryPermissions permissions = getRepository().getPermissions();
-
-        if ( permissions != null && permissions.getGroup() != null )
+        try
         {
-            executeCommand( "chgrp -f " + permissions.getGroup() + " " + basedir + "/" +
resourceName + "\n" );
-        }
+            RepositoryPermissions permissions = getRepository().getPermissions();
+
+            if ( permissions != null && permissions.getGroup() != null )
+            {
+                executeCommand( "chgrp -f " + permissions.getGroup() + " " + basedir + "/"
+ resourceName + "\n" );
+            }
 
-        if ( permissions != null && permissions.getFileMode() != null )
+            if ( permissions != null && permissions.getFileMode() != null )
+            {
+                executeCommand( "chmod -f " + permissions.getFileMode() + " " + basedir +
"/" + resourceName + "\n" );
+            }
+        }
+        catch ( CommandExecutionException e )
         {
-            executeCommand( "chmod -f " + permissions.getFileMode() + " " + basedir + "/"
+ resourceName + "\n" );
+            throw new TransferFailedException( "Error executing command for transfer", e
);
         }
         firePutCompleted( resource, source );
     }
@@ -373,4 +398,79 @@
         this.sshArgs = sshArgs;
     }
 
+    public void putDirectory( File sourceDirectory, String destinationDirectory )
+        throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException
+    {
+        String basedir = getRepository().getBasedir();
+
+        destinationDirectory = StringUtils.replace( destinationDirectory, "\\", "/" );
+
+        String path = getPath( basedir, destinationDirectory );
+        try
+        {
+            if ( getRepository().getPermissions() != null )
+            {
+                String dirPerms = getRepository().getPermissions().getDirectoryMode();
+
+                if ( dirPerms != null )
+                {
+                    String umaskCmd = "umask " + PermissionModeUtils.getUserMaskFor( dirPerms
);
+                    executeCommand( umaskCmd );
+                }
+            }
+
+            String mkdirCmd = "mkdir -p " + path;
+
+            executeCommand( mkdirCmd );
+        }
+        catch ( CommandExecutionException e )
+        {
+            throw new TransferFailedException( "Error performing commands for file transfer",
e );
+        }
+
+        File zipFile;
+        try
+        {
+            zipFile = File.createTempFile( "wagon", ".zip" );
+            zipFile.deleteOnExit();
+
+            List files = FileUtils.getFileNames( sourceDirectory, "**/**", "", false );
+
+            createZip( files, zipFile, sourceDirectory );
+        }
+        catch ( IOException e )
+        {
+            throw new TransferFailedException( "Unable to create ZIP archive of directory",
e );
+        }
+
+        put( zipFile, getPath( destinationDirectory, zipFile.getName() ) );
+
+        try
+        {
+            executeCommand( "cd " + path + "; unzip -o " + zipFile.getName() + "; rm -f "
+ zipFile.getName() );
+
+            zipFile.delete();
+
+            RepositoryPermissions permissions = getRepository().getPermissions();
+
+            if ( permissions != null && permissions.getGroup() != null )
+            {
+                executeCommand( "chgrp -Rf " + permissions.getGroup() + " " + path );
+            }
+
+            if ( permissions != null && permissions.getFileMode() != null )
+            {
+                executeCommand( "chmod -Rf " + permissions.getFileMode() + " " + path );
+            }
+        }
+        catch ( CommandExecutionException e )
+        {
+            throw new TransferFailedException( "Error performing commands for file transfer",
e );
+        }
+    }
+
+    public boolean supportsDirectoryCopy()
+    {
+        return true;
+    }
 }

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/resources/META-INF/plexus/components.xml?rev=312781&r1=312780&r2=312781&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/resources/META-INF/plexus/components.xml
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/main/resources/META-INF/plexus/components.xml
Mon Oct 10 19:04:28 2005
@@ -8,7 +8,7 @@
     </component>
     <!-- TODO: maybe this should be in the API if it is a required interface? -->
     <component>
-      <role>org.apache.maven.wagon.providers.sshext.SshCommandExecutor</role>
+      <role>org.apache.maven.wagon.CommandExecutor</role>
       <implementation>org.apache.maven.wagon.providers.sshext.ScpExternalWagon</implementation>
       <instantiation-strategy>per-lookup</instantiation-strategy>
     </component>

Added: maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/test/java/org/apache/maven/wagon/providers/sshext/SshCommandExecutorTest.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/test/java/org/apache/maven/wagon/providers/sshext/SshCommandExecutorTest.java?rev=312781&view=auto
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/test/java/org/apache/maven/wagon/providers/sshext/SshCommandExecutorTest.java
(added)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/test/java/org/apache/maven/wagon/providers/sshext/SshCommandExecutorTest.java
Mon Oct 10 19:04:28 2005
@@ -0,0 +1,36 @@
+package org.apache.maven.wagon.providers.sshext;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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 org.apache.maven.wagon.CommandExecutorTestCase;
+import org.apache.maven.wagon.repository.Repository;
+
+/**
+ * Test the command executor.
+ *
+ * @author <a href="mailto:brett@apache.org">Brett Porter</a>
+ * @version $Id$
+ */
+public class SshCommandExecutorTest
+    extends CommandExecutorTestCase
+{
+
+    protected Repository getTestRepository()
+    {
+        return new Repository( "test", "scp://localhost/" );
+    }
+}

Propchange: maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/test/java/org/apache/maven/wagon/providers/sshext/SshCommandExecutorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/test/java/org/apache/maven/wagon/providers/sshext/SshCommandExecutorTest.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/test/java/org/apache/maven/wagon/providers/sshext/TestData.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/test/java/org/apache/maven/wagon/providers/sshext/TestData.java?rev=312781&r1=312780&r2=312781&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/test/java/org/apache/maven/wagon/providers/sshext/TestData.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh-external/src/test/java/org/apache/maven/wagon/providers/sshext/TestData.java
Mon Oct 10 19:04:28 2005
@@ -32,7 +32,7 @@
     public static String getUserName()
     {
 
-        String retValue = System.getProperty( "testuser.name" );
+        String retValue = System.getProperty( "test.user" );
 
         if ( retValue == null )
         {

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java?rev=312781&r1=312780&r2=312781&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/AbstractSshWagon.java
Mon Oct 10 19:04:28 2005
@@ -29,6 +29,9 @@
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.apache.maven.wagon.TransferFailedException;
 import org.apache.maven.wagon.WagonConstants;
+import org.apache.maven.wagon.CommandExecutionException;
+import org.apache.maven.wagon.CommandExecutor;
+import org.apache.maven.wagon.PermissionModeUtils;
 import org.apache.maven.wagon.authentication.AuthenticationException;
 import org.apache.maven.wagon.authentication.AuthenticationInfo;
 import org.apache.maven.wagon.authorization.AuthorizationException;
@@ -43,15 +46,11 @@
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.List;
 import java.util.Properties;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipOutputStream;
 
 /**
  * Common SSH operations.
@@ -62,7 +61,7 @@
  */
 public abstract class AbstractSshWagon
     extends AbstractWagon
-    implements SshCommandExecutor
+    implements CommandExecutor
 {
     public static final int DEFAULT_SSH_PORT = 22;
 
@@ -369,19 +368,7 @@
         }
     }
 
-    protected static String getPath( String basedir, String dir )
-    {
-        String path;
-        path = basedir;
-        if ( !basedir.endsWith( "/" ) && !dir.startsWith( "/" ) )
-        {
-            path += "/";
-        }
-        path += dir;
-        return path;
-    }
-
-    private class WagonUserInfo
+    private static class WagonUserInfo
         implements UserInfo
     {
         private final InteractiveUserInfo userInfo;
@@ -390,14 +377,10 @@
 
         private String passphrase;
 
-        private String username;
-
         WagonUserInfo( AuthenticationInfo authInfo, InteractiveUserInfo userInfo )
         {
             this.userInfo = userInfo;
 
-            this.username = authInfo.getUserName();
-
             this.password = authInfo.getPassword();
 
             this.passphrase = authInfo.getPassphrase();
@@ -548,55 +531,6 @@
         catch ( CommandExecutionException e )
         {
             throw new TransferFailedException( "Error performing commands for file transfer",
e );
-        }
-    }
-
-    public void createZip( List files, File zipName, File basedir )
-        throws IOException
-    {
-        ZipOutputStream zos = new ZipOutputStream( new FileOutputStream( zipName ) );
-
-        try
-        {
-            for ( int i = 0; i < files.size(); i++ )
-            {
-                String file = (String) files.get( i );
-
-                file = file.replace( '\\', '/' );
-
-                writeZipEntry( zos, new File( basedir, file ), file );
-            }
-        }
-        finally
-        {
-            IOUtil.close( zos );
-        }
-    }
-
-    private void writeZipEntry( ZipOutputStream jar, File source, String entryName )
-        throws IOException
-    {
-        byte[] buffer = new byte[1024];
-
-        int bytesRead;
-
-        FileInputStream is = new FileInputStream( source );
-
-        try
-        {
-            ZipEntry entry = new ZipEntry( entryName );
-
-            jar.putNextEntry( entry );
-
-            while ( ( bytesRead = is.read( buffer ) ) != -1 )
-            {
-                jar.write( buffer, 0, bytesRead );
-            }
-        }
-
-        finally
-        {
-            is.close();
         }
     }
 

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java?rev=312781&r1=312780&r2=312781&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/ScpWagon.java
Mon Oct 10 19:04:28 2005
@@ -21,6 +21,8 @@
 import org.apache.maven.wagon.PathUtils;
 import org.apache.maven.wagon.ResourceDoesNotExistException;
 import org.apache.maven.wagon.TransferFailedException;
+import org.apache.maven.wagon.CommandExecutionException;
+import org.apache.maven.wagon.PermissionModeUtils;
 import org.apache.maven.wagon.authorization.AuthorizationException;
 import org.apache.maven.wagon.repository.RepositoryPermissions;
 import org.apache.maven.wagon.resource.Resource;

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/resources/META-INF/plexus/components.xml?rev=312781&r1=312780&r2=312781&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/resources/META-INF/plexus/components.xml
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/main/resources/META-INF/plexus/components.xml
Mon Oct 10 19:04:28 2005
@@ -35,7 +35,7 @@
       </requirements>
     </component>
     <component>
-      <role>org.apache.maven.wagon.providers.ssh.SshCommandExecutor</role>
+      <role>org.apache.maven.wagon.CommandExecutor</role>
       <implementation>org.apache.maven.wagon.providers.ssh.ScpWagon</implementation>
       <instantiation-strategy>per-lookup</instantiation-strategy>
       <requirements>

Modified: maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/SshCommandExecutorTest.java
URL: http://svn.apache.org/viewcvs/maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/SshCommandExecutorTest.java?rev=312781&r1=312780&r2=312781&view=diff
==============================================================================
--- maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/SshCommandExecutorTest.java
(original)
+++ maven/wagon/trunk/wagon-providers/wagon-ssh/src/test/java/org/apache/maven/wagon/providers/ssh/SshCommandExecutorTest.java
Mon Oct 10 19:04:28 2005
@@ -16,9 +16,8 @@
  * limitations under the License.
  */
 
-import org.apache.maven.wagon.authentication.AuthenticationInfo;
+import org.apache.maven.wagon.CommandExecutorTestCase;
 import org.apache.maven.wagon.repository.Repository;
-import org.codehaus.plexus.PlexusTestCase;
 
 /**
  * Test the command executor.
@@ -27,54 +26,11 @@
  * @version $Id$
  */
 public class SshCommandExecutorTest
-    extends PlexusTestCase
+    extends CommandExecutorTestCase
 {
-    public void testErrorInCommandExecuted()
-        throws Exception
-    {
-        SshCommandExecutor exec = (SshCommandExecutor) lookup( SshCommandExecutor.ROLE );
-
-        Repository repository = new Repository( "test", "scp://localhost/" );
-
-        AuthenticationInfo authenticationInfo = new AuthenticationInfo();
-        authenticationInfo.setUserName( System.getProperty( "user.name" ) );
-
-        exec.connect( repository, authenticationInfo );
-
-        try
-        {
-            exec.executeCommand( "fail" );
-            fail( "Command should have failed" );
-        }
-        catch ( CommandExecutionException e )
-        {
-            assertTrue( e.getMessage().endsWith( "fail: command not found" ) );
-        }
-        finally
-        {
-            exec.disconnect();
-        }
-    }
 
-    public void testExecuteSuccessfulCommand()
-        throws Exception
+    protected Repository getTestRepository()
     {
-        SshCommandExecutor exec = (SshCommandExecutor) lookup( SshCommandExecutor.ROLE );
-
-        Repository repository = new Repository( "test", "scp://localhost/" );
-
-        AuthenticationInfo authenticationInfo = new AuthenticationInfo();
-        authenticationInfo.setUserName( System.getProperty( "user.name" ) );
-
-        exec.connect( repository, authenticationInfo );
-
-        try
-        {
-            exec.executeCommand( "ls" );
-        }
-        finally
-        {
-            exec.disconnect();
-        }
+        return new Repository( "test", "scp://localhost/" );
     }
 }



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


Mime
View raw message