ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh AbstractSshMessage.java Directory.java LogListener.java SSHBase.java SSHExec.java SSHUserInfo.java Scp.java ScpFromMessage.java ScpToMessage.java
Date Wed, 09 Jul 2003 12:13:01 GMT
conor       2003/07/09 05:13:01

  Modified:    src/main/org/apache/tools/ant/taskdefs/optional/extension
                        ExtensionAdapter.java
               src/main/org/apache/tools/ant/taskdefs/optional/ssh
                        AbstractSshMessage.java Directory.java
                        LogListener.java SSHBase.java SSHExec.java
                        SSHUserInfo.java Scp.java ScpFromMessage.java
                        ScpToMessage.java
  Log:
  Checkstyle
  
  Revision  Changes    Path
  1.8       +6 -6      ant/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionAdapter.java
  
  Index: ExtensionAdapter.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/extension/ExtensionAdapter.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -w -u -r1.7 -r1.8
  --- ExtensionAdapter.java	9 Jul 2003 11:34:09 -0000	1.7
  +++ ExtensionAdapter.java	9 Jul 2003 12:12:59 -0000	1.8
  @@ -105,7 +105,7 @@
        * The URL from which the most recent version of this optional package
        * can be obtained if it is not already installed.
        */
  -    private String implementationVendorURL;
  +    private String implementationURL;
   
       /**
        * Set the name of extension.
  @@ -174,7 +174,7 @@
        */
       public void setImplementationUrl(final String implementationURL) {
           verifyNotAReference();
  -        this.implementationVendorURL = implementationURL;
  +        this.implementationURL = implementationURL;
       }
   
       /**
  @@ -195,7 +195,7 @@
               || null != implementationVersion
               || null != implementationVendorID
               || null != implementationVendor
  -            || null != implementationVendorURL) {
  +            || null != implementationURL) {
               throw tooManyAttributes();
           }
           // change this to get the objects from the other reference
  @@ -208,7 +208,7 @@
               implementationVersion = other.implementationVersion;
               implementationVendorID = other.implementationVendorID;
               implementationVendor = other.implementationVendor;
  -            implementationVendorURL = other.implementationVendorURL;
  +            implementationURL = other.implementationURL;
           } else {
               final String message =
                   reference.getRefId() + " doesn\'t refer to a Extension";
  @@ -251,7 +251,7 @@
                                 implementationVersionString,
                                 implementationVendor,
                                 implementationVendorID,
  -                              implementationVendorURL);
  +                              implementationURL);
       }
   
       /**
  
  
  
  1.4       +15 -15    ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java
  
  Index: AbstractSshMessage.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -u -r1.3 -r1.4
  --- AbstractSshMessage.java	14 Mar 2003 00:31:43 -0000	1.3
  +++ AbstractSshMessage.java	9 Jul 2003 12:12:59 -0000	1.4
  @@ -66,8 +66,8 @@
   
   public abstract class AbstractSshMessage {
   
  -    protected Session session;
  -    protected LogListener listener = new LogListener() {
  +    private Session session;
  +    private LogListener listener = new LogListener() {
           public void log(String message) {
               // do nothing;
           }
  @@ -115,8 +115,8 @@
           NumberFormat format = NumberFormat.getNumberInstance();
           format.setMaximumFractionDigits( 2 );
           format.setMinimumFractionDigits( 1 );
  -        listener.log( "File transfer time: " + format.format( duration ) +
  -                " Average Rate: " + format.format( totalLength / duration ) +
  -                " B/s" );
  +        listener.log("File transfer time: " + format.format(duration)
  +            + " Average Rate: " + format.format(totalLength / duration)
  +            + " B/s");
       }
   }
  
  
  
  1.2       +25 -20    ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Directory.java
  
  Index: Directory.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Directory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -u -r1.1 -r1.2
  --- Directory.java	6 Mar 2003 12:42:44 -0000	1.1
  +++ Directory.java	9 Jul 2003 12:12:59 -0000	1.2
  @@ -78,9 +78,10 @@
       }
   
       public void addDirectory( Directory directory ) {
  -        if( !childDirectories.contains( directory ) )
  +        if (!childDirectories.contains(directory)) {
               childDirectories.add( directory );
       }
  +    }
   
       public void addFile( File file ) {
           files.add( file );
  @@ -118,9 +119,13 @@
       }
   
       public boolean equals(Object obj) {
  -        if( obj == this ) return true;
  +        if (obj == this) {
  +            return true;
  +        }
   
  -        if( !(obj instanceof Directory) ) return false;
  +        if (!(obj instanceof Directory)) {
  +            return false;
  +        }
   
           Directory d = (Directory)obj;
   
  
  
  
  1.2       +1 -1      ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/LogListener.java
  
  Index: LogListener.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/LogListener.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -w -u -r1.1 -r1.2
  
  
  
  1.5       +29 -26    ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java
  
  Index: SSHBase.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHBase.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -w -u -r1.4 -r1.5
  --- SSHBase.java	18 Apr 2003 23:40:27 -0000	1.4
  +++ SSHBase.java	9 Jul 2003 12:12:59 -0000	1.5
  @@ -54,9 +54,9 @@
   
   package org.apache.tools.ant.taskdefs.optional.ssh;
   
  -import com.jcraft.jsch.*;
  -
  -import java.io.*;
  +import com.jcraft.jsch.JSchException;
  +import com.jcraft.jsch.Session;
  +import com.jcraft.jsch.JSch;
   
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.BuildException;
  @@ -71,11 +71,14 @@
    */
   public abstract class SSHBase extends Task implements LogListener {
           
  +    /** Default listen port for SSH daemon */
  +    private static final int SSH_PORT = 22;
  +
       private String host;
       private String keyfile;
       private String knownHosts;
       private boolean trust = false;
  -    private int port = 22;
  +    private int port = SSH_PORT;
       private boolean failOnError = true;
       private SSHUserInfo userInfo;
       
  @@ -183,7 +186,7 @@
           super.init();
           this.knownHosts = System.getProperty("user.home") + "/.ssh/known_hosts";
           this.trust = false;
  -        this.port = 22;
  +        this.port = SSH_PORT;
       }
       
       protected Session openSession() throws JSchException {
  
  
  
  1.8       +29 -22    ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
  
  Index: SSHExec.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -w -u -r1.7 -r1.8
  --- SSHExec.java	21 Apr 2003 14:27:58 -0000	1.7
  +++ SSHExec.java	9 Jul 2003 12:12:59 -0000	1.8
  @@ -78,12 +78,19 @@
    */
   public class SSHExec extends SSHBase {
   
  -    private String command = null;   // the command to execute via ssh
  -    private long maxwait = 0;   // units are milliseconds, default is 0=infinite
  -    private Thread thread = null;   // for waiting for the command to finish
  +    private final int BUFFER_SIZE = 1024;
   
  -    private String output_property = null;   // like <exec>
  -    private File output_file = null;   // like <exec>
  +    /** the command to execute via ssh */
  +    private String command = null;
  +
  +    /** units are milliseconds, default is 0=infinite */
  +    private long maxwait = 0;
  +
  +    /** for waiting for the command to finish */
  +    private Thread thread = null;
  +
  +    private String outputProperty = null;   // like <exec>
  +    private File outputFile = null;   // like <exec>
       private boolean append = false;   // like <exec>
   
       /**
  @@ -119,7 +126,7 @@
        * @param output  The file to write to.
        */
       public void setOutput(File output) {
  -        output_file = output;
  +        outputFile = output;
       }
   
       /**
  @@ -140,7 +147,7 @@
        *      will be stored.
        */
       public void setOutputproperty(String property) {
  -        output_property = property;
  +        outputProperty = property;
       }
   
       /**
  @@ -201,11 +208,11 @@
                   log("Timeout period exceeded, connection dropped.");
               } else {
                   // completed successfully
  -                if (output_property != null) {
  -                    getProject().setProperty(output_property, out.toString());
  +                if (outputProperty != null) {
  +                    getProject().setProperty(outputProperty, out.toString());
                   }
  -                if (output_file != null) {
  -                    writeToFile(out.toString(), append, output_file);
  +                if (outputFile != null) {
  +                    writeToFile(out.toString(), append, outputFile);
                   }
               }
   
  @@ -235,13 +242,13 @@
               out = new FileWriter(to.getAbsolutePath(), append);
               StringReader in = new StringReader(from);
               char[] buffer = new char[8192];
  -            int bytes_read;
  +            int bytesRead;
               while (true) {
  -                bytes_read = in.read(buffer);
  -                if (bytes_read == -1) {
  +                bytesRead = in.read(buffer);
  +                if (bytesRead == -1) {
                       break;
                   }
  -                out.write(buffer, 0, bytes_read);
  +                out.write(buffer, 0, bytesRead);
               }
               out.flush();
           } finally {
  
  
  
  1.3       +14 -14    ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHUserInfo.java
  
  Index: SSHUserInfo.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHUserInfo.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -w -u -r1.2 -r1.3
  --- SSHUserInfo.java	18 Apr 2003 23:40:27 -0000	1.2
  +++ SSHUserInfo.java	9 Jul 2003 12:12:59 -0000	1.3
  @@ -140,7 +140,7 @@
   
       /**
        * Sets the trust.
  -     * @param boolean
  +     * @param trust whether to trust or not.
        */
       public void setTrust(boolean trust) {
           this.trustAllCertificates = trust;
  
  
  
  1.6       +55 -49    ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java
  
  Index: Scp.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -w -u -r1.5 -r1.6
  --- Scp.java	18 Apr 2003 23:40:28 -0000	1.5
  +++ Scp.java	9 Jul 2003 12:12:59 -0000	1.6
  @@ -54,9 +54,12 @@
   
   package org.apache.tools.ant.taskdefs.optional.ssh;
   
  -import com.jcraft.jsch.*;
  +import com.jcraft.jsch.JSchException;
  +import com.jcraft.jsch.Session;
  +
  +import java.io.IOException;
  +import java.io.File;
   
  -import java.io.*;
   import java.util.List;
   import java.util.LinkedList;
   import java.util.Iterator;
  @@ -133,8 +136,8 @@
           }
   
           if ( fromUri == null && fileSets == null ) {
  -            throw new BuildException("Either the 'file' attribute or one " +
  -                                     "FileSet is required.");
  +            throw new BuildException("Either the 'file' attribute or one "
  +                + "FileSet is required.");
           }
   
           boolean isFromRemote = false;
  @@ -154,9 +157,9 @@
               } else if (isFromRemote && isToRemote) {
                   // not implemented yet.
               } else {
  -                throw new BuildException("'todir' and 'file' attributes " +
  -                                         "must have syntax like the following: " +
  -                                         "user:password@host:/path");
  +                throw new BuildException("'todir' and 'file' attributes "
  +                    + "must have syntax like the following: "
  +                    + "user:password@host:/path");
               }
           } catch (Exception e) {
               if(getFailonerror()) {
  @@ -182,10 +185,11 @@
               message.setLogListener( this );
               message.execute();
           } finally {
  -            if( session != null )
  +            if (session != null) {
                   session.disconnect();
           }
       }
  +    }
   
       private void upload( List fileSet, String toSshUri )
           throws IOException, JSchException {
  @@ -205,10 +209,11 @@
               message.setLogListener( this );
               message.execute();
           } finally {
  -            if( session != null )
  +            if (session != null) {
                   session.disconnect();
           }
       }
  +    }
   
       private void upload( String fromPath, String toSshUri )
           throws IOException, JSchException {
  @@ -223,10 +228,11 @@
               message.setLogListener( this );
               message.execute();
           } finally {
  -            if( session != null )
  +            if (session != null) {
                   session.disconnect();
           }
       }
  +    }
   
       private String parseUri(String uri) {
           int indexOfAt = uri.indexOf('@');
  
  
  
  1.4       +62 -43    ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java
  
  Index: ScpFromMessage.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -u -r1.3 -r1.4
  --- ScpFromMessage.java	11 Mar 2003 14:42:43 -0000	1.3
  +++ ScpFromMessage.java	9 Jul 2003 12:12:59 -0000	1.4
  @@ -54,13 +54,23 @@
   
   package org.apache.tools.ant.taskdefs.optional.ssh;
   
  -import com.jcraft.jsch.*;
  -
  -import java.io.*;
   import java.util.StringTokenizer;
  +import java.io.File;
  +import java.io.IOException;
  +import java.io.EOFException;
  +import java.io.InputStream;
  +import java.io.OutputStream;
  +import java.io.FileOutputStream;
  +import java.io.ByteArrayOutputStream;
  +import com.jcraft.jsch.JSchException;
  +import com.jcraft.jsch.Session;
  +import com.jcraft.jsch.Channel;
   
   public class ScpFromMessage extends AbstractSshMessage {
   
  +    private final byte LINE_FEED = 0x0a;
  +    private final int BUFFER_SIZE = 1024;
  +
       private String remoteFile;
       private File localFile;
       private boolean isRecursive = false;
  @@ -77,8 +87,9 @@
   
       public void execute() throws IOException, JSchException {
           String command = "scp -f ";
  -        if( isRecursive )
  +        if (isRecursive) {
               command += "-r ";
  +        }
           command += remoteFile;
           Channel channel = openExecChannel( command );
           try {
  @@ -91,9 +102,10 @@
               sendAck(out);
               startRemoteCpProtocol( in, out, localFile);
           } finally {
  -            if( channel != null )
  +            if (channel != null) {
                   channel.disconnect();
           }
  +        }
           log( "done\n" );
       }
   
  @@ -108,8 +120,12 @@
               ByteArrayOutputStream stream = new ByteArrayOutputStream();
               while( true ) {
                   int read = in.read();
  -                if( read < 0 ) return;
  -                if( (byte)read == (byte)0x0a ) break;
  +                if (read < 0) {
  +                    return;
  +                }
  +                if ((byte) read == LINE_FEED) {
  +                    break;
  +                }
                   stream.write( read );
               }
               String serverResponse = stream.toString("UTF-8");
  @@ -166,7 +182,7 @@
                               int filesize,
                               OutputStream out,
                               InputStream in) throws IOException {
  -        byte[] buf = new byte[1024];
  +        byte[] buf = new byte[BUFFER_SIZE];
           sendAck(out);
   
           // read a content of lfile
  @@ -178,12 +194,15 @@
               while (true) {
                   length = in.read( buf, 0,
                           (buf.length < filesize) ? buf.length : filesize );
  -                if( length < 0 )
  +                if (length < 0) {
                       throw new EOFException("Unexpected end of stream.");
  +                }
                   fos.write( buf, 0, length );
                   filesize -= length;
                   totalLength += length;
  -                if (filesize == 0) break;
  +                if (filesize == 0) {
  +                    break;
  +                }
               }
           } finally {
               long endTime = System.currentTimeMillis();
  
  
  
  1.4       +42 -33    ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java
  
  Index: ScpToMessage.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -u -r1.3 -r1.4
  --- ScpToMessage.java	11 Mar 2003 14:42:43 -0000	1.3
  +++ ScpToMessage.java	9 Jul 2003 12:12:59 -0000	1.4
  @@ -57,12 +57,18 @@
   import com.jcraft.jsch.Channel;
   import com.jcraft.jsch.Session;
   import com.jcraft.jsch.JSchException;
  -
  -import java.io.*;
  -import java.util.*;
  +import java.io.File;
  +import java.io.IOException;
  +import java.io.InputStream;
  +import java.io.FileInputStream;
  +import java.io.OutputStream;
  +import java.util.List;
  +import java.util.Iterator;
   
   public class ScpToMessage extends AbstractSshMessage {
   
  +    private final int BUFFER_SIZE = 1024;
  +
       private File localFile;
       private String remotePath;
       private List directoryList;
  @@ -109,10 +115,11 @@
               sendFileToRemote(localFile, in, out);
               waitForAck(in);
           } finally {
  -            if( channel != null )
  +            if (channel != null) {
                   channel.disconnect();
           }
       }
  +    }
   
       private void doMultipleTransfer() throws IOException, JSchException {
           Channel channel = openExecChannel( "scp -d -t " + remotePath );
  @@ -129,10 +136,11 @@
               }
               waitForAck(in);
           } finally {
  -            if( channel != null )
  +            if (channel != null) {
                   channel.disconnect();
           }
       }
  +    }
   
       private void sendDirectory(Directory current,
                                  InputStream in,
  @@ -177,15 +185,16 @@
   
           // send a content of lfile
           FileInputStream fis = new FileInputStream(localFile);
  -        byte[] buf = new byte[1024];
  +        byte[] buf = new byte[BUFFER_SIZE];
           long startTime = System.currentTimeMillis();
           int totalLength = 0;
           try {
  -            log( "Sending: " + localFile.getName() + " : " + 
  -                 localFile.length());
  +            log("Sending: " + localFile.getName() + " : " + localFile.length());
               while (true) {
                   int len = fis.read(buf, 0, buf.length);
  -                if (len <= 0) break;
  +                if (len <= 0) {
  +                    break;
  +                }
                   out.write(buf, 0, len);
                   totalLength += len;
               }
  
  
  

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


Mime
View raw message