Author: jdillon Date: Fri Mar 30 12:10:25 2007 New Revision: 524238 URL: http://svn.apache.org/viewvc?view=rev&rev=524238 Log: (MANTTASKS-42) Allow install and deploy tasks to include attached artifacts
Added: maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/AttachedArtifact.java (with props) maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java (with props) Modified: maven/sandbox/trunk/ant-tasks/install-deploy-attached/pom.xml maven/sandbox/trunk/ant-tasks/install-deploy-attached/sample.build.xml maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/DeployTask.java maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallTask.java Modified: maven/sandbox/trunk/ant-tasks/install-deploy-attached/pom.xml URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/ant-tasks/install-deploy-attached/pom.xml?view=diff&rev=524238&r1=524237&r2=524238 ============================================================================== --- maven/sandbox/trunk/ant-tasks/install-deploy-attached/pom.xml (original) +++ maven/sandbox/trunk/ant-tasks/install-deploy-attached/pom.xml Fri Mar 30 12:10:25 2007 @@ -72,7 +72,7 @@ <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-project</artifactId> - <version>2.0.6-SNAPSHOT</version> + <version>2.0.6</version> <exclusions> <exclusion> <artifactId>junit</artifactId> @@ -83,12 +83,12 @@ <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-error-diagnostics</artifactId> - <version>2.0.6-SNAPSHOT</version> + <version>2.0.6</version> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-settings</artifactId> - <version>2.0.6-SNAPSHOT</version> + <version>2.0.6</version> </dependency> <dependency> <groupId>org.apache.maven.wagon</groupId> @@ -110,7 +110,7 @@ <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-artifact-manager</artifactId> - <version>2.0.6-SNAPSHOT</version> + <version>2.0.6</version> <exclusions> <exclusion> <artifactId>junit</artifactId> @@ -126,7 +126,7 @@ <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-artifact</artifactId> - <version>2.0.6-SNAPSHOT</version> + <version>2.0.6</version> </dependency> <dependency> <groupId>org.apache.maven.wagon</groupId> Modified: maven/sandbox/trunk/ant-tasks/install-deploy-attached/sample.build.xml URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/ant-tasks/install-deploy-attached/sample.build.xml?view=diff&rev=524238&r1=524237&r2=524238 ============================================================================== --- maven/sandbox/trunk/ant-tasks/install-deploy-attached/sample.build.xml (original) +++ maven/sandbox/trunk/ant-tasks/install-deploy-attached/sample.build.xml Fri Mar 30 12:10:25 2007 @@ -32,7 +32,7 @@ <artifact:localRepository id="local.repository" location="${basedir}/target/local-repo" layout="default"/> - <artifact:remoteRepository id="deploy.repository" url="file://localhost/${basedir}/target/deployment-repo" layout="legacy"/> + <artifact:remoteRepository id="deploy.repository" url="file://localhost/${basedir}/target/deployment-repo" layout="default"/> <artifact:pom file="pom.xml" id="maven.project"/> @@ -212,7 +212,27 @@ <artifact:deploy file="sample-build-test.pom"> <pom file="sample-build-test.pom" /> <remoteRepository refid="deploy.repository" /> - </artifact:deploy> + </artifact:deploy> + </target> + + <target name="test-deploy-attached" depends="initTaskDefs"> + <echo message="test" file="${basedir}/target/sample-build-test.pom.asc"/> + + <artifact:deploy file="sample-build-test.pom"> + <pom file="sample-build-test.pom" /> + <remoteRepository refid="deploy.repository" /> + <attach file="${basedir}/target/sample-build-test.pom.asc" type="pom.asc"/> + </artifact:deploy> + </target> + + <target name="test-install-attached" depends="initTaskDefs"> + <echo message="test" file="${basedir}/target/sample-build-test.pom.asc"/> + + <artifact:install file="sample-build-test.pom"> + <pom file="sample-build-test.pom" /> + <localRepository refid="local.repository"/> + <attach file="${basedir}/target/sample-build-test.pom.asc" type="pom.asc"/> + </artifact:install> </target> </project> Added: maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/AttachedArtifact.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/AttachedArtifact.java?view=auto&rev=524238 ============================================================================== --- maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/AttachedArtifact.java (added) +++ maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/AttachedArtifact.java Fri Mar 30 12:10:25 2007 @@ -0,0 +1,57 @@ +package org.apache.maven.artifact.ant; + +import java.io.File; + +/* + * Copyright 2001-2005 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. + */ + +/** + * Container for specification of an attached artifact. + * + * @version $Rev$ $Date$ + */ +public class AttachedArtifact +{ + private File file; + + private String type = "jar"; + + private String classifier; + + public File getFile() { + return file; + } + + public void setFile(final File file) { + this.file = file; + } + + public String getType() { + return type; + } + + public void setType(final String type) { + this.type = type; + } + + public String getClassifier() { + return classifier; + } + + public void setClassifier(final String classifier) { + this.classifier = classifier; + } +} Propchange: maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/AttachedArtifact.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/AttachedArtifact.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/AttachedArtifact.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/DeployTask.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/DeployTask.java?view=diff&rev=524238&r1=524237&r2=524238 ============================================================================== --- maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/DeployTask.java (original) +++ maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/DeployTask.java Fri Mar 30 12:10:25 2007 @@ -26,7 +26,7 @@ import org.apache.maven.project.artifact.ProjectArtifactMetadata; import org.apache.tools.ant.BuildException; -import java.io.File; +import java.util.Iterator; /** * Deploy task, using maven-artifact. @@ -35,14 +35,12 @@ * @version $Id$ */ public class DeployTask - extends AbstractArtifactTask + extends InstallDeployTaskSupport { private RemoteRepository remoteRepository; private RemoteRepository remoteSnapshotRepository; - private File file; - protected void doExecute() { ArtifactRepository localRepo = createLocalArtifactRepository(); @@ -121,6 +119,24 @@ throw new BuildException( "Error deploying artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e ); } + + // Deploy any attached artifacts + if (attachedArtifacts != null) { + Iterator iter = attachedArtifacts.iterator(); + + while (iter.hasNext()) { + AttachedArtifact attached = (AttachedArtifact)iter.next(); + Artifact attachedArtifact = createArtifactFromAttached(attached, artifact); + + try { + deployer.deploy( attachedArtifact.getFile(), attachedArtifact, deploymentRepository, localRepo ); + } + catch (ArtifactDeploymentException e) { + throw new BuildException( + "Error deploying attached artifact '" + attachedArtifact.getDependencyConflictId() + "': " + e.getMessage(), e ); + } + } + } } public RemoteRepository getRemoteRepository() @@ -136,15 +152,5 @@ public void addRemoteRepository( RemoteRepository remoteRepository ) { this.remoteRepository = remoteRepository; - } - - public File getFile() - { - return file; - } - - public void setFile( File file ) - { - this.file = file; } } Added: maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java?view=auto&rev=524238 ============================================================================== --- maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java (added) +++ maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java Fri Mar 30 12:10:25 2007 @@ -0,0 +1,97 @@ +package org.apache.maven.artifact.ant; + +/* + * Copyright 2001-2005 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 java.io.File; +import java.util.List; +import java.util.Iterator; +import java.util.ArrayList; + +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.installer.ArtifactInstaller; +import org.apache.maven.artifact.installer.ArtifactInstallationException; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.project.MavenProjectBuilder; +import org.apache.maven.project.artifact.ProjectArtifactMetadata; +import org.apache.tools.ant.BuildException; + +/** + * Support for install/deploy tasks. + * + * @author <a href="mailto:[EMAIL PROTECTED]">Jason Dillon</a> + * @version $Id$ + */ +public abstract class InstallDeployTaskSupport + extends AbstractArtifactTask +{ + protected File file; + + protected List attachedArtifacts; + + public File getFile() + { + return file; + } + + public void setFile( File file ) + { + this.file = file; + } + + protected Artifact createArtifactFromAttached(final AttachedArtifact attached, final Artifact parent) + { + ArtifactFactory factory = (ArtifactFactory) lookup( ArtifactFactory.ROLE ); + + Artifact artifact; + if (attached.getClassifier() != null) { + artifact = factory.createArtifactWithClassifier( + parent.getGroupId(), + parent.getArtifactId(), + parent.getVersion(), + attached.getType(), + attached.getClassifier() + ); + } + else { + artifact = factory.createArtifact( + parent.getGroupId(), + parent.getArtifactId(), + parent.getVersion(), + null, // scope + attached.getType() + ); + } + + artifact.setFile( attached.getFile() ); + + return artifact; + } + + public AttachedArtifact createAttach() + { + if (attachedArtifacts == null) { + attachedArtifacts = new ArrayList(); + } + + AttachedArtifact attach = new AttachedArtifact(); + attachedArtifacts.add(attach); + + return attach; + } +} Propchange: maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallDeployTaskSupport.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallTask.java URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallTask.java?view=diff&rev=524238&r1=524237&r2=524238 ============================================================================== --- maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallTask.java (original) +++ maven/sandbox/trunk/ant-tasks/install-deploy-attached/src/main/java/org/apache/maven/artifact/ant/InstallTask.java Fri Mar 30 12:10:25 2007 @@ -17,6 +17,7 @@ */ import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.installer.ArtifactInstallationException; import org.apache.maven.artifact.installer.ArtifactInstaller; import org.apache.maven.artifact.metadata.ArtifactMetadata; @@ -26,6 +27,9 @@ import org.apache.tools.ant.BuildException; import java.io.File; +import java.util.List; +import java.util.ArrayList; +import java.util.Iterator; /** * Install task, using maven-artifact. @@ -35,10 +39,8 @@ * @todo should be able to incorporate into the install mojo? */ public class InstallTask - extends AbstractArtifactTask + extends InstallDeployTaskSupport { - private File file; - protected void doExecute() { ArtifactRepository localRepo = createLocalArtifactRepository(); @@ -72,15 +74,23 @@ throw new BuildException( "Error installing artifact '" + artifact.getDependencyConflictId() + "': " + e.getMessage(), e ); } - } - - public File getFile() - { - return file; - } - public void setFile( File file ) - { - this.file = file; + // Install any attached artifacts + if (attachedArtifacts != null) { + Iterator iter = attachedArtifacts.iterator(); + + while (iter.hasNext()) { + AttachedArtifact attached = (AttachedArtifact)iter.next(); + Artifact attachedArtifact = createArtifactFromAttached(attached, artifact); + + try { + installer.install( attachedArtifact.getFile(), attachedArtifact, localRepo ); + } + catch (ArtifactInstallationException e) { + throw new BuildException( + "Error installing attached artifact '" + attachedArtifact.getDependencyConflictId() + "': " + e.getMessage(), e ); + } + } + } } }