Index: src/main/org/apache/maven/artifact/deployer/BaseArtifactDeployer.java
===================================================================
RCS file: src/main/org/apache/maven/artifact/deployer/BaseArtifactDeployer.java
diff -N src/main/org/apache/maven/artifact/deployer/BaseArtifactDeployer.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/main/org/apache/maven/artifact/deployer/BaseArtifactDeployer.java 10 Feb 2004 14:49:35 -0000
@@ -0,0 +1,122 @@
+
+/* ====================================================================
+ * 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
+ * .
+ *
+ * ====================================================================
+ */
+package org.apache.maven.artifact.deployer;
+
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.maven.MavenException;
+import org.apache.maven.deploy.DeployTool;
+import org.apache.maven.deploy.RepositoryInfo;
+import org.apache.maven.project.Project;
+
+/**
+ * @author Domingos Creado (dcreado@users.sf.net)
+ * @version 1.0
+ */
+public class BaseArtifactDeployer {
+
+ /**
+ * @param artifact
+ * @param type
+ * @param project
+ * @param snapshot
+ */
+ protected void doDeploy(List srcFiles, List destFiles, Project project , String repotype)
+ throws MavenException {
+
+ DeployTool deployTool = new DeployTool();
+
+ // trick add special values to context for default repository;
+
+ String repoStr =
+ (String) project.getContext().getVariable("maven."+repotype+".list");
+
+ if (repoStr == null || repoStr.length() == 0) {
+ System.out.println("No remote repository was defined.");
+ return;
+ }
+ String[] repos = StringUtils.split(repoStr, ",");
+
+ System.out.println(
+ "Will deploy to " + repos.length + " repository(ies): " + repoStr);
+ for (int i = 0; i < repos.length; i++) {
+
+ String repo = repos[i].trim();
+ System.out.println("Deploying to repository: " + repo);
+ RepositoryInfo repoInfo = null;
+ try {
+ repoInfo =
+ RepositoryInfoBuilder.getRepositoryInfo(project, repo, repotype);
+
+ deployTool.deploy(repoInfo, srcFiles, destFiles);
+ } catch (Exception e) {
+ String msg =
+ "Failed to deploy to: "
+ + repoInfo.getRepositoryAlias()
+ + " Reason: "
+ + e.getMessage();
+ System.out.print(msg);
+ // deploy to next repository
+ e.printStackTrace();
+ continue;
+ }
+
+ }
+ }
+
+}
Index: src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
===================================================================
RCS file: /home/cvspublic/maven-plugins/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java,v
retrieving revision 1.15
diff -u -r1.15 DefaultArtifactDeployer.java
--- src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java 10 Dec 2003 21:16:33 -0000 1.15
+++ src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java 10 Feb 2004 14:49:36 -0000
@@ -62,6 +62,8 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import java.util.PropertyResourceBundle;
+import java.util.ResourceBundle;
import java.util.TimeZone;
import org.apache.commons.io.FileUtils;
@@ -81,476 +83,391 @@
* @author Michal Maczka
* @version $Id: DefaultArtifactDeployer.java,v 1.15 2003/12/10 21:16:33 epugh Exp $
*/
-public class DefaultArtifactDeployer implements ArtifactDeployer
-{
+public class DefaultArtifactDeployer
+ extends BaseArtifactDeployer
+ implements ArtifactDeployer {
+
+ /**
+ * Indicate if POM of given artifact should be also deployed
+ * to remote repository*/
+ public static final boolean DEPLOY_POM = true;
+
+ /**
+ * Indicate if POM of given artifact should be also deployed
+ * in local repository*/
+ public static final boolean INSTALL_POM = true;
+
+ /**
+ * Indicate if snapshot versio of
+ * POM of given artifact should be also deployed
+ * to remote repository*/
+ public static final boolean DEPLOY_POM_SNAPSHOT = true;
+
+ /**
+ * Indicate if POM of given artifact should be also installed
+ * in local repository*/
+ public static final boolean INSTALL_POM_SNAPSHOT = true;
+
+ /**
+ * Date/time stamp which is appended to snapshot filenames
+ */
+ public final static DateFormat SNAPSHOT_SIGNATURE_FMT =
+ new SimpleDateFormat("yyyyMMdd.HHmmss");
+
+ static {
+ SNAPSHOT_SIGNATURE_FMT.setTimeZone(TimeZone.getTimeZone("GMT"));
+ }
+
+ /**
+ * @see ArtifactDeployer#deploy(String, String, Project)
+ *
+ * This is "5 files" version.
+ * It deploys (example):
+ * foo-20030620.124616.jar,
+ * foo-20030620.124616.jar.md5 ,
+ * foo-SNAPSHOT.jar
+ * foo-SNAPSHOT.jar.md5
+ * foo-snapshot-version
+ *
+ */
+ public void deploy(String artifact, String type, Project project)
+ throws MavenException {
+ File file;
+ if ("pom".equals(type)) {
+ file = project.getFile();
+ } else {
+ file = getFileForArtifact(artifact);
+ }
+ File md5File = createMD5Checksum(file);
+ String repositoryPath =
+ getRepositoryFullPath(type, project, project.getCurrentVersion());
+
+ List srcFiles = new ArrayList();
+ srcFiles.add(file.getAbsolutePath());
+ srcFiles.add(md5File.getAbsolutePath());
+
+ List destFiles = new ArrayList();
+ destFiles.add(repositoryPath);
+ destFiles.add(repositoryPath + ".md5");
+
+ //do not deploy POM twice
+ if (DEPLOY_POM && !"pom".equals(type)) {
+ deploy(artifact, "pom", project);
+ }
+ doDeploy(srcFiles, destFiles, project);
+ //Delete md5 file
+ md5File.delete();
+ }
+
+ /**
+ * @see DefaultArtifactDeployer#deploySnapshot(String, String, Project)
+ */
+ public void deploySnapshot(String artifact, String type, Project project)
+ throws MavenException {
+
+ String snapshotSignature = getSnapshotSignature();
+ File file;
+ if ("pom".equals(type)) {
+ file = project.getFile();
+ } else {
+ file = getFileForArtifact(artifact);
+ }
+ File md5File = createMD5Checksum(file);
+ File snapshotVersionFile =
+ createSnapshotVersionFile(file, snapshotSignature, project, type);
+
+ 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 =
+ getRepositoryFullPath(
+ type,
+ project,
+ MavenConstants.SNAPSHOT_SIGNIFIER);
+ String timestampedFilename =
+ getRepositoryFullPath(type, project, snapshotSignature);
+ String snapshotVersionsFilename =
+ getRepositoryDirectoryPath(type, project)
+ + project.getArtifactId()
+ + "-snapshot-version";
+
+ List destFiles = new ArrayList();
+ destFiles.add(snapshotFilename);
+ destFiles.add(snapshotFilename + ".md5");
+ destFiles.add(timestampedFilename);
+ destFiles.add(timestampedFilename + ".md5");
+ destFiles.add(snapshotVersionsFilename);
+
+ // do not deploy POM twice
+ if (DEPLOY_POM_SNAPSHOT && !"pom".equals(type)) {
+ deploySnapshot(artifact, "pom", project);
+ }
+
+ doDeploy(srcFiles, destFiles, project);
+ // Delete md5 file
+ md5File.delete();
+ };
+
+ /**
+ * @see ArtifactDeployer#install(String, String, Project)
+ */
+ public void install(String artifact, String type, Project project)
+ throws MavenException {
+ File file;
+ if ("pom".equals(type)) {
+ file = project.getFile();
+ } else {
+ file = getFileForArtifact(artifact);
+ }
+ doInstall(file, type, project, project.getCurrentVersion());
+ // do not install twice
+ if (INSTALL_POM && !"pom".equals(type)) {
+ doInstall(
+ project.getFile(),
+ "pom",
+ project,
+ project.getCurrentVersion());
+ }
+ }
+
+ /**
+ * @see ArtifactDeployer#installSnapshot(String, String, Project)
+ */
+ public void installSnapshot(String artifact, String type, Project project)
+ throws MavenException {
+ File file;
+ if ("pom".equals(type)) {
+ file = project.getFile();
+ } else {
+ file = getFileForArtifact(artifact);
+ }
+ String snapshotSignature = getSnapshotSignature();
+ System.out.println("Installing snapshot of:'" + artifact + "''");
+ doInstall(file, type, project, MavenConstants.SNAPSHOT_SIGNIFIER);
+ doInstall(file, type, project, snapshotSignature);
+ if (INSTALL_POM_SNAPSHOT && !"pom".equals(type)) {
+ File projectFile = project.getFile();
+ doInstall(
+ projectFile,
+ "pom",
+ project,
+ MavenConstants.SNAPSHOT_SIGNIFIER);
+ doInstall(projectFile, "pom", project, snapshotSignature);
+ }
+ }
+
+ /**
+ * Install given file in local repository
+ * @param artifact the artifact file to install
+ * @param type The type of the artiafct
+ * @param project
+ * @param version String denominating the version of the artifact
+ * @throws MavenException
+ */
+ private void doInstall(
+ File file,
+ String type,
+ Project project,
+ String version)
+ throws MavenException {
+ try {
+ File destFile =
+ new File(
+ getLocalRepository(project),
+ getRepositoryFullPath(type, project, version));
+ if (!destFile.getParentFile().exists()) {
+ destFile.getParentFile().mkdirs();
+ }
+ System.out.println(
+ "Copying: from '" + file + "' to: '" + destFile + "'");
+ FileUtils.copyFile(file, destFile);
+ } catch (IOException e) {
+ String msg =
+ "Cannot install file: '"
+ + file
+ + "'. Reason: "
+ + e.getMessage();
+ throw new MavenException(msg, e);
+ }
+ }
+
+ /**
+ * @param artifact
+ * @param type
+ * @param project
+ */
+ private void doDeploy(List srcFiles, List destFiles, Project project)
+ throws MavenException {
+
+ super.doDeploy(srcFiles, destFiles, project, "repo");
+
+ }
+
+ /**
+ * Return the local repository path form given project
+ * @param project
+ * @return The path to local repoository in local file system
+ */
+ private String getLocalRepository(Project project) {
+ return project.getContext().getMavenRepoLocal();
+ }
+
+ /**
+ * Return relative path from repositorry root
+ * for given parameters
+ * @param type Artifact type
+ * @param project
+ * @param snapshot
+ * @return
+ * @todo replace this with RepoistoryLayout Service
+ */
+ private String getRepositoryFullPath(
+ String type,
+ Project project,
+ String version) {
+ StringBuffer path = new StringBuffer();
+ path.append(project.getArtifactDirectory());
+ path.append("/");
+ path.append(type + "s");
+ path.append("/");
+ path.append(project.getArtifactId());
+ path.append("-");
+ path.append(version);
+ path.append(".");
+ path.append(extensionForType(type));
+ return path.toString();
+ }
+
+ /**
+ * Return relative path from repositorry root to a directory where
+ * given artifact will be stored
+ * @param type Artifact type
+ * @param project
+ * @param snapshot
+ * @return
+ * @todo replace this with RepoistoryLayout Service
+ */
+ private String getRepositoryDirectoryPath(String type, Project project) {
+ StringBuffer path = new StringBuffer();
+ path.append(project.getArtifactDirectory());
+ path.append("/");
+ path.append(type + "s");
+ path.append("/");
+ return path.toString();
+ }
+
+ /**
+ *
+ * @return
+ */
+ private String getSnapshotSignature() {
+ Date now = new Date();
+ return SNAPSHOT_SIGNATURE_FMT.format(now);
+ }
+
+ /**
+ *
+ * @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();
+ }
+
+ /**
+ * Create a file which contains timestamp of the latetst snapshot
+ *
+ * @param snapshotVersion
+ * @param project
+ * @param type
+ * @return
+ */
+ private File createSnapshotVersionFile(
+ File artifact,
+ String snapshotVersion,
+ Project project,
+ String type)
+ throws MavenException {
+ File file = null;
+ String filename =
+ project.getArtifactId() + "-" + type + "-snapshot-version";
+ try {
+ file = new File(artifact.getParent(), filename);
+ FileUtils.fileWrite(file.getAbsolutePath(), snapshotVersion);
+
+ } catch (Exception e) {
+ throw new MavenException(
+ "Cannot create snapshot-version file:" + file);
+ }
+ return file;
+ }
+
+ /**
+ * Create MD5 checksum file for given file. File is created
+ * in the same folder
+ * @param File
+ * @return The File which contatins MD5 checksum
+ * @throws MavenException when opertaion failed
+ */
+ 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();
+
+ File md5ChecksumFile = null;
+ try {
+ md5ChecksumFile = new File(file.getAbsoluteFile() + ".md5");
+ FileUtils.fileWrite(md5ChecksumFile.getAbsolutePath(), checksum);
+ } catch (Exception e) {
+ throw new MavenException(
+ "Cannot create md5 checksum file: " + md5ChecksumFile);
+
+ }
+ return md5ChecksumFile;
+ }
+
+ /**
+ * Return file extension for given type
+ * @todo Dirty hack Repository Layout Service from maven-new should be used
+ * @return extension for given type
+ */
+ private String extensionForType(String type) {
+ String extension = null;
+ try {
+
+ ResourceBundle res =
+ PropertyResourceBundle.getBundle(
+ "plugin-resources.ArtifactExtensions");
+ return res.getString(type);
+ } catch (java.util.MissingResourceException e) {
+ return type;
+ }
- /**
- * Indicate if POM of given artifact should be also deployed
- * to remote repository*/
- public static final boolean DEPLOY_POM = true;
-
- /**
- * Indicate if POM of given artifact should be also deployed
- * in local repository*/
- public static final boolean INSTALL_POM = true;
-
- /**
- * Indicate if snapshot versio of
- * POM of given artifact should be also deployed
- * to remote repository*/
- public static final boolean DEPLOY_POM_SNAPSHOT = true;
-
- /**
- * Indicate if POM of given artifact should be also installed
- * in local repository*/
- public static final boolean INSTALL_POM_SNAPSHOT = true;
-
- /**
- * Date/time stamp which is appended to snapshot filenames
- */
- public final static DateFormat SNAPSHOT_SIGNATURE_FMT =
- new SimpleDateFormat("yyyyMMdd.HHmmss");
-
- static {
- SNAPSHOT_SIGNATURE_FMT.setTimeZone(TimeZone.getTimeZone("GMT"));
- }
-
- /**
- * @see ArtifactDeployer#deploy(String, String, Project)
- *
- * This is "5 files" version.
- * It deploys (example):
- * foo-20030620.124616.jar,
- * foo-20030620.124616.jar.md5 ,
- * foo-SNAPSHOT.jar
- * foo-SNAPSHOT.jar.md5
- * foo-snapshot-version
- *
- */
- public void deploy(String artifact, String type, Project project)
- throws MavenException
- {
- File file;
- if("pom".equals(type))
- {
- file = project.getFile();
- }
- else
- {
- file = getFileForArtifact(artifact);
- }
- File md5File = createMD5Checksum(file);
- String repositoryPath =
- getRepositoryFullPath(type, project, project.getCurrentVersion());
-
- List srcFiles = new ArrayList();
- srcFiles.add(file.getAbsolutePath());
- srcFiles.add(md5File.getAbsolutePath());
-
- List destFiles = new ArrayList();
- destFiles.add(repositoryPath);
- destFiles.add(repositoryPath + ".md5");
-
- //do not deploy POM twice
- if (DEPLOY_POM && !"pom".equals(type))
- {
- deploy(artifact, "pom", project);
- }
- doDeploy(srcFiles, destFiles, project);
- //Delete md5 file
- md5File.delete();
- }
-
- /**
- * @see DefaultArtifactDeployer#deploySnapshot(String, String, Project)
- */
- public void deploySnapshot(String artifact, String type, Project project)
- throws MavenException
- {
-
- String snapshotSignature = getSnapshotSignature();
- File file;
- if("pom".equals(type))
- {
- file = project.getFile();
- }
- else
- {
- file = getFileForArtifact(artifact);
- }
- File md5File = createMD5Checksum(file);
- File snapshotVersionFile =
- createSnapshotVersionFile(file, snapshotSignature, project, type);
-
- 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 =
- getRepositoryFullPath(
- type,
- project,
- MavenConstants.SNAPSHOT_SIGNIFIER);
- String timestampedFilename =
- getRepositoryFullPath(type, project, snapshotSignature);
- String snapshotVersionsFilename =
- getRepositoryDirectoryPath(type, project)
- + project.getArtifactId()
- + "-snapshot-version";
-
- List destFiles = new ArrayList();
- destFiles.add(snapshotFilename);
- destFiles.add(snapshotFilename + ".md5");
- destFiles.add(timestampedFilename);
- destFiles.add(timestampedFilename + ".md5");
- destFiles.add(snapshotVersionsFilename);
-
- // do not deploy POM twice
- if (DEPLOY_POM_SNAPSHOT && !"pom".equals(type))
- {
- deploySnapshot(artifact, "pom", project);
- }
-
- doDeploy(srcFiles, destFiles, project);
- // Delete md5 file
- md5File.delete();
- };
-
- /**
- * @see ArtifactDeployer#install(String, String, Project)
- */
- public void install(String artifact, String type, Project project)
- throws MavenException
- {
- File file;
- if("pom".equals(type))
- {
- file = project.getFile();
- }
- else
- {
- file = getFileForArtifact(artifact);
- }
- doInstall(file, type, project, project.getCurrentVersion());
- // do not install twice
- if (INSTALL_POM && !"pom".equals(type))
- {
- doInstall(
- project.getFile(),
- "pom",
- project,
- project.getCurrentVersion());
- }
- }
-
- /**
- * @see ArtifactDeployer#installSnapshot(String, String, Project)
- */
- public void installSnapshot(String artifact, String type, Project project)
- throws MavenException
- {
- File file;
- if("pom".equals(type))
- {
- file = project.getFile();
- }
- else
- {
- file = getFileForArtifact(artifact);
- }
- String snapshotSignature = getSnapshotSignature();
- System.out.println("Installing snapshot of:'" + artifact + "''");
- doInstall(file, type, project, MavenConstants.SNAPSHOT_SIGNIFIER);
- doInstall(file, type, project, snapshotSignature);
- if (INSTALL_POM_SNAPSHOT && !"pom".equals(type))
- {
- File projectFile = project.getFile();
- doInstall(
- projectFile,
- "pom",
- project,
- MavenConstants.SNAPSHOT_SIGNIFIER);
- doInstall(projectFile, "pom", project, snapshotSignature);
- }
- }
-
- /**
- * Install given file in local repository
- * @param artifact the artifact file to install
- * @param type The type of the artiafct
- * @param project
- * @param version String denominating the version of the artifact
- * @throws MavenException
- */
- private void doInstall(
- File file,
- String type,
- Project project,
- String version)
- throws MavenException
- {
- try
- {
- File destFile =
- new File(
- getLocalRepository(project),
- getRepositoryFullPath(type, project, version));
- if (!destFile.getParentFile().exists())
- {
- destFile.getParentFile().mkdirs();
- }
- System.out.println(
- "Copying: from '" + file + "' to: '" + destFile + "'");
- FileUtils.copyFile(file, destFile);
- }
- catch (IOException e)
- {
- String msg =
- "Cannot install file: '"
- + file
- + "'. Reason: "
- + e.getMessage();
- throw new MavenException(msg, e);
- }
- }
-
- /**
- * @param artifact
- * @param type
- * @param project
- * @param snapshot
- */
- private void doDeploy(List srcFiles, List destFiles, Project project)
- throws MavenException
- {
-
- DeployTool deployTool = new DeployTool();
-
- // trick add special values to context for default repository;
-
- String repoStr =
- (String) project.getContext().getVariable("maven.repo.list");
-
- if (repoStr == null || repoStr.length() == 0)
- {
- System.out.println("No remote repository was defined.");
- return;
- }
- String[] repos = StringUtils.split(repoStr, ",");
-
- System.out.println(
- "Will deploy to " + repos.length + " repository(ies): " + repoStr);
- for (int i = 0; i < repos.length; i++)
- {
-
- String repo = repos[i].trim();
- System.out.println("Deploying to repository: " + repo);
- RepositoryInfo repoInfo = null;
- try
- {
- repoInfo =
- RepositoryInfoBuilder.getRepositoryInfo(project, repo);
-
- deployTool.deploy(repoInfo, srcFiles, destFiles);
- }
- catch (Exception e)
- {
- String msg =
- "Failed to deploy to: "
- + repoInfo.getRepositoryAlias()
- + " Reason: "
- + e.getMessage();
- System.out.print(msg);
- // deploy to next repository
- e.printStackTrace();
- continue;
- }
-
- }
- }
-
- /**
- * Return the local repository path form given project
- * @param project
- * @return The path to local repoository in local file system
- */
- private String getLocalRepository(Project project)
- {
- return project.getContext().getMavenRepoLocal();
- }
-
- /**
- * Return relative path from repositorry root
- * for given parameters
- * @param type Artifact type
- * @param project
- * @param snapshot
- * @return
- * @todo replace this with RepoistoryLayout Service
- */
- private String getRepositoryFullPath(
- String type,
- Project project,
- String version)
- {
- StringBuffer path = new StringBuffer();
- path.append(project.getArtifactDirectory());
- path.append("/");
- path.append(type + "s");
- path.append("/");
- path.append(project.getArtifactId());
- path.append("-");
- path.append(version);
- path.append(".");
- path.append(extensionForType(type));
- return path.toString();
- }
-
- /**
- * Return relative path from repositorry root to a directory where
- * given artifact will be stored
- * @param type Artifact type
- * @param project
- * @param snapshot
- * @return
- * @todo replace this with RepoistoryLayout Service
- */
- private String getRepositoryDirectoryPath(String type, Project project)
- {
- StringBuffer path = new StringBuffer();
- path.append(project.getArtifactDirectory());
- path.append("/");
- path.append(type + "s");
- path.append("/");
- return path.toString();
- }
-
- /**
- *
- * @return
- */
- private String getSnapshotSignature()
- {
- Date now = new Date();
- return SNAPSHOT_SIGNATURE_FMT.format(now);
- }
-
- /**
- *
- * @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();
- }
-
- /**
- * Create a file which contains timestamp of the latetst snapshot
- *
- * @param snapshotVersion
- * @param project
- * @param type
- * @return
- */
- private File createSnapshotVersionFile(
- File artifact,
- String snapshotVersion,
- Project project,
- String type)
- throws MavenException
- {
- File file = null;
- String filename =
- project.getArtifactId() + "-" + type + "-snapshot-version";
- try
- {
- file = new File(artifact.getParent(), filename);
- FileUtils.fileWrite(file.getAbsolutePath(), snapshotVersion);
-
- }
- catch (Exception e)
- {
- throw new MavenException(
- "Cannot create snapshot-version file:" + file);
- }
- return file;
- }
-
- /**
- * Create MD5 checksum file for given file. File is created
- * in the same folder
- * @param File
- * @return The File which contatins MD5 checksum
- * @throws MavenException when opertaion failed
- */
- 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();
-
- File md5ChecksumFile = null;
- try
- {
- md5ChecksumFile = new File(file.getAbsoluteFile() + ".md5");
- FileUtils.fileWrite(md5ChecksumFile.getAbsolutePath(), checksum);
- }
- catch (Exception e)
- {
- throw new MavenException(
- "Cannot create md5 checksum file: " + md5ChecksumFile);
-
- }
- return md5ChecksumFile;
- }
-
- /**
- * Return file extension for given type
- * @todo Dirty hack Repository Layout Service from maven-new should be used
- * @return extension for given type
- */
- private String extensionForType(String type)
- {
- if (type.equals("ejb"))
- {
- return "jar";
- }
- else if (type.equals("plugin"))
- {
- return "jar";
- }
- return type;
- }
+ }
}
Index: src/main/org/apache/maven/artifact/deployer/DeployBean.java
===================================================================
RCS file: /home/cvspublic/maven-plugins/artifact/src/main/org/apache/maven/artifact/deployer/DeployBean.java,v
retrieving revision 1.3
diff -u -r1.3 DeployBean.java
--- src/main/org/apache/maven/artifact/deployer/DeployBean.java 29 Jun 2003 11:57:39 -0000 1.3
+++ src/main/org/apache/maven/artifact/deployer/DeployBean.java 10 Feb 2004 14:49:36 -0000
@@ -56,9 +56,10 @@
* ====================================================================
*/
+
+import java.io.File;
+
import org.apache.maven.MavenException;
-import org.apache.maven.artifact.deployer.ArtifactDeployer;
-import org.apache.maven.artifact.deployer.DefaultArtifactDeployer;
import org.apache.maven.project.Project;
/**
@@ -69,122 +70,142 @@
* @author Michal Maczka
* @version $Id: DeployBean.java,v 1.3 2003/06/29 11:57:39 michal Exp $
*/
-public class DeployBean
-{
- ArtifactDeployer artifactDeployer = null;
-
- private Project project = null;
- private String artifact = null;
- private String type = null;
-
- public DeployBean()
- {
- artifactDeployer = new DefaultArtifactDeployer();
- }
-
- /**
- * @return
- */
- public String getArtifact()
- {
- return artifact;
- }
-
- /**
- * @param artifact
- */
- public void setArtifact(String artifact)
- {
- this.artifact = artifact;
- }
-
- /**
- * @return
- */
- public Project getProject()
- {
- return project;
- }
-
- /**
- * @param project
- */
- public void setProject(Project project)
- {
- this.project = project;
- }
-
- /**
- * @return
- */
- public String getType()
- {
- return type;
- }
-
- /**
- * @param type
- */
- public void setType(String type)
- {
- this.type = type;
- }
-
- /**
- *
- * @throws MavenException
- */
- protected void checkAttributes() throws MavenException
- {
- if (project == null)
- {
- throw new MavenException("attribute 'project' is required");
- }
-
- if (artifact == null)
- {
- throw new MavenException("attribute 'artifact' is required");
- }
- if (type == null)
- {
- throw new MavenException("attribute 'type' is required");
- }
- }
-
- /**
- *
- */
- public void deploy() throws MavenException
- {
- checkAttributes();
- artifactDeployer.deploy(artifact, type, project);
- }
-
- /**
- *
- */
- public void deploySnapshot() throws MavenException
- {
- checkAttributes();
- artifactDeployer.deploySnapshot(artifact, type, project);
- }
-
- /**
- *
- */
- public void install() throws MavenException
- {
- checkAttributes();
- artifactDeployer.install(artifact, type, project);
- }
-
- /**
- *
- */
- public void installSnapshot() throws MavenException
- {
- checkAttributes();
- artifactDeployer.installSnapshot(artifact, type, project);
- }
+public class DeployBean {
+ ArtifactDeployer artifactDeployer = null;
+ private Project project = null;
+ private String artifact = null;
+ private String type = null;
+ private String repositoryType = "repo";
+
+
+ public DeployBean() {
+ //artifactDeployer = new DefaultArtifactDeployer();
+ }
+
+ /**
+ * @return
+ */
+ public String getArtifact() {
+ return artifact;
+ }
+
+ /**
+ * @param artifact
+ */
+ public void setArtifact(String artifact) {
+ this.artifact = artifact;
+ }
+
+ /**
+ * @return
+ */
+ public Project getProject() {
+ return project;
+ }
+
+ /**
+ * @param project
+ */
+ public void setProject(Project project) {
+ this.project = project;
+ }
+
+ /**
+ * @return
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @param type
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+
+ /**
+ * @return
+ */
+ public String getRepositoryType() {
+ return repositoryType;
+ }
+
+
+ /**
+ * @param string
+ */
+ public void setRepositoryType(String string) {
+ repositoryType = string;
+ }
+
+ /**
+ *
+ * @throws MavenException
+ */
+ protected void checkAttributes() throws MavenException {
+ if (project == null) {
+ throw new MavenException("attribute 'project' is required");
+ }
+
+ if (artifact == null) {
+ throw new MavenException("attribute 'artifact' is required");
+ }
+ File artifactObj = new File(artifact);
+ if(!artifactObj.exists() || !artifactObj.canRead()){
+ throw new MavenException("the artifact to deploy does not exists or I cann't read it");
+ }
+
+ if(repositoryType.equalsIgnoreCase("repo")){
+
+ if (type == null) {
+ throw new MavenException("attribute 'type' is required");
+ }
+ artifactDeployer = new DefaultArtifactDeployer();
+
+ } else if(repositoryType.equalsIgnoreCase("site")) {
+
+ artifactDeployer = new SiteArtifactDeployer();
+ } else {
+ throw new MavenException("attribute 'repositoryType' points to a unknow type of repository");
+ }
+ }
+
+ /**
+ *
+ */
+ public void deploy() throws MavenException {
+ checkAttributes();
+ getArtifactDeployer().deploy(artifact, type, project);
+ }
+
+ /**
+ *
+ */
+ public void deploySnapshot() throws MavenException {
+ checkAttributes();
+ getArtifactDeployer().deploySnapshot(artifact, type, project);
+ }
+
+ /**
+ *
+ */
+ public void install() throws MavenException {
+ checkAttributes();
+ getArtifactDeployer().install(artifact, type, project);
+ }
+
+ /**
+ *
+ */
+ public void installSnapshot() throws MavenException {
+ checkAttributes();
+ getArtifactDeployer().installSnapshot(artifact, type, project);
+ }
+
+ ArtifactDeployer getArtifactDeployer(){
+ return artifactDeployer;
+ }
}
Index: src/main/org/apache/maven/artifact/deployer/RepositoryInfoBuilder.java
===================================================================
RCS file: /home/cvspublic/maven-plugins/artifact/src/main/org/apache/maven/artifact/deployer/RepositoryInfoBuilder.java,v
retrieving revision 1.1
diff -u -r1.1 RepositoryInfoBuilder.java
--- src/main/org/apache/maven/artifact/deployer/RepositoryInfoBuilder.java 17 Jul 2003 11:13:17 -0000 1.1
+++ src/main/org/apache/maven/artifact/deployer/RepositoryInfoBuilder.java 10 Feb 2004 14:49:36 -0000
@@ -68,104 +68,115 @@
* @author Michal Maczka
* @version $Id: RepositoryInfoBuilder.java,v 1.1 2003/07/17 11:13:17 michal Exp $
*/
-public class RepositoryInfoBuilder
-{
+public class RepositoryInfoBuilder {
- /**
- *
- * @param project. Will lookup the properties in the context of this project
- * @param repository The name (alias) of the repository
- * like repo1 taken from property: maven.deploy.repos= repo1, repo2
- * @return Deploy request
- * @throws WrongParameterException
- */
- public static RepositoryInfo getRepositoryInfo(
- Project project,
- String repository)
- throws MalformedURLException
- {
-
- RepositoryInfo repoInfo = new RepositoryInfo();
- repoInfo.setRepositoryAlias(repository);
- String url =
- (String) project.getContext().getVariable(
- "maven.repo." + repository);
- String username =
- (String) project.getContext().getVariable(
- "maven.repo." + repository + ".username");
-
- String password =
- (String) project.getContext().getVariable(
- "maven.repo." + repository + ".password");
-
- String passphrase =
- (String) project.getContext().getVariable(
- "maven.repo." + repository + ".passphrase");
-
- String privateKey =
- (String) project.getContext().getVariable(
- "maven.repo." + repository + ".privatekey");
-
- String dir =
- (String) project.getContext().getVariable(
- "maven.repo." + repository + ".directory");
-
- String port =
- (String) project.getContext().getVariable(
- "maven.repo." + repository + ".port");
-
- String remoteGroup =
- (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();
-
- repoInfo.setUserName(username);
- repoInfo.setPassword(password);
- repoInfo.setPassphrase(passphrase);
- repoInfo.setPrivateKey(privateKey);
- repoInfo.setGroup(remoteGroup);
- repoInfo.setUrl(url);
- repoInfo.setProxyHost(proxyHost);
- repoInfo.setProxyUserName(proxyUser);
- repoInfo.setProxyPassword(proxyPassword);
- if (port != null)
- {
- try
- {
-
- repoInfo.setPort(Integer.parseInt(port));
- }
- catch (Exception e)
- {
- throw new MalformedURLException(
- "maven.repo." + repository + ".port should be an integer");
- }
- }
- if (proxyPort != null)
- {
- try
- {
- repoInfo.setProxyPort(
- Integer.parseInt(proxyPort.trim()));
- }
- catch (Exception e)
- {
- throw new MalformedURLException(
- "maven.repo."
- + repository
- + ".proxy.port should be an integer");
- }
- }
+ /**
+ *
+ * @param project. Will lookup the properties in the context of this project
+ * @param repository The name (alias) of the repository
+ * like repo1 taken from property: maven.deploy.repos= repo1, repo2
+ * @return Repository Information
+ * @throws MalformedURLException
+ */
+ public static RepositoryInfo getRepositoryInfo(
+ Project project,
+ String repository)
+ throws MalformedURLException {
+ return getRepositoryInfo(project, repository, "repo");
+
+ }
+
+ /**
+ *
+ * @param project. Will lookup the properties in the context of this project
+ * @param repository The name (alias) of the repository
+ * like repo1 taken from property: maven.deploy.repos= repo1, repo2
+ * @param repotype The prefix of the repository properties
+ * @return Repository Information
+ * @throws MalformedURLException
+ */
+ public static RepositoryInfo getRepositoryInfo(
+ Project project,
+ String repository,
+ String repotype)
+ throws MalformedURLException {
+ RepositoryInfo repoInfo = new RepositoryInfo();
+ repoInfo.setRepositoryAlias(repository);
+ String url =
+ (String) project.getContext().getVariable(
+ "maven." + repotype + "." + repository);
+ String username =
+ (String) project.getContext().getVariable(
+ "maven." + repotype + "." + repository + ".username");
+
+ String password =
+ (String) project.getContext().getVariable(
+ "maven." + repotype + "." + repository + ".password");
+
+ String passphrase =
+ (String) project.getContext().getVariable(
+ "maven." + repotype + "." + repository + ".passphrase");
+
+ String privateKey =
+ (String) project.getContext().getVariable(
+ "maven." + repotype + "." + repository + ".privatekey");
+
+ String dir =
+ (String) project.getContext().getVariable(
+ "maven." + repotype + "." + repository + ".directory");
+
+ String port =
+ (String) project.getContext().getVariable(
+ "maven." + repotype + "." + repository + ".port");
+
+ String remoteGroup =
+ (String) project.getContext().getVariable(
+ "maven." + repotype + "." + 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();
+
+ repoInfo.setUserName(username);
+ repoInfo.setPassword(password);
+ repoInfo.setPassphrase(passphrase);
+ repoInfo.setPrivateKey(privateKey);
+ repoInfo.setGroup(remoteGroup);
+ repoInfo.setUrl(url);
+ repoInfo.setProxyHost(proxyHost);
+ repoInfo.setProxyUserName(proxyUser);
+ repoInfo.setProxyPassword(proxyPassword);
+ if (port != null) {
+ try {
+
+ repoInfo.setPort(Integer.parseInt(port));
+ } catch (Exception e) {
+ throw new MalformedURLException(
+ "maven."
+ + repotype
+ + "."
+ + repository
+ + ".port should be an integer");
+ }
+ }
+ if (proxyPort != null) {
+ try {
+ repoInfo.setProxyPort(Integer.parseInt(proxyPort.trim()));
+ } catch (Exception e) {
+ throw new MalformedURLException(
+ "maven."
+ + repotype
+ + "."
+ + repository
+ + ".proxy.port should be an integer");
+ }
+ }
- repoInfo.setBasedir(dir);
- return repoInfo;
-
- }
+ repoInfo.setBasedir(dir);
+ return repoInfo;
+ }
}
Index: src/main/org/apache/maven/artifact/deployer/SiteArtifactDeployer.java
===================================================================
RCS file: src/main/org/apache/maven/artifact/deployer/SiteArtifactDeployer.java
diff -N src/main/org/apache/maven/artifact/deployer/SiteArtifactDeployer.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/main/org/apache/maven/artifact/deployer/SiteArtifactDeployer.java 10 Feb 2004 14:49:36 -0000
@@ -0,0 +1,161 @@
+/* ====================================================================
+ * 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
+ * .
+ *
+ * ====================================================================
+ */
+package org.apache.maven.artifact.deployer;
+
+import java.io.File;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.maven.MavenException;
+import org.apache.maven.project.Project;
+
+/**
+ * @author Domingos Creado (dcreado@users.sf.net)
+ * @version 1.0
+ */
+public class SiteArtifactDeployer
+ extends BaseArtifactDeployer
+ implements ArtifactDeployer {
+
+ /* (non-Javadoc)
+ * @see org.apache.maven.artifact.deployer.ArtifactDeployer#deploy(java.lang.String, java.lang.String, org.apache.maven.project.Project)
+ */
+ public void deploy(String artifact, String type, Project project)
+ throws MavenException {
+ List source = new LinkedList();
+ List target = new LinkedList();
+ createDeployFileList(source, target, artifact, project);
+ super.doDeploy(source, target, project, "site");
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.maven.artifact.deployer.ArtifactDeployer#deploySnapshot(java.lang.String, java.lang.String, org.apache.maven.project.Project)
+ */
+ public void deploySnapshot(String artifact, String type, Project project)
+ throws MavenException {
+ deploy(artifact, type, project);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.maven.artifact.deployer.ArtifactDeployer#install(java.lang.String, java.lang.String, org.apache.maven.project.Project)
+ */
+ public void install(String artifact, String type, Project project)
+ throws MavenException {
+ throw new MavenException("site repository does not support this operation");
+
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.maven.artifact.deployer.ArtifactDeployer#installSnapshot(java.lang.String, java.lang.String, org.apache.maven.project.Project)
+ */
+ public void installSnapshot(String artifact, String type, Project project)
+ throws MavenException {
+ throw new MavenException("site repository does not support this operation");
+ }
+
+ /**
+ * @param source
+ * @param target
+ */
+ private void createDeployFileList(
+ List source,
+ List target,
+ String artifact,
+ Project project) {
+ File sourceArtifact = new File(artifact);
+
+ if (!sourceArtifact.isDirectory()) {
+ source.add(artifact);
+ target.add("");
+ return;
+ }
+
+ String relativeTargetPath = project.getArtifactDirectory() + "/";
+ File relativeRootFolder = sourceArtifact;
+ createFileList(source, target, relativeRootFolder, relativeTargetPath);
+
+ }
+
+ /**
+ * @param source
+ * @param target
+ * @param relativeRootFolder
+ * @param relativeTargetPath
+ */
+ private void createFileList(
+ List source,
+ List target,
+ File relativeRootFolder,
+ String relativeTargetPath) {
+
+ String[] childrens = relativeRootFolder.list();
+ for (int i = 0; i < childrens.length; i++) {
+ String aFile = childrens[i];
+ File aFileObj =
+ new File(relativeRootFolder.getAbsolutePath(), aFile);
+ if (aFileObj.isFile()) {
+ source.add(aFileObj.getAbsolutePath());
+ target.add(relativeTargetPath + aFile);
+ } else {
+ createFileList(
+ source,
+ target,
+ aFileObj,
+ relativeTargetPath + aFile + "/");
+ }
+ }
+ }
+}
Index: src/plugin-resources/ArtifactExtensions.properties
===================================================================
RCS file: src/plugin-resources/ArtifactExtensions.properties
diff -N src/plugin-resources/ArtifactExtensions.properties
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ src/plugin-resources/ArtifactExtensions.properties 10 Feb 2004 14:49:37 -0000
@@ -0,0 +1,4 @@
+ejb=jar
+plugin=jar
+sql=zip
+javadoc=zip