add missing classes and check for artifact 1.3+

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@115534 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
brett
2004-06-25 13:48:54 +00:00
parent 3d259ceb83
commit d529e06834
3 changed files with 199 additions and 0 deletions

19
dist/plugin.jelly vendored
View File

@@ -23,8 +23,27 @@
xmlns:ant="jelly:ant"
xmlns:maven="jelly:maven"
xmlns:artifact="artifact"
xmlns:deploy="deploy"
xmlns:util="jelly:util">
<!-- Poor mans version check - plugin dependencies still suck for multiple versions -->
<maven:get plugin="maven-artifact-plugin" property="plugin" var="artifactPlugin" />
<j:if test="${artifactPlugin.currentVersion.compareTo('1.3') lt 0}">
<ant:fail>
Must have artifact plugin v1.3 installed to use this version of the dist plugin.
Try: maven plugin:download -DgroupId=maven -DartifactId=maven-artifact-plugin -Dversion=1.3
</ant:fail>
</j:if>
<!-- Can remove deploy dependency above when this is gone -->
<maven:get plugin="maven-deploy-plugin" property="plugin" var="deployPlugin" />
<j:if test="${deployPlugin != null}">
<ant:fail>
Must remove the deploy plugin to use this version of the dist plugin.
Please delete ${deployPlugin.artifactId}-${deployPlugin.currentVersion}.jar from
${maven.plugin.dir} and ${maven.plugin.unpacked.dir} (if it exists)
</ant:fail>
</j:if>
<j:new var="distTypeHandler" className="org.apache.maven.dist.DistributionArtifactTypeHandler" />
<!-- ================================================================== -->

View File

@@ -0,0 +1,86 @@
package org.apache.maven.dist;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
import org.apache.maven.MavenException;
import org.apache.maven.project.Project;
import org.apache.maven.repository.ArtifactTypeHandler;
/**
* This will do until wagon debuts.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id: DistributionArtifactTypeHandler.java,v 1.1 2004/06/25 13:48:53 brett Exp $
*/
public class DistributionArtifactTypeHandler implements ArtifactTypeHandler
{
/**
* Map an artifact to a repository directory path.
*
* @param project the project for the artifact
* @param type The type of the artifact
* @return the path
*/
public String constructRepositoryDirectoryPath(String type, Project project) throws MavenException
{
StringBuffer path = new StringBuffer();
path.append(project.getArtifactDirectory());
path.append("/distributions/");
return path.toString();
}
/**
* Map an artifact to a repository path.
*
* @param project the project for the artifact
* @param type The type of the artifact
* @param version The version of the artifact (may be a snapshot)
* @return the path
*/
public String constructRepositoryFullPath(String type, Project project, String version) throws MavenException
{
StringBuffer path = new StringBuffer(constructRepositoryDirectoryPath(type, project));
path.append(project.getArtifactId());
path.append("-");
path.append(version);
if (!type.startsWith("distribution")) {
throw new MavenException("Type is not a distribution (is " + type + ")");
}
String subtype = type.substring(12);
if (subtype.startsWith("-src")) {
path.append("-src");
subtype = subtype.substring(4);
}
if (subtype.equals("-targz")) {
path.append(".tar.gz");
}
else if (subtype.equals("-tarbz2")) {
path.append(".tar.bz2");
}
else if (subtype.equals("-zip")) {
path.append(".zip");
}
else {
throw new MavenException("Unrecognised distribution type (is " + type + ")");
}
return path.toString();
}
}

View File

@@ -0,0 +1,94 @@
package org.apache.maven.dist;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ====================================================================
*/
import org.apache.maven.MavenException;
import org.apache.maven.project.Project;
import org.apache.maven.repository.ArtifactTypeHandler;
import junit.framework.TestCase;
/**
* This will do until wagon debuts.
*
* @author <a href="mailto:brett@apache.org">Brett Porter</a>
* @version $Id: DistributionArtifactTypeHandlerTest.java,v 1.1 2004/06/25 13:48:54 brett Exp $
*/
public class DistributionArtifactTypeHandlerTest extends TestCase
{
private Project project;
private ArtifactTypeHandler handler;
private static final String VERSION = "VERSION";
public void setUp() throws Exception
{
project = new Project();
project.setGroupId("groupId");
project.setArtifactId("artifactId");
handler = new DistributionArtifactTypeHandler();
}
public void testConstructRepositoryDirectoryPath() throws Exception
{
assertEquals("check artifact directory", "groupId/distributions/",
handler.constructRepositoryDirectoryPath("distribution-targz", project));
assertEquals("check artifact directory", "groupId/distributions/",
handler.constructRepositoryDirectoryPath("distribution-tarbz2", project));
assertEquals("check artifact directory", "groupId/distributions/",
handler.constructRepositoryDirectoryPath("distribution-zip", project));
assertEquals("check artifact directory", "groupId/distributions/",
handler.constructRepositoryDirectoryPath("distribution-src-targz", project));
assertEquals("check artifact directory", "groupId/distributions/",
handler.constructRepositoryDirectoryPath("distribution-src-tarbz2", project));
assertEquals("check artifact directory", "groupId/distributions/",
handler.constructRepositoryDirectoryPath("distribution-src-zip", project));
}
public void testConstructRepositoryFullPath() throws Exception
{
try {
handler.constructRepositoryFullPath("foo", project, VERSION);
fail("expected exception");
}
catch (MavenException expected) {
assertTrue("expected exception", true);
}
try {
handler.constructRepositoryFullPath("distribution", project, VERSION);
fail("expected exception");
}
catch (MavenException expected) {
assertTrue("expected exception", true);
}
assertEquals("check artifact path", "groupId/distributions/artifactId-VERSION.tar.gz",
handler.constructRepositoryFullPath("distribution-targz", project, VERSION));
assertEquals("check artifact path", "groupId/distributions/artifactId-VERSION.tar.bz2",
handler.constructRepositoryFullPath("distribution-tarbz2", project, VERSION));
assertEquals("check artifact path", "groupId/distributions/artifactId-VERSION.zip",
handler.constructRepositoryFullPath("distribution-zip", project, VERSION));
assertEquals("check artifact path", "groupId/distributions/artifactId-VERSION-src.tar.gz",
handler.constructRepositoryFullPath("distribution-src-targz", project, VERSION));
assertEquals("check artifact path", "groupId/distributions/artifactId-VERSION-src.tar.bz2",
handler.constructRepositoryFullPath("distribution-src-tarbz2", project, VERSION));
assertEquals("check artifact path", "groupId/distributions/artifactId-VERSION-src.zip",
handler.constructRepositoryFullPath("distribution-src-zip", project, VERSION));
}
}