Here are answers to your questions + new patches.

Q: I don't see you using SSHBase in AbstractSshMessage at all, so you
  don't need to add it as an attribute.  The subclasses only need to
  know whether verbose output has been requested, so they don't need
  a reference to sshbase either, just the flag.

A: I just added it so when they start using another property/attribute from
SSHBase they could do so.
But I do as you suggest.

Q: You are changing the public API of some classes.  This may be
  necessary, but we must not remove the old signatures completely.
  Delegate to the new one using reasonable defaults and @deprecate the
  old ones, but don't remove them.

A: Fixed.

* We've removed all @author tags in CVS HEAD, your patch shows that
  you're working copy is from the 1.6 branch.  You'd better use CVS
  HEAD for your patch, but the difference can be adapted to easily.

A: Fixed.

And here are the patches:

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 7 Apr 2004 12:12:39 -0000
@@ -31,6 +31,7 @@
 public abstract class AbstractSshMessage {
+    protected boolean verbose;
     private Session session;
     private LogListener listener = new LogListener() {
         public void log(String message) {
@@ -38,10 +39,15 @@
         }
     };
-    public AbstractSshMessage(Session session) {
+    public AbstractSshMessage(boolean verbose, Session session) {
+        this.verbose = verbose;
         this.session = session;
     }
+    public AbstractSshMessage(Session session) {
+        this(false, session);
+    }
+
     protected Channel openExecChannel(String command) throws JSchException
{
         ChannelExec channel = (ChannelExec) session.openChannel("exec");
         channel.setCommand(command);
@@ -114,4 +120,24 @@
             + " Average Rate: " + format.format(totalLength / duration)
             + " B/s");
     }
+
+    /*
+        Track progress every 10% if 100kb < filesize < 1mb. For larger
files track 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 7 Apr 2004 12:12:39 -0000
@@ -41,6 +41,7 @@
     private int port = SSH_PORT;
     private boolean failOnError = true;
     private SSHUserInfo userInfo;
+    protected boolean verbose = false;
     /**
      * Constructor for SSHBase.
@@ -142,6 +143,15 @@
         return port;
     }
+    /**
+     * If true, show verbose progress information.
+     *
+     * @param v if "true" then be verbose
+     */
+    public void setVerbose(boolean v) {
+        verbose = v;
+    }
+
     public void init() throws BuildException {
         super.init();
         this.knownHosts = System.getProperty("user.home") +
"/.ssh/known_hosts";
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 7 Apr 2004 12:12:39 -0000
@@ -140,7 +140,7 @@
         try {
             session = openSession();
             ScpFromMessage message =
-                new ScpFromMessage(session, file,
+                new ScpFromMessage(verbose, session, file,
                                    getProject().resolveFile(toPath),
                                    fromSshUri.endsWith("*"));
             log("Receiving file: " + file);
@@ -169,7 +169,7 @@
             }
             if (!list.isEmpty()) {
                 session = openSession();
-                ScpToMessage message = new ScpToMessage(session, list,
file);
+                ScpToMessage message = new ScpToMessage(verbose, session,
list, file);
                 message.setLogListener(this);
                 message.execute();
             }
@@ -188,7 +188,7 @@
         try {
             session = openSession();
             ScpToMessage message =
-                new ScpToMessage(session,
getProject().resolveFile(fromPath),
+                new ScpToMessage(verbose, 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 7 Apr 2004 12:12:39 -0000
@@ -38,16 +38,24 @@
     private File localFile;
     private boolean isRecursive = false;
-    public ScpFromMessage(Session session,
+    public ScpFromMessage(boolean verbose,
+                          Session session,
                            String aRemoteFile,
                            File aLocalFile,
                            boolean recursive) {
-        super(session);
+        super(verbose, session);
         this.remoteFile = aRemoteFile;
         this.localFile = aLocalFile;
         this.isRecursive = recursive;
     }
+    public ScpFromMessage(Session session,
+                          String aRemoteFile,
+                          File aLocalFile,
+                          boolean recursive) {
+        this(false, session, aRemoteFile, aLocalFile, recursive);
+    }
+
     public void execute() throws IOException, JSchException {
         String command = "scp -f ";
         if (isRecursive) {
@@ -153,6 +161,13 @@
         int length;
         int totalLength = 0;
         long startTime = System.currentTimeMillis();
+
+        // only track progress for files larger than 100kb in verbose mode
+        boolean trackProgress = verbose && 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 +181,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 7 Apr 2004 12:12:39 -0000
@@ -36,24 +36,38 @@
     private String remotePath;
     private List directoryList;
-    public ScpToMessage(Session session,
+    public ScpToMessage(boolean verbose,
+                        Session session,
                         File aLocalFile,
                         String aRemotePath) {
-        super(session);
+        super(verbose, session);
         this.localFile = aLocalFile;
         this.remotePath = aRemotePath;
     }
     public ScpToMessage(Session session,
+                        File aLocalFile,
+                        String aRemotePath) {
+        this(false, session, aLocalFile, aRemotePath);
+    }
+
+    public ScpToMessage(boolean verbose,
+                        Session session,
                          List aDirectoryList,
                          String aRemotePath) {
-        super(session);
+        super(verbose, session);
         this.directoryList = aDirectoryList;
         this.remotePath = aRemotePath;
     }
+    public ScpToMessage(Session session,
+                        List aDirectoryList,
+                        String aRemotePath) {
+        this(false, session, aDirectoryList, aRemotePath);
+    }
+
     public void execute() throws IOException, JSchException {
         if (directoryList != null) {
             doMultipleTransfer();
@@ -150,6 +164,11 @@
         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 = verbose && filesize > 102400;
+        int percentTransmitted = 0;
+
         try {
             log("Sending: " + localFile.getName() + " : " +
localFile.length());
             while (true) {
@@ -159,6 +178,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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to