ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rami Ojares" <rami.oja...@elisa.fi>
Subject Re: SSH tracking
Date Tue, 06 Apr 2004 16:01:21 GMT
> I'd like to see your patch modified so that you'll only see a progress
> report when the (new) attribute verbose has been set to true.  Just
> like <get> does today.

Have a look at this patch Stefan. (It's patch from the whole directory)
I added verbose attribute and rearranged things a little.

cvs server: Diffing .
Index: AbstractSshMessage.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Abst
ractSshMessage.java,v
retrieving revision 1.8
diff -B -b -u -r1.8 AbstractSshMessage.java
--- AbstractSshMessage.java 9 Feb 2004 21:05:34 -0000 1.8
+++ AbstractSshMessage.java 6 Apr 2004 15:56:23 -0000
@@ -31,14 +31,17 @@
 public abstract class AbstractSshMessage {
+    protected SSHBase sshBase;
     private Session session;
+
     private LogListener listener = new LogListener() {
         public void log(String message) {
             // do nothing;
         }
     };
-    public AbstractSshMessage(Session session) {
+    public AbstractSshMessage(SSHBase sshBase, Session session) {
+        this.sshBase = sshBase;
         this.session = session;
     }
@@ -114,4 +117,24 @@
             + " Average Rate: " + format.format(totalLength / duration)
             + " B/s");
     }
+
+    /*
+        Track progress every 10% if 100kb < filesize < 1mb. For larger
files trck progress for every percent transmitted.
+    */
+    protected int trackProgress(int filesize, int totalLength, int
percentTransmitted) {
+
+        int percent = (int) Math.round(Math.floor((totalLength /
(double)filesize) * 100));
+
+        if (percent > percentTransmitted) {
+            if ( filesize < 1048576 && (percent % 10 != 0) ) {
+                // do not track between tenths
+            }
+            else {
+                log("" + percent + "%");
+            }
+        }
+
+        return percent;
+    }
+
 }
Index: SSHBase.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHB
ase.java,v
retrieving revision 1.10
diff -B -b -u -r1.10 SSHBase.java
--- SSHBase.java 9 Mar 2004 16:48:37 -0000 1.10
+++ SSHBase.java 6 Apr 2004 15:56:24 -0000
@@ -41,6 +41,7 @@
     private int port = SSH_PORT;
     private boolean failOnError = true;
     private SSHUserInfo userInfo;
