Code clean-up and docs provided

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113541 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
michal committed 2003-06-29 11:57:40 +00:00
1 parent 7870c16e79
commit e9549c0bf4
27 files changed
+1185 -240

No files matched your search

@@ -61,23 +61,39 @@ import org.apache.maven.project.Project;
/**
*
* The Bean which serves as Proxy To Hibernate API
* <br/>
* The Bean which is used in Jelly Scripts
* and serves as a proxy to Artifact Deployer API
*
* Note that all paths in repository are computed
* and source file name is igonred.
*
* Other remark: To deploy an artifact means much
* more then to copy signle file. In every case
* also MD5 file created and copied to remote repository.
* In case of snapshots the process in even more complex.
*
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: ArtifactDeployer.java,v 1.1 2003/06/16 14:26:01 michal Exp $
* @version $Id: ArtifactDeployer.java,v 1.2 2003/06/29 11:57:39 michal Exp $
*/
public interface ArtifactDeployer
{
/**
* Deploy given artifact to remote repository
* @param artifact
* @param type
* @param project
* @throws MavenException
* Deploy given artifact to remote repository
*
* @param artifact Artifact filename
* @param type The type of the artifact
* (like <code>war</code>, <code>jar</code>)
* @param project The project which is a producer of the artifact
* POM conatains a bunch of varaiables which are used
* to control the deployment process (e.g
* <ul>
* <li>artifactId<li>
* <li>groupId</li>
* <li>list of remote repositories</li>
* </ul>
*
* @throws MavenException
*/
public void deploy(String artifact, String type, Project project)
throws MavenException;
@@ -85,30 +101,37 @@ public interface ArtifactDeployer
/**
* Deploy given artifact as a snapshot to remote repository
* @param artifact
* @param type
* @param project
* @param type The type of the artifact
* (like <code>war</code>, <code>jar</code>)
* @param project The project which is a producer of the artifact
* @see ArtifactDeployer#deploy(String, String, Project)
*
* @throws MavenException
*/
public void deploySnapshot(String artifact, String type, Project project)
throws MavenException;
/**
* Install given artifact in local repository
* @param artifact
* @param type
* @param project
* @param artifact file name of the artifact
* @param type The type of the artifact
* (like <code>war</code>, <code>jar</code>)
* @param project The project which is a producer of the artifact
* @throws MavenException
*/
*/
public void install(String artifact, String type, Project project)
throws MavenException;
/**
* Install given artifact as snapshot in local repository
* @param artifact
* @param type
* @param project
* @param type The type of the artifact
* (like <code>war</code>, <code>jar</code>)
* @param project The project which is a producer of the artifact
* @throws MavenException
*/
*/
public void installSnapshot(String artifact, String type, Project project)
throws MavenException;
}
@@ -76,13 +76,13 @@ import org.apache.maven.util.MD5Sum;
*
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: DefaultArtifactDeployer.java,v 1.9 2003/06/25 15:25:19 michal Exp $
* @version $Id: DefaultArtifactDeployer.java,v 1.10 2003/06/29 11:57:39 michal Exp $
*/
public class DefaultArtifactDeployer implements ArtifactDeployer
{
/**
*
* Date/time stamp which is appended to snapshot filenames
*/
public final static DateFormat SNAPSHOT_MARKER =
new SimpleDateFormat("yyyyMMdd.HHmmss");
@@ -191,8 +191,8 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
}
/**
* Install given file in local repsoitory
* @param artifact the artifact file to insatall
* Install given file in local repository
* @param artifact the artifact file to install
* @param type The type of the artiafct
* @param project
* @param version String denominating the version of the artifact
@@ -254,10 +254,8 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
// trick add special values to context for default repository;
String repos =
(String) project.getContext().getVariable("maven.repo.repos");
System.out.println("repos: " + repos);
(String) project.getContext().getVariable("maven.repo.list");
String distSite = project.getDistributionSite();
if (distSite != null && distSite.length() > 0)
{
@@ -273,7 +271,7 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
if (repos == null || repos.length() == 0)
{
System.out.println("No remote repository is defined");
System.out.println("No remote repository is defined for deployment");
return;
}
String[] repoArray = StringUtils.split(repos, ",");
@@ -328,8 +326,9 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
}
/**
*
* Return the local repository path form given project
* @param project
* @return The path to local repoository in local file system
*/
private String getLocalRepository(Project project)
{
@@ -337,11 +336,13 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
}
/**
*
* @param type
* @param project
* Return relative path from repositorry root
* for given parameters
* @param type Artifact type
* @param project
* @param snapshot
* @return
* @todo replace this with RepoistoryLayout Service
*/
private String getRepositoryPath(
String type,
@@ -355,6 +356,14 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
return path.toString();
}
/**
*
* @param type
* @param project
* @param version
* @return
*/
private String getRepositoryFile(
String type,
Project project,
@@ -441,6 +450,11 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
}
/**
* Create MD5 checksum file for given file. File is created
* in the same folder
* @param File
* @return The <code>File</code> which contatins MD5 checksum
* @throws MavenException when opertaion failed
*/
private File createMD5Checksum(File file) throws MavenException
{
@@ -475,9 +489,9 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
}
/**
*
* Return file extension for given type
* @todo Dirty hack util Repository Layout Service is used
* @return
* @return extension for given type
*/
private String extensionForType(String type)
{
@@ -64,10 +64,10 @@ import org.apache.maven.project.Project;
/**
*
* The Bean which provides access to Artifact Deployement API
* for jelly scripts.
* from jelly scripts.
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: DeployBean.java,v 1.2 2003/06/25 15:25:19 michal Exp $
* @version $Id: DeployBean.java,v 1.3 2003/06/29 11:57:39 michal Exp $
*/
public class DeployBean
{
@@ -156,7 +156,6 @@ public class DeployBean
*/
public void deploy() throws MavenException
{
System.out.println("deploy called");
checkAttributes();
artifactDeployer.deploy(artifact, type, project);
}
@@ -58,6 +58,7 @@ package org.apache.maven.artifact.deployer;
import org.apache.maven.deploy.DeployRequest;
import org.apache.maven.deploy.exceptions.DeployException;
import org.apache.maven.deploy.exceptions.WrongParameterException;
import org.apache.maven.project.Project;
/**
@@ -65,7 +66,7 @@ import org.apache.maven.project.Project;
* Perform mapping between project's properties and attributes of DeployRequest class.
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: DeployRequestBuilder.java,v 1.1 2003/06/25 15:25:19 michal Exp $
* @version $Id: DeployRequestBuilder.java,v 1.2 2003/06/29 11:57:39 michal Exp $
*/
public class DeployRequestBuilder
{
@@ -122,29 +123,27 @@ public class DeployRequestBuilder
"maven.repo." + repository + ".group");
String proxyHost =
(String) project.getContext().getVariable(
"maven.repo." + repository + ".proxy");
(String) project.getContext().getProxyHost();
String proxyUser =
(String) project.getContext().getVariable(
"maven.repo." + repository + ".proxy.username");
(String) project.getContext().getProxyUserName();
String proxyPassword =
(String) project.getContext().getVariable(
"maven.repo." + repository + ".proxy.password");
(String) project.getContext().getProxyPassword();
String proxyPort =
(String) project.getContext().getVariable(
"maven." + repository + ".proxy.port");
request.setUser(username);
(String) project.getContext().getProxyPort();
request.setUserName(username);
request.setPassword(password);
request.setPassphrase(passphrase);
request.setPrivateKey(privateKey);
request.setGroup(remoteGroup);
request.setUrl(url);
request.setProxyHost(proxyHost);
request.setProxyUser(proxyUser);
request.setProxyPass(proxyPassword);
request.setProxyUserName(proxyUser);
request.setProxyPassword(proxyPassword);
if (port != null)
{
try
@@ -154,7 +153,7 @@ public class DeployRequestBuilder
}
catch (Exception e)
{
throw new DeployException("maven.repo." + repository + ".port should be an integer");
throw new WrongParameterException("maven.repo." + repository + ".port should be an integer");
}
}
if (proxyPort != null)
@@ -165,7 +164,7 @@ public class DeployRequestBuilder
}
catch (Exception e)
{
throw new DeployException("maven.repo." + repository + ".proxy.port should be an integer");
throw new WrongParameterException("maven.repo." + repository + ".proxy.port should be an integer");
}
}
@@ -18,7 +18,7 @@ package org.apache.maven.deploy;
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* 3. The end-userName documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
@@ -57,42 +57,72 @@ package org.apache.maven.deploy;
*/
/**
* Holder of the variables which are used by deployers for
* esatblishing connection to remote hosts and to
* deploy the file to correct location in remote file system
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: DeployRequest.java,v 1.4 2003/06/25 15:25:19 michal Exp $
* @version $Id: DeployRequest.java,v 1.5 2003/06/29 11:57:40 michal Exp $
*/
public class DeployRequest
{
/** Used to mark */
public final static int UNKNOWN_PORT = -1;
public final static String HEADER_USER_AGENT =
"Maven-Deploy-" + DeployTool.VERSION;
/** The nickname (alias) of the repository*/
private String repositoryAlias;
/** URL of the remote host*/
private String url;
/** Port of remote host */
private int port = UNKNOWN_PORT;
/** The directory where artifact will be placed */
private String destDir;
/** The filename of the artifact */
private String destFile;
/** The artifact file in local file system */
private String srcFile;
/*
* Resource access user / password /group
*/
private String user;
/** The login name of the user in @ remote host*/
private String userName;
/** Password */
private String password;
/** Remote group name */
private String group;
/** The passpharse of the user's private key file */
private String passphrase;
/** The absoluth path to private key file */
private String privateKey;
/*
* Proxy server settings. If proxy host is not null, settings will be used.
*/
/** Proxy Server host*/
private String proxyHost = null;
private String proxyUser = null;
private String proxyPass = null;
/** the login name of the user @ Proxy Server host*/
private String proxyUserName = null;
/** the password user @ Proxy Server host*/
private String proxyPassword = null;
/** Proxy server port */
private int proxyPort = UNKNOWN_PORT;
/** Indicates if debug mode should be used*/
private boolean debugOn = false;
/**
* Set the alias of the repository
* @param repositoryAlias
*/
public void setRepositoryAlias(String repositoryAlias)
@@ -101,7 +131,8 @@ public class DeployRequest
}
/**
* @return
* Get the port of the host
* @return the port of the remote host where repository resides.
*/
public int getPort()
{
@@ -109,6 +140,7 @@ public class DeployRequest
}
/**
* Set the port of the remote host
* @param port
*/
public void setPort(int port)
@@ -117,7 +149,12 @@ public class DeployRequest
}
/**
* @return
* Get the passphrase of the private key file.
* Passphrase is used only when host/protocol supports
* authetification via exchange of private/public keys
* and private key was provided.
*
* @return the passphrase of the private key file
*/
public String getPassphrase()
{
@@ -125,7 +162,8 @@ public class DeployRequest
}
/**
* @param passphrase
* Set the passphrase of the private key file
* @param passphrase the passphrase of the private key file
*/
public void setPassphrase(String passphrase)
{
@@ -133,7 +171,8 @@ public class DeployRequest
}
/**
* @return
* Get the absoluth path to the private key
* @return the path to private key
*/
public String getPrivateKey()
{
@@ -141,7 +180,8 @@ public class DeployRequest
}
/**
* @param privateKey
* Set the aboluth path to private key
* @param privateKey The path to private key in local file system
*/
public void setPrivateKey(String privateKey)
{
@@ -149,7 +189,10 @@ public class DeployRequest
}
/**
* @return
* Get the remote group to which will belong to
* after deployemnt. Not all protolcols support
* allow to change the group of the artifact
* @return remote group
*/
public String getGroup()
{
@@ -157,7 +200,9 @@ public class DeployRequest
}
/**
* @param group
* Set the remote group for artifact which is deployed
* @param group The remote group to which
* artifact which is deployed will belong
*/
public void setGroup(String group)
{
@@ -173,7 +218,8 @@ public class DeployRequest
}
/**
* @return
* Get aboluth path to local files = artifact
* @return Path to artifact file
*/
public String getSrcFile()
{
@@ -181,6 +227,7 @@ public class DeployRequest
}
/**
* Set the aboluthe path to artifact file
* @param srcFile
*/
public void setSrcFile(String inputFile)
@@ -189,7 +236,10 @@ public class DeployRequest
}
/**
* @return
* Get destination directory in remote file system for
* the artifact
*
* @return destination dir for artifact
*/
public String getDestDir()
{
@@ -197,7 +247,9 @@ public class DeployRequest
}
/**
* @param destDir
* Set destinatin directory in remote file system
*
* @param destDir the remote path for the artifact
*/
public void setDestDir(String outputDir)
{
@@ -205,6 +257,7 @@ public class DeployRequest
}
/**
* Get destination file name
* @return
*/
public String getDestFile()
@@ -213,6 +266,7 @@ public class DeployRequest
}
/**
* Set destination file name
* @param destFile
*/
public void setDestFile(String outputFile)
@@ -221,7 +275,9 @@ public class DeployRequest
}
/**
* @return
* Get the password to be used when user will be authetificated
* while connection to remote host is established
* @return the password of user
*/
public String getPassword()
{
@@ -229,6 +285,8 @@ public class DeployRequest
}
/**
*
*
* @param password
*/
public void setPassword(String pass)
@@ -237,7 +295,8 @@ public class DeployRequest
}
/**
* @return
* Returhn proxy server host name
* @return proxy server host name
*/
public String getProxyHost()
{
@@ -245,6 +304,7 @@ public class DeployRequest
}
/**
* Set proxy host name
* @param proxyHost
*/
public void setProxyHost(String proxyHost)
@@ -253,23 +313,26 @@ public class DeployRequest
}
/**
* @return
* Get user's password used to login to proxy server
* @return the user's password at proxy host
*/
public String getProxyPass()
public String getProxyPassword()
{
return proxyPass;
return proxyPassword;
}
/**
* @param proxyPass
* Set the proxy server password
* @param proxyPassword teh epassword to use to login to a proxy server
*/
public void setProxyPass(String proxyPass)
public void setProxyPassword(String proxyPass)
{
this.proxyPass = proxyPass;
this.proxyPassword = proxyPass;
}
/**
* @return
* Get the proxy port
* @return Poroxy server port
*/
public int getProxyPort()
{
@@ -277,6 +340,7 @@ public class DeployRequest
}
/**
* Set the proxy port
* @param proxyPort
*/
public void setProxyPort(int proxyPort)
@@ -285,23 +349,27 @@ public class DeployRequest
}
/**
*
* Get the proxy user name
* @return
*/
public String getProxyUser()
public String getProxyUserName()
{
return proxyUser;
return proxyUserName;
}
/**
* @param proxyUser
* Set the proxy user name
* @param proxyUserName the proxy user name
*/
public void setProxyUser(String proxyUser)
public void setProxyUserName(String proxyUser)
{
this.proxyUser = proxyUser;
this.proxyUserName = proxyUser;
}
/**
* @return
* Get url of remote host
* @return URL (with protocol) of remote host
*/
public String getUrl()
{
@@ -309,7 +377,8 @@ public class DeployRequest
}
/**
* @param url
* Set url of remote host
* @param url url of remote host
*/
public void setUrl(String url)
{
@@ -317,24 +386,26 @@ public class DeployRequest
}
/**
* @return
* Get user login name at remote host
* @return user name at remote host
*/
public String getUser()
public String getUserName()
{
return user;
return userName;
}
/**
* @param user
* Set user name at remote host
* @param userName
*/
public void setUser(String user)
public void setUserName(String user)
{
this.user = user;
this.userName = user;
}
/**
* Cut of protocol from the URL
* @return
* Return the host name (Cuts of protocol from the URL)
* @return The host name
*/
public String getHost()
{
@@ -342,11 +413,13 @@ public class DeployRequest
{
return "localhost";
}
return url.substring(url.indexOf("://") + 3);
return url.substring(url.indexOf("://") + 3).trim();
}
/**
* @return
* Get the name of the repository to which deploy attempt will be made
*
* @return the name (nickname, alias) of the repository
*/
public String getRepositoryAlias()
{
@@ -354,4 +427,22 @@ public class DeployRequest
return repositoryAlias;
}
/**
* Get Debug mode
* @return the debug mode
*/
public boolean isDebugOn()
{
return debugOn;
}
/**
* Set deplyer in debug mode - more messages will be wriiten
* @param debugOn
*/
public void setDebugOn(boolean debugOn)
{
this.debugOn = debugOn;
}
}
@@ -62,27 +62,44 @@ import org.apache.maven.deploy.deployers.FtpDeployer;
import org.apache.maven.deploy.deployers.HttpDeployer;
import org.apache.maven.deploy.deployers.SFtpDeployer;
import org.apache.maven.deploy.deployers.ScpDeployer;
import org.apache.maven.deploy.exceptions.DeployException;
import org.apache.maven.deploy.exceptions.UnsupportedProtocolDeployException;
import org.apache.maven.deploy.exceptions.NotAuthorizedDeployException;
import org.apache.maven.deploy.exceptions.ProxyNotAuthorizedDeployException;
import org.apache.maven.deploy.exceptions.TransferFailedException;
import org.apache.maven.deploy.exceptions.UnsupportedProtocolException;
import org.apache.maven.deploy.exceptions.WrongParameterException;
/**
*
* Delegates
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: DeployTool.java,v 1.4 2003/06/25 12:33:11 michal Exp $
* @version $Id: DeployTool.java,v 1.5 2003/06/29 11:57:40 michal Exp $
*/
public class DeployTool
{
/** Current Version **/
public static final String VERSION = "1.0-dev";
public void performUpload(DeployRequest request) throws DeployException
/**
* Upload (deploy) artifact to remote repository using
* paramerters kepts in <code>DeployReequest</code>
* @param request The settings
* @throws DeployException When operation fails
*/
public void performUpload(DeployRequest request)
throws
TransferFailedException,
NotAuthorizedDeployException,
ProxyNotAuthorizedDeployException,
TransferFailedException,
WrongParameterException,
UnsupportedProtocolException
{
String url = request.getUrl();
Deployer deployer = null;
if (url == null || url.length() == 1)
{
throw new DeployException(
"No URL provided for repsoitory: "
throw new WrongParameterException(
"No URL provided for repository: "
+ request.getRepositoryAlias());
}
if (url.startsWith(HttpDeployer.PROTOCOL))
@@ -107,7 +124,7 @@ public class DeployTool
}
if (deployer == null)
{
throw new UnsupportedProtocolDeployException(url);
throw new UnsupportedProtocolException(url);
}
deployer.deploy(request);
@@ -1,7 +1,10 @@
package org.apache.maven.deploy.deployers;
import org.apache.maven.deploy.DeployRequest;
import org.apache.maven.deploy.exceptions.DeployException;
import org.apache.maven.deploy.exceptions.NotAuthorizedDeployException;
import org.apache.maven.deploy.exceptions.ProxyNotAuthorizedDeployException;
import org.apache.maven.deploy.exceptions.TransferFailedException;
import org.apache.maven.deploy.exceptions.WrongParameterException;
/* ====================================================================
* The Apache Software License, Version 1.1
@@ -61,15 +64,27 @@ import org.apache.maven.deploy.exceptions.DeployException;
/**
* Interface for all Maven deployers.
*
* Deployer which uploads a file to remote host accordingly to paramters
* recieved in <i>deploy request</i>
*
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
* @version $Id: Deployer.java,v 1.1 2003/06/17 22:05:59 michal Exp $
* @version $Id: Deployer.java,v 1.2 2003/06/29 11:57:40 michal Exp $
*/
public interface Deployer
{
/**
*
* @param request
* Perform an unppload of single file to remote host
* @param request <code>DeployRequest</code> which should contatin all parameters
* which are necessery to upload a file
* to remote host.
*/
public void deploy(DeployRequest request) throws DeployException;
public void deploy(DeployRequest request)
throws
TransferFailedException,
NotAuthorizedDeployException,
ProxyNotAuthorizedDeployException,
TransferFailedException,
WrongParameterException;
}
@@ -61,40 +61,43 @@ import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.maven.deploy.DeployRequest;
import org.apache.maven.deploy.exceptions.DeployException;
import org.apache.maven.deploy.exceptions.TransferFailedException;
/**
* Deployer which deploys to directory visible in local
* file system.
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: FileDeployer.java,v 1.5 2003/06/25 15:25:18 michal Exp $
* @version $Id: FileDeployer.java,v 1.6 2003/06/29 11:57:40 michal Exp $
*/
public class FileDeployer implements Deployer
{
/** Protocol understandable by this deployer*/
public final static String PROTOCOL = "file://";
/**
* @see org.apache.maven.fetch.fetchers.Fetcher#fetchUrl(java.lang.String, java.io.OutputStream)
*/
public void deploy(DeployRequest request) throws DeployException
public void deploy(DeployRequest request) throws TransferFailedException
{
try
{
File inputFile = new File(request.getSrcFile());
File srcFile = new File(request.getSrcFile());
File outputFile =
File destFile =
new File(request.getHost(), request.getDestDir());
if (! outputFile.exists())
if (! destFile.exists())
{
outputFile.mkdirs();
destFile.mkdirs();
}
outputFile = new File( outputFile, request.getDestFile());
FileUtils.copyFile(inputFile, outputFile);
destFile = new File( destFile, request.getDestFile());
FileUtils.copyFile(srcFile, destFile);
}
catch (IOException e)
{
throw new DeployException("Cannot copy file: " + e.getMessage());
throw new TransferFailedException("Cannot copy file: " + e.getMessage());
}
}
}
@@ -66,11 +66,7 @@ import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPConnectionClosedException;
import org.apache.commons.net.ftp.FTPReply;
import org.apache.maven.deploy.DeployRequest;
import org.apache.maven.deploy.exceptions.DeployException;
import org.apache.maven.deploy.exceptions.TransferFailedException;
/**
* An FTP deployer based on the FTPClient in the Commons Net package.
@@ -80,41 +76,44 @@ import org.apache.maven.deploy.exceptions.DeployException;
*
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: FtpDeployer.java,v 1.4 2003/06/25 15:25:18 michal Exp $
* @version $Id: FtpDeployer.java,v 1.5 2003/06/29 11:57:39 michal Exp $
*
*
*/
public class FtpDeployer extends AbstractDeployer
{
/** Protocol understandable by this deployer*/
public final static String PROTOCOL = "ftp://";
/**
* Description of the Method
*/
public void deploy(DeployRequest request) throws DeployException
{
String username = request.getUser();
String password = request.getPassword();
String host = request.getHost();
FTPClient ftp = new FTPClient();
ftp.addProtocolCommandListener(
new PrintCommandListener(new PrintWriter(System.out)));
/**
* @see Deployer#deploy(DeployRequest)
*/
public void deploy(DeployRequest request) throws TransferFailedException
{
String username = request.getUserName();
String password = request.getPassword();
String host = request.getHost();
FTPClient ftp = new FTPClient();
if (request.isDebugOn())
{
ftp.addProtocolCommandListener(
new PrintCommandListener(new PrintWriter(System.out)));
}
try
{
{
int reply;
if ( request.getPort()!= DeployRequest.UNKNOWN_PORT)
if (request.getPort() != DeployRequest.UNKNOWN_PORT)
{
ftp.connect(host, request.getPort());
ftp.connect(host, request.getPort());
}
else
{
ftp.connect(host);
}
}
System.out.println("Connected to " + host + ".");
// After connection attempt, you should check the reply code to verify
@@ -122,10 +121,10 @@ public class FtpDeployer extends AbstractDeployer
reply = ftp.getReplyCode();
if (FTPReply.isPositiveCompletion(reply) == false)
{
{
ftp.disconnect();
System.err.println();
throw new DeployException("FTP server refused connection.");
throw new TransferFailedException("FTP server refused connection.");
}
}
catch (IOException e)
@@ -140,12 +139,12 @@ public class FtpDeployer extends AbstractDeployer
{
// do nothing
}
}
throw new DeployException("Could not connect to server.");
}
throw new TransferFailedException("Could not connect to server.");
}
__main : try
{
{
if (ftp.login(username.trim(), password.trim()) == false)
{
ftp.logout();
@@ -162,15 +161,15 @@ public class FtpDeployer extends AbstractDeployer
String workingDir = request.getDestDir();
String filename = request.getDestFile();
System.out.println("Working directory " + workingDir);
System.out.println("Filename: " + filename);
System.out.println("Filename: " + filename);
ftp.makeDirectory(workingDir);
ftp.changeWorkingDirectory( workingDir);
ftp.storeFile(filename, new FileInputStream(request.getSrcFile()));
ftp.changeWorkingDirectory(workingDir);
ftp.storeFile(filename, new FileInputStream(request.getSrcFile()));
ftp.logout();
}
catch (FTPConnectionClosedException e)
{
throw new DeployException("Server closed connection.");
{
throw new TransferFailedException("Server closed connection.");
}
catch (IOException e)
{
@@ -227,5 +226,5 @@ public class FtpDeployer extends AbstractDeployer
writer.flush();
}
}
}
@@ -59,7 +59,8 @@ package org.apache.maven.deploy.deployers;
import java.io.File;
import org.apache.maven.deploy.DeployRequest;
import org.apache.maven.deploy.exceptions.DeployException;
import org.apache.maven.deploy.exceptions.TransferFailedException;
import org.apache.maven.deploy.exceptions.WrongParameterException;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Proxy;
@@ -69,36 +70,39 @@ import com.jcraft.jsch.Session;
import com.jcraft.jsch.UserInfo;
/**
* An ssh2 deployer that uses the JSch library and the JCE.
* A base class for deployers using protocols from SSH2 family
* and JSch library for underlining implmenetation
*
* This class deals with authetification stage of the process.
* This class deals with authentification stage of the process.
*
* We will first try to
* use public keys for authentication and if that doesn't work then we fall back
* to using the login and password of the user in question. NOTE: We are
* assuming the standard port of 22.
* to using the login and password
*
*
* @version $Id: GenericSshDeployer.java,v 1.2 2003/06/25 15:25:18 michal Exp $
* @version $Id: GenericSshDeployer.java,v 1.3 2003/06/29 11:57:40 michal Exp $
* @todo still have to account for differing setups for people deploying to
* their own sites and to the central repository.
* @todo improve exception handling
*/
public abstract class GenericSshDeployer extends AbstractDeployer
{
/** Default port used for SSH protocol */
public final static int DEFAULT_SSH_PORT = 22;
/** Default port used by SOCKS5 proxy server */
public final static int SOCKS5_PROXY_PORT = 1080;
/**
* @see Deployer#project
*
* @todo better way of guessing what kind of proxy server is used
* by user
* by user. Jsch Supports among others SOCKS and HTTP proxies
*/
public Session getSession(DeployRequest request) throws DeployException
public Session getSession(final DeployRequest request)
throws TransferFailedException
{
try
{
JSch jsch = new JSch();
@@ -108,36 +112,11 @@ public abstract class GenericSshDeployer extends AbstractDeployer
{
port = DEFAULT_SSH_PORT;
}
System.out.println("host: '"+ request.getHost() + "'");
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.getUserName(), host, port);
// Look for the private key and use it if available.
if (request.getPrivateKey() != null)
{
@@ -145,12 +124,54 @@ public abstract class GenericSshDeployer extends AbstractDeployer
if (privateKey.exists())
{
if (request.getPassphrase() == null)
{
String msg =
"Private key provided "
+ "without passpharse for repo: "
+ request.getRepositoryAlias();
throw new WrongParameterException(msg);
}
System.out.println("Using private key: " + privateKey);
jsch.addIdentity(
privateKey.getAbsolutePath(),
request.getPassphrase());
}
else
{
String msg = "Private key: " + privateKey + " not found ";
throw new WrongParameterException(msg);
}
}
String proxyHost = request.getProxyHost();
if (proxyHost != null)
{
Proxy proxy = null;
int proxyPort = request.getProxyPort();
// HACK:
//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.getProxyUserName(),
request.getProxyPassword());
}
else
{
proxy = new ProxyHTTP(proxyHost, proxyPort);
((ProxyHTTP) proxy).setUserPasswd(
request.getProxyUserName(),
request.getProxyPassword());
}
proxy.connect(session, host, port);
}
// username and password will be given via UserInfo interface.
UserInfo ui = new MavenUserInfo(request);
session.setUserInfo(ui);
@@ -161,7 +182,7 @@ public abstract class GenericSshDeployer extends AbstractDeployer
catch (Exception e)
{
e.printStackTrace();
throw new DeployException(
throw new TransferFailedException(
"Cannot connect. Reason: " + e.getMessage(),
e);
}
@@ -70,13 +70,13 @@ import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.commons.httpclient.methods.PutMethod;
import org.apache.maven.deploy.DeployRequest;
import org.apache.maven.deploy.exceptions.DeployException;
import org.apache.maven.deploy.exceptions.TransferFailedException;
/**
* 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.3 2003/06/25 15:25:18 michal Exp $
* @version $Id: HttpDeployer.java,v 1.4 2003/06/29 11:57:39 michal Exp $
*
* @todo still have to account for differing setups for people deploying to
* their own sites and to the central repository.
@@ -86,12 +86,14 @@ import org.apache.maven.deploy.exceptions.DeployException;
*/
public class HttpDeployer extends AbstractDeployer
{
/**Protocol understood by by this deployer*/
public final static String PROTOCOL = "http://";
/**
* Description of the Method
*/
public void deploy(DeployRequest request) throws DeployException
public void deploy(DeployRequest request) throws TransferFailedException
{
URL url = null;
try
@@ -104,7 +106,7 @@ public class HttpDeployer extends AbstractDeployer
Credentials creds =
new UsernamePasswordCredentials(
request.getUser(),
request.getUserName(),
request.getPassword());
//create a singular HttpClient object
@@ -135,7 +137,7 @@ public class HttpDeployer extends AbstractDeployer
}
catch(FileNotFoundException io)
{
throw new DeployException("input file: '"+ request.getSrcFile() + " not found ");
throw new TransferFailedException("input file: '"+ request.getSrcFile() + " not found ");
}
//turn follow redirects off
@@ -58,7 +58,8 @@ package org.apache.maven.deploy.deployers;
import org.apache.commons.lang.StringUtils;
import org.apache.maven.deploy.DeployRequest;
import org.apache.maven.deploy.exceptions.DeployException;
import org.apache.maven.deploy.exceptions.TransferFailedException;
import org.apache.maven.deploy.exceptions.WrongParameterException;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSchException;
@@ -70,21 +71,24 @@ import com.jcraft.jsch.SftpException;
* An SSH2/SFTP deployer
*
* @author Michal Maczka
* @version $Revision: 1.3 $ $Date: 2003/06/25 15:25:18 $
* @version $Revision: 1.4 $ $Date: 2003/06/29 11:57:39 $
*/
public class SFtpDeployer extends GenericSshDeployer
{
/**Protocol understood by by this deployer*/
public final static String PROTOCOL = "sftp://";
/** SSH2 Chanel names used to communicate with the server*/
private final static String SFTP_CHANNEL = "sftp";
/** artibute of file used in SSH which denotes is given file is a directory*/
private static final int S_IFDIR = 0x4000;
/**
* @see Deployer#project
*
* @todo better way of guessing what king of proxy server is used
* @see Deployer#deploy(DeployRequest)
*/
public void deploy(DeployRequest request) throws DeployException
public void deploy(DeployRequest request)
throws TransferFailedException, WrongParameterException
{
Integer groupId = null;
try
@@ -96,7 +100,7 @@ public class SFtpDeployer extends GenericSshDeployer
}
catch (NumberFormatException e)
{
throw new DeployException("SFTP deployer: remote group should be an integer");
throw new WrongParameterException("SFTP deployer: remote group should be an integer");
}
Session session = getSession(request);
@@ -109,7 +113,7 @@ public class SFtpDeployer extends GenericSshDeployer
// directory
String[] dirs = StringUtils.split(request.getDestDir(), "/");
for (int i = 0; i < dirs.length; i++)
{
{
try
{
SftpATTRS attrs = channel.stat(dirs[i]);
@@ -120,7 +124,7 @@ public class SFtpDeployer extends GenericSshDeployer
}
else
{
throw new DeployException(
throw new WrongParameterException(
"Incorrect remote path:" + request.getDestDir());
}
}
@@ -147,7 +151,7 @@ public class SFtpDeployer extends GenericSshDeployer
String msg =
"Error occured while deploying to remote host:"
+ request.getHost();
throw new DeployException(msg, e);
throw new TransferFailedException(msg, e);
}
catch (JSchException e)
@@ -155,7 +159,7 @@ public class SFtpDeployer extends GenericSshDeployer
String msg =
"Error occured while deploying to remote host:"
+ request.getHost();
throw new DeployException(msg, e);
throw new TransferFailedException(msg, e);
}
finally
{
@@ -62,7 +62,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import org.apache.maven.deploy.DeployRequest;
import org.apache.maven.deploy.exceptions.DeployException;
import org.apache.maven.deploy.exceptions.TransferFailedException;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.Session;
@@ -71,21 +71,21 @@ import com.jcraft.jsch.Session;
* An SSH2/SCP deployer
*
* @author Michal Maczka
* @version $Revision: 1.2 $ $Date: 2003/06/25 15:25:18 $
* @version $Revision: 1.3 $ $Date: 2003/06/29 11:57:40 $
*/
public class ScpDeployer extends GenericSshDeployer
{
/**Protocol understood by by this deployer*/
public final static String PROTOCOL = "scp://";
/** SSH2 Chanel names used to communicate with the server*/
public final static String EXEC_CHANNEL = "exec";
/**
* @see Deployer#project
*
* @todo better way of guessing what king of proxy server is used
* @see Deployer#deploy(DeployRequest)
*
*/
public void deploy(DeployRequest request) throws DeployException
public void deploy(DeployRequest request) throws TransferFailedException
{
Session session = getSession(request);
@@ -116,10 +116,10 @@ public class ScpDeployer extends GenericSshDeployer
}
/**
* Execute simple command
* Execute <i>"simple"</i> remote command using exec channel
*/
private void executeSimpleCommand(Session session, String command)
throws DeployException
throws TransferFailedException
{
System.out.println("Executing command: " + command);
@@ -134,7 +134,7 @@ public class ScpDeployer extends GenericSshDeployer
}
catch (Exception e)
{
throw new DeployException(
throw new TransferFailedException(
"Cannot execute remote command: " + command);
}
finally
@@ -151,7 +151,7 @@ public class ScpDeployer extends GenericSshDeployer
* Code extracted from JSCH exaples
*/
private void doCopy(Session session, DeployRequest request)
throws DeployException
throws TransferFailedException
{
try
@@ -231,7 +231,7 @@ public class ScpDeployer extends GenericSshDeployer
String msg =
"Error occured while deploying to remote host:"
+ request.getHost();
throw new DeployException(msg,e);
throw new TransferFailedException(msg,e);
}
}
@@ -58,11 +58,11 @@ package org.apache.maven.deploy.exceptions;
/**
*
* Root class for all exception thrown by Deployers
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: DeployException.java,v 1.1 2003/06/17 22:06:00 michal Exp $
* @version $Id: DeployException.java,v 1.2 2003/06/29 11:57:39 michal Exp $
*/
public class DeployException extends Exception
public abstract class DeployException extends Exception
{
private final String message;
private final Throwable cause;
@@ -0,0 +1,88 @@
package org.apache.maven.deploy.exceptions;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
/**
* Exception which should be thrown when IO error occures during
* making remote copy of the file
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: TransferFailedException.java,v 1.1 2003/06/29 11:57:39 michal Exp $
*/
public class TransferFailedException extends DeployException
{
/**
* @param message
*/
public TransferFailedException(String message)
{
super(message);
}
/**
* @param message
* @param cause
*/
public TransferFailedException(String message, Throwable cause)
{
super(message, cause);
// TODO Auto-generated constructor stub
}
}
@@ -60,14 +60,14 @@ package org.apache.maven.deploy.exceptions;
/**
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: UnsupportedProtocolDeployException.java,v 1.1 2003/06/17 22:06:00 michal Exp $
* @version $Id: UnsupportedProtocolException.java,v 1.1 2003/06/29 11:57:39 michal Exp $
*/
public class UnsupportedProtocolDeployException extends DeployException
public class UnsupportedProtocolException extends DeployException
{
/**
* @param message
*/
public UnsupportedProtocolDeployException(String message)
public UnsupportedProtocolException(String message)
{
super(message);
}
@@ -76,7 +76,7 @@ public class UnsupportedProtocolDeployException extends DeployException
* @param message
* @param cause
*/
public UnsupportedProtocolDeployException(String message, Throwable cause)
public UnsupportedProtocolException(String message, Throwable cause)
{
super(message, cause);
}
@@ -0,0 +1,84 @@
package org.apache.maven.deploy.exceptions;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
/**
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: WrongParameterException.java,v 1.1 2003/06/29 11:57:39 michal Exp $
*/
public class WrongParameterException extends DeployException
{
/**
* @param message
*/
public WrongParameterException(String message)
{
super(message);
}
/**
* @param message
* @param cause
*/
public WrongParameterException(String message, Throwable cause)
{
super(message, cause);
}
}