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 f14934d8..3fb3cd7f 100644 --- a/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java +++ b/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java @@ -56,7 +56,9 @@ package org.apache.maven.artifact.deployer; */ import java.io.File; +import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -67,13 +69,14 @@ import org.apache.maven.MavenConstants; import org.apache.maven.MavenException; import org.apache.maven.deploy.DeployTool; import org.apache.maven.project.Project; +import org.apache.maven.util.MD5Sum; /** * * Default implemenataion of Artifact Deployer interface * * @author Michal Maczka - * @version $Id: DefaultArtifactDeployer.java,v 1.4 2003/06/19 22:02:37 michal Exp $ + * @version $Id: DefaultArtifactDeployer.java,v 1.5 2003/06/20 15:24:52 michal Exp $ */ public class DefaultArtifactDeployer implements ArtifactDeployer { @@ -87,20 +90,34 @@ public class DefaultArtifactDeployer implements ArtifactDeployer /** * @see ArtifactDeployer#deploy(String, String, Project) */ - public void deploy(String file, String type, Project project) + public void deploy(String artifact, String type, Project project) throws MavenException { - System.out.println("deploy"); - doDeploy(file, type, project, project.getCurrentVersion()); + + File file = getFileForArtifact(artifact); + File md5File = createMD5Checksum(file); + String repositoryPath = + getRepositoryPath(type, project, project.getCurrentVersion()); + String repositoryFile = + getRepositoryFile(type, project, project.getCurrentVersion()); + doDeploy(file, md5File, project, repositoryPath, repositoryFile); } /** * @see DefaultArtifactDeployer#deploySnapshot(String, String, Project) */ - public void deploySnapshot(String file, String type, Project project) + public void deploySnapshot(String artifact, String type, Project project) throws MavenException { - doDeploy(file, type, project, MavenConstants.SNAPSHOT_SIGNIFIER); + File file = getFileForArtifact(artifact); + File md5File = createMD5Checksum(file); + String repositoryPath = + getRepositoryPath(type, project, MavenConstants.SNAPSHOT_SIGNIFIER); + String repositoryFile = + getRepositoryFile(type, project, MavenConstants.SNAPSHOT_SIGNIFIER); + doDeploy(file, md5File, project, repositoryPath, repositoryFile); + doDeploy(file, md5File, project, repositoryPath, repositoryFile); + } /** @@ -109,7 +126,8 @@ public class DefaultArtifactDeployer implements ArtifactDeployer public void install(String artifact, String type, Project project) throws MavenException { - doInstall(artifact, type, project, project.getCurrentVersion()); + File file = getFileForArtifact(artifact); + doInstall(file, type, project, project.getCurrentVersion()); } /** @@ -118,14 +136,11 @@ public class DefaultArtifactDeployer implements ArtifactDeployer public void installSnapshot(String artifact, String type, Project project) throws MavenException { + File file = getFileForArtifact(artifact); System.out.println("Installing snapshot of:'" + artifact + "''"); try { - doInstall( - artifact, - type, - project, - MavenConstants.SNAPSHOT_SIGNIFIER); + doInstall(file, type, project, MavenConstants.SNAPSHOT_SIGNIFIER); } catch (MavenException e) { @@ -133,7 +148,7 @@ public class DefaultArtifactDeployer implements ArtifactDeployer } try { - doInstall(artifact, type, project, getSnapshotVersion()); + doInstall(file, type, project, getSnapshotVersion()); } catch (MavenException e) { @@ -150,7 +165,7 @@ public class DefaultArtifactDeployer implements ArtifactDeployer * @throws MavenException */ private void doInstall( - String artifact, + File file, String type, Project project, String version) @@ -158,27 +173,26 @@ public class DefaultArtifactDeployer implements ArtifactDeployer { try - { - File file = + { + File destFile = new File( getLocalRepository(project), getRepositoryPath(type, project, version)); - if (!file.exists()) { file.mkdirs(); } file = new File(file, getRepositoryFile(type, project, version)); System.out.println( - "Copying: from '" + artifact + "' to: '" + file + "'"); - FileUtils.copyFile(new File(artifact), file); + "Copying: from '" + file + "' to: '" + destFile + "'"); + FileUtils.copyFile(file, destFile); } catch (IOException e) { String msg = "Cannot install file: '" - + artifact + + file + "'. Reason: " + e.getMessage(); throw new MavenException(msg, e); @@ -193,10 +207,11 @@ public class DefaultArtifactDeployer implements ArtifactDeployer * @param snapshot */ private void doDeploy( - String artifact, - String type, + File file, + File md5File, Project project, - String version) + String repositoryPath, + String repositoryFile) throws MavenException { @@ -206,8 +221,8 @@ public class DefaultArtifactDeployer implements ArtifactDeployer String repos = (String) project.getContext().getVariable("maven.repo.repos"); - - System.out.println( "repos: "+ repos ); + + System.out.println("repos: " + repos); String distSite = project.getDistributionSite(); if (distSite != null && distSite.length() > 0) @@ -221,50 +236,69 @@ public class DefaultArtifactDeployer implements ArtifactDeployer repos = "central, " + repos; } - if (repos == null || repos.length() == 0) { - System.out.println("No remote repository is defined"); - return; + System.out.println("No remote repository is defined"); + return; } String[] repoArray = StringUtils.split(repos, ","); System.out.println( "Will deploy to " + repoArray.length + " repo(s): " + repos); + - String repositoryPath = getRepositoryPath(type, project, version); - + for (int i = 0; i < repoArray.length; i++) { String repo = repoArray[i].trim(); System.out.println("Deploying to repo: " + repo); - MavenDeployRequest request = + MavenDeployRequest deployRequest = new MavenDeployRequest( repo, project, repo, - artifact, + file.getAbsolutePath(), repositoryPath, - getRepositoryFile(type, project, version)); + repositoryFile); + + MavenDeployRequest md5DeployRequest = + new MavenDeployRequest( + repo, + project, + repo, + md5File.getAbsolutePath(), + repositoryPath, + repositoryFile + ".md5"); - System.out.println( - "Deploying: '" - + artifact - + "' to host: '" - + request.getHost() - + "' remote path: '" - + request.getOutputDir()); try { - deployTool.performUpload(request); + System.out.println( + "Deploying: '" + + file + + "' to host: '" + + deployRequest.getHost() + + "' remote path: '" + + deployRequest.getOutputDir()); + deployTool.performUpload(deployRequest); + + System.out.println( + "Deploying: '" + + md5File + + "' to host: '" + + md5DeployRequest.getHost() + + "' remote path: '" + + md5DeployRequest.getOutputDir()); + deployTool.performUpload(md5DeployRequest); } catch (Exception e) { e.printStackTrace(); - throw new MavenException("Cannot deploy. Reason:" + e.getMessage(), e); + throw new MavenException( + "Cannot deploy. Reason:" + e.getMessage(), + e); } } @@ -338,4 +372,95 @@ public class DefaultArtifactDeployer implements ArtifactDeployer return type; } + /** + * + * @param artifact + * @return + */ + private File getFileForArtifact(String artifact) throws MavenException + { + File file = new File(artifact); + if (!file.exists()) + { + String msg = "Artifact file: '" + artifact + "' must exist"; + throw new MavenException(msg); + } + if (!file.canRead()) + { + String msg = "Artifact file: '" + artifact + "' must be readable"; + throw new MavenException(msg); + } + if (file.isDirectory()) + { + String msg = + "Artifact file: '" + artifact + "' must not be a directory"; + throw new MavenException(msg); + } + return file.getAbsoluteFile(); + + } + + private File createMD5Checksum(File file) throws MavenException + { + MD5Sum md5Sum = new MD5Sum(); + md5Sum.setFile(file); + try + { + md5Sum.execute(); + } + catch (Exception e) + { + + throw new MavenException("MD5 checksum error: " + e.getMessage(), e); + } + String checksum = md5Sum.getChecksum(); + + String basename = FileUtils.basename(file.getAbsolutePath()); + File md5ChecksumFile = null; + try + { + md5ChecksumFile = + File.createTempFile(basename, ".md5", file.getParentFile()); + } + catch (IOException e) + { + // Cannot create file in the same directory where we have + // will try in default temporary-file directory + try + { + md5ChecksumFile = File.createTempFile(basename, ".md5"); + } + catch (Exception e2) + { + throw new MavenException("Cannot create md5 checksum file"); + } + } + Writer writer = null; + try + { + System.out.println("sum:" + checksum); + writer = new FileWriter(md5ChecksumFile); + writer.write(checksum); + } + catch (IOException e1) + { + throw new MavenException("Error occured while writing to md5 cheksum file"); + } + finally + { + if (writer != null) + { + try + { + writer.close(); + } + catch (IOException e2) + { + } + } + } + return md5ChecksumFile; + + } + } diff --git a/artifact/src/main/org/apache/maven/artifact/deployer/MavenDeployRequest.java b/artifact/src/main/org/apache/maven/artifact/deployer/MavenDeployRequest.java index 6a1f96e8..4ba6db1b 100644 --- a/artifact/src/main/org/apache/maven/artifact/deployer/MavenDeployRequest.java +++ b/artifact/src/main/org/apache/maven/artifact/deployer/MavenDeployRequest.java @@ -64,7 +64,7 @@ import org.apache.maven.project.Project; * The Bean which serves as Proxy for Jelly scripts To Artifact Deployement API * * @author Michal Maczka - * @version $Id: MavenDeployRequest.java,v 1.3 2003/06/19 22:02:37 michal Exp $ + * @version $Id: MavenDeployRequest.java,v 1.4 2003/06/20 15:24:52 michal Exp $ */ public class MavenDeployRequest extends DeployRequest { @@ -167,9 +167,12 @@ public class MavenDeployRequest extends DeployRequest setInputFile(inputFile); - String ouputDir = dir + "/" + outputDir; + if (dir != null) + { + outputDir = dir + "/" + outputDir; + } setOutputFile(outputFile); - setOutputDir(ouputDir); + setOutputDir(outputDir); } diff --git a/artifact/src/main/org/apache/maven/deploy/deployers/FileDeployer.java b/artifact/src/main/org/apache/maven/deploy/deployers/FileDeployer.java index e92f4614..374b338f 100644 --- a/artifact/src/main/org/apache/maven/deploy/deployers/FileDeployer.java +++ b/artifact/src/main/org/apache/maven/deploy/deployers/FileDeployer.java @@ -66,7 +66,7 @@ import org.apache.maven.deploy.exceptions.DeployException; /** * * @author Michal Maczka - * @version $Id: FileDeployer.java,v 1.2 2003/06/19 22:02:36 michal Exp $ + * @version $Id: FileDeployer.java,v 1.3 2003/06/20 15:24:52 michal Exp $ */ public class FileDeployer implements Deployer { @@ -87,10 +87,7 @@ public class FileDeployer implements Deployer { outputFile.mkdirs(); } - outputFile = new File( outputFile, request.getOutputFile()); - System.out.println("Copining from: " + inputFile + " to: " + outputFile); - - + outputFile = new File( outputFile, request.getOutputFile()); FileUtils.copyFile(inputFile, outputFile); } catch (IOException e)