You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by pg...@apache.org on 2010/05/21 06:14:19 UTC
svn commit: r946867 - in /maven/plugins/trunk/maven-antrun-plugin/src:
it/attach-artifact-test/ main/java/org/apache/maven/ant/tasks/
main/java/org/apache/maven/plugin/antrun/
main/resources/org/apache/maven/ant/tasks/ site/apt/tasks/
Author: pgier
Date: Fri May 21 04:14:17 2010
New Revision: 946867
URL: http://svn.apache.org/viewvc?rev=946867&view=rev
Log:
[MANTRUN-100] Add custom task to attach an artifact to the current build.
Added:
maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/
maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/invoker.properties (with props)
maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/pom.xml (with props)
maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/verify.bsh (with props)
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.java (with props)
maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/attachArtifact.apt.vm (with props)
Modified:
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AbstractAntMojo.java
maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/ant/tasks/antlib.xml
maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/dependencyFilesets.apt.vm
maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/tasks.apt.vm
Added: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/invoker.properties?rev=946867&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/invoker.properties (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/invoker.properties Fri May 21 04:14:17 2010
@@ -0,0 +1 @@
+invoker.goals=install
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/invoker.properties
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/invoker.properties
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/pom.xml?rev=946867&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/pom.xml (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/pom.xml Fri May 21 04:14:17 2010
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you 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.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>antrun-plugin.test</groupId>
+ <artifactId>antrun-plugin-attach-artifact-test</artifactId>
+ <packaging>pom</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <inceptionYear>2006</inceptionYear>
+ <name>Maven Antrun Plugin Test</name>
+ <url>http://maven.apache.org</url>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>@pom.version@</version>
+ <executions>
+ <execution>
+ <id>attach-artifact-test</id>
+ <phase>package</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <zip destfile="junk.zip"
+ basedir="."
+ includes="*.xml"
+ />
+ <attachartifact file="junk.zip" classifier="foo" type="zip"/>
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/verify.bsh?rev=946867&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/verify.bsh (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/verify.bsh Fri May 21 04:14:17 2010
@@ -0,0 +1,24 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+import org.codehaus.plexus.util.*;
+
+try
+{
+ String zipFilePath = "../../local-repo/antrun-plugin/test/antrun-plugin-attach-artifact-test/1.0-SNAPSHOT/antrun-plugin-attach-artifact-test-1.0-SNAPSHOT-foo.zip";
+ File installedZipFile = new File( basedir, zipFilePath );
+
+ if ( ! installedZipFile.exists() )
+ {
+ System.out.println( "Zip file not installed: " + installedZipFile );
+ return false;
+ }
+}
+catch( Throwable t )
+{
+ t.printStackTrace();
+ return false;
+}
+
+return true;
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/verify.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/attach-artifact-test/verify.bsh
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.java?rev=946867&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.java (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.java Fri May 21 04:14:17 2010
@@ -0,0 +1,136 @@
+package org.apache.maven.ant.tasks;
+
+import java.io.File;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.plugin.antrun.AbstractAntMojo;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.artifact.AttachedArtifact;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.codehaus.plexus.util.FileUtils;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+public class AttachArtifactTask extends Task
+{
+
+ /**
+ * The refId of the maven project.
+ */
+ private String mavenProjectRefId = AbstractAntMojo.DEFAULT_MAVEN_PROJECT_REFID;
+
+ /**
+ * The file to attach.
+ */
+ private File file;
+
+ /**
+ * The classifier of the artifact to attach
+ */
+ private String classifier;
+
+ /**
+ * The type of the artifact to attach. Defaults to file extension.
+ */
+ private String type;
+
+ public void execute()
+ {
+ if ( file == null )
+ {
+ throw new BuildException( "File is a required parameter." );
+ }
+
+ if ( !file.exists() )
+ {
+ throw new BuildException( "File does not exist: " + file );
+ }
+
+ if ( this.getProject().getReference( mavenProjectRefId ) == null )
+ {
+ throw new BuildException( "Maven project reference not found: " + mavenProjectRefId );
+ }
+
+ if ( type == null )
+ {
+ type = FileUtils.getExtension( file.getName() );
+ }
+
+ MavenProject mavenProject = (MavenProject) this.getProject().getReference( "maven.project" );
+
+ if ( classifier == null )
+ {
+ mavenProject.setFile( file );
+ }
+ else
+ {
+ ArtifactHandler handler = new DefaultArtifactHandler( type );
+ Artifact artifact = new AttachedArtifact(mavenProject.getArtifact(), type, classifier, handler);
+ artifact.setFile( file );
+ artifact.setResolved( true );
+ log( "Attaching " + file + " as an attached artifact", Project.MSG_VERBOSE );
+ mavenProject.addAttachedArtifact( artifact );
+ }
+ }
+
+ public File getFile()
+ {
+ return file;
+ }
+
+ public void setFile( File file )
+ {
+ this.file = file;
+ }
+
+ public String getMavenProjectRefId()
+ {
+ return mavenProjectRefId;
+ }
+
+ public void setMavenProjectRefId( String mavenProjectRefId )
+ {
+ this.mavenProjectRefId = mavenProjectRefId;
+ }
+
+ public String getClassifier()
+ {
+ return classifier;
+ }
+
+ public void setClassifier( String classifier )
+ {
+ this.classifier = classifier;
+ }
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public void setType( String type )
+ {
+ this.type = type;
+ }
+}
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/AttachArtifactTask.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java?rev=946867&r1=946866&r2=946867&view=diff
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java (original)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java Fri May 21 04:14:17 2010
@@ -29,13 +29,15 @@ import org.apache.maven.ant.tasks.suppor
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.filter.AndArtifactFilter;
+import org.apache.maven.plugin.antrun.AbstractAntMojo;
import org.apache.maven.project.MavenProject;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileSet;
/**
- * Ant task which create a fileset for each dependency in a Maven project.
+ * Ant task which create a fileset for each dependency in a Maven project, and a
+ * fileset containing all selected dependencies.
*
* @author pgier
*/
@@ -43,14 +45,12 @@ public class DependencyFilesetsTask
extends Task
{
- public final static String DEFAULT_MAVEN_PROJECT_REFID = "maven.project";
-
public final static String DEFAULT_PROJECT_DEPENDENCIES_ID = "maven.project.dependencies";
/**
* The project ref Id of the project being used.
*/
- private String mavenProjectId = DEFAULT_MAVEN_PROJECT_REFID;
+ private String mavenProjectId = AbstractAntMojo.DEFAULT_MAVEN_PROJECT_REFID;
/**
* The id to store the dependencies fileset.
Modified: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AbstractAntMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AbstractAntMojo.java?rev=946867&r1=946866&r2=946867&view=diff
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AbstractAntMojo.java (original)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AbstractAntMojo.java Fri May 21 04:14:17 2010
@@ -56,6 +56,11 @@ public abstract class AbstractAntMojo
{
/**
+ * The refid used to store the Maven project object in the Ant build.
+ */
+ public final static String DEFAULT_MAVEN_PROJECT_REFID = "maven.project";
+
+ /**
* The path to The XML file containing the definition of the Maven tasks.
*/
public final static String ANTLIB = "org/apache/maven/ant/tasks/antlib.xml";
@@ -169,7 +174,7 @@ public abstract class AbstractAntMojo
/* set maven.plugin.classpath with plugin dependencies */
antProject.addReference( "maven.plugin.classpath", getPathFromArtifacts( pluginArtifacts, antProject ) );
- antProject.addReference( "maven.project", getMavenProject() );
+ antProject.addReference( DEFAULT_MAVEN_PROJECT_REFID, getMavenProject() );
antProject.addReference( "maven.local.repository", localRepository );
initMavenTasks( antProject );
Modified: maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/ant/tasks/antlib.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/ant/tasks/antlib.xml?rev=946867&r1=946866&r2=946867&view=diff
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/ant/tasks/antlib.xml (original)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/ant/tasks/antlib.xml Fri May 21 04:14:17 2010
@@ -1,6 +1,7 @@
<?xml version="1.0"?>
<antlib>
+ <taskdef name="attachartifact" classname="org.apache.maven.ant.tasks.AttachArtifactTask"/>
<taskdef name="dependencyfilesets" classname="org.apache.maven.ant.tasks.DependencyFilesetsTask"/>
</antlib>
Added: maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/attachArtifact.apt.vm
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/attachArtifact.apt.vm?rev=946867&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/attachArtifact.apt.vm (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/attachArtifact.apt.vm Fri May 21 04:14:17 2010
@@ -0,0 +1,77 @@
+ ------
+ AttachArtifact Task
+ ------
+ Paul Gier
+ ------
+ May 2010
+ ------
+
+ ~~ Licensed to the Apache Software Foundation (ASF) under one
+ ~~ or more contributor license agreements. See the NOTICE file
+ ~~ distributed with this work for additional information
+ ~~ regarding copyright ownership. The ASF licenses this file
+ ~~ to you 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.
+
+ ~~ NOTE: For help with the syntax of this file, see:
+ ~~ http://maven.apache.org/doxia/references/apt-format.html
+
+AttachArtifact Task
+
+ This task will attatch an artifact to the current Maven project. This is can be used to install and
+ deploy an artifact generated by the Ant tasks.
+
+* Task Parameters
+
+*---------------+--------------------------------------------------------+-----------------------------------*
+|| Attribute || Description || Required |
+*---------------+--------------------------------------------------------+-----------------------------------*
+| file | The file to attach to the project | Yes |
+*---------------+--------------------------------------------------------+-----------------------------------*
+| classifier | A classifier assigned to the artifact | No, defaults to no classifier |
+*---------------+--------------------------------------------------------+-----------------------------------*
+| type | The type of the artifact, zip, war, etc | No, defaults to jar |
+*---------------+--------------------------------------------------------+-----------------------------------*
+
+
+* Example
+
+ This example shows how to use the <<<attachartifact>>> task.
+
+------
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <id>attach-artifact</id>
+ <phase>package</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+ <zip destfile="my-project-src.zip"
+ basedir="."
+ includes="*.*"
+ />
+ <attachartifact file="my-project-src.zip" classifier="src" type="zip"/>
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+------
+
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/attachArtifact.apt.vm
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/attachArtifact.apt.vm
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/dependencyFilesets.apt.vm
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/dependencyFilesets.apt.vm?rev=946867&r1=946866&r2=946867&view=diff
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/dependencyFilesets.apt.vm (original)
+++ maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/dependencyFilesets.apt.vm Fri May 21 04:14:17 2010
@@ -56,23 +56,36 @@ DependencyFilesets Task
This example shows how to access individual dependencies and the combined dependency fileset.
------
- <configuration>
- <tasks>
-
- <dependencyfilesets prefix="mydeps."/>
- <mkdir dir="target/dependencies"/>
- <copy todir="target/dependencies">
- <fileset refid="mydeps.junit:junit:jar"/>
- <fileset refid="mydeps.org.apache.ant:ant:jar"/>
- </copy>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>${project.version}</version>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>package</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
- <mkdir dir="target/dependencies2"/>
- <copy todir="target/dependencies2" flatten="true">
- <fileset refid="mydeps.maven.project.dependencies"/>
- </copy>
-
- </tasks>
- </configuration>
-
+ <dependencyfilesets prefix="mydeps."/>
+ <mkdir dir="target/dependencies"/>
+ <copy todir="target/dependencies">
+ <fileset refid="mydeps.junit:junit:jar"/>
+ <fileset refid="mydeps.org.apache.ant:ant:jar"/>
+ </copy>
+
+ <mkdir dir="target/dependencies2"/>
+ <copy todir="target/dependencies2" flatten="true">
+ <fileset refid="mydeps.maven.project.dependencies"/>
+ </copy>
+
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
------
Modified: maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/tasks.apt.vm
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/tasks.apt.vm?rev=946867&r1=946866&r2=946867&view=diff
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/tasks.apt.vm (original)
+++ maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/tasks.apt.vm Fri May 21 04:14:17 2010
@@ -35,9 +35,8 @@ Ant Tasks
*-----------------------------------------------------+--------------------------------------------------------+
|| Task || Description |
*---------------+--------------------------------------------------------+
+| {{{./attachArtifact.html}attachartifact}} | Attach an artifact to the current Maven project |
+*---------------+--------------------------------------------------------+
| {{{./dependencyFilesets.html}dependencyfilesets}} | Creates a fileset for each of the Maven project dependencies and adds them to the Ant build |
*---------------+--------------------------------------------------------+
-
- * {{{./dependencyFilesets.html}dependencyfilesets}} Creates a filesets for the current
- Maven project dependencies and adds them to the Ant build.
-
\ No newline at end of file
+
\ No newline at end of file