various bugfixes

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@116100 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
brett 2004-09-28 09:20:40 +00:00
parent adabb3cfd5
commit b4ec0d61d1
10 changed files with 246 additions and 127 deletions

View File

@ -25,7 +25,7 @@
<name>Maven Artifact Plugin</name> <name>Maven Artifact Plugin</name>
<!-- WARNING: some dependency checks will break if we get to 1.10, need to go to 2.0 from there --> <!-- WARNING: some dependency checks will break if we get to 1.10, need to go to 2.0 from there -->
<currentVersion>1.4</currentVersion> <currentVersion>1.4.1-SNAPSHOT</currentVersion>
<description>Tools to manage artifacts and deployment. Requires Maven 1.0 RC4</description> <description>Tools to manage artifacts and deployment. Requires Maven 1.0 RC4</description>
<shortDescription>Tools to manage artifacts and deployment</shortDescription> <shortDescription>Tools to manage artifacts and deployment</shortDescription>
<url>http://maven.apache.org/reference/plugins/artifact/</url> <url>http://maven.apache.org/reference/plugins/artifact/</url>

View File

@ -27,7 +27,7 @@ import org.apache.maven.project.Project;
* Perform mapping between project's properties and attributes of DeployRequest class. * Perform mapping between project's properties and attributes of DeployRequest class.
* *
* @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a> * @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: RepositoryInfoBuilder.java,v 1.7 2004/07/06 13:42:25 brett Exp $ * @version $Id: RepositoryInfoBuilder.java,v 1.8 2004/09/28 09:20:40 brett Exp $
*/ */
public class RepositoryInfoBuilder public class RepositoryInfoBuilder
{ {
@ -83,6 +83,10 @@ public class RepositoryInfoBuilder
(String) project.getContext().getVariable( (String) project.getContext().getVariable(
"maven.repo." + repository + ".group"); "maven.repo." + repository + ".group");
String remoteMode =
(String) project.getContext().getVariable(
"maven.repo." + repository + ".mode");
String passiveModeOn = String passiveModeOn =
(String) project.getContext().getVariable( (String) project.getContext().getVariable(
"maven.repo." + repository + ".passiveModeOn"); "maven.repo." + repository + ".passiveModeOn");
@ -115,11 +119,16 @@ public class RepositoryInfoBuilder
username = (String) project.getContext().getVariable("maven.username"); username = (String) project.getContext().getVariable("maven.username");
} }
if (remoteMode == null) {
remoteMode = "664";
}
repoInfo.setUserName(username); repoInfo.setUserName(username);
repoInfo.setPassword(password); repoInfo.setPassword(password);
repoInfo.setPassphrase(passphrase); repoInfo.setPassphrase(passphrase);
repoInfo.setPrivateKey(privateKey); repoInfo.setPrivateKey(privateKey);
repoInfo.setGroup(remoteGroup); repoInfo.setGroup(remoteGroup);
repoInfo.setMode(remoteMode);
repoInfo.setUrl(url); repoInfo.setUrl(url);
repoInfo.setProxyHost(proxyHost); repoInfo.setProxyHost(proxyHost);
repoInfo.setProxyUserName(proxyUser); repoInfo.setProxyUserName(proxyUser);

View File

