From 2c2b0e5aacc0b4bc7e18b9fb497b9a1c4c4807ac Mon Sep 17 00:00:00 2001 From: brett Date: Fri, 25 Jun 2004 13:50:05 +0000 Subject: [PATCH] finalise implementation of legacy deployment method git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115535 13f79535-47bb-0310-9956-ffa450edef68 --- artifact/plugin.jelly | 96 +++++++++++--- artifact/project.xml | 1 + .../deployer/DefaultArtifactDeployer.java | 117 ++++++++++-------- .../org/apache/maven/deploy/DeployTool.java | 11 +- .../deploy/deployers/ExternalDeployer.java | 10 +- .../maven/deploy/deployers/FtpDeployer.java | 12 +- .../deploy/deployers/GenericSshDeployer.java | 13 +- .../maven/deploy/deployers/HttpDeployer.java | 13 +- .../maven/deploy/deployers/SFtpDeployer.java | 12 +- .../maven/deploy/deployers/ScpDeployer.java | 39 +++--- 10 files changed, 214 insertions(+), 110 deletions(-) diff --git a/artifact/plugin.jelly b/artifact/plugin.jelly index b35f297c..cd3617c2 100644 --- a/artifact/plugin.jelly +++ b/artifact/plugin.jelly @@ -17,7 +17,6 @@ */ --> - - - - - + + + + + + + + + + + @@ -87,14 +101,50 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -195,6 +245,8 @@ + DEPRECATED: use of deploy:artifact tag and the legacy deploy method are deprecated + + + + + + + - Moving ${artifact} to the ${resolvedDirectory} on ${siteAddress} + Copying ${artifact} to the ${resolvedDirectory} on ${siteAddress} 1.3-SNAPSHOT Tools to manage artifacts and deployment diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java b/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java index 82d6212b..848ad3a8 100644 --- a/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java +++ b/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java @@ -45,7 +45,7 @@ import org.apache.maven.util.MD5Sum; * * * @author Michal Maczka - * @version $Id: DefaultArtifactDeployer.java,v 1.20 2004/06/23 13:04:28 brett Exp $ + * @version $Id: DefaultArtifactDeployer.java,v 1.21 2004/06/25 13:50:05 brett Exp $ */ public class DefaultArtifactDeployer implements ArtifactDeployer { @@ -103,25 +103,29 @@ public class DefaultArtifactDeployer implements ArtifactDeployer file = getFileForArtifact(artifact); } File md5File = createMD5Checksum(file); - String repositoryPath = - handler.constructRepositoryFullPath(type, project, project.getCurrentVersion()); + try { + String repositoryPath = + handler.constructRepositoryFullPath(type, project, project.getCurrentVersion()); - List srcFiles = new ArrayList(); - srcFiles.add(file.getAbsolutePath()); - srcFiles.add(md5File.getAbsolutePath()); + List srcFiles = new ArrayList(); + srcFiles.add(file.getAbsolutePath()); + srcFiles.add(md5File.getAbsolutePath()); + + List destFiles = new ArrayList(); + destFiles.add(repositoryPath); + destFiles.add(repositoryPath + ".md5"); - List destFiles = new ArrayList(); - destFiles.add(repositoryPath); - destFiles.add(repositoryPath + ".md5"); - - //do not deploy POM twice - if (DEPLOY_POM && !POM_TYPE.equals(type)) - { - deploy(artifact, POM_TYPE, project, POM_ARTIFACT_TYPE_HANDLER); + //do not deploy POM twice + if (DEPLOY_POM && !POM_TYPE.equals(type)) + { + deploy(artifact, POM_TYPE, project, POM_ARTIFACT_TYPE_HANDLER); + } + doDeploy(srcFiles, destFiles, project); + } + finally { + //Delete md5 file + md5File.delete(); } - doDeploy(srcFiles, destFiles, project); - //Delete md5 file - md5File.delete(); } /** @@ -144,43 +148,49 @@ public class DefaultArtifactDeployer implements ArtifactDeployer File md5File = createMD5Checksum(file); File snapshotVersionFile = createSnapshotVersionFile(file, snapshotSignature, project, type); + try { + List srcFiles = new ArrayList(); + srcFiles.add(file.getAbsolutePath()); + srcFiles.add(md5File.getAbsolutePath()); + srcFiles.add(file.getAbsolutePath()); + srcFiles.add(md5File.getAbsolutePath()); - List srcFiles = new ArrayList(); - srcFiles.add(file.getAbsolutePath()); - srcFiles.add(md5File.getAbsolutePath()); - srcFiles.add(file.getAbsolutePath()); - srcFiles.add(md5File.getAbsolutePath()); - srcFiles.add(snapshotVersionFile.getAbsolutePath()); + String snapshotFilename = + handler.constructRepositoryFullPath( + type, + project, + MavenConstants.SNAPSHOT_SIGNIFIER); + String timestampedFilename = + handler.constructRepositoryFullPath(type, project, snapshotSignature); - String snapshotFilename = - handler.constructRepositoryFullPath( - type, - project, - MavenConstants.SNAPSHOT_SIGNIFIER); - String timestampedFilename = - handler.constructRepositoryFullPath(type, project, snapshotSignature); - String snapshotVersionsFilename = - handler.constructRepositoryDirectoryPath(type, project) - + project.getArtifactId() - + "-snapshot-version"; + List destFiles = new ArrayList(); + destFiles.add(snapshotFilename); + destFiles.add(snapshotFilename + ".md5"); + destFiles.add(timestampedFilename); + destFiles.add(timestampedFilename + ".md5"); - List destFiles = new ArrayList(); - destFiles.add(snapshotFilename); - destFiles.add(snapshotFilename + ".md5"); - destFiles.add(timestampedFilename); - destFiles.add(timestampedFilename + ".md5"); - destFiles.add(snapshotVersionsFilename); + srcFiles.add(snapshotVersionFile.getAbsolutePath()); - // do not deploy POM twice - if (DEPLOY_POM_SNAPSHOT && !POM_TYPE.equals(type)) - { - deploySnapshot(artifact, POM_TYPE, project, POM_ARTIFACT_TYPE_HANDLER); + String snapshotVersionsFilename = + handler.constructRepositoryDirectoryPath(type, project) + + project.getArtifactId() + + "-snapshot-version"; + destFiles.add(snapshotVersionsFilename); + + // do not deploy POM twice + if (DEPLOY_POM_SNAPSHOT && !POM_TYPE.equals(type)) + { + deploySnapshot(artifact, POM_TYPE, project, POM_ARTIFACT_TYPE_HANDLER); + } + + doDeploy(srcFiles, destFiles, project); } - - doDeploy(srcFiles, destFiles, project); - // Delete md5 file - md5File.delete(); - }; + finally { + // Delete md5 file + md5File.delete(); + snapshotVersionFile.delete(); + } + } /** * @see ArtifactDeployer#install(String, String, Project, ArtifactTypeHandler) @@ -226,7 +236,7 @@ public class DefaultArtifactDeployer implements ArtifactDeployer file = getFileForArtifact(artifact); } String snapshotSignature = getSnapshotSignature(); - System.out.println("Installing snapshot of:'" + artifact + "''"); + LOG.info("Installing snapshot of:'" + artifact + "''"); doInstall(file, type, project, MavenConstants.SNAPSHOT_SIGNIFIER, handler); doInstall(file, type, project, snapshotSignature, handler); if (INSTALL_POM_SNAPSHOT && !POM_TYPE.equals(type)) @@ -268,8 +278,7 @@ public class DefaultArtifactDeployer implements ArtifactDeployer { destFile.getParentFile().mkdirs(); } - System.out.println( - "Copying: from '" + file + "' to: '" + destFile + "'"); + LOG.info("Copying: from '" + file + "' to: '" + destFile + "'"); FileUtils.copyFile(file, destFile); } catch (IOException e) @@ -360,13 +369,13 @@ public class DefaultArtifactDeployer implements ArtifactDeployer String[] repos = StringUtils.split(repoStr, ","); - System.out.println( "Will deploy to " + repos.length + " repository(ies): " + repoStr); + LOG.info( "Will deploy to " + repos.length + " repository(ies): " + repoStr); boolean success = false; for (int i = 0; i < repos.length; i++) { String repo = repos[i].trim(); - System.out.println("Deploying to repository: " + repo); + LOG.info("Deploying to repository: " + repo); RepositoryInfo repoInfo = null; try { diff --git a/artifact/src/main/org/apache/maven/deploy/DeployTool.java b/artifact/src/main/org/apache/maven/deploy/DeployTool.java index fa8f2f1d..3a9073ee 100644 --- a/artifact/src/main/org/apache/maven/deploy/DeployTool.java +++ b/artifact/src/main/org/apache/maven/deploy/DeployTool.java @@ -20,6 +20,8 @@ package org.apache.maven.deploy; import java.util.Iterator; import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.maven.deploy.deployers.Deployer; import org.apache.maven.deploy.deployers.ExternalDeployer; import org.apache.maven.deploy.deployers.FileDeployer; @@ -35,13 +37,15 @@ import org.apache.maven.deploy.exceptions.UnsupportedProtocolException; * Utility class * * @author Michal Maczka - * @version $Id: DeployTool.java,v 1.11 2004/05/02 15:04:34 vmassol Exp $ + * @version $Id: DeployTool.java,v 1.12 2004/06/25 13:50:05 brett Exp $ */ public class DeployTool { /** Current Version **/ public static final String VERSION = "1.0-dev"; + private static final Log LOG = LogFactory.getLog(DeployTool.class); + /** * Returns deployer which is able to deploy to repository * described by host info. @@ -130,7 +134,7 @@ public class DeployTool String srcFile = (String) srcIterator.next(); String destFile = (String) destIterator.next(); DeployRequest request = new DeployRequest(srcFile, destFile); - System.out.println("Deploying: " + srcFile + "-->" + destFile); + LOG.info("Deploying: " + srcFile + "-->" + destFile); deployer.deploy(request); } } @@ -142,7 +146,8 @@ public class DeployTool } catch (Exception e) { + LOG.error("Error cleaning up from the deployer", e); } } } -} \ No newline at end of file +} diff --git a/artifact/src/main/org/apache/maven/deploy/deployers/ExternalDeployer.java b/artifact/src/main/org/apache/maven/deploy/deployers/ExternalDeployer.java index 24517d69..7e13fdad 100644 --- a/artifact/src/main/org/apache/maven/deploy/deployers/ExternalDeployer.java +++ b/artifact/src/main/org/apache/maven/deploy/deployers/ExternalDeployer.java @@ -17,6 +17,8 @@ package org.apache.maven.deploy.deployers; * ==================================================================== */ +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.maven.deploy.RepositoryInfo; import org.apache.maven.deploy.DeployRequest; import org.apache.maven.deploy.exceptions.AuthenticationException; @@ -27,7 +29,7 @@ import org.apache.maven.deploy.exceptions.TransferFailedException; * Deployers which for every deployment request * starts a new external process (e.g batch file, shell script) * - * @version $Id: ExternalDeployer.java,v 1.4 2004/03/02 14:59:31 evenisse Exp $ + * @version $Id: ExternalDeployer.java,v 1.5 2004/06/25 13:50:05 brett Exp $ * @todo still have to account for differing setups for people deploying to * their own sites and to the central repository. * @todo finich @@ -39,6 +41,8 @@ public class ExternalDeployer extends AbstractDeployer private String cmd = null; + private static final Log LOG = LogFactory.getLog(ExternalDeployer.class); + /* (non-Javadoc) * @see org.apache.maven.deploy.deployers.Deployer#init(org.apache.maven.deploy.HostInfo) */ @@ -68,14 +72,14 @@ public class ExternalDeployer extends AbstractDeployer try { - System.out.println( + LOG.debug( "Staring external process: '" + cmd + "' to deploy:'" + request.getDestFile()); Process process = Runtime.getRuntime().exec(cmd, params); process.waitFor(); - System.out.println("External process finished"); + LOG.debug("External process finished"); } catch (Exception e) { diff --git a/artifact/src/main/org/apache/maven/deploy/deployers/FtpDeployer.java b/artifact/src/main/org/apache/maven/deploy/deployers/FtpDeployer.java index 95ab6875..b014b648 100644 --- a/artifact/src/main/org/apache/maven/deploy/deployers/FtpDeployer.java +++ b/artifact/src/main/org/apache/maven/deploy/deployers/FtpDeployer.java @@ -22,6 +22,8 @@ import java.io.IOException; import java.io.PrintWriter; import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.commons.net.ProtocolCommandEvent; import org.apache.commons.net.ProtocolCommandListener; import org.apache.commons.net.ftp.FTP; @@ -40,10 +42,10 @@ import org.apache.maven.deploy.exceptions.TransferFailedException; * * @author Jason van Zyl * @author Michal Maczka - * @version $Id: FtpDeployer.java,v 1.10 2004/06/14 13:36:48 brett Exp $ + * @version $Id: FtpDeployer.java,v 1.11 2004/06/25 13:50:05 brett Exp $ * * @todo review exception handling - * + * @todo don't spool to System.out * */ public class FtpDeployer extends AbstractDeployer @@ -52,6 +54,7 @@ public class FtpDeployer extends AbstractDeployer public final static String PROTOCOL = "ftp://"; private FTPClient ftp = null; + private static final Log LOG = LogFactory.getLog(FtpDeployer.class); /* (non-Javadoc) * @see org.apache.maven.deploy.deployers.Deployer#init(org.apache.maven.deploy.HostInfo) @@ -82,7 +85,7 @@ public class FtpDeployer extends AbstractDeployer { ftp.connect(host); } - System.out.println("Connected to " + host + "."); + LOG.info("Connected to " + host + "."); // After connection attempt, you should check the reply code to verify // success. @@ -91,7 +94,6 @@ public class FtpDeployer extends AbstractDeployer if (FTPReply.isPositiveCompletion(reply) == false) { ftp.disconnect(); - System.err.println(); throw new AuthenticationException("FTP server refused connection."); } } @@ -118,7 +120,7 @@ public class FtpDeployer extends AbstractDeployer throw new AuthenticationException("Cannot login to remote system"); } - System.out.println("Remote system is " + ftp.getSystemName()); + LOG.info("Remote system is " + ftp.getSystemName()); // Set to binary mode. ftp.setFileType(FTP.BINARY_FILE_TYPE); diff --git a/artifact/src/main/org/apache/maven/deploy/deployers/GenericSshDeployer.java b/artifact/src/main/org/apache/maven/deploy/deployers/GenericSshDeployer.java index f6cb330a..48038e6a 100644 --- a/artifact/src/main/org/apache/maven/deploy/deployers/GenericSshDeployer.java +++ b/artifact/src/main/org/apache/maven/deploy/deployers/GenericSshDeployer.java @@ -19,6 +19,9 @@ package org.apache.maven.deploy.deployers; import java.io.File; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.apache.maven.deploy.RepositoryInfo; import org.apache.maven.deploy.exceptions.AuthenticationException; @@ -40,7 +43,7 @@ import com.jcraft.jsch.UserInfo; * and if that doesn't work then we fall back * to using the login and password * - * @version $Id: GenericSshDeployer.java,v 1.9 2004/06/14 13:36:48 brett Exp $ + * @version $Id: GenericSshDeployer.java,v 1.10 2004/06/25 13:50:05 brett Exp $ * @todo still have to account for differing setups for people deploying to * their own sites and to the central repository. * @todo improve exception handling @@ -58,6 +61,8 @@ public abstract class GenericSshDeployer extends AbstractDeployer private Session session = null; + private static final Log LOG = LogFactory.getLog(GenericSshDeployer.class); + /** * @return */ @@ -99,7 +104,7 @@ public abstract class GenericSshDeployer extends AbstractDeployer { port = DEFAULT_SSH_PORT; } - System.out.println("host: '" + repoInfo.getHost() + "'"); + LOG.debug("host: '" + repoInfo.getHost() + "'"); String host = repoInfo.getHost(); session = jsch.getSession(repoInfo.getUserName(), host, port); @@ -120,7 +125,7 @@ public abstract class GenericSshDeployer extends AbstractDeployer throw new AuthenticationException(msg); } - System.out.println("Using private key: " + privateKey); + LOG.info("Using private key: " + privateKey); jsch.addIdentity( privateKey.getAbsolutePath(), repoInfo.getPassphrase()); @@ -229,7 +234,7 @@ public abstract class GenericSshDeployer extends AbstractDeployer */ public void showMessage(String message) { - System.out.println(message); + LOG.info(message); } diff --git a/artifact/src/main/org/apache/maven/deploy/deployers/HttpDeployer.java b/artifact/src/main/org/apache/maven/deploy/deployers/HttpDeployer.java index 183895b0..d93cd775 100644 --- a/artifact/src/main/org/apache/maven/deploy/deployers/HttpDeployer.java +++ b/artifact/src/main/org/apache/maven/deploy/deployers/HttpDeployer.java @@ -38,7 +38,7 @@ import org.apache.maven.deploy.exceptions.TransferFailedException; * An HTTP deployer based the Commons HttpClient library. * * @author Jason van Zyl - * @version $Id: HttpDeployer.java,v 1.6 2004/03/02 14:59:31 evenisse Exp $ + * @version $Id: HttpDeployer.java,v 1.7 2004/06/25 13:50:05 brett Exp $ * * @todo still have to account for differing setups for people deploying to * their own sites and to the central repository. @@ -137,16 +137,13 @@ public class HttpDeployer extends AbstractDeployer { client.executeMethod(method); } - catch (HttpException he) + catch (HttpException e) { - System.err.println("Http error connecting to '" + url + "'"); - System.err.println(he.getMessage()); - System.exit(-4); + throw new TransferFailedException("Http error connecting to '" + url + "'", e); } - catch (IOException ioe) + catch (IOException e) { - System.err.println("Unable to connect to '" + url + "'"); - System.exit(-3); + throw new TransferFailedException("Unable to connect to '" + url + "'", e); } //get the request headers diff --git a/artifact/src/main/org/apache/maven/deploy/deployers/SFtpDeployer.java b/artifact/src/main/org/apache/maven/deploy/deployers/SFtpDeployer.java index 5683a7c9..65b01b16 100644 --- a/artifact/src/main/org/apache/maven/deploy/deployers/SFtpDeployer.java +++ b/artifact/src/main/org/apache/maven/deploy/deployers/SFtpDeployer.java @@ -18,6 +18,9 @@ package org.apache.maven.deploy.deployers; */ import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.apache.maven.deploy.RepositoryInfo; import org.apache.maven.deploy.DeployRequest; import org.apache.maven.deploy.exceptions.AuthenticationException; @@ -32,10 +35,12 @@ import com.jcraft.jsch.SftpProgressMonitor; * An SSH2/SFTP deployer * * @author Michal Maczka - * @version $Revision: 1.10 $ $Date: 2004/06/14 13:36:48 $ + * @version $Revision: 1.11 $ $Date: 2004/06/25 13:50:05 $ */ public class SFtpDeployer extends GenericSshDeployer { + private static final Log LOG = LogFactory.getLog(SFtpDeployer.class); + /**Protocol understood by by this deployer*/ public final static String PROTOCOL = "sftp://"; @@ -145,12 +150,12 @@ public class SFtpDeployer extends GenericSshDeployer { if (getRepositoryInfo().isDebugOn()) { - System.out.println("Changing group to: " + groupId); + LOG.info("Changing group to: " + groupId); } channel.chgrp(groupId.intValue(), request.getDestFile()); if (getRepositoryInfo().isDebugOn()) { - System.out.println("Group successfully changed"); + LOG.info("Group successfully changed"); } } @@ -173,6 +178,7 @@ public class SFtpDeployer extends GenericSshDeployer } + /** @todo use logger */ class ProgressMonitor implements SftpProgressMonitor { diff --git a/artifact/src/main/org/apache/maven/deploy/deployers/ScpDeployer.java b/artifact/src/main/org/apache/maven/deploy/deployers/ScpDeployer.java index c1a2befd..f5f87d65 100644 --- a/artifact/src/main/org/apache/maven/deploy/deployers/ScpDeployer.java +++ b/artifact/src/main/org/apache/maven/deploy/deployers/ScpDeployer.java @@ -20,6 +20,9 @@ package org.apache.maven.deploy.deployers; import com.jcraft.jsch.ChannelExec; import com.jcraft.jsch.Session; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + import org.apache.maven.deploy.DeployRequest; import org.apache.maven.deploy.RepositoryInfo; import org.apache.maven.deploy.exceptions.AuthenticationException; @@ -39,10 +42,12 @@ import java.util.List; * An SSH2/SCP deployer * * @author Michal Maczka - * @version $Revision: 1.10 $ $Date: 2004/06/14 13:36:48 $ + * @version $Revision: 1.11 $ $Date: 2004/06/25 13:50:05 $ */ public class ScpDeployer extends GenericSshDeployer { + private static final Log LOG = LogFactory.getLog(ScpDeployer.class); + /**Protocol understood by this deployer*/ public final static String PROTOCOL = "scp://"; @@ -103,7 +108,7 @@ public class ScpDeployer extends GenericSshDeployer */ public void deploy(DeployRequest request) throws TransferFailedException { - System.out.println("deployNotCompressed=" + deployNotCompressed); + LOG.debug("deployNotCompressed=" + deployNotCompressed); if (deployNotCompressed) { doDeployNotCompressed(request); @@ -247,7 +252,7 @@ public class ScpDeployer extends GenericSshDeployer private void executeSimpleCommand(Session session, String command) throws TransferFailedException { - System.out.println("Executing command: " + command); + LOG.info("Executing command: " + command); ChannelExec channel = null; @@ -293,7 +298,7 @@ public class ScpDeployer extends GenericSshDeployer // exec 'scp -t rfile' remotely String command = "scp -t " + destFile; - System.out.println("Executing command: " + command); + LOG.debug("Executing command: " + command); channel = (ChannelExec) session.openChannel(EXEC_CHANNEL); channel.setCommand(command); @@ -339,20 +344,24 @@ public class ScpDeployer extends GenericSshDeployer while (tmp[0] != 0); // send a content of inputFile - FileInputStream fis = new FileInputStream(srcFile); byte[] buf = new byte[1024]; - - while (true) - { - int len = fis.read(buf, 0, buf.length); - - if (len <= 0) + FileInputStream fis = new FileInputStream(srcFile); + try { + while (true) { - break; + int len = fis.read(buf, 0, buf.length); + + if (len <= 0) + { + break; + } + + out.write(buf, 0, len); + out.flush(); } - - out.write(buf, 0, len); - out.flush(); + } + finally { + fis.close(); } // send '\0'