+    private boolean verbose = false;
     /**
      * Constructor for SSHBase.
@@ -142,6 +143,18 @@
         return port;
     }
+    /**
+     * If true, show verbose progress information.
+     *
+     * @param v if "true" then be verbose
+     */
+    public void setVerbose(boolean v) {
+        verbose = v;
+    }
+    public boolean isVerbose() {
+        return this.verbose;
+    }
+
     public void init() throws BuildException {
         super.init();
         this.knownHosts = System.getProperty("user.home") +
"/.ssh/known_hosts";
Index: SSHExec.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHE
xec.java,v
retrieving revision 1.15
diff -B -b -u -r1.15 SSHExec.java
--- SSHExec.java 9 Mar 2004 16:48:37 -0000 1.15
+++ SSHExec.java 6 Apr 2004 15:56:24 -0000
@@ -34,7 +34,9 @@
 /**
  * Executes a command on a remote machine via ssh.
  *
- * @version   $Revision: 1.15 $
+ * @author    Robert Anderson, riznob@hotmail.com
+ * @author    Dale Anson, danson@germane-software.com
+ * @version   $Revision: 1.9.2.5 $
  * @created   February 2, 2003
  * @since     Ant 1.6
  */
Index: SSHUserInfo.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHU
serInfo.java,v
retrieving revision 1.8
diff -B -b -u -r1.8 SSHUserInfo.java
--- SSHUserInfo.java 9 Mar 2004 16:48:37 -0000 1.8
+++ SSHUserInfo.java 6 Apr 2004 15:56:24 -0000
@@ -20,6 +20,7 @@
 import com.jcraft.jsch.UserInfo;
 /**
+ * @author rhanderson
  */
 public class SSHUserInfo implements UserInfo {
Index: Scp.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/Scp.
java,v
retrieving revision 1.14
diff -B -b -u -r1.14 Scp.java
--- Scp.java 9 Mar 2004 16:48:37 -0000 1.14
+++ Scp.java 6 Apr 2004 15:56:24 -0000
@@ -36,6 +36,7 @@
 /**
  * Ant task for sending files to remote machine over ssh/scp.
  *
+ * @author charliehubbard76@yahoo.com
  * @since Ant 1.6
  */
 public class Scp extends SSHBase {
@@ -140,7 +141,7 @@
         try {
             session = openSession();
             ScpFromMessage message =
-                new ScpFromMessage(session, file,
+                new ScpFromMessage(this, session, file,
                                    getProject().resolveFile(toPath),
                                    fromSshUri.endsWith("*"));
             log("Receiving file: " + file);
@@ -169,7 +170,7 @@
             }
             if (!list.isEmpty()) {
                 session = openSession();
-                ScpToMessage message = new ScpToMessage(session, list,
file);
+                ScpToMessage message = new ScpToMessage(this, session,
list, file);
                 message.setLogListener(this);
                 message.execute();
             }
@@ -188,7 +189,7 @@
         try {
             session = openSession();
             ScpToMessage message =
-                new ScpToMessage(session,
getProject().resolveFile(fromPath),
+                new ScpToMessage(this, session,
getProject().resolveFile(fromPath),
                                  file);
             message.setLogListener(this);
             message.execute();
Index: ScpFromMessage.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpF
romMessage.java,v
retrieving revision 1.7
diff -B -b -u -r1.7 ScpFromMessage.java
--- ScpFromMessage.java 9 Feb 2004 21:05:34 -0000 1.7
+++ ScpFromMessage.java 6 Apr 2004 15:56:25 -0000
@@ -38,11 +38,12 @@
     private File localFile;
     private boolean isRecursive = false;
-    public ScpFromMessage(Session session,
+    public ScpFromMessage(SSHBase sshBase,
+                          Session session,
                            String aRemoteFile,
                            File aLocalFile,
                            boolean recursive) {
-        super(session);
+        super(sshBase, session);
         this.remoteFile = aRemoteFile;
         this.localFile = aLocalFile;
         this.isRecursive = recursive;
@@ -153,6 +154,13 @@
         int length;
         int totalLength = 0;
         long startTime = System.currentTimeMillis();
+
+        // only track progress for files larger than 100kb in verbose mode
+        boolean trackProgress = sshBase.isVerbose() && filesize > 102400;
+        // since filesize keeps on decreasing we have to store the initial
filesize
+        int initFilesize = filesize;
+        int percentTransmitted = 0;
+
         try {
             while (true) {
                 length = in.read(buf, 0,
@@ -166,6 +174,9 @@
                 if (filesize == 0) {
                     break;
                 }
+
+                if (trackProgress)
+                    percentTransmitted = trackProgress(initFilesize,
totalLength, percentTransmitted);
             }
         } finally {
             long endTime = System.currentTimeMillis();
Index: ScpToMessage.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpT
oMessage.java,v
retrieving revision 1.8
diff -B -b -u -r1.8 ScpToMessage.java
--- ScpToMessage.java 9 Feb 2004 21:05:34 -0000 1.8
+++ ScpToMessage.java 6 Apr 2004 15:56:25 -0000
@@ -32,23 +32,26 @@
     private final int BUFFER_SIZE = 1024;
+
     private File localFile;
     private String remotePath;
     private List directoryList;
-    public ScpToMessage(Session session,
+    public ScpToMessage(SSHBase sshBase,
+                        Session session,
                         File aLocalFile,
                         String aRemotePath) {
-        super(session);
+        super(sshBase, session);
         this.localFile = aLocalFile;
         this.remotePath = aRemotePath;
     }
-    public ScpToMessage(Session session,
+    public ScpToMessage(SSHBase sshBase,
+                        Session session,
                          List aDirectoryList,
                          String aRemotePath) {
-        super(session);
+        super(sshBase, session);
         this.directoryList = aDirectoryList;
         this.remotePath = aRemotePath;
@@ -134,6 +137,7 @@
     private void sendFileToRemote(File localFile,
                                    InputStream in,
                                    OutputStream out) throws IOException {
+
         // send "C0644 filesize filename", where filename should not
include '/'
         int filesize = (int) localFile.length();
         String command = "C0644 " + filesize + " ";
@@ -150,8 +154,13 @@
         byte[] buf = new byte[BUFFER_SIZE];
         long startTime = System.currentTimeMillis();
         int totalLength = 0;
+
+        // only track progress for files larger than 100kb in verbose mode
+        boolean trackProgress = sshBase.isVerbose() && filesize > 102400;
+        int percentTransmitted = 0;
+
         try {
-            log("Sending: " + localFile.getName() + " : " +
localFile.length());
+            log("Sending: " + localFile.getName() + " : " +
localFile.length() + " bytes");
             while (true) {
                 int len = fis.read(buf, 0, buf.length);
                 if (len <= 0) {
@@ -159,6 +168,9 @@
                 }
                 out.write(buf, 0, len);
                 totalLength += len;
+                // only track prgress for files larger than 100kb in
verbose mode
+                if (trackProgress)
+                    percentTransmitted = trackProgress(filesize,
totalLength, percentTransmitted);
             }
             out.flush();
             sendAck(out);


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


Mime
View raw message