Refactoring to make it simillar to fetch component in maven-new.
Code is not yet fully functional. git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113512 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8aa4847bcd
commit
60fbeaab28
@ -46,6 +46,14 @@
|
||||
<version>2.0-beta1</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>1.0</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
|
||||
@ -62,12 +62,10 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.maven.MavenConstants;
|
||||
import org.apache.maven.MavenException;
|
||||
import org.apache.maven.artifact.deployer.deploy.Deployer;
|
||||
import org.apache.maven.artifact.deployer.deploy.FtpDeployer;
|
||||
import org.apache.maven.artifact.deployer.deploy.HttpDeployer;
|
||||
import org.apache.maven.artifact.deployer.deploy.SshDeployer;
|
||||
import org.apache.maven.deploy.DeployTool;
|
||||
import org.apache.maven.project.Project;
|
||||
|
||||
/**
|
||||
@ -75,7 +73,7 @@ import org.apache.maven.project.Project;
|
||||
* Default implemenataion of Artifact Deployer interface
|
||||
*
|
||||
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: DefaultArtifactDeployer.java,v 1.1 2003/06/16 14:26:01 michal Exp $
|
||||
* @version $Id: DefaultArtifactDeployer.java,v 1.2 2003/06/17 22:06:00 michal Exp $
|
||||
*/
|
||||
public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
{
|
||||
@ -191,72 +189,64 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
String version)
|
||||
throws MavenException
|
||||
{
|
||||
String repoPath = getRepositoryPath(type, project, version);
|
||||
String host = getDistributionHost(project);
|
||||
String remotePath = getDistributionDirectory(project) + "/" + repoPath;
|
||||
Deployer deployer = getDeployer(host);
|
||||
|
||||
//Cut of protcol prefix from host name
|
||||
|
||||
host = host.substring( host.indexOf("://") + 3 );
|
||||
|
||||
|
||||
DeployTool deployTool = new DeployTool();
|
||||
|
||||
// trick add special values to context for default repository;
|
||||
|
||||
String repos =
|
||||
(String) project.getContext().getVariable("maven.deploy.repos");
|
||||
|
||||
String distSite = project.getDistributionSite();
|
||||
if (distSite != null && distSite.length() > 0)
|
||||
{
|
||||
project.getContext().setVariable(
|
||||
"maven.deploy.default.url",
|
||||
project.getDistributionSite());
|
||||
project.getContext().setVariable(
|
||||
"maven.deploy.default.dir",
|
||||
project.getDistributionDirectory());
|
||||
|
||||
repos = "default, " + repos;
|
||||
}
|
||||
|
||||
String repositoryPath = getRepositoryPath(type, project, version);
|
||||
|
||||
String[] repoArray = StringUtils.split(repos, ",");
|
||||
|
||||
System.out.println(
|
||||
"Deploying: '"
|
||||
+ artifact
|
||||
+ "' to host: '"
|
||||
+ host
|
||||
+ "' remote path: '"
|
||||
+ remotePath);
|
||||
MavenAuthenticationInfo authInfo = new MavenAuthenticationInfo(project);
|
||||
deployer.deploy(authInfo, host, artifact, remotePath);
|
||||
System.out.println("Deployment finished");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param project
|
||||
* @return
|
||||
*/
|
||||
private String getDistributionHost(Project project) throws MavenException
|
||||
{
|
||||
String host = host = project.getDistributionSite();
|
||||
if (host == null || host.length() == 0)
|
||||
"Will deploy to " + repoArray.length + " repo(s): " + repos);
|
||||
for (int i = 0; i < repoArray.length; i++)
|
||||
{
|
||||
host =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deployer.host");
|
||||
}
|
||||
if (host == null)
|
||||
{
|
||||
throw new MavenException("Distribution host is not set");
|
||||
}
|
||||
|
||||
return host;
|
||||
}
|
||||
String repo = repoArray[i];
|
||||
System.out.println("Deploying to repo: " + repo);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param project
|
||||
* @return
|
||||
* @throws MavenException
|
||||
*/
|
||||
private String getDistributionDirectory(Project project)
|
||||
throws MavenException
|
||||
{
|
||||
MavenDeployRequest request =
|
||||
new MavenDeployRequest(
|
||||
project,
|
||||
repo,
|
||||
artifact,
|
||||
repositoryPath,
|
||||
getRepositoryFile(type, project, version));
|
||||
|
||||
String dir = project.getDistributionDirectory();
|
||||
|
||||
if (dir == null || dir.length() == 0)
|
||||
{
|
||||
dir =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deployer.remote.directory");
|
||||
System.out.println(
|
||||
"Deploying: '"
|
||||
+ artifact
|
||||
+ "' to host: '"
|
||||
+ request.getHost()
|
||||
+ "' remote path: '"
|
||||
+ request.getOutputDir());
|
||||
try
|
||||
{
|
||||
deployTool.performUpload(request);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new MavenException("Cannot deploy", e);
|
||||
}
|
||||
|
||||
}
|
||||
if (dir == null)
|
||||
{
|
||||
throw new MavenException("Distribution directory is not set");
|
||||
}
|
||||
return dir;
|
||||
|
||||
}
|
||||
|
||||
@ -285,14 +275,21 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
path.append(project.getArtifactDirectory());
|
||||
path.append("/");
|
||||
path.append(type + "s");
|
||||
path.append("/");
|
||||
return path.toString();
|
||||
}
|
||||
|
||||
private String getRepositoryFile(
|
||||
String type,
|
||||
Project project,
|
||||
String version)
|
||||
{
|
||||
StringBuffer path = new StringBuffer();
|
||||
path.append(project.getArtifactId());
|
||||
path.append("-");
|
||||
path.append(version);
|
||||
path.append(".");
|
||||
path.append(extensionForType(type));
|
||||
return path.toString();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,37 +317,4 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param host
|
||||
* @param project
|
||||
* @return
|
||||
* @throws MavenException
|
||||
*/
|
||||
private Deployer getDeployer(String host) throws MavenException
|
||||
{
|
||||
Deployer deployer = null;
|
||||
|
||||
if (host.startsWith("http://"))
|
||||
{
|
||||
deployer = new HttpDeployer();
|
||||
}
|
||||
else
|
||||
if (host.startsWith("ssh://"))
|
||||
{
|
||||
deployer = new SshDeployer();
|
||||
}
|
||||
else
|
||||
if (host.startsWith("ftp://"))
|
||||
{
|
||||
deployer = new FtpDeployer();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new MavenException(
|
||||
"unsupported protocol: '" + host + "'");
|
||||
}
|
||||
return deployer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,168 @@
|
||||
package org.apache.maven.artifact.deployer;
|
||||
|
||||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
* Copyright (c) 2001 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 MavenSession" 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 MavenSession", 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/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
import org.apache.maven.deploy.DeployRequest;
|
||||
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.1 2003/06/17 22:06:00 michal Exp $
|
||||
*/
|
||||
public class MavenDeployRequest extends DeployRequest
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param project
|
||||
* @param repository This is alias name of the repository
|
||||
* like </i>repo1</i> taken from <i>maven.deploy.repos= repo1, repo2</i>
|
||||
* @param inputDir
|
||||
* @param outputDir
|
||||
* @param outputFile
|
||||
*/
|
||||
public MavenDeployRequest(
|
||||
Project project,
|
||||
String repository,
|
||||
String inputFile,
|
||||
String outputDir,
|
||||
String outputFile)
|
||||
{
|
||||
super();
|
||||
String username =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deploy." + repository + ".username");
|
||||
|
||||
System.out.println(repository + " username:" + username);
|
||||
String password =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deploy." + repository + ".password");
|
||||
|
||||
System.out.println(repository + " password: '" + password + "'");
|
||||
|
||||
String passphrase =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deploy." + repository + ".passphrase");
|
||||
|
||||
String privateKey =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deploy." + repository + ".privatekey");
|
||||
|
||||
String url =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deploy." + repository + ".url");
|
||||
|
||||
String dir =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deploy." + repository + ".dir");
|
||||
|
||||
String port =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deploy." + repository + ".port");
|
||||
|
||||
String proxyHost =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deploy." + repository + ".proxy.host");
|
||||
String proxyUser =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deploy." + repository + ".proxy.username");
|
||||
String proxyPassword =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deploy." + repository + ".proxy.password");
|
||||
|
||||
String proxyPort =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deploy." + repository + ".proxy.port");
|
||||
|
||||
setUser(username);
|
||||
setPass(password);
|
||||
setPassphrase(passphrase);
|
||||
setPrivateKey(url);
|
||||
setUrl(url);
|
||||
|
||||
try
|
||||
{
|
||||
setPort(Integer.parseInt(port));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
setProxyHost(proxyHost);
|
||||
setProxyUser(proxyUser);
|
||||
setProxyPass(proxyPassword);
|
||||
}
|
||||
try
|
||||
{
|
||||
setProxyPort(Integer.parseInt(proxyPort));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
setInputFile(inputFile);
|
||||
|
||||
String ouputDir = dir + "/" + outputDir;
|
||||
setOutputFile(outputFile);
|
||||
setOutputDir(ouputDir);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
357
artifact/src/main/org/apache/maven/deploy/DeployRequest.java
Normal file
357
artifact/src/main/org/apache/maven/deploy/DeployRequest.java
Normal file
@ -0,0 +1,357 @@
|
||||
package org.apache.maven.deploy;
|
||||
|
||||
/* ====================================================================
|
||||
* 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: DeployRequest.java,v 1.1 2003/06/17 22:06:00 michal Exp $
|
||||
*/
|
||||
public class DeployRequest
|
||||
{
|
||||
public final static int UNKNOWN_PORT = -1;
|
||||
|
||||
private String url;
|
||||
private int port = UNKNOWN_PORT;
|
||||
private String outputDir;
|
||||
private String outputFile;
|
||||
private String inputFile;
|
||||
|
||||
/*
|
||||
* Resource access user / pass /group
|
||||
*/
|
||||
private String user;
|
||||
private String pass;
|
||||
private String group;
|
||||
private String passphrase;
|
||||
private String privateKey;
|
||||
|
||||
public DeployRequest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public DeployRequest(String url)
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
// private boolean resumeDownload = false;
|
||||
private String headerUserAgent = "Maven-Deploy-" + DeployTool.VERSION;
|
||||
|
||||
/*
|
||||
* Proxy settings. If proxyHost is not null, settings will be used.
|
||||
*/
|
||||
private String proxyHost = null;
|
||||
private String proxyUser = null;
|
||||
private String proxyPass = null;
|
||||
private int proxyPort = UNKNOWN_PORT;
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getPort()
|
||||
{
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param port
|
||||
*/
|
||||
public void setPort(int port)
|
||||
{
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getPassphrase()
|
||||
{
|
||||
return passphrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param passphrase
|
||||
*/
|
||||
public void setPassphrase(String passphrase)
|
||||
{
|
||||
this.passphrase = passphrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getPrivateKey()
|
||||
{
|
||||
return privateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param privateKey
|
||||
*/
|
||||
public void setPrivateKey(String privateKey)
|
||||
{
|
||||
this.privateKey = privateKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getGroup()
|
||||
{
|
||||
return group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param group
|
||||
*/
|
||||
public void setGroup(String group)
|
||||
{
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getHeaderUserAgent()
|
||||
{
|
||||
return headerUserAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param headerUserAgent
|
||||
*/
|
||||
public void setHeaderUserAgent(String headerUserAgent)
|
||||
{
|
||||
this.headerUserAgent = headerUserAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getInputFile()
|
||||
{
|
||||
return inputFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param inputFile
|
||||
*/
|
||||
public void setInputFile(String inputFile)
|
||||
{
|
||||
this.inputFile = inputFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getOutputDir()
|
||||
{
|
||||
return outputDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param outputDir
|
||||
*/
|
||||
public void setOutputDir(String outputDir)
|
||||
{
|
||||
this.outputDir = outputDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getOutputFile()
|
||||
{
|
||||
return outputFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param outputFile
|
||||
*/
|
||||
public void setOutputFile(String outputFile)
|
||||
{
|
||||
this.outputFile = outputFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getPass()
|
||||
{
|
||||
return pass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pass
|
||||
*/
|
||||
public void setPass(String pass)
|
||||
{
|
||||
this.pass = pass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getProxyHost()
|
||||
{
|
||||
return proxyHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param proxyHost
|
||||
*/
|
||||
public void setProxyHost(String proxyHost)
|
||||
{
|
||||
this.proxyHost = proxyHost;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getProxyPass()
|
||||
{
|
||||
return proxyPass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param proxyPass
|
||||
*/
|
||||
public void setProxyPass(String proxyPass)
|
||||
{
|
||||
this.proxyPass = proxyPass;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getProxyPort()
|
||||
{
|
||||
return proxyPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param proxyPort
|
||||
*/
|
||||
public void setProxyPort(int proxyPort)
|
||||
{
|
||||
this.proxyPort = proxyPort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getProxyUser()
|
||||
{
|
||||
return proxyUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param proxyUser
|
||||
*/
|
||||
public void setProxyUser(String proxyUser)
|
||||
{
|
||||
this.proxyUser = proxyUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getUrl()
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param url
|
||||
*/
|
||||
public void setUrl(String url)
|
||||
{
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getUser()
|
||||
{
|
||||
return user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param user
|
||||
*/
|
||||
public void setUser(String user)
|
||||
{
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cut of protocol from the URL
|
||||
* @return
|
||||
*/
|
||||
public String getHost()
|
||||
{
|
||||
if (url == null )
|
||||
{
|
||||
return "localhost";
|
||||
}
|
||||
return url.substring(url.indexOf("://") + 3);
|
||||
}
|
||||
|
||||
}
|
||||
107
artifact/src/main/org/apache/maven/deploy/DeployTool.java
Normal file
107
artifact/src/main/org/apache/maven/deploy/DeployTool.java
Normal file
@ -0,0 +1,107 @@
|
||||
package org.apache.maven.deploy;
|
||||
|
||||
/* ====================================================================
|
||||
* 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/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
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.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.1 2003/06/17 22:06:00 michal Exp $
|
||||
*/
|
||||
public class DeployTool
|
||||
{
|
||||
public static final String VERSION = "1.0-dev";
|
||||
|
||||
public void performUpload(DeployRequest request) throws DeployException
|
||||
{
|
||||
|
||||
String url = request.getUrl();
|
||||
Deployer deployer = null;
|
||||
|
||||
if (url.startsWith("http://"))
|
||||
{
|
||||
deployer = new HttpDeployer();
|
||||
}
|
||||
|
||||
if (url.startsWith("file://"))
|
||||
{
|
||||
deployer = new FileDeployer();
|
||||
}
|
||||
if (url.startsWith("ssh://"))
|
||||
{
|
||||
deployer = new SshDeployer();
|
||||
}
|
||||
if (url.startsWith("ftp://"))
|
||||
{
|
||||
deployer = new FtpDeployer();
|
||||
}
|
||||
if (deployer == null)
|
||||
{
|
||||
throw new UnsupportedProtocolDeployException(url);
|
||||
}
|
||||
deployer.deploy(request);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package org.apache.maven.artifact.deployer.deploy;
|
||||
package org.apache.maven.deploy.deployers;
|
||||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
@ -60,18 +60,9 @@ package org.apache.maven.artifact.deployer.deploy;
|
||||
*
|
||||
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
|
||||
* @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: AbstractDeployer.java,v 1.1 2003/06/16 14:26:01 michal Exp $
|
||||
* @version $Id: AbstractDeployer.java,v 1.1 2003/06/17 22:05:59 michal Exp $
|
||||
*/
|
||||
public abstract class AbstractDeployer implements Deployer
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public abstract void deploy(
|
||||
AuthenticationInfo authInfo,
|
||||
String host,
|
||||
String localPath,
|
||||
String remotePath);
|
||||
|
||||
}
|
||||
@ -1,4 +1,7 @@
|
||||
package org.apache.maven.artifact.deployer.deploy;
|
||||
package org.apache.maven.deploy.deployers;
|
||||
|
||||
import org.apache.maven.deploy.DeployRequest;
|
||||
import org.apache.maven.deploy.exceptions.DeployException;
|
||||
|
||||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
@ -60,20 +63,13 @@ package org.apache.maven.artifact.deployer.deploy;
|
||||
* Interface for all Maven deployers.
|
||||
*
|
||||
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
|
||||
* @version $Id: Deployer.java,v 1.1 2003/06/16 14:26:01 michal Exp $
|
||||
* @version $Id: Deployer.java,v 1.1 2003/06/17 22:05:59 michal Exp $
|
||||
*/
|
||||
public interface Deployer
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @param authInfo
|
||||
* @param host
|
||||
* @param localPath
|
||||
* @param remotePath
|
||||
* @param request
|
||||
*/
|
||||
public void deploy(
|
||||
AuthenticationInfo authInfo,
|
||||
String host,
|
||||
String localPath,
|
||||
String remotePath);
|
||||
public void deploy(DeployRequest request) throws DeployException;
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
package org.apache.maven.deploy.deployers;
|
||||
|
||||
/* ====================================================================
|
||||
* 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/>.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.maven.deploy.DeployRequest;
|
||||
import org.apache.maven.deploy.exceptions.DeployException;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: FileDeployer.java,v 1.1 2003/06/17 22:05:59 michal Exp $
|
||||
*/
|
||||
public class FileDeployer implements Deployer
|
||||
{
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.fetch.fetchers.Fetcher#fetchUrl(java.lang.String, java.io.OutputStream)
|
||||
*/
|
||||
public void deploy(DeployRequest request) throws DeployException
|
||||
{
|
||||
try
|
||||
{
|
||||
File inputFile = new File( request.getInputFile() );
|
||||
File outputFile = new File( request.getOutputDir(), request.getOutputFile());
|
||||
FileUtils.copyFile(inputFile, outputFile);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new DeployException("Cannot copy file: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,4 @@
|
||||
package org.apache.maven.artifact.deployer.deploy;
|
||||
package org.apache.maven.deploy.deployers;
|
||||
|
||||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
@ -65,6 +65,8 @@ import org.apache.commons.net.ftp.FTP;
|
||||
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;
|
||||
|
||||
|
||||
|
||||
@ -75,30 +77,40 @@ import org.apache.commons.net.ftp.FTPReply;
|
||||
*
|
||||
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
|
||||
*
|
||||
* @version $Id: FtpDeployer.java,v 1.1 2003/06/16 14:26:01 michal Exp $
|
||||
* @version $Id: FtpDeployer.java,v 1.1 2003/06/17 22:05:59 michal Exp $
|
||||
*
|
||||
* @todo account for username and password.
|
||||
*/
|
||||
public class FtpDeployer extends AbstractDeployer
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
public void deploy(AuthenticationInfo authInfo, String host, String localPath, String remotePath)
|
||||
public void deploy(DeployRequest request) throws DeployException
|
||||
{
|
||||
String username = authInfo.getUsername();
|
||||
String password = authInfo.getPassword();
|
||||
|
||||
String username = request.getUser();
|
||||
String password = request.getPass();
|
||||
String host = request.getHost();
|
||||
|
||||
|
||||
FTPClient ftp = new FTPClient();
|
||||
|
||||
|
||||
ftp.addProtocolCommandListener(
|
||||
new PrintCommandListener(new PrintWriter(System.out)));
|
||||
|
||||
try
|
||||
{
|
||||
int reply;
|
||||
ftp.connect(host);
|
||||
if ( request.getPort()!= DeployRequest.UNKNOWN_PORT)
|
||||
{
|
||||
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
|
||||
@ -106,10 +118,10 @@ public class FtpDeployer extends AbstractDeployer
|
||||
reply = ftp.getReplyCode();
|
||||
|
||||
if (FTPReply.isPositiveCompletion(reply) == false)
|
||||
{
|
||||
{
|
||||
ftp.disconnect();
|
||||
System.err.println("FTP server refused connection.");
|
||||
System.exit(1);
|
||||
System.err.println();
|
||||
throw new DeployException("FTP server refused connection.");
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
@ -124,10 +136,8 @@ public class FtpDeployer extends AbstractDeployer
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
System.err.println("Could not connect to server.");
|
||||
e.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
throw new DeployException("Could not connect to server.");
|
||||
}
|
||||
|
||||
__main : try
|
||||
@ -145,20 +155,18 @@ public class FtpDeployer extends AbstractDeployer
|
||||
// Use passive mode as default because most of us are
|
||||
// behind firewalls these days.
|
||||
ftp.enterLocalPassiveMode();
|
||||
String workingDir = remotePath.substring(0, remotePath.lastIndexOf("/"));
|
||||
String filename = remotePath.substring(remotePath.lastIndexOf("/")+1);
|
||||
String workingDir = request.getOutputDir();
|
||||
String filename = request.getOutputFile();
|
||||
System.out.println("Working directory " + workingDir);
|
||||
System.out.println("Filename: " + filename);
|
||||
System.out.println("LocalPath: " + localPath);
|
||||
System.out.println("Filename: " + filename);
|
||||
ftp.makeDirectory(workingDir);
|
||||
ftp.changeWorkingDirectory( workingDir);
|
||||
ftp.storeFile(filename, new FileInputStream(localPath));
|
||||
ftp.storeFile(filename, new FileInputStream(request.getInputFile()));
|
||||
ftp.logout();
|
||||
}
|
||||
catch (FTPConnectionClosedException e)
|
||||
{
|
||||
System.err.println("Server closed connection.");
|
||||
e.printStackTrace();
|
||||
{
|
||||
throw new DeployException("Server closed connection.");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
@ -1,4 +1,4 @@
|
||||
package org.apache.maven.artifact.deployer.deploy;
|
||||
package org.apache.maven.deploy.deployers;
|
||||
|
||||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
@ -56,7 +56,8 @@ package org.apache.maven.artifact.deployer.deploy;
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
@ -66,17 +67,16 @@ import org.apache.commons.httpclient.Header;
|
||||
import org.apache.commons.httpclient.HostConfiguration;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpException;
|
||||
import org.apache.commons.httpclient.URI;
|
||||
import org.apache.commons.httpclient.URIException;
|
||||
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;
|
||||
|
||||
/**
|
||||
* 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/16 14:26:01 michal Exp $
|
||||
* @version $Id: HttpDeployer.java,v 1.1 2003/06/17 22:05:59 michal Exp $
|
||||
*
|
||||
* @todo still have to account for differing setups for people deploying to
|
||||
* their own sites and to the central repository.
|
||||
@ -90,16 +90,12 @@ public class HttpDeployer extends AbstractDeployer
|
||||
/**
|
||||
* Description of the Method
|
||||
*/
|
||||
public void deploy(
|
||||
AuthenticationInfo authInfo,
|
||||
String host,
|
||||
String localPath,
|
||||
String remotePath)
|
||||
public void deploy(DeployRequest request) throws DeployException
|
||||
{
|
||||
URL url = null;
|
||||
try
|
||||
{
|
||||
url = new URL(remotePath);
|
||||
url = new URL(request.getUrl());
|
||||
}
|
||||
catch (MalformedURLException murle)
|
||||
{
|
||||
@ -107,11 +103,12 @@ public class HttpDeployer extends AbstractDeployer
|
||||
|
||||
Credentials creds =
|
||||
new UsernamePasswordCredentials(
|
||||
authInfo.getUsername(),
|
||||
authInfo.getPassphrase());
|
||||
request.getUser(),
|
||||
request.getPass());
|
||||
|
||||
//create a singular HttpClient object
|
||||
HttpClient client = new HttpClient();
|
||||
|
||||
|
||||
//establish a connection within 5 seconds
|
||||
client.setConnectionTimeout(5000);
|
||||
@ -124,21 +121,21 @@ public class HttpDeployer extends AbstractDeployer
|
||||
|
||||
//
|
||||
HostConfiguration hc = new HostConfiguration();
|
||||
try
|
||||
{
|
||||
hc.setHost(new URI(url));
|
||||
}
|
||||
catch (URIException e)
|
||||
{
|
||||
throw new RuntimeException(e.toString());
|
||||
}
|
||||
|
||||
hc.setHost(request.getHost());
|
||||
//start a session with the webserver
|
||||
client.setHostConfiguration(hc);
|
||||
|
||||
//create a method object
|
||||
PutMethod method = new PutMethod(url.getPath());
|
||||
method.setRequestBody(new File(localPath).toString());
|
||||
|
||||
try
|
||||
{
|
||||
method.setRequestBody(new FileInputStream(request.getInputFile()));
|
||||
}
|
||||
catch(FileNotFoundException io)
|
||||
{
|
||||
throw new DeployException("input file: '"+ request.getInputFile() + " not found ");
|
||||
}
|
||||
|
||||
//turn follow redirects off
|
||||
method.setFollowRedirects(false);
|
||||
@ -1,4 +1,4 @@
|
||||
package org.apache.maven.artifact.deployer.deploy;
|
||||
package org.apache.maven.deploy.deployers;
|
||||
|
||||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
@ -67,7 +67,7 @@ import java.io.FileInputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
|
||||
|
||||
import org.apache.maven.deploy.DeployRequest;
|
||||
|
||||
/**
|
||||
* An ssh2 deployer that uses the JSch library and the JCE. We will first try to
|
||||
@ -76,35 +76,34 @@ import java.io.PipedOutputStream;
|
||||
* 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/16 14:26:01 michal Exp $
|
||||
* @version $Id: SshDeployer.java,v 1.1 2003/06/17 22:05:59 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
|
||||
{
|
||||
|
||||
private AuthenticationInfo authInfo = null;
|
||||
|
||||
public final static int DEFAULT_SSH_PORT = 22;
|
||||
/**
|
||||
* @see Deployer#project
|
||||
*/
|
||||
public void deploy(
|
||||
AuthenticationInfo authInfo,
|
||||
String host,
|
||||
String localArtifactPath,
|
||||
String remoteArtifactPath)
|
||||
public void deploy(DeployRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
this.authInfo = authInfo;
|
||||
JSch jsch = new JSch();
|
||||
Session session = jsch.getSession(host, 22);
|
||||
|
||||
int port = request.getPort();
|
||||
if (port == DeployRequest.UNKNOWN_PORT)
|
||||
{
|
||||
port = DEFAULT_SSH_PORT;
|
||||
}
|
||||
Session session =
|
||||
jsch.getSession(request.getHost(), port);
|
||||
//22
|
||||
|
||||
// Look for the private key and use it if available.
|
||||
File privateKey =
|
||||
new File(
|
||||
new File(System.getProperty("user.home"), ".ssh"),
|
||||
"id_dsa");
|
||||
File privateKey = new File(request.getPrivateKey());
|
||||
|
||||
if (privateKey.exists())
|
||||
{
|
||||
@ -112,12 +111,17 @@ public class SshDeployer extends AbstractDeployer
|
||||
}
|
||||
|
||||
// username and password will be given via UserInfo interface.
|
||||
UserInfo ui = new MavenUserInfo();
|
||||
UserInfo ui = new MavenUserInfo(request);
|
||||
session.setUserInfo(ui);
|
||||
session.connect();
|
||||
|
||||
String inputFile = request.getInputFile();
|
||||
// exec 'scp -t remoteArtifactPath' remotely
|
||||
String command = "scp -t " + remoteArtifactPath;
|
||||
String command =
|
||||
"scp -t "
|
||||
+ request.getOutputDir()
|
||||
+ "/"
|
||||
+ request.getOutputFile();
|
||||
Channel channel = session.openChannel("exec");
|
||||
((ChannelExec) channel).setCommand(command);
|
||||
|
||||
@ -139,18 +143,8 @@ public class SshDeployer extends AbstractDeployer
|
||||
while (tmp[0] != 0);
|
||||
|
||||
// send "C0644 filesize filename", where filename should not include '/'
|
||||
int filesize = (int) (new File(localArtifactPath)).length();
|
||||
command = "C0644 " + filesize + " ";
|
||||
if (localArtifactPath.lastIndexOf('/') > 0)
|
||||
{
|
||||
command
|
||||
+= localArtifactPath.substring(
|
||||
localArtifactPath.lastIndexOf('/') + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
command += localArtifactPath;
|
||||
}
|
||||
int filesize = (int) (new File( inputFile )).length();
|
||||
command = "C0644 " + filesize + " " + inputFile;
|
||||
command += "\n";
|
||||
out.write(command.getBytes());
|
||||
out.flush();
|
||||
@ -163,7 +157,7 @@ public class SshDeployer extends AbstractDeployer
|
||||
while (tmp[0] != 0);
|
||||
|
||||
// send a content of localArtifactPath
|
||||
FileInputStream fis = new FileInputStream(localArtifactPath);
|
||||
FileInputStream fis = new FileInputStream(inputFile);
|
||||
byte[] buf = new byte[1024];
|
||||
while (true)
|
||||
{
|
||||
@ -201,14 +195,19 @@ public class SshDeployer extends AbstractDeployer
|
||||
public class MavenUserInfo implements UserInfo
|
||||
{
|
||||
|
||||
|
||||
|
||||
DeployRequest request;
|
||||
|
||||
MavenUserInfo(DeployRequest request)
|
||||
{
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name attribute of the MavenUserInfo object
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return authInfo.getUsername();
|
||||
return request.getUser();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -216,7 +215,7 @@ public class SshDeployer extends AbstractDeployer
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
return authInfo.getPassword();
|
||||
return request.getPass();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -224,7 +223,7 @@ public class SshDeployer extends AbstractDeployer
|
||||
*/
|
||||
public String getPassphrase(String message)
|
||||
{
|
||||
return authInfo.getPassphrase();
|
||||
return request.getPassphrase();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1,9 +1,9 @@
|
||||
package org.apache.maven.artifact.deployer.deploy;
|
||||
package org.apache.maven.deploy.exceptions;
|
||||
|
||||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
* Copyright (c) 2001 The Apache Software Foundation. All rights
|
||||
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -26,12 +26,12 @@ package org.apache.maven.artifact.deployer.deploy;
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Apache" and "Apache Software Foundation" and
|
||||
* "Apache MavenSession" must not be used to endorse or promote products
|
||||
* "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 MavenSession", nor may "Apache" appear in their name, without
|
||||
* "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
|
||||
@ -58,44 +58,40 @@ package org.apache.maven.artifact.deployer.deploy;
|
||||
|
||||
|
||||
/**
|
||||
* Holder of the infomarmation which is used to authentificate user
|
||||
* during deployment process.
|
||||
*
|
||||
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Revision: 1.1 $ $Date: 2003/06/16 14:26:01 $
|
||||
* @version $Id: DeployException.java,v 1.1 2003/06/17 22:06:00 michal Exp $
|
||||
*/
|
||||
public interface AuthenticationInfo
|
||||
public class DeployException extends Exception
|
||||
{
|
||||
private final String message;
|
||||
private final Throwable cause;
|
||||
public DeployException(String message, Throwable cause)
|
||||
{
|
||||
this.message = message;
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
public DeployException(String message)
|
||||
{
|
||||
this.message = message;
|
||||
this.cause = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public abstract String getPassphrase();
|
||||
/**
|
||||
* @param passphrase
|
||||
*/
|
||||
public abstract void setPassphrase(String passphrase);
|
||||
public Throwable getCause()
|
||||
{
|
||||
return cause;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public abstract String getPassword();
|
||||
/**
|
||||
* @param password
|
||||
*/
|
||||
public abstract void setPassword(String password);
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public abstract String getUsername();
|
||||
/**
|
||||
* @param username
|
||||
*/
|
||||
public abstract void setUsername(String username);
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public abstract String getRemoteGroup();
|
||||
/**
|
||||
* @param remoteGroup
|
||||
*/
|
||||
public abstract void setRemoteGroup(String remoteGroup);
|
||||
}
|
||||
public String getMessage()
|
||||
{
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
package org.apache.maven.artifact.deployer.deploy;
|
||||
package org.apache.maven.deploy.exceptions;
|
||||
|
||||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
* Copyright (c) 2001 The Apache Software Foundation. All rights
|
||||
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -26,12 +26,12 @@ package org.apache.maven.artifact.deployer.deploy;
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Apache" and "Apache Software Foundation" and
|
||||
* "Apache MavenSession" must not be used to endorse or promote products
|
||||
* "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 MavenSession", nor may "Apache" appear in their name, without
|
||||
* "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
|
||||
@ -56,88 +56,29 @@ package org.apache.maven.artifact.deployer.deploy;
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* The Bean which serves as Proxy To Hibernate API
|
||||
* <br/>
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: GenericAuthenticationInfo.java,v 1.1 2003/06/16 14:26:01 michal Exp $
|
||||
* @version $Id: NotAuthorizedDeployException.java,v 1.1 2003/06/17 22:06:00 michal Exp $
|
||||
*/
|
||||
public class GenericAuthenticationInfo implements AuthenticationInfo
|
||||
public class NotAuthorizedDeployException extends DeployException
|
||||
{
|
||||
private String username;
|
||||
private String password;
|
||||
private String passphrase;
|
||||
private String remoteGroup;
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @param message
|
||||
*/
|
||||
public String getPassphrase()
|
||||
public NotAuthorizedDeployException(String message)
|
||||
{
|
||||
return passphrase;
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param passphrase
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public void setPassphrase(String passphrase)
|
||||
public NotAuthorizedDeployException(String message, Throwable cause)
|
||||
{
|
||||
this.passphrase = passphrase;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getPassword()
|
||||
{
|
||||
return password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param password
|
||||
*/
|
||||
public void setPassword(String password)
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getUsername()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param username
|
||||
*/
|
||||
public void setUsername(String username)
|
||||
{
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getRemoteGroup()
|
||||
{
|
||||
return remoteGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param remoteGroup
|
||||
*/
|
||||
public void setRemoteGroup(String remoteGroup)
|
||||
{
|
||||
this.remoteGroup = remoteGroup;
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,9 +1,9 @@
|
||||
package org.apache.maven.artifact.deployer;
|
||||
package org.apache.maven.deploy.exceptions;
|
||||
|
||||
/* ====================================================================
|
||||
* The Apache Software License, Version 1.1
|
||||
*
|
||||
* Copyright (c) 2001 The Apache Software Foundation. All rights
|
||||
* Copyright (c) 2003 The Apache Software Foundation. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -26,12 +26,12 @@ package org.apache.maven.artifact.deployer;
|
||||
* if and wherever such third-party acknowledgments normally appear.
|
||||
*
|
||||
* 4. The names "Apache" and "Apache Software Foundation" and
|
||||
* "Apache MavenSession" must not be used to endorse or promote products
|
||||
* "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 MavenSession", nor may "Apache" appear in their name, without
|
||||
* "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
|
||||
@ -56,39 +56,31 @@ package org.apache.maven.artifact.deployer;
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
import org.apache.maven.project.Project;
|
||||
import org.apache.maven.artifact.deployer.deploy.GenericAuthenticationInfo;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Maps information kept in POM to AuthetificationInfo interface
|
||||
* <br/>
|
||||
*
|
||||
*
|
||||
*
|
||||
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: MavenAuthenticationInfo.java,v 1.1 2003/06/16 14:26:01 michal Exp $
|
||||
* @version $Id: ProxyNotAuthorizedDeployException.java,v 1.1 2003/06/17 22:06:00 michal Exp $
|
||||
*/
|
||||
public class MavenAuthenticationInfo extends GenericAuthenticationInfo
|
||||
public class ProxyNotAuthorizedDeployException extends DeployException
|
||||
{
|
||||
|
||||
|
||||
public MavenAuthenticationInfo(Project project)
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public ProxyNotAuthorizedDeployException(String message)
|
||||
{
|
||||
String username =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deployer.username");
|
||||
String password =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deployer.password");
|
||||
String passphrase =
|
||||
(String) project.getContext().getVariable(
|
||||
"maven.deployer.passphrase");
|
||||
|
||||
setUsername(username);
|
||||
setPassword(password);
|
||||
setPassphrase(passphrase);
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public ProxyNotAuthorizedDeployException(String message, Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@ -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: UnsupportedProtocolDeployException.java,v 1.1 2003/06/17 22:06:00 michal Exp $
|
||||
*/
|
||||
public class UnsupportedProtocolDeployException extends DeployException
|
||||
{
|
||||
/**
|
||||
* @param message
|
||||
*/
|
||||
public UnsupportedProtocolDeployException(String message)
|
||||
{
|
||||
super(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @param cause
|
||||
*/
|
||||
public UnsupportedProtocolDeployException(String message, Throwable cause)
|
||||
{
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user