Browse Source

checkstyle

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@477342 13f79535-47bb-0310-9956-ffa450edef68
master
Peter Reilly 18 years ago
parent
commit
03167c0970
4 changed files with 52 additions and 46 deletions
  1. +5
    -3
      src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java
  2. +10
    -0
      src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHUserInfo.java
  3. +16
    -21
      src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java
  4. +21
    -22
      src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java

+ 5
- 3
src/main/org/apache/tools/ant/taskdefs/optional/ssh/AbstractSshMessage.java View File

@@ -23,8 +23,6 @@ import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSchException; import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session; import com.jcraft.jsch.Session;
import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.SftpATTRS;
import com.jcraft.jsch.SftpException;
import com.jcraft.jsch.SftpProgressMonitor; import com.jcraft.jsch.SftpProgressMonitor;


import java.io.IOException; import java.io.IOException;
@@ -231,7 +229,11 @@ public abstract class AbstractSshMessage {


private ProgressMonitor monitor = null; private ProgressMonitor monitor = null;


protected SftpProgressMonitor getProgressMonitor(){
/**
* Get the progress monitor.
* @return the progress monitor.
*/
protected SftpProgressMonitor getProgressMonitor() {
if (monitor == null) { if (monitor == null) {
monitor = new ProgressMonitor(); monitor = new ProgressMonitor();
} }


+ 10
- 0
src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHUserInfo.java View File

@@ -190,6 +190,16 @@ public class SSHUserInfo implements UserInfo, UIKeyboardInteractive {
//log(message, Project.MSG_DEBUG); //log(message, Project.MSG_DEBUG);
} }


/**
* Implementation of UIKeyboardInteractive#promptKeyboardInteractive.
* @param destination not used.
* @param name not used.
* @param instruction not used.
* @param prompt the method checks if this is one in length.
* @param echo the method checks if the first element is false.
* @return the password in an size one array if there is a password
* and if the prompt and echo checks pass.
*/
public String[] promptKeyboardInteractive(String destination, public String[] promptKeyboardInteractive(String destination,
String name, String name,
String instruction, String instruction,


+ 16
- 21
src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessageBySftp.java View File

@@ -20,15 +20,9 @@ package org.apache.tools.ant.taskdefs.optional.ssh;


import java.io.File; import java.io.File;
import java.io.IOException; 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.JSchException;
import com.jcraft.jsch.Session; import com.jcraft.jsch.Session;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.SftpException; import com.jcraft.jsch.SftpException;
import com.jcraft.jsch.SftpATTRS; import com.jcraft.jsch.SftpATTRS;
@@ -91,12 +85,13 @@ public class ScpFromMessageBySftp extends ScpFromMessage {
try { try {
SftpATTRS attrs = channel.stat(remoteFile); SftpATTRS attrs = channel.stat(remoteFile);
if (attrs.isDir() && !remoteFile.endsWith("/")) { if (attrs.isDir() && !remoteFile.endsWith("/")) {
remoteFile=remoteFile+"/";
remoteFile = remoteFile + "/";
} }
} catch(SftpException ee) {
} catch (SftpException ee) {
// Ignored
} }
getDir(channel, remoteFile, localFile); getDir(channel, remoteFile, localFile);
} catch(SftpException e) {
} catch (SftpException e) {
throw new JSchException(e.toString()); throw new JSchException(e.toString());
} finally { } finally {
if (channel != null) { if (channel != null) {
@@ -109,10 +104,10 @@ public class ScpFromMessageBySftp extends ScpFromMessage {
private void getDir(ChannelSftp channel, private void getDir(ChannelSftp channel,
String remoteFile, String remoteFile,
File localFile) throws IOException, SftpException { File localFile) throws IOException, SftpException {
String pwd=remoteFile;
if (remoteFile.lastIndexOf('/')!=-1) {
if (remoteFile.length()>1) {
pwd=remoteFile.substring(0, remoteFile.lastIndexOf('/'));
String pwd = remoteFile;
if (remoteFile.lastIndexOf('/') != -1) {
if (remoteFile.length() > 1) {
pwd = remoteFile.substring(0, remoteFile.lastIndexOf('/'));
} }
} }
channel.cd(pwd); channel.cd(pwd);
@@ -120,7 +115,7 @@ public class ScpFromMessageBySftp extends ScpFromMessage {
localFile.mkdirs(); localFile.mkdirs();
} }
java.util.Vector files = channel.ls(remoteFile); java.util.Vector files = channel.ls(remoteFile);
for(int i = 0; i < files.size(); i++){
for (int i = 0; i < files.size(); i++) {
ChannelSftp.LsEntry le = (ChannelSftp.LsEntry) files.elementAt(i); ChannelSftp.LsEntry le = (ChannelSftp.LsEntry) files.elementAt(i);
String name = le.getFilename(); String name = le.getFilename();
if (le.getAttrs().isDir()) { if (le.getAttrs().isDir()) {
@@ -130,7 +125,7 @@ public class ScpFromMessageBySftp extends ScpFromMessage {
getDir(channel, getDir(channel,
channel.pwd() + "/" + name + "/", channel.pwd() + "/" + name + "/",
new File(localFile, le.getFilename())); new File(localFile, le.getFilename()));
} else{
} else {
getFile(channel, le, localFile); getFile(channel, le, localFile);
} }
} }
@@ -145,14 +140,14 @@ public class ScpFromMessageBySftp extends ScpFromMessage {
String path = localFile.getAbsolutePath(); String path = localFile.getAbsolutePath();
int i = 0; int i = 0;
if ((i = path.lastIndexOf(File.pathSeparator)) != -1) { if ((i = path.lastIndexOf(File.pathSeparator)) != -1) {
if (path.length()>File.pathSeparator.length()) {
if (path.length() > File.pathSeparator.length()) {
new File(path.substring(0, i)).mkdirs(); new File(path.substring(0, i)).mkdirs();
} }
} }
} }


if (localFile.isDirectory()) { if (localFile.isDirectory()) {
localFile=new File(localFile, remoteFile);
localFile = new File(localFile, remoteFile);
} }


long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
@@ -160,15 +155,15 @@ public class ScpFromMessageBySftp extends ScpFromMessage {


SftpProgressMonitor monitor = null; SftpProgressMonitor monitor = null;
boolean trackProgress = getVerbose() && totalLength > 102400; boolean trackProgress = getVerbose() && totalLength > 102400;
if (trackProgress){
if (trackProgress) {
monitor = getProgressMonitor(); monitor = getProgressMonitor();
} }
try{
try {
log("Receiving: " + remoteFile + " : " + le.getAttrs().getSize()); log("Receiving: " + remoteFile + " : " + le.getAttrs().getSize());
channel.get(remoteFile, localFile.getAbsolutePath(), monitor); channel.get(remoteFile, localFile.getAbsolutePath(), monitor);
} finally{
} finally {
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
logStats(startTime, endTime, (int)totalLength);
logStats(startTime, endTime, (int) totalLength);
} }
} }
} }

+ 21
- 22
src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessageBySftp.java View File

@@ -18,19 +18,14 @@


package org.apache.tools.ant.taskdefs.optional.ssh; package org.apache.tools.ant.taskdefs.optional.ssh;


import com.jcraft.jsch.Channel;
import com.jcraft.jsch.Session; import com.jcraft.jsch.Session;
import com.jcraft.jsch.ChannelSftp; import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSchException; import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.SftpException; import com.jcraft.jsch.SftpException;
import com.jcraft.jsch.SftpProgressMonitor; import com.jcraft.jsch.SftpProgressMonitor;
import com.jcraft.jsch.SftpATTRS;


import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.util.List; import java.util.List;
import java.util.Iterator; import java.util.Iterator;


@@ -134,10 +129,9 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ {
ChannelSftp channel = openSftpChannel(); ChannelSftp channel = openSftpChannel();
try { try {
channel.connect(); channel.connect();
try{
try {
sendFileToRemote(channel, localFile, remotePath); sendFileToRemote(channel, localFile, remotePath);
}
catch(SftpException e){
} catch (SftpException e) {
throw new JSchException(e.toString()); throw new JSchException(e.toString());
} }
} finally { } finally {
@@ -152,14 +146,13 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ {
try { try {
channel.connect(); channel.connect();


try{
try {
channel.cd(remotePath); channel.cd(remotePath);
for (Iterator i = directoryList.iterator(); i.hasNext();) { for (Iterator i = directoryList.iterator(); i.hasNext();) {
Directory current = (Directory) i.next(); Directory current = (Directory) i.next();
sendDirectory(channel, current); sendDirectory(channel, current);
} }
}
catch(SftpException e){
} catch (SftpException e) {
throw new JSchException(e.toString()); throw new JSchException(e.toString());
} }
} finally { } finally {
@@ -184,13 +177,12 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ {
private void sendDirectoryToRemote(ChannelSftp channel, private void sendDirectoryToRemote(ChannelSftp channel,
Directory directory) Directory directory)
throws IOException, SftpException { throws IOException, SftpException {
String dir=directory.getDirectory().getName();
try{
String dir = directory.getDirectory().getName();
try {
channel.stat(dir); channel.stat(dir);
}
catch (SftpException e) {
} catch (SftpException e) {
// dir does not exist. // dir does not exist.
if (e.id==ChannelSftp.SSH_FX_NO_SUCH_FILE) {
if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
channel.mkdir(dir); channel.mkdir(dir);
} }
} }
@@ -205,8 +197,8 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ {
throws IOException, SftpException { throws IOException, SftpException {
long filesize = localFile.length(); long filesize = localFile.length();


if (remotePath==null) {
remotePath=localFile.getName();
if (remotePath == null) {
remotePath = localFile.getName();
} }


long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
@@ -216,17 +208,16 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ {
boolean trackProgress = getVerbose() && filesize > 102400; boolean trackProgress = getVerbose() && filesize > 102400;


SftpProgressMonitor monitor = null; SftpProgressMonitor monitor = null;
if (trackProgress){
if (trackProgress) {
monitor = getProgressMonitor(); monitor = getProgressMonitor();
} }


try{
try {
if (this.getVerbose()) { if (this.getVerbose()) {
log("Sending: " + localFile.getName() + " : " + filesize); log("Sending: " + localFile.getName() + " : " + filesize);
} }
channel.put(localFile.getAbsolutePath(), remotePath, monitor); channel.put(localFile.getAbsolutePath(), remotePath, monitor);
}
finally {
} finally {
if (this.getVerbose()) { if (this.getVerbose()) {
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
logStats(startTime, endTime, (int) totalLength); logStats(startTime, endTime, (int) totalLength);
@@ -234,10 +225,18 @@ public class ScpToMessageBySftp extends ScpToMessage/*AbstractSshMessage*/ {
} }
} }


/**
* Get the local file.
* @return the local file.
*/
public File getLocalFile() { public File getLocalFile() {
return localFile; return localFile;
} }


/**
* Get the remote path.
* @return the remote path.
*/
public String getRemotePath() { public String getRemotePath() {
return remotePath; return remotePath;
} }


Loading…
Cancel
Save