dion        2003/08/07 09:57:48

  Modified:    src/plugins-build/artifact Tag: MAVEN_RC1_STABLE .cvsignore
               src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers
                        Tag: MAVEN_RC1_STABLE ScpDeployer.java
                        GenericSshDeployer.java SFtpDeployer.java
                        FileDeployer.java Deployer.java
                        AbstractDeployer.java
  Added:       src/plugins-build/artifact/src/main/org/apache/maven/deploy/util
                        Tag: MAVEN_RC1_STABLE Packager.java
  Log:
  Update from back ported fixes
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +2 -0      maven/src/plugins-build/artifact/.cvsignore
  
  Index: .cvsignore
  ===================================================================
  RCS file: /home/cvs/maven/src/plugins-build/artifact/.cvsignore,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- .cvsignore        16 Jun 2003 14:26:01 -0000      1.1
  +++ .cvsignore        7 Aug 2003 16:57:48 -0000       1.1.2.1
  @@ -1,3 +1,5 @@
   target
   velocity.log
   maven.log
  +.classpath
  +.project
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.5.4.1   +202 -24   
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/ScpDeployer.java
  
  Index: ScpDeployer.java
  ===================================================================
  RCS file: 
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/ScpDeployer.java,v
  retrieving revision 1.5
  retrieving revision 1.5.4.1
  diff -u -r1.5 -r1.5.4.1
  --- ScpDeployer.java  17 Jul 2003 11:13:17 -0000      1.5
  +++ ScpDeployer.java  7 Aug 2003 16:57:48 -0000       1.5.4.1
  @@ -1,5 +1,4 @@
   package org.apache.maven.deploy.deployers;
  -
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  @@ -56,20 +55,27 @@
    * ====================================================================
    */
   
  +import com.jcraft.jsch.ChannelExec;
  +import com.jcraft.jsch.Session;
  +
  +import org.apache.maven.deploy.DeployRequest;
  +import org.apache.maven.deploy.RepositoryInfo;
  +import org.apache.maven.deploy.exceptions.AuthenticationException;
  +import org.apache.maven.deploy.exceptions.TransferFailedException;
  +import org.apache.maven.deploy.util.Packager;
  +
   import java.io.File;
   import java.io.FileInputStream;
  +import java.io.IOException;
   import java.io.InputStream;
   import java.io.OutputStream;
   
  -import org.apache.maven.deploy.DeployRequest;
  -import org.apache.maven.deploy.exceptions.TransferFailedException;
  -
  -import com.jcraft.jsch.ChannelExec;
  -import com.jcraft.jsch.Session;
  +import java.util.LinkedList;
  +import java.util.List;
   
   /**
  - * An SSH2/SCP deployer 
  - * 
  + * An SSH2/SCP deployer
  + *
    * @author Michal Maczka
    * @version $Revision$ $Date$
    */
  @@ -80,54 +86,216 @@
   
       /** SSH2 Channel name used to communicate with the server*/
       public final static String EXEC_CHANNEL = "exec";
  +    public final static String COMPRESS = "maven.deployer.scp.compress";
  +
  +    /**
  +     *  I want to have compression by default
  +     *   so if system property is missing flag will be set to false
  +     *  that's why I am using deployNotCompressed variable name instead of 
  +     *   straight forward deployCompressed
  +     */
  +    public boolean deployNotCompressed = true;
  +    private List srcFiles = new LinkedList();
  +    private List destFiles = new LinkedList();
  +
  +    /**
  +     * @see org.apache.maven.deploy.deployers.Deployer#release()
  +     */
  +    public void flush() throws TransferFailedException
  +    {
  +        if (!deployNotCompressed)
  +        {
  +            doDeployCompressed();
  +        }
  +
  +        super.flush();
  +    }
  +
  +    /**
  +     * @return
  +     */
  +    public boolean isDeployNotCompressed()
  +    {
  +        return deployNotCompressed;
  +    }
  +
  +    /**
  +     * @param deployCompressed
  +     */
  +    public void setDeployNotCompressed(boolean deployNotCompressed)
  +    {
  +        this.deployNotCompressed = deployNotCompressed;
  +    }
  +
  +    /**
  +     * @todo Find better way to configure deployer
  +     * @see 
org.apache.maven.deploy.deployers.Deployer#init(org.apache.maven.deploy.RepositoryInfo)
  +     */
  +    public void init(RepositoryInfo repoInfo) throws AuthenticationException
  +    {
  +        setDeployNotCompressed(Boolean.getBoolean(COMPRESS));
  +        super.init(repoInfo);
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.maven.deploy.deployers.Deployer#deploy(org.apache.maven.deploy.DeployRequest)
  +     */
  +    public void deploy(DeployRequest request) throws TransferFailedException
  +    {
  +        if (deployNotCompressed)
  +        {
  +            doDeployNotCompressed(request);
  +        }
  +        else
  +        {
  +            srcFiles.add(request.getSrcFile());
  +            destFiles.add(request.getDestFile());
  +        }
  +    }
   
       /**
        * @see Deployer#deploy(DeployRequest)
        *
        */
  -    public void deploy(DeployRequest request) throws TransferFailedException
  -    {        
  +    public void doDeployNotCompressed(DeployRequest request)
  +        throws TransferFailedException
  +    {
           Session session = getSession();
           String mkdirCmd =
               "mkdir -p "
  -                + getAuthenticationInfo().getBasedir()
  +                + getRepositoryInfo().getBasedir()
                   + "/"
                   + request.dirname()
                   + "\n";
  +
           executeSimpleCommand(session, mkdirCmd);
   
           doCopy(session, request);
  -        if (getAuthenticationInfo().getGroup() != null)
  -        {
   
  +        if (getRepositoryInfo().getGroup() != null)
  +        {
               String chgrpCmd =
                   "chgrp "
  -                    + getAuthenticationInfo().getGroup()
  +                    + getRepositoryInfo().getGroup()
                       + " "
  -                    + getAuthenticationInfo().getBasedir()
  +                    + getRepositoryInfo().getBasedir()
                       + "/"
                       + request.getDestFile()
                       + "\n";
  +
               executeSimpleCommand(session, chgrpCmd);
           }
  +    }
  +
  +    /**
  +     * @see Deployer#deploy(DeployRequest)
  +     *
  +     */
  +    public void doDeployCompressed() throws TransferFailedException
  +    {
  +        Session session = getSession();
  +        File zip = null;
  +
  +        try
  +        {
  +            zip = File.createTempFile("maven-deployer-", ".zip");
  +            Packager.createZip(srcFiles, destFiles, zip);
  +        }
  +        catch (IOException e)
  +        {
  +            if ((zip != null) && zip.exists())
  +            {
  +                try
  +                {
  +                    zip.delete();
  +                }
  +                catch (Exception ee)
  +                {
  +                    // ignore
  +                    // file is left in temp directory
  +                    // no tragedy
  +                }
  +            }
  +
  +            throw new TransferFailedException("Cannot create ZIP file");
  +        }
  +
  +        try
  +        {
  +            DeployRequest request =
  +                new DeployRequest(zip.getAbsolutePath(), zip.getName());
  +
  +            doCopy(session, request);
  +
  +            String unzipCmd =
  +                "unzip -d -u "
  +                    + getRepositoryInfo().getBasedir()
  +                    + " "
  +                    + getRepositoryInfo().getBasedir()
  +                    + "/"
  +                    + request.getDestFile()
  +                    + "\n";
  +            executeSimpleCommand(session, unzipCmd);
  +
  +            //@ this is not working!
  +            String rmCmd =
  +                "rm -f "
  +                    + getRepositoryInfo().getBasedir()
  +                    + "/"
  +                    + request.getDestFile()
  +                    + "\n";
  +
  +            executeSimpleCommand(session, rmCmd);
  +
  +            if (getRepositoryInfo().getGroup() != null)
  +            {
  +                String chgrpCmd =
  +                    "chgrp -r"
  +                        + getRepositoryInfo().getGroup()
  +                        + " "
  +                        + getRepositoryInfo().getBasedir()
  +                        + "\n";
  +
  +                executeSimpleCommand(session, chgrpCmd);
  +            }
   
  +        }
  +        finally
  +        {
  +            if ((zip != null) && zip.exists())
  +            {
  +                try
  +                {
  +                    zip.delete();
  +                }
  +                catch (Exception ee)
  +                {
  +                    // ignore
  +                    // file is left in temp directory
  +                    // no tragedy
  +                }
  +            }
  +        }
       }
   
       /**
  -     * Execute <i>"simple"</i> remote command using exec channel  
  +     * Execute <i>"simple"</i> remote command using exec channel
        */
       private void executeSimpleCommand(Session session, String command)
           throws TransferFailedException
       {
  -
           System.out.println("Executing command: " + command);
  +
           ChannelExec channel = null;
  +
           try
           {
               channel = (ChannelExec) session.openChannel(EXEC_CHANNEL);
               channel.setCommand(command);
  +
               OutputStream out = channel.getOutputStream();
               InputStream in = channel.getInputStream();
  +
               channel.connect();
           }
           catch (Exception e)
  @@ -151,23 +319,25 @@
       private void doCopy(Session session, DeployRequest request)
           throws TransferFailedException
       {
  -
           ChannelExec channel = null;
  +
           try
           {
               String srcFile = request.getSrcFile();
               String destFile =
  -                getAuthenticationInfo().getBasedir()
  -                    + "/"
  -                    + request.getDestFile();
  +                getRepositoryInfo().getBasedir() + "/" + request.getDestFile();
  +
               // exec 'scp -t rfile' remotely
               String command = "scp -t " + destFile;
  +
               System.out.println("Executing command: " + command);
               channel = (ChannelExec) session.openChannel(EXEC_CHANNEL);
               channel.setCommand(command);
  +
               // get I/O streams for remote scp
               OutputStream out = channel.getOutputStream();
               InputStream in = channel.getInputStream();
  +
               channel.connect();
   
               byte[] tmp = new byte[1];
  @@ -181,7 +351,9 @@
   
               // send "C0644 filesize filename", where filename should not include '/'
               int filesize = (int) (new File(srcFile)).length();
  +
               command = "C0644 " + filesize + " ";
  +
               if (srcFile.lastIndexOf('/') > 0)
               {
                   command += srcFile.substring(srcFile.lastIndexOf('/') + 1);
  @@ -190,6 +362,7 @@
               {
                   command += srcFile;
               }
  +
               command += "\n";
   
               out.write(command.getBytes());
  @@ -205,11 +378,16 @@
               // send a content of inputFile
               FileInputStream fis = new FileInputStream(srcFile);
               byte[] buf = new byte[1024];
  +
               while (true)
               {
                   int len = fis.read(buf, 0, buf.length);
  +
                   if (len <= 0)
  +                {
                       break;
  +                }
  +
                   out.write(buf, 0, len);
                   out.flush();
               }
  @@ -230,7 +408,8 @@
           {
               String msg =
                   "Error occured while deploying to remote host:"
  -                    + getAuthenticationInfo().getHost();
  +                    + getRepositoryInfo().getHost();
  +
               throw new TransferFailedException(msg, e);
           }
           finally
  @@ -241,5 +420,4 @@
               }
           }
       }
  -
   }
  
  
  
  1.5.4.1   +2 -2      
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/GenericSshDeployer.java
  
  Index: GenericSshDeployer.java
  ===================================================================
  RCS file: 
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/GenericSshDeployer.java,v
  retrieving revision 1.5
  retrieving revision 1.5.4.1
  diff -u -r1.5 -r1.5.4.1
  --- GenericSshDeployer.java   18 Jul 2003 07:37:17 -0000      1.5
  +++ GenericSshDeployer.java   7 Aug 2003 16:57:48 -0000       1.5.4.1
  @@ -108,7 +108,7 @@
       /* (non-Javadoc)
        * @see org.apache.maven.deploy.deployers.Deployer#getAuthenticationInfo()
        */
  -    public RepositoryInfo getAuthenticationInfo()
  +    public RepositoryInfo getRepositoryInfo()
       {
           return repoInfo;
       }
  
  
  
  1.6.4.1   +5 -5      
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/SFtpDeployer.java
  
  Index: SFtpDeployer.java
  ===================================================================
  RCS file: 
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/SFtpDeployer.java,v
  retrieving revision 1.6
  retrieving revision 1.6.4.1
  diff -u -r1.6 -r1.6.4.1
  --- SFtpDeployer.java 17 Jul 2003 11:13:17 -0000      1.6
  +++ SFtpDeployer.java 7 Aug 2003 16:57:48 -0000       1.6.4.1
  @@ -166,7 +166,7 @@
                   }
   
               }
  -            if (getAuthenticationInfo().isDebugOn())
  +            if (getRepositoryInfo().isDebugOn())
               {
                   channel.put(
                       request.getSrcFile(),
  @@ -182,12 +182,12 @@
   
               if (groupId != null)
               {
  -                if (getAuthenticationInfo().isDebugOn())
  +                if (getRepositoryInfo().isDebugOn())
                   {
                       System.out.println("Changing group to: " + groupId);
                   }
                   channel.chgrp(groupId.intValue(), request.getDestFile());
  -                if (getAuthenticationInfo().isDebugOn())
  +                if (getRepositoryInfo().isDebugOn())
                   {
                       System.out.println("Group successfully changed");
                   }
  @@ -204,7 +204,7 @@
   
               String msg =
                   "Error occured while deploying to remote host:"
  -                    + getAuthenticationInfo().getHost()
  +                    + getRepositoryInfo().getHost()
                       + ":"
                       + e.getMessage();
               throw new TransferFailedException(msg, e);
  
  
  
  1.8.4.1   +2 -2      
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/FileDeployer.java
  
  Index: FileDeployer.java
  ===================================================================
  RCS file: 
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/FileDeployer.java,v
  retrieving revision 1.8
  retrieving revision 1.8.4.1
  diff -u -r1.8 -r1.8.4.1
  --- FileDeployer.java 17 Jul 2003 11:13:17 -0000      1.8
  +++ FileDeployer.java 7 Aug 2003 16:57:48 -0000       1.8.4.1
  @@ -71,7 +71,7 @@
    * @author <a href="[EMAIL PROTECTED]">Michal Maczka</a> 
    * @version $Id$
    */
  -public class FileDeployer implements Deployer
  +public class FileDeployer extends AbstractDeployer
   {
   
       private RepositoryInfo repoInfo;
  
  
  
  1.3.4.1   +21 -16    
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/Deployer.java
  
  Index: Deployer.java
  ===================================================================
  RCS file: 
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/Deployer.java,v
  retrieving revision 1.3
  retrieving revision 1.3.4.1
  diff -u -r1.3 -r1.3.4.1
  --- Deployer.java     17 Jul 2003 11:13:16 -0000      1.3
  +++ Deployer.java     7 Aug 2003 16:57:48 -0000       1.3.4.1
  @@ -1,9 +1,6 @@
   package org.apache.maven.deploy.deployers;
   
  -import org.apache.maven.deploy.RepositoryInfo;
   import org.apache.maven.deploy.DeployRequest;
  -import org.apache.maven.deploy.exceptions.AuthenticationException;
  -import org.apache.maven.deploy.exceptions.TransferFailedException;
   
   /* ====================================================================
    * The Apache Software License, Version 1.1
  @@ -60,45 +57,53 @@
    *
    * ====================================================================
    */
  +import org.apache.maven.deploy.RepositoryInfo;
  +import org.apache.maven.deploy.exceptions.AuthenticationException;
  +import org.apache.maven.deploy.exceptions.TransferFailedException;
   
   /**
  - * 
  - * Common interface for classes capable of uploading a file to remote host 
  - 
  + *
  + * Common interface for classes capable of uploading a file to remote host
  +
    *
    * @author <a href="mailto:[EMAIL PROTECTED]">Michal Maczka</a>
    * @version $Id$
    */
   public interface Deployer
   {
  -
       /**
        * Set the information about host to which we will deploy.
  -     * In this method deployer can allocate the resources which will 
  +     * In this method deployer can allocate the resources which will
        * be needed to perform an upload. E.g.  connection to remote host
  -     * can be opened, 
  +     * can be opened,
        * Resources allocated in this metod should
        * be release when deloyer is not needed any more
  -     * @see #release()  
  +     * @see #release()
        *
        * @param repoInfo
        * @throws AuthenticationException when connection to remote host cannot be 
established
        */
  -    public void init(RepositoryInfo repoInfo)
  +    public void init( RepositoryInfo repoInfo )
           throws AuthenticationException;
   
       /**
  -     * Release all resources which were allocated  
  +     * Release all resources which were allocated
        * by this deployer (e.g. a connection to remote host)
        *
        */
  -    public void release();
  +    public void release(  );
   
       /**
        * Perform an upload of single file to remote host
        * @param request <code>DeployRequest</code> which should contatin all 
parameters
        * which are necessery to upload a file
  -     * to remote host.  
  +     * to remote host.
  +     */
  +    public void deploy( DeployRequest request )
  +        throws TransferFailedException;
  +
  +    /**
  +     * 
        */
  -    public void deploy(DeployRequest request) throws TransferFailedException;
  +    public void flush() throws TransferFailedException;
   }
  
  
  
  1.1.4.1   +7 -2      
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/AbstractDeployer.java
  
  Index: AbstractDeployer.java
  ===================================================================
  RCS file: 
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/AbstractDeployer.java,v
  retrieving revision 1.1
  retrieving revision 1.1.4.1
  diff -u -r1.1 -r1.1.4.1
  --- AbstractDeployer.java     17 Jun 2003 22:05:59 -0000      1.1
  +++ AbstractDeployer.java     7 Aug 2003 16:57:48 -0000       1.1.4.1
  @@ -1,4 +1,7 @@
   package org.apache.maven.deploy.deployers;
  +
  +import org.apache.maven.deploy.exceptions.TransferFailedException;
  +
   /* ====================================================================
    * The Apache Software License, Version 1.1
    *
  @@ -64,5 +67,7 @@
    */
   public abstract class AbstractDeployer implements Deployer
   {
  -
  +    public void flush() throws TransferFailedException
  +    {
  +    }
   }
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +1 -1      
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/util/Packager.java
  
  Index: Packager.java
  ===================================================================
  RCS file: 
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/util/Packager.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to