maven-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mic...@apache.org
Subject cvs commit: maven/src/plugins-build/artifact project.xml
Date Tue, 24 Jun 2003 22:22:55 GMT
michal      2003/06/24 15:22:55

  Modified:    src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers
                        FtpDeployer.java FileDeployer.java
                        HttpDeployer.java
               src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer
                        DefaultArtifactDeployer.java
                        MavenDeployRequest.java
               src/plugins-build/artifact/src/main/org/apache/maven/deploy
                        DeployRequest.java DeployTool.java
               src/plugins-build/artifact project.xml
  Added:       src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers
                        SFtpDeployer.java
  Removed:     src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers
                        SshDeployer.java
  Log:
  Changed SCP Deployer to SFTP deployer. I am done with functionality
  (except of Http Deployer) 
  Now I will test it deeper and assure that everything works.
  
  
  Revision  Changes    Path
  1.3       +11 -7     maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/FtpDeployer.java
  
  Index: FtpDeployer.java
  ===================================================================
  RCS file: /home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/FtpDeployer.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FtpDeployer.java	19 Jun 2003 22:02:36 -0000	1.2
  +++ FtpDeployer.java	24 Jun 2003 22:22:54 -0000	1.3
  @@ -75,15 +75,20 @@
   /**
    * An FTP deployer based on the FTPClient in the Commons Net package.
    *
  + * Proxy server for FTPClient is not supported:
  + * {@link http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18039}
  + * 
    * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
  - *
  + * @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
    * @version $Id$
  - *
  - * @todo account for username and password.
  + * 
  + * 
    */
   public class FtpDeployer extends AbstractDeployer
   {
  -        
  +    
  +    public final static String PROTOCOL = "ftp://";
  +            
       /**
        * Description of the Method
        */
  @@ -140,8 +145,7 @@
           }
   
           __main : try
  -        {
  -            System.out.println("username: '" + username +"' password: '"+  password+"'");
  +        {            
               if (ftp.login(username.trim(), password.trim()) == false)
               {
                   ftp.logout();
  
  
  
  1.4       +3 -1      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FileDeployer.java	20 Jun 2003 15:24:52 -0000	1.3
  +++ FileDeployer.java	24 Jun 2003 22:22:54 -0000	1.4
  @@ -71,6 +71,8 @@
   public class FileDeployer implements Deployer
   {
   
  +    public final static String PROTOCOL = "file://";
  +
       /**
        * @see org.apache.maven.fetch.fetchers.Fetcher#fetchUrl(java.lang.String, java.io.OutputStream)
        */
  
  
  
  1.2       +2 -1      maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/HttpDeployer.java
  
  Index: HttpDeployer.java
  ===================================================================
  RCS file: /home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/HttpDeployer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- HttpDeployer.java	17 Jun 2003 22:05:59 -0000	1.1
  +++ HttpDeployer.java	24 Jun 2003 22:22:54 -0000	1.2
  @@ -87,6 +87,7 @@
   public class HttpDeployer extends AbstractDeployer
   {
   
  +    public final static String PROTOCOL = "http://";
       /**
        * Description of the Method
        */
  
  
  
  1.1                  maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/SFtpDeployer.java
  
  Index: SFtpDeployer.java
  ===================================================================
  package org.apache.maven.deploy.deployers;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache MavenSession" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache MavenSession", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  import java.io.File;
  
  import org.apache.commons.lang.StringUtils;
  import org.apache.maven.deploy.DeployRequest;
  import org.apache.maven.deploy.exceptions.DeployException;
  
  import com.jcraft.jsch.ChannelSftp;
  import com.jcraft.jsch.JSch;
  import com.jcraft.jsch.Proxy;
  import com.jcraft.jsch.ProxyHTTP;
  import com.jcraft.jsch.ProxySOCKS5;
  import com.jcraft.jsch.Session;
  import com.jcraft.jsch.SftpATTRS;
  import com.jcraft.jsch.UserInfo;
  
  /**
   * An ssh2 deployer that uses the JSch library and the JCE. We will first try to
   * use public keys for authentication and if that doesn't work then we fall back
   * to using the login and password of the user in question. NOTE: We are
   * assuming the standard port of 22.
   *
   * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
   * @version $Id: SFtpDeployer.java,v 1.1 2003/06/24 22:22:54 michal Exp $
   * @todo still have to account for differing setups for people deploying to
   *      their own sites and to the central repository.
   */
  public class SFtpDeployer extends AbstractDeployer
  {
  
      public final static String PROTOCOL = "sftp://";
  
      public final static String SFTP_CHANNEL = "sftp";
      public final static int DEFAULT_SSH_PORT = 22;
      public final static int SOCKS5_PROXY_PORT = 1080;
      public final static int S_IFDIR = 0x4000;
  
      /**
       * @see Deployer#project
       * 
       * @todo better way of guessing what king of proxy server is used
       */
      public void deploy(DeployRequest request) throws DeployException
      {
          Integer groupId = null;
          try
          {
              if (request.getGroup() != null)
              {
                  groupId = Integer.getInteger(request.getGroup());
              }
          }
          catch (NumberFormatException e)
          {
              throw new DeployException("For sftp protocol remote group should be an integer");
          }
          try
          {
              JSch jsch = new JSch();
  
              int port = request.getPort();
              if (port == DeployRequest.UNKNOWN_PORT)
              {
                  port = DEFAULT_SSH_PORT;
              }
              String host = request.getHost();
              Session session = jsch.getSession(request.getUser(), host, port);
  
              String proxyHost = request.getProxyHost();
  
              if (proxyHost != null)
              {
                  Proxy proxy = null;
                  int proxyPort = request.getProxyPort();
                  //if port == 1080 we will use SOCKS5 Proxy
                  // otherwise will use HTTP Proxy
  
                  if (proxyPort == SOCKS5_PROXY_PORT)
                  {
                      proxy = new ProxySOCKS5(proxyHost);
                      ((ProxySOCKS5) proxy).setUserPasswd(
                          request.getProxyUser(),
                          request.getProxyPass());
                  }
                  else
                  {
                      proxy = new ProxyHTTP(proxyHost, proxyPort);
                      ((ProxyHTTP) proxy).setUserPasswd(
                          request.getProxyUser(),
                          request.getProxyPass());
                  }
                  proxy.connect(session, host, port);
  
              }
  
              // Look for the private key and use it if available.
              if (request.getPrivateKey() != null)
              {
                  File privateKey = new File(request.getPrivateKey());
  
                  if (privateKey.exists())
                  {
                      System.out.println("Using private key: " + privateKey);
                      jsch.addIdentity(
                          privateKey.getAbsolutePath(),
                          request.getPassphrase());
                  }
              }
              // username and password will be given via UserInfo interface.
              UserInfo ui = new MavenUserInfo(request);
              session.setUserInfo(ui);
              session.connect();
  
              ChannelSftp channel =
                  (ChannelSftp) session.openChannel(SFTP_CHANNEL);
              channel.connect();
              // iterate over all directories in the path. try to create
              // directory 
              String[] dirs = StringUtils.split(request.getOutputDir(), "/");
              for (int i = 0; i < dirs.length; i++)
              {
                  System.out.println("processing: " + dirs[i]);
                  try
                  {
                      SftpATTRS attrs = channel.stat(dirs[i]);
                      if ((attrs.getPermissions() & S_IFDIR) != 0)
                      {
                          // file exists and is dierctory
                          channel.cd(dirs[i]);
                      }
                      else
                      {
                          throw new DeployException(
                              "Remote path:"
                                  + request.getOutputDir()
                                  + "is not correct");
                      }
                  }
                  catch (Exception e)
                  {
                      // file does not exists
                      channel.mkdir(dirs[i]);
                      channel.cd(dirs[i]);
                  }
  
              }
  
              channel.put(request.getInputFile(), request.getOutputFile());
  
              if (groupId != null)
              {
                  channel.chgrp(groupId.intValue(), request.getOutputFile());
              }
  
          }
          catch (Exception e)
          {
              e.printStackTrace();
              throw new DeployException(
                  "Cannot deploy. Reason: " + e.getMessage(),
                  e);
          }
      }
  
      /**
       * MavenUserInfo class which returns the necessary name and password from
       * the POM to secure an ssh connection.
       */
      public class MavenUserInfo implements UserInfo
      {
  
          DeployRequest request;
  
          MavenUserInfo(DeployRequest request)
          {
              this.request = request;
          }
  
          public String getPassphrase()
          {
              return request.getPassphrase();
          }
  
          /* (non-Javadoc)
           * @see com.jcraft.jsch.UserInfo#getPassword()
           */
          public String getPassword()
          {
              return request.getPass();
          }
  
          /* (non-Javadoc)
           * @see com.jcraft.jsch.UserInfo#promptPassphrase(java.lang.String)
           */
          public boolean promptPassphrase(String arg0)
          {
              return true;
          }
  
          /* (non-Javadoc)
           * @see com.jcraft.jsch.UserInfo#promptPassword(java.lang.String)
           */
          public boolean promptPassword(String arg0)
          {
              return true;
          }
  
          /**
           * @see com.jcraft.jsch.UserInfo#promptYesNo(java.lang.String)
           */
          public boolean promptYesNo(String arg0)
          {
              return true;
          }
  
          /* (non-Javadoc)
           * @see com.jcraft.jsch.UserInfo#showMessage(java.lang.String)
           */
          public void showMessage(String message)
          {
              System.out.println(message);
  
          }
  
      }
  
  }
  
  
  
  1.8       +2 -2      maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
  
  Index: DefaultArtifactDeployer.java
  ===================================================================
  RCS file: /home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- DefaultArtifactDeployer.java	24 Jun 2003 16:20:51 -0000	1.7
  +++ DefaultArtifactDeployer.java	24 Jun 2003 22:22:55 -0000	1.8
  @@ -214,7 +214,7 @@
               {
                   destFile.mkdirs();
               }
  -            destFile = new File(file, getRepositoryFile(type, project, version));
  +            destFile = new File(destFile, getRepositoryFile(type, project, version));
               System.out.println(
                   "Copying: from '" + file + "' to: '" + destFile + "'");
               FileUtils.copyFile(file, destFile);
  
  
  
  1.5       +3 -4      maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer/MavenDeployRequest.java
  
  Index: MavenDeployRequest.java
  ===================================================================
  RCS file: /home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer/MavenDeployRequest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- MavenDeployRequest.java	20 Jun 2003 15:24:52 -0000	1.4
  +++ MavenDeployRequest.java	24 Jun 2003 22:22:55 -0000	1.5
  @@ -95,8 +95,7 @@
           String username =
               (String) project.getContext().getVariable(
                   "maven.repo." + repository + ".username");
  -
  -        System.out.println(repository + " username:" + username);
  +        
           String password =
               (String) project.getContext().getVariable(
                   "maven.repo." + repository + ".password");
  @@ -141,7 +140,7 @@
           setUser(username);
           setPass(password);
           setPassphrase(passphrase);
  -        setPrivateKey(url.trim());
  +        setPrivateKey(privateKey);
           setGroup(remoteGroup);
           setUrl(url.trim());
   
  
  
  
  1.3       +2 -2      maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/DeployRequest.java
  
  Index: DeployRequest.java
  ===================================================================
  RCS file: /home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/DeployRequest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DeployRequest.java	19 Jun 2003 22:02:37 -0000	1.2
  +++ DeployRequest.java	24 Jun 2003 22:22:55 -0000	1.3
  @@ -63,7 +63,7 @@
    */
   public class DeployRequest
   {
  -    
  +   
   
       public final static int UNKNOWN_PORT = -1;
   
  
  
  
  1.3       +8 -10     maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/DeployTool.java
  
  Index: DeployTool.java
  ===================================================================
  RCS file: /home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/DeployTool.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DeployTool.java	19 Jun 2003 22:02:37 -0000	1.2
  +++ DeployTool.java	24 Jun 2003 22:22:55 -0000	1.3
  @@ -60,7 +60,7 @@
   import org.apache.maven.deploy.deployers.FileDeployer;
   import org.apache.maven.deploy.deployers.FtpDeployer;
   import org.apache.maven.deploy.deployers.HttpDeployer;
  -import org.apache.maven.deploy.deployers.SshDeployer;
  +import org.apache.maven.deploy.deployers.SFtpDeployer;
   import org.apache.maven.deploy.exceptions.DeployException;
   import org.apache.maven.deploy.exceptions.UnsupportedProtocolDeployException;
   
  @@ -75,7 +75,6 @@
   
       public void performUpload(DeployRequest request) throws DeployException
       {
  -
           String url = request.getUrl();
           Deployer deployer = null;
   
  @@ -85,22 +84,21 @@
                   "No URL provided for repsoitory: "
                       + request.getRepositoryAlias());
           }
  -        if (url.startsWith("http://"))
  +        if (url.startsWith(HttpDeployer.PROTOCOL))
           {
               deployer = new HttpDeployer();
           }
  -
  -        if (url.startsWith("file://"))
  +        if (url.startsWith(FileDeployer.PROTOCOL))
           {
               deployer = new FileDeployer();
           }
  -        if (url.startsWith("ssh://"))
  +        if (url.startsWith(FtpDeployer.PROTOCOL))
           {
  -            deployer = new SshDeployer();
  +            deployer = new FtpDeployer();
           }
  -        if (url.startsWith("ftp://"))
  +        if (url.startsWith(SFtpDeployer.PROTOCOL))
           {
  -            deployer = new FtpDeployer();
  +            deployer = new SFtpDeployer();
           }
           if (deployer == null)
           {
  
  
  
  1.3       +1 -1      maven/src/plugins-build/artifact/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/maven/src/plugins-build/artifact/project.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- project.xml	17 Jun 2003 22:06:01 -0000	1.2
  +++ project.xml	24 Jun 2003 22:22:55 -0000	1.3
  @@ -59,7 +59,7 @@
       <dependency>
         <groupId>jsch</groupId>
         <artifactId>jsch</artifactId>
  -      <version>0.0.9</version>
  +      <version>0.1.5</version>
         <type>jar</type>
       </dependency>
   
  
  
  

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


Mime
View raw message