Changed SCP Deployer to SFTP deployer. I am done with functionality
(except of Http Deployer) Now I will test it deeper and assure that everything works. git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113536 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
1 parent
a460147e30
commit
f1ac6b0815
9 files changed
+167
-140
No files matched your search
@@ -59,7 +59,7 @@
|
||||
<dependency>
|
||||
<groupId>jsch</groupId>
|
||||
<artifactId>jsch</artifactId>
|
||||
<version>0.0.9</version>
|
||||
<version>0.1.5</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ import org.apache.maven.util.MD5Sum;
|
||||
* Default implemenataion of Artifact Deployer interface
|
||||
*
|
||||
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: DefaultArtifactDeployer.java,v 1.7 2003/06/24 16:20:51 michal Exp $
|
||||
* @version $Id: DefaultArtifactDeployer.java,v 1.8 2003/06/24 22:22:55 michal Exp $
|
||||
*/
|
||||
public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
{
|
||||
@@ -214,7 +214,7 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
{
|
||||
destFile.mkdirs();
|
||||
}
|
||||
destFile = new File(file, getRepositoryFile(type, project, version));
|
||||
destFile = new File(destFile, getRepositoryFile(type, project, version));
|
||||
System.out.println(
|
||||
"Copying: from '" + file + "' to: '" + destFile + "'");
|
||||
FileUtils.copyFile(file, destFile);
|
||||
|
||||
@@ -64,7 +64,7 @@ import org.apache.maven.project.Project;
|
||||
* The Bean which serves as Proxy for Jelly scripts To Artifact Deployement API
|
||||
*
|
||||
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: MavenDeployRequest.java,v 1.4 2003/06/20 15:24:52 michal Exp $
|
||||
* @version $Id: MavenDeployRequest.java,v 1.5 2003/06/24 22:22:55 michal Exp $
|
||||
*/
|
||||
public class MavenDeployRequest extends DeployRequest
|
||||
{
|
||||
@@ -95,8 +95,7 @@ public class MavenDeployRequest extends DeployRequest
|
||||
String username =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.repo." + repository + ".username");
|
||||
|
||||
System.out.println(repository + " username:" + username);
|
||||
|
||||
String password =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.repo." + repository + ".password");
|
||||
@@ -141,7 +140,7 @@ public class MavenDeployRequest extends DeployRequest
|
||||
setUser(username);
|
||||
setPass(password);
|
||||
setPassphrase(passphrase);
|
||||
setPrivateKey(url.trim());
|
||||
setPrivateKey(privateKey);
|
||||
setGroup(remoteGroup);
|
||||
setUrl(url.trim());
|
||||
|
||||
|
||||
@@ -59,11 +59,11 @@ package org.apache.maven.deploy;
|
||||
/**
|
||||
*
|
||||
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: DeployRequest.java,v 1.2 2003/06/19 22:02:37 michal Exp $
|
||||
* @version $Id: DeployRequest.java,v 1.3 2003/06/24 22:22:55 michal Exp $
|
||||
*/
|
||||
public class DeployRequest
|
||||
{
|
||||
|
||||
|
||||
|
||||
public final static int UNKNOWN_PORT = -1;
|
||||
|
||||
|
||||
@@ -60,14 +60,14 @@ import org.apache.maven.deploy.deployers.Deployer;
|
||||
import org.apache.maven.deploy.deployers.FileDeployer;
|
||||
import org.apache.maven.deploy.deployers.FtpDeployer;
|
||||
import org.apache.maven.deploy.deployers.HttpDeployer;
|
||||
import org.apache.maven.deploy.deployers.SshDeployer;
|
||||
import org.apache.maven.deploy.deployers.SFtpDeployer;
|
||||
import org.apache.maven.deploy.exceptions.DeployException;
|
||||
import org.apache.maven.deploy.exceptions.UnsupportedProtocolDeployException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: DeployTool.java,v 1.2 2003/06/19 22:02:37 michal Exp $
|
||||
* @version $Id: DeployTool.java,v 1.3 2003/06/24 22:22:55 michal Exp $
|
||||
*/
|
||||
public class DeployTool
|
||||
{
|
||||
@@ -75,7 +75,6 @@ public class DeployTool
|
||||
|
||||
public void performUpload(DeployRequest request) throws DeployException
|
||||
{
|
||||
|
||||
String url = request.getUrl();
|
||||
Deployer deployer = null;
|
||||
|
||||
@@ -85,23 +84,22 @@ public class DeployTool
|
||||
"No URL provided for repsoitory: "
|
||||
+ request.getRepositoryAlias());
|
||||
}
|
||||
if (url.startsWith("http://"))
|
||||
if (url.startsWith(HttpDeployer.PROTOCOL))
|
||||
{
|
||||
deployer = new HttpDeployer();
|
||||
}
|
||||
|
||||
if (url.startsWith("file://"))
|
||||
if (url.startsWith(FileDeployer.PROTOCOL))
|
||||
{
|
||||
deployer = new FileDeployer();
|
||||
}
|
||||
if (url.startsWith("ssh://"))
|
||||
{
|
||||
deployer = new SshDeployer();
|
||||
}
|
||||
if (url.startsWith("ftp://"))
|
||||
if (url.startsWith(FtpDeployer.PROTOCOL))
|
||||
{
|
||||
deployer = new FtpDeployer();
|
||||
}
|
||||
if (url.startsWith(SFtpDeployer.PROTOCOL))
|
||||
{
|
||||
deployer = new SFtpDeployer();
|
||||
}
|
||||
if (deployer == null)
|
||||
{
|
||||
throw new UnsupportedProtocolDeployException(url);
|
||||
|
||||
@@ -66,11 +66,13 @@ import org.apache.maven.deploy.exceptions.DeployException;
|
||||
/**
|
||||
*
|
||||
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: FileDeployer.java,v 1.3 2003/06/20 15:24:52 michal Exp $
|
||||
* @version $Id: FileDeployer.java,v 1.4 2003/06/24 22:22:54 michal Exp $
|
||||
*/
|
||||
public class FileDeployer implements Deployer
|
||||
{
|
||||
|
||||
public final static String PROTOCOL = "file://";
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.fetch.fetchers.Fetcher#fetchUrl(java.lang.String, java.io.OutputStream)
|
||||
*/
|
||||
|
||||
@@ -75,15 +75,20 @@ import org.apache.maven.deploy.exceptions.DeployException;
|
||||
/**
|
||||
* An FTP deployer based on the FTPClient in the Commons Net package.
|
||||
*
|
||||
* Proxy server for FTPClient is not supported:
|
||||
* {@link http://nagoya.apache.org/bugzilla/show_bug.cgi?id=18039}
|
||||
*
|
||||
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
|
||||
*
|
||||
* @version $Id: FtpDeployer.java,v 1.2 2003/06/19 22:02:36 michal Exp $
|
||||
*
|
||||
* @todo account for username and password.
|
||||
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: FtpDeployer.java,v 1.3 2003/06/24 22:22:54 michal Exp $
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class FtpDeployer extends AbstractDeployer
|
||||
{
|
||||
|
||||
|
||||
public final static String PROTOCOL = "ftp://";
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
@@ -140,8 +145,7 @@ public class FtpDeployer extends AbstractDeployer
|
||||
}
|
||||
|
||||
__main : try
|
||||
{
|
||||
System.out.println("username: '" + username +"' password: '"+ password+"'");
|
||||
{
|
||||
if (ftp.login(username.trim(), password.trim()) == false)
|
||||
{
|
||||
ftp.logout();
|
||||
|
||||
@@ -76,7 +76,7 @@ import org.apache.maven.deploy.exceptions.DeployException;
|
||||
* An HTTP deployer based the Commons HttpClient library.
|
||||
*
|
||||
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
|
||||
* @version $Id: HttpDeployer.java,v 1.1 2003/06/17 22:05:59 michal Exp $
|
||||
* @version $Id: HttpDeployer.java,v 1.2 2003/06/24 22:22:54 michal Exp $
|
||||
*
|
||||
* @todo still have to account for differing setups for people deploying to
|
||||
* their own sites and to the central repository.
|
||||
@@ -87,6 +87,7 @@ import org.apache.maven.deploy.exceptions.DeployException;
|
||||
public class HttpDeployer extends AbstractDeployer
|
||||
{
|
||||
|
||||
public final static String PROTOCOL = "http://";
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
|
||||
+134
-111
@@ -56,18 +56,20 @@ package org.apache.maven.deploy.deployers;
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.UserInfo;
|
||||
import com.jcraft.jsch.ChannelExec;
|
||||
import com.jcraft.jsch.Session;
|
||||
import com.jcraft.jsch.Channel;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.deploy.DeployRequest;
|
||||
import org.apache.maven.deploy.exceptions.DeployException;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
import com.jcraft.jsch.JSch;
|
||||
import com.jcraft.jsch.Proxy;
|
||||
import com.jcraft.jsch.ProxyHTTP;
|
||||
import com.jcraft.jsch.ProxySOCKS5;
|
||||
import com.jcraft.jsch.Session;
|
||||
import com.jcraft.jsch.SftpATTRS;
|
||||
import com.jcraft.jsch.UserInfo;
|
||||
|
||||
/**
|
||||
* An ssh2 deployer that uses the JSch library and the JCE. We will first try to
|
||||
@@ -76,115 +78,144 @@ import org.apache.maven.deploy.DeployRequest;
|
||||
* assuming the standard port of 22.
|
||||
*
|
||||
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
|
||||
* @version $Id: SshDeployer.java,v 1.1 2003/06/17 22:05:59 michal Exp $
|
||||
* @version $Id: SFtpDeployer.java,v 1.1 2003/06/24 22:22:54 michal Exp $
|
||||
* @todo still have to account for differing setups for people deploying to
|
||||
* their own sites and to the central repository.
|
||||
*/
|
||||
public class SshDeployer extends AbstractDeployer
|
||||
public class SFtpDeployer extends AbstractDeployer
|
||||
{
|
||||
|
||||
public final static int DEFAULT_SSH_PORT = 22;
|
||||
public final static String PROTOCOL = "sftp://";
|
||||
|
||||
public final static String SFTP_CHANNEL = "sftp";
|
||||
public final static int DEFAULT_SSH_PORT = 22;
|
||||
public final static int SOCKS5_PROXY_PORT = 1080;
|
||||
public final static int S_IFDIR = 0x4000;
|
||||
|
||||
/**
|
||||
* @see Deployer#project
|
||||
*
|
||||
* @todo better way of guessing what king of proxy server is used
|
||||
*/
|
||||
public void deploy(DeployRequest request)
|
||||
public void deploy(DeployRequest request) throws DeployException
|
||||
{
|
||||
Integer groupId = null;
|
||||
try
|
||||
{
|
||||
if (request.getGroup() != null)
|
||||
{
|
||||
groupId = Integer.getInteger(request.getGroup());
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new DeployException("For sftp protocol remote group should be an integer");
|
||||
}
|
||||
try
|
||||
{
|
||||
JSch jsch = new JSch();
|
||||
|
||||
|
||||
int port = request.getPort();
|
||||
if (port == DeployRequest.UNKNOWN_PORT)
|
||||
{
|
||||
port = DEFAULT_SSH_PORT;
|
||||
port = DEFAULT_SSH_PORT;
|
||||
}
|
||||
String host = request.getHost();
|
||||
Session session = jsch.getSession(request.getUser(), host, port);
|
||||
|
||||
String proxyHost = request.getProxyHost();
|
||||
|
||||
if (proxyHost != null)
|
||||
{
|
||||
Proxy proxy = null;
|
||||
int proxyPort = request.getProxyPort();
|
||||
//if port == 1080 we will use SOCKS5 Proxy
|
||||
// otherwise will use HTTP Proxy
|
||||
|
||||
if (proxyPort == SOCKS5_PROXY_PORT)
|
||||
{
|
||||
proxy = new ProxySOCKS5(proxyHost);
|
||||
((ProxySOCKS5) proxy).setUserPasswd(
|
||||
request.getProxyUser(),
|
||||
request.getProxyPass());
|
||||
}
|
||||
else
|
||||
{
|
||||
proxy = new ProxyHTTP(proxyHost, proxyPort);
|
||||
((ProxyHTTP) proxy).setUserPasswd(
|
||||
request.getProxyUser(),
|
||||
request.getProxyPass());
|
||||
}
|
||||
proxy.connect(session, host, port);
|
||||
|
||||
}
|
||||
Session session =
|
||||
jsch.getSession(request.getHost(), port);
|
||||
//22
|
||||
|
||||
// Look for the private key and use it if available.
|
||||
File privateKey = new File(request.getPrivateKey());
|
||||
|
||||
if (privateKey.exists())
|
||||
if (request.getPrivateKey() != null)
|
||||
{
|
||||
session.setIdentity(privateKey.getPath());
|
||||
}
|
||||
File privateKey = new File(request.getPrivateKey());
|
||||
|
||||
if (privateKey.exists())
|
||||
{
|
||||
System.out.println("Using private key: " + privateKey);
|
||||
jsch.addIdentity(
|
||||
privateKey.getAbsolutePath(),
|
||||
request.getPassphrase());
|
||||
}
|
||||
}
|
||||
// username and password will be given via UserInfo interface.
|
||||
UserInfo ui = new MavenUserInfo(request);
|
||||
session.setUserInfo(ui);
|
||||
session.connect();
|
||||
|
||||
String inputFile = request.getInputFile();
|
||||
// exec 'scp -t remoteArtifactPath' remotely
|
||||
String command =
|
||||
"scp -t "
|
||||
+ request.getOutputDir()
|
||||
+ "/"
|
||||
+ request.getOutputFile();
|
||||
Channel channel = session.openChannel("exec");
|
||||
((ChannelExec) channel).setCommand(command);
|
||||
|
||||
// plug I/O streams for remote scp
|
||||
PipedOutputStream out = new PipedOutputStream();
|
||||
channel.setInputStream(new PipedInputStream(out));
|
||||
PipedInputStream in = new PipedInputStream();
|
||||
channel.setOutputStream(new PipedOutputStream(in));
|
||||
|
||||
ChannelSftp channel =
|
||||
(ChannelSftp) session.openChannel(SFTP_CHANNEL);
|
||||
channel.connect();
|
||||
|
||||
byte[] tmp = new byte[1];
|
||||
|
||||
// wait for '\0'
|
||||
do
|
||||
// iterate over all directories in the path. try to create
|
||||
// directory
|
||||
String[] dirs = StringUtils.split(request.getOutputDir(), "/");
|
||||
for (int i = 0; i < dirs.length; i++)
|
||||
{
|
||||
in.read(tmp, 0, 1);
|
||||
}
|
||||
while (tmp[0] != 0);
|
||||
|
||||
// send "C0644 filesize filename", where filename should not include '/'
|
||||
int filesize = (int) (new File( inputFile )).length();
|
||||
command = "C0644 " + filesize + " " + inputFile;
|
||||
command += "\n";
|
||||
out.write(command.getBytes());
|
||||
out.flush();
|
||||
|
||||
// wait for '\0'
|
||||
do
|
||||
{
|
||||
in.read(tmp, 0, 1);
|
||||
}
|
||||
while (tmp[0] != 0);
|
||||
|
||||
// send a content of localArtifactPath
|
||||
FileInputStream fis = new FileInputStream(inputFile);
|
||||
byte[] buf = new byte[1024];
|
||||
while (true)
|
||||
{
|
||||
int len = fis.read(buf, 0, buf.length);
|
||||
if (len <= 0)
|
||||
System.out.println("processing: " + dirs[i]);
|
||||
try
|
||||
{
|
||||
break;
|
||||
SftpATTRS attrs = channel.stat(dirs[i]);
|
||||
if ((attrs.getPermissions() & S_IFDIR) != 0)
|
||||
{
|
||||
// file exists and is dierctory
|
||||
channel.cd(dirs[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new DeployException(
|
||||
"Remote path:"
|
||||
+ request.getOutputDir()
|
||||
+ "is not correct");
|
||||
}
|
||||
}
|
||||
out.write(buf, 0, len);
|
||||
out.flush();
|
||||
catch (Exception e)
|
||||
{
|
||||
// file does not exists
|
||||
channel.mkdir(dirs[i]);
|
||||
channel.cd(dirs[i]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// send '\0'
|
||||
buf[0] = 0;
|
||||
out.write(buf, 0, 1);
|
||||
out.flush();
|
||||
channel.put(request.getInputFile(), request.getOutputFile());
|
||||
|
||||
// wait for '\0'
|
||||
do
|
||||
if (groupId != null)
|
||||
{
|
||||
in.read(tmp, 0, 1);
|
||||
channel.chgrp(groupId.intValue(), request.getOutputFile());
|
||||
}
|
||||
while (tmp[0] != 0);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println(e);
|
||||
e.printStackTrace();
|
||||
throw new DeployException(
|
||||
"Cannot deploy. Reason: " + e.getMessage(),
|
||||
e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,68 +225,60 @@ public class SshDeployer extends AbstractDeployer
|
||||
*/
|
||||
public class MavenUserInfo implements UserInfo
|
||||
{
|
||||
|
||||
|
||||
DeployRequest request;
|
||||
|
||||
|
||||
MavenUserInfo(DeployRequest request)
|
||||
{
|
||||
this.request = request;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name attribute of the MavenUserInfo object
|
||||
*/
|
||||
public String getName()
|
||||
public String getPassphrase()
|
||||
{
|
||||
return request.getUser();
|
||||
return request.getPassphrase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the password attribute of the MavenUserInfo object
|
||||
/* (non-Javadoc)
|
||||
* @see com.jcraft.jsch.UserInfo#getPassword()
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
return request.getPass();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the passphrase attribute of the MavenUserInfo object
|
||||
/* (non-Javadoc)
|
||||
* @see com.jcraft.jsch.UserInfo#promptPassphrase(java.lang.String)
|
||||
*/
|
||||
public String getPassphrase(String message)
|
||||
public boolean promptPassphrase(String arg0)
|
||||
{
|
||||
return request.getPassphrase();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required to satisfy UserInfo interface. Not used currently.
|
||||
/* (non-Javadoc)
|
||||
* @see com.jcraft.jsch.UserInfo#promptPassword(java.lang.String)
|
||||
*/
|
||||
public boolean promptNameAndPassphrase(String message)
|
||||
public boolean promptPassword(String arg0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required to satisfy UserInfo interface. Not used currently.
|
||||
* @see com.jcraft.jsch.UserInfo#promptYesNo(java.lang.String)
|
||||
*/
|
||||
public boolean promptNameAndPassword(String message)
|
||||
public boolean promptYesNo(String arg0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Required to satisfy UserInfo interface. Not used currently.
|
||||
/* (non-Javadoc)
|
||||
* @see com.jcraft.jsch.UserInfo#showMessage(java.lang.String)
|
||||
*/
|
||||
public boolean retry()
|
||||
public void showMessage(String message)
|
||||
{
|
||||
return true;
|
||||
System.out.println(message);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Required to satisfy UserInfo interface. Not used currently.
|
||||
*/
|
||||
public boolean prompt(String message)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user