michal 2003/07/02 05:42:23
Modified: src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers
FtpDeployer.java SFtpDeployer.java ScpDeployer.java
FileDeployer.java
src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer
DefaultArtifactDeployer.java
DeployRequestBuilder.java
src/plugins-build/artifact/src/main/org/apache/maven/deploy
DeployRequest.java DeployTool.java
Added: src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers
ExternalDeployer.java
Log:
Added EXTERNAL deployer and made some minor optimzation.
External deployer is a deployer which starts external process
for each deployment request.
This deployer conceptually close to what what used in maven-deploy plugin
Thanks to this deployer external tools like ssh shells/scp etc. can be used
for deploying artifacts.
Such feature might be useful for users who want to relay on external security
infrastructure for making deployments.
Still need to test this deployer (I haven't tried it on UNIX) and define
list of parameters passed from deployer to the external process and fix
their order.
Revision Changes Path
1.6 +6 -7
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/FtpDeployer.java
Index: FtpDeployer.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/FtpDeployer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- FtpDeployer.java 29 Jun 2003 11:57:39 -0000 1.5
+++ FtpDeployer.java 2 Jul 2003 12:42:13 -0000 1.6
@@ -158,12 +158,11 @@
// Use passive mode as default because most of us are
// behind firewalls these days.
ftp.enterLocalPassiveMode();
- String workingDir = request.getDestDir();
- String filename = request.getDestFile();
- System.out.println("Working directory " + workingDir);
- System.out.println("Filename: " + filename);
- ftp.makeDirectory(workingDir);
- ftp.changeWorkingDirectory(workingDir);
+ ftp.changeWorkingDirectory(request.getBaseDir());
+ String destDir = request.getDestDir();
+ String filename = request.getDestFile();
+ ftp.makeDirectory(destDir);
+ ftp.changeWorkingDirectory(destDir);
ftp.storeFile(filename, new FileInputStream(request.getSrcFile()));
ftp.logout();
}
1.5 +3 -2
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/SFtpDeployer.java
Index: SFtpDeployer.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/SFtpDeployer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SFtpDeployer.java 29 Jun 2003 11:57:39 -0000 1.4
+++ SFtpDeployer.java 2 Jul 2003 12:42:13 -0000 1.5
@@ -111,7 +111,8 @@
channel.connect();
// iterate over all directories in the path. try to create
// directory
- String[] dirs = StringUtils.split(request.getDestDir(), "/");
+ String destPath = request.getBaseDir() + "/" + request.getDestDir();
+ String[] dirs = StringUtils.split(destPath, "/");
for (int i = 0; i < dirs.length; i++)
{
try
1.4 +22 -12
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/ScpDeployer.java
Index: ScpDeployer.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/ScpDeployer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ScpDeployer.java 29 Jun 2003 11:57:40 -0000 1.3
+++ ScpDeployer.java 2 Jul 2003 12:42:21 -0000 1.4
@@ -92,7 +92,12 @@
try
{
- String mkdirCmd = "mkdir -p " + request.getDestDir() + "\n";
+ String mkdirCmd =
+ "mkdir -p "
+ + request.getBaseDir()
+ + "/"
+ + request.getDestDir()
+ + "\n";
executeSimpleCommand(session, mkdirCmd);
doCopy(session, request);
@@ -103,6 +108,10 @@
"chgrp "
+ request.getGroup()
+ " "
+ + request.getBaseDir()
+ + "/"
+ + request.getDestDir()
+ + "/"
+ request.getDestFile()
+ "\n";
executeSimpleCommand(session, chgrpCmd);
@@ -156,11 +165,12 @@
try
{
- String inputFile = request.getSrcFile();
- String outputFile = request.getDestFile();
- String outputDir = request.getDestDir();
+ String srcFile = request.getSrcFile();
+ String destFile = request.getDestFile();
+ String destDir =
+ request.getBaseDir() + "/" + request.getDestDir();
// exec 'scp -t rfile' remotely
- String command = "scp -t " + outputDir + "/" + outputFile;
+ String command = "scp -t " + destDir + "/" + destFile;
System.out.println("Executing command: " + command);
ChannelExec channel =
(ChannelExec) session.openChannel(EXEC_CHANNEL);
@@ -180,15 +190,15 @@
while (tmp[0] != 0);
// send "C0644 filesize filename", where filename should not include '/'
- int filesize = (int) (new File(inputFile)).length();
+ int filesize = (int) (new File(srcFile)).length();
command = "C0644 " + filesize + " ";
- if (inputFile.lastIndexOf('/') > 0)
+ if (srcFile.lastIndexOf('/') > 0)
{
- command += inputFile.substring(inputFile.lastIndexOf('/') + 1);
+ command += srcFile.substring(srcFile.lastIndexOf('/') + 1);
}
else
{
- command += inputFile;
+ command += srcFile;
}
command += "\n";
@@ -203,7 +213,7 @@
while (tmp[0] != 0);
// send a content of inputFile
- FileInputStream fis = new FileInputStream(inputFile);
+ FileInputStream fis = new FileInputStream(srcFile);
byte[] buf = new byte[1024];
while (true)
{
@@ -231,7 +241,7 @@
String msg =
"Error occured while deploying to remote host:"
+ request.getHost();
- throw new TransferFailedException(msg,e);
+ throw new TransferFailedException(msg, e);
}
}
1.7 +4 -4
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/FileDeployer.java
Index: FileDeployer.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/FileDeployer.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FileDeployer.java 29 Jun 2003 11:57:40 -0000 1.6
+++ FileDeployer.java 2 Jul 2003 12:42:21 -0000 1.7
@@ -86,12 +86,12 @@
File srcFile = new File(request.getSrcFile());
File destFile =
- new File(request.getHost(), request.getDestDir());
-
+ new File(request.getHost(), request.getBaseDir());
+ destFile = new File(destFile, request.getDestDir());
if (! destFile.exists())
{
destFile.mkdirs();
- }
+ }
destFile = new File( destFile, request.getDestFile());
FileUtils.copyFile(srcFile, destFile);
}
1.1
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/ExternalDeployer.java
Index: ExternalDeployer.java
===================================================================
package org.apache.maven.deploy.deployers;
import org.apache.maven.deploy.DeployRequest;
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
*
* 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 [EMAIL PROTECTED]
*
* 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/>.
*
* ====================================================================
*/
/**
* Deployers which runs external script or program as new process.
*
* @version $Id: ExternalDeployer.java,v 1.1 2003/07/02 12:42:19 michal Exp $
* @todo still have to account for differing setups for people deploying to
* their own sites and to the central repository.
* @todo finich
*/
public class ExternalDeployer extends AbstractDeployer
{
public final static String PROTOCOL = "external://";
/* (non-Javadoc)
* @see
org.apache.maven.deploy.deployers.Deployer#deploy(org.apache.maven.deploy.DeployRequest)
*/
public void deploy(DeployRequest request)
throws
TransferFailedException,
NotAuthorizedDeployException,
ProxyNotAuthorizedDeployException,
TransferFailedException,
WrongParameterException
{
String cmd = request.getHost();
String[] params =
{
request.getSrcFile(),
request.getDestDir(),
request.getDestFile(),
};
try
{
System.out.println("Staring external process: '" + cmd + "'");
Process process = Runtime.getRuntime().exec(cmd,params);
process.waitFor();
System.out.println("External process finished");
}
catch (Exception e)
{
throw new TransferFailedException("Failed to deploy with extrnal
program",e);
}
}
}
1.11 +23 -14
maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
Index: DefaultArtifactDeployer.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- DefaultArtifactDeployer.java 29 Jun 2003 11:57:39 -0000 1.10
+++ DefaultArtifactDeployer.java 2 Jul 2003 12:42:23 -0000 1.11
@@ -67,6 +67,7 @@
import org.apache.maven.MavenException;
import org.apache.maven.deploy.DeployRequest;
import org.apache.maven.deploy.DeployTool;
+import org.apache.maven.deploy.exceptions.WrongParameterException;
import org.apache.maven.project.Project;
import org.apache.maven.util.MD5Sum;
@@ -255,7 +256,7 @@
String repos =
(String) project.getContext().getVariable("maven.repo.list");
-
+
String distSite = project.getDistributionSite();
if (distSite != null && distSite.length() > 0)
{
@@ -271,7 +272,8 @@
if (repos == null || repos.length() == 0)
{
- System.out.println("No remote repository is defined for deployment");
+ System.out.println(
+ "No remote repository is defined for deployment");
return;
}
String[] repoArray = StringUtils.split(repos, ",");
@@ -285,20 +287,26 @@
String repo = repoArray[i].trim();
System.out.println("Deploying to repo: " + repo);
- for (int j = 0; j < srcFilenames.length; j++)
+ DeployRequest request = null;
+
+ // Will create only one request per repository
+ try
{
+ request = DeployRequestBuilder.getDeployRequest(project, repo);
+ request.setDestDir(destPath);
+ }
+ catch (WrongParameterException e)
+ {
+ System.out.print(e.getMessage());
+ continue;
+ }
- DeployRequest request = null;
+ for (int j = 0; j < srcFilenames.length; j++)
+ {
try
{
- request =
- DeployRequestBuilder.getDeployRequest(
- repo,
- project,
- repo,
- srcFilenames[j],
- destPath,
- destFilenames[j]);
+ request.setSrcFile(srcFilenames[j]);
+ request.setDestFile(destFilenames[j]);
System.out.println(
"Deploying: '"
@@ -306,6 +314,8 @@
+ "' to host: '"
+ request.getHost()
+ "' remote path: '"
+ + request.getBaseDir()
+ + "/"
+ request.getDestDir()
+ "' remote file: '"
+ request.getDestFile());
@@ -356,7 +366,6 @@
return path.toString();
}
-
/**
*
* @param type
1.3 +24 -37
maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer/DeployRequestBuilder.java
Index: DeployRequestBuilder.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer/DeployRequestBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DeployRequestBuilder.java 29 Jun 2003 11:57:39 -0000 1.2
+++ DeployRequestBuilder.java 2 Jul 2003 12:42:23 -0000 1.3
@@ -57,7 +57,6 @@
*/
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;
@@ -71,26 +70,23 @@
public class DeployRequestBuilder
{
+
/**
*
- * @param project
- * @param repository Alias(name) of the repository
- * like </i>repo1</i> taken from propertt: <i>maven.deploy.repos= repo1,
repo2</i>
- * @param srcDir
- * @param srcDir
- * @param destFile
+ * @param project. Will lookup the properties in the context of this project
+ * @param repository The name (alias) of the repository
+ * like </i>repo1</i> taken from property: <i>maven.deploy.repos= repo1,
repo2</i>
+ * @return Deploy request
+ * @throws WrongParameterException
*/
public static DeployRequest getDeployRequest(
- String repositoryAlias,
Project project,
- String repository,
- String srcFile,
- String destDir,
- String destFile) throws DeployException
+ String repository)
+ throws WrongParameterException
{
DeployRequest request = new DeployRequest();
- request.setRepositoryAlias(repositoryAlias);
+ request.setRepositoryAlias(repository);
String url =
(String) project.getContext().getVariable(
"maven.repo." + repository);
@@ -122,19 +118,13 @@
(String) project.getContext().getVariable(
"maven.repo." + repository + ".group");
- String proxyHost =
- (String) project.getContext().getProxyHost();
- String proxyUser =
- (String) project.getContext().getProxyUserName();
-
-
- String proxyPassword =
- (String) project.getContext().getProxyPassword();
-
-
- String proxyPort =
- (String) project.getContext().getProxyPort();
-
+ String proxyHost = (String) project.getContext().getProxyHost();
+ String proxyUser = (String) project.getContext().getProxyUserName();
+
+ String proxyPassword = (String) project.getContext().getProxyPassword();
+
+ String proxyPort = (String) project.getContext().getProxyPort();
+
request.setUserName(username);
request.setPassword(password);
request.setPassphrase(passphrase);
@@ -153,7 +143,8 @@
}
catch (Exception e)
{
- throw new WrongParameterException("maven.repo." + repository +
".port should be an integer");
+ throw new WrongParameterException(
+ "maven.repo." + repository + ".port should be an integer");
}
}
if (proxyPort != null)
@@ -164,18 +155,14 @@
}
catch (Exception e)
{
- throw new WrongParameterException("maven.repo." + repository +
".proxy.port should be an integer");
+ throw new WrongParameterException(
+ "maven.repo."
+ + repository
+ + ".proxy.port should be an integer");
}
}
- request.setSrcFile(srcFile);
-
- if (dir != null)
- {
- destDir = dir + "/" + destDir;
- }
- request.setDestFile(destFile);
- request.setDestDir(destDir);
+ request.setBaseDir(dir);
return request;
}
1.6 +40 -17
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/DeployRequest.java
Index: DeployRequest.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/DeployRequest.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DeployRequest.java 29 Jun 2003 11:57:40 -0000 1.5
+++ DeployRequest.java 2 Jul 2003 12:42:23 -0000 1.6
@@ -78,47 +78,52 @@
/** 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 baseDir;
+
+ /**
+ * The directory where artifact will be placed
+ * It is relative to base dir
+ */
private String destDir;
-
+
/** The filename of the artifact */
private String destFile;
-
+
/** The artifact file in local file system */
private String srcFile;
/** 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 host*/
+ /** Proxy Server host*/
private String proxyHost = 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*/
+ /** Indicates if debug mode should be used*/
private boolean debugOn = false;
/**
@@ -218,7 +223,25 @@
}
/**
- * Get aboluth path to local files = artifact
+ * Get base directory
+ * @return base directory
+ */
+ public String getBaseDir()
+ {
+ return baseDir;
+ }
+
+ /**
+ * Set base directory
+ * @param baseDir
+ */
+ public void setBaseDir(String baseDir)
+ {
+ this.baseDir = baseDir;
+ }
+
+ /**
+ * Get absolute path to local file = artifact
* @return Path to artifact file
*/
public String getSrcFile()
@@ -227,7 +250,7 @@
}
/**
- * Set the aboluthe path to artifact file
+ * Set the absolute path to artifact file
* @param srcFile
*/
public void setSrcFile(String inputFile)
1.6 +7 -1
maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/DeployTool.java
Index: DeployTool.java
===================================================================
RCS file:
/home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/DeployTool.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DeployTool.java 29 Jun 2003 11:57:40 -0000 1.5
+++ DeployTool.java 2 Jul 2003 12:42:23 -0000 1.6
@@ -57,6 +57,7 @@
*/
import org.apache.maven.deploy.deployers.Deployer;
+import org.apache.maven.deploy.deployers.ExternalDeployer;
import org.apache.maven.deploy.deployers.FileDeployer;
import org.apache.maven.deploy.deployers.FtpDeployer;
import org.apache.maven.deploy.deployers.HttpDeployer;
@@ -122,10 +123,15 @@
{
deployer = new ScpDeployer();
}
+ if (url.startsWith(ExternalDeployer.PROTOCOL))
+ {
+ deployer = new ExternalDeployer();
+ }
if (deployer == null)
{
throw new UnsupportedProtocolException(url);
}
+
deployer.deploy(request);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]