add a custom type handler
git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115528 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -76,6 +76,7 @@
|
||||
project="${project}"
|
||||
type="${type}"
|
||||
artifact="${artifact}"
|
||||
typeHandler="${typeHandler}"
|
||||
/>
|
||||
</j:otherwise>
|
||||
</j:choose>
|
||||
@@ -87,7 +88,6 @@
|
||||
<j:choose>
|
||||
<j:when test="${legacy}">
|
||||
<!-- TODO: what about -snapshot-versioa, SNAPSHOT symlink? -->
|
||||
<!-- TODO: make artifact a relative path -->
|
||||
<maven:makeRelativePath basedir="${basedir}" var="artifact" path="${artifact}" separator="/" />
|
||||
<util:file var="f" name="${artifact}" />
|
||||
<deploy:artifact
|
||||
@@ -102,6 +102,7 @@
|
||||
project="${project}"
|
||||
type="${type}"
|
||||
artifact="${artifact}"
|
||||
typeHandler="${typeHandler}"
|
||||
/>
|
||||
</j:otherwise>
|
||||
</j:choose>
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
<dependency>
|
||||
<groupId>maven</groupId>
|
||||
<artifactId>maven</artifactId>
|
||||
<version>1.0-rc2</version>
|
||||
<version>1.0</version>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.apache.maven.artifact.deployer;
|
||||
|
||||
import org.apache.maven.MavenException;
|
||||
import org.apache.maven.project.Project;
|
||||
import org.apache.maven.repository.ArtifactTypeHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -34,65 +35,60 @@ import org.apache.maven.project.Project;
|
||||
* In case of snapshots the process in even more complex.
|
||||
*
|
||||
* @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: ArtifactDeployer.java,v 1.4 2004/05/02 15:04:34 vmassol Exp $
|
||||
* @version $Id: ArtifactDeployer.java,v 1.5 2004/06/23 13:04:28 brett Exp $
|
||||
*/
|
||||
public interface ArtifactDeployer
|
||||
{
|
||||
|
||||
/**
|
||||
* Deploy given artifact to remote repository
|
||||
* Deploy given artifact to remote repository.
|
||||
*
|
||||
* @param artifact Artifact filename
|
||||
* @param type The type of the artifact
|
||||
* (like <code>war</code>, <code>jar</code>)
|
||||
* @param project The project which is a producer of the artifact
|
||||
* POM conatains a bunch of varaiables which are used
|
||||
* to control the deployment process (e.g
|
||||
* <ul>
|
||||
* <li>artifactId<li>
|
||||
* <li>groupId</li>
|
||||
* <li>list of remote repositories</li>
|
||||
* </ul>
|
||||
* @param handler the type handler for the artifact
|
||||
*
|
||||
* @throws MavenException
|
||||
*/
|
||||
public void deploy(String artifact, String type, Project project)
|
||||
public void deploy(String artifact, String type, Project project, ArtifactTypeHandler handler)
|
||||
throws MavenException;
|
||||
|
||||
/**
|
||||
* Deploy given artifact as a snapshot to remote repository
|
||||
* Deploy given artifact as a snapshot to remote repository.
|
||||
* @param artifact
|
||||
* @param type The type of the artifact
|
||||
* (like <code>war</code>, <code>jar</code>)
|
||||
* @param project The project which is a producer of the artifact
|
||||
* @param handler the type handler for the artifact
|
||||
* @see ArtifactDeployer#deploy(String, String, Project)
|
||||
*
|
||||
* @throws MavenException
|
||||
*/
|
||||
public void deploySnapshot(String artifact, String type, Project project)
|
||||
public void deploySnapshot(String artifact, String type, Project project, ArtifactTypeHandler handler)
|
||||
throws MavenException;
|
||||
|
||||
/**
|
||||
* Install given artifact in local repository
|
||||
* Install given artifact in local repository.
|
||||
* @param artifact file name of the artifact
|
||||
* @param type The type of the artifact
|
||||
* (like <code>war</code>, <code>jar</code>)
|
||||
* @param project The project which is a producer of the artifact
|
||||
* @param handler the type handler for the artifact
|
||||
* @throws MavenException
|
||||
*/
|
||||
public void install(String artifact, String type, Project project)
|
||||
public void install(String artifact, String type, Project project, ArtifactTypeHandler handler)
|
||||
throws MavenException;
|
||||
|
||||
/**
|
||||
* Install given artifact as snapshot in local repository
|
||||
* Install given artifact as snapshot in local repository.
|
||||
* @param artifact
|
||||
* @param type The type of the artifact
|
||||
* (like <code>war</code>, <code>jar</code>)
|
||||
* @param project The project which is a producer of the artifact
|
||||
* @param handler the type handler for the artifact
|
||||
* @throws MavenException
|
||||
*/
|
||||
public void installSnapshot(String artifact, String type, Project project)
|
||||
public void installSnapshot(String artifact, String type, Project project, ArtifactTypeHandler handler)
|
||||
throws MavenException;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,8 @@ import org.apache.maven.MavenException;
|
||||
import org.apache.maven.deploy.DeployTool;
|
||||
import org.apache.maven.deploy.RepositoryInfo;
|
||||
import org.apache.maven.project.Project;
|
||||
import org.apache.maven.repository.ArtifactTypeHandler;
|
||||
import org.apache.maven.repository.DefaultArtifactTypeHandler;
|
||||
import org.apache.maven.util.MD5Sum;
|
||||
|
||||
/**
|
||||
@@ -43,11 +45,13 @@ import org.apache.maven.util.MD5Sum;
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: DefaultArtifactDeployer.java,v 1.19 2004/06/14 13:36:47 brett Exp $
|
||||
* @version $Id: DefaultArtifactDeployer.java,v 1.20 2004/06/23 13:04:28 brett Exp $
|
||||
*/
|
||||
public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
{
|
||||
|
||||
private static final String POM_TYPE = "pom";
|
||||
|
||||
/**
|
||||
* Indicate if POM of given artifact should be also deployed
|
||||
* to remote repository*/
|
||||
@@ -69,6 +73,8 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
* in local repository*/
|
||||
public static final boolean INSTALL_POM_SNAPSHOT = true;
|
||||
|
||||
private static final ArtifactTypeHandler POM_ARTIFACT_TYPE_HANDLER = new DefaultArtifactTypeHandler();
|
||||
|
||||
/**
|
||||
* Date/time stamp which is appended to snapshot filenames
|
||||
*/
|
||||
@@ -82,22 +88,13 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
private static final Log LOG = LogFactory.getLog(DefaultArtifactDeployer.class);
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
* @see ArtifactDeployer#deploy(String, String, Project, ArtifactTypeHandler)
|
||||
*/
|
||||
public void deploy(String artifact, String type, Project project)
|
||||
public void deploy(String artifact, String type, Project project, ArtifactTypeHandler handler)
|
||||
throws MavenException
|
||||
{
|
||||
File file;
|
||||
if("pom".equals(type))
|
||||
if(POM_TYPE.equals(type))
|
||||
{
|
||||
file = project.getFile();
|
||||
}
|
||||
@@ -107,7 +104,7 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
}
|
||||
File md5File = createMD5Checksum(file);
|
||||
String repositoryPath =
|
||||
getRepositoryFullPath(type, project, project.getCurrentVersion());
|
||||
handler.constructRepositoryFullPath(type, project, project.getCurrentVersion());
|
||||
|
||||
List srcFiles = new ArrayList();
|
||||
srcFiles.add(file.getAbsolutePath());
|
||||
@@ -118,9 +115,9 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
destFiles.add(repositoryPath + ".md5");
|
||||
|
||||
//do not deploy POM twice
|
||||
if (DEPLOY_POM && !"pom".equals(type))
|
||||
if (DEPLOY_POM && !POM_TYPE.equals(type))
|
||||
{
|
||||
deploy(artifact, "pom", project);
|
||||
deploy(artifact, POM_TYPE, project, POM_ARTIFACT_TYPE_HANDLER);
|
||||
}
|
||||
doDeploy(srcFiles, destFiles, project);
|
||||
//Delete md5 file
|
||||
@@ -128,15 +125,15 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DefaultArtifactDeployer#deploySnapshot(String, String, Project)
|
||||
* @see DefaultArtifactDeployer#deploySnapshot(String, String, Project, ArtifactTypeHandler)
|
||||
*/
|
||||
public void deploySnapshot(String artifact, String type, Project project)
|
||||
public void deploySnapshot(String artifact, String type, Project project, ArtifactTypeHandler handler)
|
||||
throws MavenException
|
||||
{
|
||||
|
||||
String snapshotSignature = getSnapshotSignature();
|
||||
File file;
|
||||
if("pom".equals(type))
|
||||
if(POM_TYPE.equals(type))
|
||||
{
|
||||
file = project.getFile();
|
||||
}
|
||||
@@ -156,14 +153,14 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
srcFiles.add(snapshotVersionFile.getAbsolutePath());
|
||||
|
||||
String snapshotFilename =
|
||||
getRepositoryFullPath(
|
||||
handler.constructRepositoryFullPath(
|
||||
type,
|
||||
project,
|
||||
MavenConstants.SNAPSHOT_SIGNIFIER);
|
||||
String timestampedFilename =
|
||||
getRepositoryFullPath(type, project, snapshotSignature);
|
||||
handler.constructRepositoryFullPath(type, project, snapshotSignature);
|
||||
String snapshotVersionsFilename =
|
||||
getRepositoryDirectoryPath(type, project)
|
||||
handler.constructRepositoryDirectoryPath(type, project)
|
||||
+ project.getArtifactId()
|
||||
+ "-snapshot-version";
|
||||
|
||||
@@ -175,9 +172,9 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
destFiles.add(snapshotVersionsFilename);
|
||||
|
||||
// do not deploy POM twice
|
||||
if (DEPLOY_POM_SNAPSHOT && !"pom".equals(type))
|
||||
if (DEPLOY_POM_SNAPSHOT && !POM_TYPE.equals(type))
|
||||
{
|
||||
deploySnapshot(artifact, "pom", project);
|
||||
deploySnapshot(artifact, POM_TYPE, project, POM_ARTIFACT_TYPE_HANDLER);
|
||||
}
|
||||
|
||||
doDeploy(srcFiles, destFiles, project);
|
||||
@@ -186,13 +183,13 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
};
|
||||
|
||||
/**
|
||||
* @see ArtifactDeployer#install(String, String, Project)
|
||||
* @see ArtifactDeployer#install(String, String, Project, ArtifactTypeHandler)
|
||||
*/
|
||||
public void install(String artifact, String type, Project project)
|
||||
public void install(String artifact, String type, Project project, ArtifactTypeHandler handler)
|
||||
throws MavenException
|
||||
{
|
||||
File file;
|
||||
if("pom".equals(type))
|
||||
if(POM_TYPE.equals(type))
|
||||
{
|
||||
file = project.getFile();
|
||||
}
|
||||
@@ -200,26 +197,27 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
{
|
||||
file = getFileForArtifact(artifact);
|
||||
}
|
||||
doInstall(file, type, project, project.getCurrentVersion());
|
||||
doInstall(file, type, project, project.getCurrentVersion(), handler);
|
||||
// do not install twice
|
||||
if (INSTALL_POM && !"pom".equals(type))
|
||||
if (INSTALL_POM && !POM_TYPE.equals(type))
|
||||
{
|
||||
doInstall(
|
||||
project.getFile(),
|
||||
"pom",
|
||||
POM_TYPE,
|
||||
project,
|
||||
project.getCurrentVersion());
|
||||
project.getCurrentVersion(),
|
||||
POM_ARTIFACT_TYPE_HANDLER);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ArtifactDeployer#installSnapshot(String, String, Project)
|
||||
* @see ArtifactDeployer#installSnapshot(String, String, Project, ArtifactTypeHandler)
|
||||
*/
|
||||
public void installSnapshot(String artifact, String type, Project project)
|
||||
public void installSnapshot(String artifact, String type, Project project, ArtifactTypeHandler handler)
|
||||
throws MavenException
|
||||
{
|
||||
File file;
|
||||
if("pom".equals(type))
|
||||
if(POM_TYPE.equals(type))
|
||||
{
|
||||
file = project.getFile();
|
||||
}
|
||||
@@ -229,17 +227,18 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
}
|
||||
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))
|
||||
doInstall(file, type, project, MavenConstants.SNAPSHOT_SIGNIFIER, handler);
|
||||
doInstall(file, type, project, snapshotSignature, handler);
|
||||
if (INSTALL_POM_SNAPSHOT && !POM_TYPE.equals(type))
|
||||
{
|
||||
File projectFile = project.getFile();
|
||||
doInstall(
|
||||
projectFile,
|
||||
"pom",
|
||||
POM_TYPE,
|
||||
project,
|
||||
MavenConstants.SNAPSHOT_SIGNIFIER);
|
||||
doInstall(projectFile, "pom", project, snapshotSignature);
|
||||
MavenConstants.SNAPSHOT_SIGNIFIER,
|
||||
POM_ARTIFACT_TYPE_HANDLER);
|
||||
doInstall(projectFile, POM_TYPE, project, snapshotSignature, POM_ARTIFACT_TYPE_HANDLER);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,7 +254,8 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
File file,
|
||||
String type,
|
||||
Project project,
|
||||
String version)
|
||||
String version,
|
||||
ArtifactTypeHandler handler)
|
||||
throws MavenException
|
||||
{
|
||||
try
|
||||
@@ -263,7 +263,7 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
File destFile =
|
||||
new File(
|
||||
getLocalRepository(project),
|
||||
getRepositoryFullPath(type, project, version));
|
||||
handler.constructRepositoryFullPath(type, project, version));
|
||||
if (!destFile.getParentFile().exists())
|
||||
{
|
||||
destFile.getParentFile().mkdirs();
|
||||
@@ -405,52 +405,6 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
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
|
||||
@@ -559,25 +513,4 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
|
||||
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";
|
||||
}
|
||||
else if (type.equals("uberjar"))
|
||||
{
|
||||
return "jar";
|
||||
}
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ 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;
|
||||
import org.apache.maven.repository.ArtifactTypeHandler;
|
||||
import org.apache.maven.repository.DefaultArtifactTypeHandler;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -28,7 +30,7 @@ import org.apache.maven.project.Project;
|
||||
* from jelly scripts.
|
||||
*
|
||||
* @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
|
||||
* @version $Id: DeployBean.java,v 1.5 2004/05/02 15:04:34 vmassol Exp $
|
||||
* @version $Id: DeployBean.java,v 1.6 2004/06/23 13:04:28 brett Exp $
|
||||
*/
|
||||
public class DeployBean
|
||||
{
|
||||
@@ -37,12 +39,29 @@ public class DeployBean
|
||||
private Project project = null;
|
||||
private String artifact = null;
|
||||
private String type = null;
|
||||
private ArtifactTypeHandler typeHandler = null;
|
||||
|
||||
public DeployBean()
|
||||
{
|
||||
artifactDeployer = new DefaultArtifactDeployer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public ArtifactTypeHandler getTypeHandler()
|
||||
{
|
||||
return typeHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param typeHandler
|
||||
*/
|
||||
public void setTypeHandler(ArtifactTypeHandler typeHandler)
|
||||
{
|
||||
this.typeHandler = typeHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@@ -110,6 +129,10 @@ public class DeployBean
|
||||
{
|
||||
throw new MavenException("attribute 'type' is required");
|
||||
}
|
||||
if (typeHandler == null)
|
||||
{
|
||||
typeHandler = new DefaultArtifactTypeHandler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +141,7 @@ public class DeployBean
|
||||
public void deploy() throws MavenException
|
||||
{
|
||||
checkAttributes();
|
||||
artifactDeployer.deploy(artifact, type, project);
|
||||
artifactDeployer.deploy(artifact, type, project, typeHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +150,7 @@ public class DeployBean
|
||||
public void deploySnapshot() throws MavenException
|
||||
{
|
||||
checkAttributes();
|
||||
artifactDeployer.deploySnapshot(artifact, type, project);
|
||||
artifactDeployer.deploySnapshot(artifact, type, project, typeHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,7 +159,7 @@ public class DeployBean
|
||||
public void install() throws MavenException
|
||||
{
|
||||
checkAttributes();
|
||||
artifactDeployer.install(artifact, type, project);
|
||||
artifactDeployer.install(artifact, type, project, typeHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +168,7 @@ public class DeployBean
|
||||
public void installSnapshot() throws MavenException
|
||||
{
|
||||
checkAttributes();
|
||||
artifactDeployer.installSnapshot(artifact, type, project);
|
||||
artifactDeployer.installSnapshot(artifact, type, project, typeHandler);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
</properties>
|
||||
<body>
|
||||
<release version="1.3" date="In CVS">
|
||||
<action dev="brett" type="add">Add typeHandler parameter to tags to specify a custom handler</action>
|
||||
<action dev="brett" type="add">Switch between modern and legacy mode based on properties defined</action>
|
||||
<action dev="brett" type="add">Absorb the deploy plugin to give one point of migration</action>
|
||||
<action dev="brett" type="fix">Build and run against the installed version of Maven</action>
|
||||
<action dev="evenisse" type="fix" due-to="Martin van den Bemt" issue="MPJAR-29">Replace Apache Jakarta Maven by Apache Maven in Manifest</action>
|
||||
|
||||
Reference in New Issue
Block a user