@ -23,7 +23,7 @@ package org.apache.maven.deploy;
* perform a deployment. * perform a deployment.
* *
* @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a> * @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: RepositoryInfo.java,v 1.6 2004/07/06 13:42:25 brett Exp $ * @version $Id: RepositoryInfo.java,v 1.7 2004/09/28 09:20:40 brett Exp $
*/ */
public class RepositoryInfo public class RepositoryInfo
{ {
@ -55,6 +55,9 @@ public class RepositoryInfo
/** Remote group name */ /** Remote group name */
private String group; private String group;
/** File mode. */
private String mode;
/** The passpharse of the user's private key file */ /** The passpharse of the user's private key file */
private String passphrase; private String passphrase;
@ -187,6 +190,16 @@ public class RepositoryInfo
this.privateKey = privateKey; this.privateKey = privateKey;
} }
public String getMode()
{
return mode;
}
public void setMode( String mode )
{
this.mode = mode;
}
/** /**
* Get the remote group to which will belong to * Get the remote group to which will belong to
* after deployemnt. Not all protolcols support * after deployemnt. Not all protolcols support
@ -389,28 +402,28 @@ public class RepositoryInfo
this.passiveModeOn = passiveModeOn; this.passiveModeOn = passiveModeOn;
} }
public String getScpArgs() { public String getScpArgs() {
return scpArgs; return scpArgs;
} }
public void setScpArgs(String scpArgs) { public void setScpArgs(String scpArgs) {
this.scpArgs = scpArgs; this.scpArgs = scpArgs;
} }
public String getScpExe() { public String getScpExe() {
return scpExe; return scpExe;
} }
public void setScpExe(String scpExe) { public void setScpExe(String scpExe) {
this.scpExe = scpExe; this.scpExe = scpExe;
} }
public String getSshArgs() { public String getSshArgs() {
return sshArgs; return sshArgs;
} }
public void setSshArgs(String sshArgs) { public void setSshArgs(String sshArgs) {
this.sshArgs = sshArgs; this.sshArgs = sshArgs;
} }
public String getSshExe() { public String getSshExe() {
return sshExe; return sshExe;
} }
public void setSshExe(String sshExe) { public void setSshExe(String sshExe) {
this.sshExe = sshExe; this.sshExe = sshExe;
} }
} }

View File

@ -42,7 +42,7 @@ import org.apache.maven.deploy.exceptions.TransferFailedException;
* *
* @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a> * @author <a href="mailto:jason@zenplex.com">Jason van Zyl</a>
* @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a> * @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: FtpDeployer.java,v 1.12 2004/06/25 18:50:38 brett Exp $ * @version $Id: FtpDeployer.java,v 1.13 2004/09/28 09:20:40 brett Exp $
* *
* @todo review exception handling * @todo review exception handling
* @todo don't spool to System.out * @todo don't spool to System.out
@ -176,6 +176,9 @@ public class FtpDeployer extends AbstractDeployer
ftp.storeFile( ftp.storeFile(
request.filename(), request.filename(),
new FileInputStream(request.getSrcFile())); new FileInputStream(request.getSrcFile()));
// TODO: test first, then mark MPARTIFACT-24 complete
//ftp.executeSiteCommand( "CHGRP " + request.getGroup() + " " + request.filename() );
//ftp.executeSiteCommand( "CHMOD " + request.getMode() + " " + request.filename() );
for (int i = 0; i < dirs.length; i++) for (int i = 0; i < dirs.length; i++)
{ {
ftp.changeWorkingDirectory(".."); ftp.changeWorkingDirectory("..");

View File

@ -43,7 +43,7 @@ import com.jcraft.jsch.UserInfo;
* and if that doesn't work then we fall back * and if that doesn't work then we fall back
* to using the login and password * to using the login and password
* *
* @version $Id: GenericSshDeployer.java,v 1.11 2004/06/25 18:19:35 brett Exp $ * @version $Id: GenericSshDeployer.java,v 1.12 2004/09/28 09:20:40 brett Exp $
* @todo still have to account for differing setups for people deploying to * @todo still have to account for differing setups for people deploying to
* their own sites and to the central repository. * their own sites and to the central repository.
* @todo improve exception handling * @todo improve exception handling
@ -84,7 +84,10 @@ public abstract class GenericSshDeployer extends AbstractDeployer
*/ */
public void release() public void release()
{ {
session.disconnect(); if ( session != null )
{
session.disconnect();
}
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -93,6 +96,18 @@ public abstract class GenericSshDeployer extends AbstractDeployer
public void init(RepositoryInfo repoInfo) public void init(RepositoryInfo repoInfo)
throws AuthenticationException throws AuthenticationException
{ {
try {
Class.forName( "javax.crypto.spec.DHParameterSpec" );
}
catch ( ClassNotFoundException e )
{
LOG.error( "JCE is required for an SSH based deployer" );
LOG.error( "Please use JDK 1.4 or above, or install a JCE provider" );
LOG.error( "A free (GPL) provider is available from Bouncycastle:" );
LOG.error( "http://www.bouncycastle.org/" );
throw new AuthenticationException( "JCE required" );
}
try try
{ {
@ -168,9 +183,8 @@ public abstract class GenericSshDeployer extends AbstractDeployer
} }
catch (Exception e) catch (Exception e)
{ {
throw new AuthenticationException( LOG.debug("Connection failure exception", e);
"Cannot connect. Reason: " + e.getMessage(), throw new AuthenticationException( "Cannot connect. Reason: " + e.getMessage() );
e);
} }
} }

View File

@ -35,7 +35,7 @@ import com.jcraft.jsch.SftpProgressMonitor;
* An SSH2/SFTP deployer * An SSH2/SFTP deployer
* *
* @author Michal Maczka * @author Michal Maczka
* @version $Revision: 1.11 $ $Date: 2004/06/25 13:50:05 $ * @version $Revision: 1.12 $ $Date: 2004/09/28 09:20:40 $
*/ */
public class SFtpDeployer extends GenericSshDeployer public class SFtpDeployer extends GenericSshDeployer
{ {
@ -152,7 +152,7 @@ public class SFtpDeployer extends GenericSshDeployer
{ {
LOG.info("Changing group to: " + groupId); LOG.info("Changing group to: " + groupId);
} }
channel.chgrp(groupId.intValue(), request.getDestFile()); channel.chgrp(groupId.intValue(), request.filename());
if (getRepositoryInfo().isDebugOn()) if (getRepositoryInfo().isDebugOn())
{ {
LOG.info("Group successfully changed"); LOG.info("Group successfully changed");

View File

@ -42,7 +42,7 @@ import java.util.List;
* An SSH2/SCP deployer * An SSH2/SCP deployer
* *
* @author Michal Maczka * @author Michal Maczka
* @version $Revision: 1.12 $ $Date: 2004/07/06 14:29:30 $ * @version $Revision: 1.13 $ $Date: 2004/09/28 09:20:40 $
*/ */
public class ScpDeployer extends GenericSshDeployer public class ScpDeployer extends GenericSshDeployer
{ {
@ -138,6 +138,18 @@ public class ScpDeployer extends GenericSshDeployer
executeSimpleCommand(session, mkdirCmd); executeSimpleCommand(session, mkdirCmd);
// If an old SNAPSHOT exists, remove it
if (request.getDestFile().indexOf("SNAPSHOT") > 0) {
String cmd =
"rm -f "
+ getRepositoryInfo().getBasedir()
+ "/"
+ request.getDestFile()
+ "\n";
executeSimpleCommand(session, cmd);
}
doCopy(session, request); doCopy(session, request);
if (getRepositoryInfo().getGroup() != null) if (getRepositoryInfo().getGroup() != null)
@ -153,6 +165,20 @@ public class ScpDeployer extends GenericSshDeployer
executeSimpleCommand(session, chgrpCmd); executeSimpleCommand(session, chgrpCmd);
} }
if (getRepositoryInfo().getMode() != null)
{
String chmodCmd =
"chmod "
+ getRepositoryInfo().getMode()
+ " "
+ getRepositoryInfo().getBasedir()
+ "/"
+ request.getDestFile()
+ "\n";
executeSimpleCommand(session, chmodCmd);
}
} }
/** /**

View File

@ -19,12 +19,16 @@ package org.apache.maven.deploy.deployers;
*/ */
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.maven.MavenUtils;
import org.apache.maven.deploy.DeployRequest; import org.apache.maven.deploy.DeployRequest;
import org.apache.maven.deploy.RepositoryInfo; import org.apache.maven.deploy.RepositoryInfo;
import org.apache.maven.deploy.exceptions.AuthenticationException; import org.apache.maven.deploy.exceptions.AuthenticationException;
@ -55,11 +59,11 @@ public class ScpExeDeployer extends AbstractDeployer
*/ */
public void init(RepositoryInfo repoInfo) throws AuthenticationException public void init(RepositoryInfo repoInfo) throws AuthenticationException
{ {
repositoryInfo = repoInfo; repositoryInfo = repoInfo;
} }
private RepositoryInfo getRepositoryInfo() { private RepositoryInfo getRepositoryInfo() {
return repositoryInfo; return repositoryInfo;
} }
/** /**
@ -98,110 +102,139 @@ public class ScpExeDeployer extends AbstractDeployer
executeSimpleCommand(chgrpCmd); executeSimpleCommand(chgrpCmd);
} }
if (getRepositoryInfo().getMode() != null)
{
String chmodCmd =
"chmod "
+ getRepositoryInfo().getMode()
+ " "
+ getRepositoryInfo().getBasedir()
+ "/"
+ request.getDestFile()
+ "\n";
executeSimpleCommand(chmodCmd);
}
} }
private String arrayToString(String[] array) { private String arrayToString(String[] array) {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
for (int i=0; i<array.length; i++) { for (int i=0; i<array.length; i++) {
sb.append(array[i]); sb.append(array[i]);
sb.append(" "); sb.append(" ");
} }
return sb.toString(); return sb.toString();
} }
private void executeSimpleCommand(String cmd) throws TransferFailedException { private void executeSimpleCommand(String cmd) throws TransferFailedException {
String args = getRepositoryInfo().getSshArgs(); String args = getRepositoryInfo().getSshArgs();
if (args == null) { String sshCmd = getRepositoryInfo().getSshExe() + " " +
args = ""; ( args == null ? "" : args + " " ) +
getRepositoryInfo().getUserName() + "@" + getRepositoryInfo().getHost() + " " +
cmd;
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing command: " + sshCmd);
}
Process p = Runtime.getRuntime().exec(sshCmd);
// any error message?
StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR");
// any output?
StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(), "OUTPUT");
// kick them off
errorGobbler.start();
outputGobbler.start();
int returnCode = p.waitFor();
if (returnCode != 0) {
LOG.debug( "exit code = " + returnCode );
throw new TransferFailedException("Error executing command: " + cmd);
}
} catch (IOException e) {
LOG.error("Error executing command: " + cmd);
throw new TransferFailedException("Error executing command: ", e);
} catch (InterruptedException e) {
LOG.error("Error executing command: " + cmd);
throw new TransferFailedException("Error executing command: ", e);
} }
String[] sshCmd = { getRepositoryInfo().getSshExe(),
args,
getRepositoryInfo().getUserName() + "@" + getRepositoryInfo().getHost(),
cmd };
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing command: " + arrayToString(sshCmd));
}
Process p = Runtime.getRuntime().exec(sshCmd);
p.waitFor();
} catch (IOException e) {
LOG.error("Error executing command: " + cmd);
throw new TransferFailedException("Error executing command: ", e);
} catch (InterruptedException e) {
LOG.error("Error executing command: " + cmd);
throw new TransferFailedException("Error executing command: ", e);
}
} }
private void doCopy(DeployRequest request) throws TransferFailedException { private void doCopy(DeployRequest request) throws TransferFailedException {
String srcFile = request.getSrcFile(); String srcFile;
String destFile = getRepositoryInfo().getBasedir() + "/" + request.getDestFile(); try {
String dest = getRepositoryInfo().getUserName() + "@" + getRepositoryInfo().getHost() + ":" + destFile; srcFile = MavenUtils.makeRelativePath( new File( System.getProperty( "user.dir" ) ), request.getSrcFile() );
String args = getRepositoryInfo().getScpArgs(); } catch (IOException e) {
if (args == null) { throw new TransferFailedException("Error locating artifact to deploy: ", e);
args = ""; }
} String destFile = getRepositoryInfo().getBasedir() + "/" + request.getDestFile();
if (destFile.indexOf("SNAPSHOT") > 0) {
// If an old SNAPSHOT exists, remove it
executeSimpleCommand("rm -f " + destFile);
}
if (destFile.indexOf("SNAPSHOT") > 0) { String args = getRepositoryInfo().getScpArgs();
// If an old SNAPSHOT exists, remove it String scpCmd = getRepositoryInfo().getScpExe() + " " +
executeSimpleCommand("rm -r " + destFile); ( args == null ? "" : args + " " ) +
} srcFile + " " +
getRepositoryInfo().getUserName() + "@" + getRepositoryInfo().getHost() + ":" + destFile;
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing command: " + scpCmd);
}
Process p = Runtime.getRuntime().exec(scpCmd);
// any error message?
StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR");
String[] scpCmd = { getRepositoryInfo().getScpExe(), // any output?
args, StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(), "OUTPUT");
srcFile,
dest };
try {
if (LOG.isDebugEnabled()) {
LOG.debug("Executing command: " + arrayToString(scpCmd));
}
Process p = Runtime.getRuntime().exec(scpCmd);
// any error message?
StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR");
// any output? // kick them off
StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(), "OUTPUT"); errorGobbler.start();
outputGobbler.start();
// kick them off int returnCode = p.waitFor();
errorGobbler.start(); if (returnCode != 0) {
outputGobbler.start(); LOG.debug( "exit code = " + returnCode );
throw new TransferFailedException("Error executing command: " + scpCmd);
p.waitFor(); }
} catch (IOException e) { } catch (IOException e) {
LOG.error("Error executing command: " + cmd); LOG.error("Error executing command: " + cmd);
throw new TransferFailedException("Error executing command: ", e); throw new TransferFailedException("Error executing command: ", e);
} catch (InterruptedException e) { } catch (InterruptedException e) {
LOG.error("Error executing command: " + cmd); LOG.error("Error executing command: " + cmd);
throw new TransferFailedException("Error executing command: ", e); throw new TransferFailedException("Error executing command: ", e);
} }
} }
private class StreamGobbler extends Thread private class StreamGobbler extends Thread
{ {
private InputStream is; private InputStream is;
private String type; private String type;
public StreamGobbler(InputStream is, String type) { public StreamGobbler(InputStream is, String type) {
this.is = is; this.is = is;
this.type = type; this.type = type;
} }
public void run() { public void run() {
try { try {
InputStreamReader isr = new InputStreamReader(is); InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr); BufferedReader br = new BufferedReader(isr);
String line = null; String line = null;
while ((line = br.readLine()) != null) { while ((line = br.readLine()) != null) {
LOG.debug(type + ">" + line); LOG.debug(type + ">" + line);
} }
br.close(); br.close();
isr.close(); isr.close();
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace(); ioe.printStackTrace();
} }
} }
} }
} }

View File

@ -25,6 +25,18 @@
<author email="vmassol@apache.org">Vincent Massol</author> <author email="vmassol@apache.org">Vincent Massol</author>
</properties> </properties>
<body> <body>
<release version="1.4.1" date="in CVS">
<action dev="brett" type="fix" issue="MPARTIFACT-38">Allow scpexe protocol to work better with args</action>
<action dev="brett" type="fix" issue="MPARTIFACT-34">Check return code of spawned external processes</action>
<action dev="brett" type="fix" issue="MPARTIFACT-32">Remove old snapshots that were created with symlinks before deployment.</action>
<action dev="brett" type="fix" issue="MPARTIFACT-29">Fix group setting for scpexe deployer</action>
<action dev="brett" type="fix" issue="MPARTIFACT-28">Run scpexe with a relative path so it works on cygwin.</action>
<action dev="brett" type="fix" issue="MPARTIFACT-26">Improve error reporting on a JCEless install attempting to use built in SSH.</action>
<action dev="brett" type="fix" issue="MPARTIFACT-27">Only log JSCH exceptions in debug mode, report exception</action>
<action dev="brett" type="fix" issue="MPARTIFACT-30">Fix group setting for scp deployer</action>
<action dev="brett" type="fix" issue="MPARTIFACT-12">Add mode setting for remote repository</action>
<action dev="brett" type="fix" issue="MPARTIFACT-11">Fix group setting for SFTP deployer</action>
</release>
<release version="1.4" date="2004-07-10"> <release version="1.4" date="2004-07-10">
<action dev="brett" type="fix" issue="MPARTIFACT-23">Add overwrite option to unzip - necessary to run in batch mode</action> <action dev="brett" type="fix" issue="MPARTIFACT-23">Add overwrite option to unzip - necessary to run in batch mode</action>
<action dev="brett" type="add" issue="MPARTIFACT-22" due-to="Leif Nelson">Add an scp executable deployer</action> <action dev="brett" type="add" issue="MPARTIFACT-22" due-to="Leif Nelson">Add an scp executable deployer</action>

View File

@ -98,8 +98,17 @@
<td>maven.repo.x.group</td> <td>maven.repo.x.group</td>
<td> <td>
The remote group (UNIX group) to which The remote group (UNIX group) to which
artifact will belong after it the artifact will belong after it
will be deployed is deployed
</td>
<td>Yes</td>
</tr>
<tr>
<td>maven.repo.x.mode</td>
<td>
The remote file mode (UNIX permissions) to which
the artifact will be set to after it
is deployed. Default is <code>664</code>.
</td> </td>
<td>Yes</td> <td>Yes</td>
</tr> </tr>