bodewig 2004/04/07 06:30:30 Modified: . CONTRIBUTORS src/main/org/apache/tools/ant/taskdefs/optional/ssh AbstractSshMessage.java SSHBase.java Scp.java ScpFromMessage.java ScpToMessage.java Log: Add progress report to <scp>. Submitted by: Rami Ojares Revision Changes Path 1.9 +2 -1 ant/CONTRIBUTORS Index: CONTRIBUTORS =================================================================== RCS file: /home/cvs/ant/CONTRIBUTORS,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- CONTRIBUTORS 7 Apr 2004 12:13:30 -0000 1.8 +++ CONTRIBUTORS 7 Apr 2004 13:30:30 -0000 1.9 @@ -148,8 +148,9 @@ Phillip Wells Pierre Delisle Pierre Dittgen -Raphael Pierquin R Handerson +Rami Ojares +Raphael Pierquin Richard Evans Rick Beton Robert Anderson 1.9 +38 -0 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- AbstractSshMessage.java 9 Feb 2004 21:05:34 -0000 1.8 +++ AbstractSshMessage.java 7 Apr 2004 13:30:30 -0000 1.9 @@ -32,6 +32,7 @@ public abstract class AbstractSshMessage { private Session session; + private boolean verbose; private LogListener listener = new LogListener() { public void log(String message) { // do nothing; @@ -39,6 +40,14 @@ }; public AbstractSshMessage(Session session) { + this(false, session); + } + + /** + * @since Ant 1.6.2 + */ + public AbstractSshMessage(boolean verbose, Session session) { + this.verbose = verbose; this.session = session; } @@ -114,4 +123,33 @@ + " Average Rate: " + format.format(totalLength / duration) + " B/s"); } + + /** + * @since Ant 1.6.2 + */ + protected final boolean getVerbose() { + return verbose; + } + + /* + * Track progress every 10% if 100kb < filesize < 1mb. For larger + * files track progress for every percent transmitted. + */ + protected final 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; + } + } 1.11 +15 -0 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.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- SSHBase.java 9 Mar 2004 16:48:37 -0000 1.10 +++ SSHBase.java 7 Apr 2004 13:30:30 -0000 1.11 @@ -40,6 +40,7 @@ private String knownHosts; private int port = SSH_PORT; private boolean failOnError = true; + private boolean verbose; private SSHUserInfo userInfo; /** @@ -69,6 +70,20 @@ public boolean getFailonerror() { return failOnError; + } + + /** + * @since Ant 1.6.2 + */ + public void setVerbose(boolean failure) { + verbose = failure; + } + + /** + * @since Ant 1.6.2 + */ + public boolean getVerbose() { + return verbose; } /** 1.15 +5 -4 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.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- Scp.java 9 Mar 2004 16:48:37 -0000 1.14 +++ Scp.java 7 Apr 2004 13:30:30 -0000 1.15 @@ -140,7 +140,7 @@ try { session = openSession(); ScpFromMessage message = - new ScpFromMessage(session, file, + new ScpFromMessage(getVerbose(), session, file, getProject().resolveFile(toPath), fromSshUri.endsWith("*")); log("Receiving file: " + file); @@ -169,7 +169,8 @@ } if (!list.isEmpty()) { session = openSession(); - ScpToMessage message = new ScpToMessage(session, list, file); + ScpToMessage message = new ScpToMessage(getVerbose(), session, + list, file); message.setLogListener(this); message.execute(); } @@ -188,8 +189,8 @@ try { session = openSession(); ScpToMessage message = - new ScpToMessage(session, getProject().resolveFile(fromPath), - file); + new ScpToMessage(getVerbose(), session, + getProject().resolveFile(fromPath), file); message.setLogListener(this); message.execute(); } finally { 1.8 +29 -4 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.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ScpFromMessage.java 9 Feb 2004 21:05:34 -0000 1.7 +++ ScpFromMessage.java 7 Apr 2004 13:30:30 -0000 1.8 @@ -38,14 +38,25 @@ private File localFile; private boolean isRecursive = false; + /** + * @since Ant 1.6.2 + */ + public ScpFromMessage(boolean verbose, + Session session, + String aRemoteFile, + File aLocalFile, + boolean recursive) { + super(verbose, session); + this.remoteFile = aRemoteFile; + this.localFile = aLocalFile; + this.isRecursive = recursive; + } + public ScpFromMessage(Session session, String aRemoteFile, File aLocalFile, boolean recursive) { - super(session); - this.remoteFile = aRemoteFile; - this.localFile = aLocalFile; - this.isRecursive = recursive; + this(false, session, aRemoteFile, aLocalFile, recursive); } public void execute() throws IOException, JSchException { @@ -153,6 +164,14 @@ int length; int totalLength = 0; long startTime = System.currentTimeMillis(); + + // only track progress for files larger than 100kb in verbose mode + boolean trackProgress = getVerbose() && 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, @@ -165,6 +184,12 @@ totalLength += length; if (filesize == 0) { break; + } + + if (trackProgress) { + percentTransmitted = trackProgress(initFilesize, + totalLength, + percentTransmitted); } } } finally { 1.9 +48 -6 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- ScpToMessage.java 9 Feb 2004 21:05:34 -0000 1.8 +++ ScpToMessage.java 7 Apr 2004 13:30:30 -0000 1.9 @@ -36,22 +36,50 @@ private String remotePath; private List directoryList; - public ScpToMessage(Session session, + /** + * @since Ant 1.6.2 + */ + public ScpToMessage(boolean verbose, + Session session, File aLocalFile, String aRemotePath) { - super(session); + this(verbose, session, aRemotePath); this.localFile = aLocalFile; + } + + /** + * @since Ant 1.6.2 + */ + public ScpToMessage(boolean verbose, + Session session, + List aDirectoryList, + String aRemotePath) { + this(verbose, session, aRemotePath); + + this.directoryList = aDirectoryList; + } + + /** + * @since Ant 1.6.2 + */ + private ScpToMessage(boolean verbose, + Session session, + String aRemotePath) { + super(verbose, session); this.remotePath = aRemotePath; } public ScpToMessage(Session session, + File aLocalFile, + String aRemotePath) { + this(false, session, aLocalFile, aRemotePath); + } + + public ScpToMessage(Session session, List aDirectoryList, String aRemotePath) { - super(session); - - this.directoryList = aDirectoryList; - this.remotePath = aRemotePath; + this(false, session, aDirectoryList, aRemotePath); } public void execute() throws IOException, JSchException { @@ -150,6 +178,14 @@ 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 = getVerbose() && filesize > 102400; + // since filesize keeps on decreasing we have to store the + // initial filesize + int initFilesize = filesize; + int percentTransmitted = 0; + try { log("Sending: " + localFile.getName() + " : " + localFile.length()); while (true) { @@ -159,6 +195,12 @@ } out.write(buf, 0, len); totalLength += len; + + if (trackProgress) { + percentTransmitted = trackProgress(initFilesize, + totalLength, + percentTransmitted); + } } out.flush(); sendAck(out);
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]