From d529e06834e6fedd0278dbfe5808f21582161a60 Mon Sep 17 00:00:00 2001 From: brett Date: Fri, 25 Jun 2004 13:48:54 +0000 Subject: [PATCH] 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 --- dist/plugin.jelly | 19 ++++ .../dist/DistributionArtifactTypeHandler.java | 86 +++++++++++++++++ .../DistributionArtifactTypeHandlerTest.java | 94 +++++++++++++++++++ 3 files changed, 199 insertions(+) create mode 100644 dist/src/main/org/apache/maven/dist/DistributionArtifactTypeHandler.java create mode 100644 dist/src/test/org/apache/maven/dist/DistributionArtifactTypeHandlerTest.java diff --git a/dist/plugin.jelly b/dist/plugin.jelly index 4ec2fe11..7572a69b 100644 --- a/dist/plugin.jelly +++ b/dist/plugin.jelly @@ -23,8 +23,27 @@ xmlns:ant="jelly:ant" xmlns:maven="jelly:maven" xmlns:artifact="artifact" + xmlns:deploy="deploy" xmlns:util="jelly:util"> + + + + + 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 + + + + + + + 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) + + + diff --git a/dist/src/main/org/apache/maven/dist/DistributionArtifactTypeHandler.java b/dist/src/main/org/apache/maven/dist/DistributionArtifactTypeHandler.java new file mode 100644 index 00000000..b65d3f54 --- /dev/null +++ b/dist/src/main/org/apache/maven/dist/DistributionArtifactTypeHandler.java @@ -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 Brett Porter + * @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(); + } +} + diff --git a/dist/src/test/org/apache/maven/dist/DistributionArtifactTypeHandlerTest.java b/dist/src/test/org/apache/maven/dist/DistributionArtifactTypeHandlerTest.java new file mode 100644 index 00000000..83461dce --- /dev/null +++ b/dist/src/test/org/apache/maven/dist/DistributionArtifactTypeHandlerTest.java @@ -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 Brett Porter + * @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)); + } +} +