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/03/19 17:26:22 UTC
svn commit: r925310 - in /maven/plugins/trunk/maven-antrun-plugin/src:
it/filesets-test/ it/filesets-test/src/ it/filesets-test/src/main/
it/filesets-test/src/main/java/ main/java/org/apache/maven/ant/
main/java/org/apache/maven/ant/tasks/ main/java/or...
Author: pgier
Date: Fri Mar 19 16:26:21 2010
New Revision: 925310
URL: http://svn.apache.org/viewvc?rev=925310&view=rev
Log:
[MANTRUN-47] Add a custom task that creates filesets containing the project dependencies.
Added:
maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/
maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/goals.txt (with props)
maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/pom.xml (with props)
maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/src/
maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/src/main/
maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/src/main/java/
maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/src/main/java/Test.java (with props)
maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/verify.bsh (with props)
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java (with props)
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/SpecificScopesArtifactFilter.java (with props)
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/TypesArtifactFilter.java (with props)
maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/
maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/
maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/
maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/ant/
maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/ant/tasks/
maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/ant/tasks/antlib.xml (with props)
maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/
maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/dependencyFilesets.apt.vm (with props)
maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/tasks.apt.vm (with props)
Modified:
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AbstractAntMojo.java
maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java
maven/plugins/trunk/maven-antrun-plugin/src/site/apt/examples/classpaths.apt.vm
maven/plugins/trunk/maven-antrun-plugin/src/site/site.xml
Added: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/goals.txt
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/goals.txt?rev=925310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/goals.txt (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/goals.txt Fri Mar 19 16:26:21 2010
@@ -0,0 +1 @@
+clean generate-resources
\ No newline at end of file
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/goals.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/goals.txt
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/pom.xml?rev=925310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/pom.xml (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/pom.xml Fri Mar 19 16:26:21 2010
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>org.apache.maven.plugins.antrun</groupId>
+ <artifactId>properties-test</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <name>Test for passing properties to the ant build</name>
+ <description>Test for passing properties to the ant build</description>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-antrun-plugin</artifactId>
+ <version>@pom.version@</version>
+ <executions>
+ <execution>
+ <id>antrun</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>run</goal>
+ </goals>
+ <configuration>
+ <tasks>
+
+ <dependencyfilesets prefix="test."/>
+ <mkdir dir="target/dependencies"/>
+ <copy todir="target/dependencies">
+ <fileset refid="test.junit:junit:jar"/>
+ <fileset refid="test.org.apache.ant:ant:jar"/>
+ </copy>
+
+ <mkdir dir="target/dependencies2"/>
+ <copy todir="target/dependencies2" flatten="true">
+ <fileset refid="test.maven.project.dependencies"/>
+ </copy>
+
+ </tasks>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant</artifactId>
+ <version>1.7.1</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.2</version>
+ </dependency>
+ </dependencies>
+
+
+</project>
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/pom.xml
------------------------------------------------------------------------------
svn:executable = *
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/src/main/java/Test.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/src/main/java/Test.java?rev=925310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/src/main/java/Test.java (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/src/main/java/Test.java Fri Mar 19 16:26:21 2010
@@ -0,0 +1,7 @@
+public class Test {
+
+ public static void main(String args[]) {
+ System.out.println("done");
+ }
+
+}
\ No newline at end of file
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/src/main/java/Test.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/src/main/java/Test.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/verify.bsh
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/verify.bsh?rev=925310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/verify.bsh (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/verify.bsh Fri Mar 19 16:26:21 2010
@@ -0,0 +1,45 @@
+import java.io.*;
+import java.util.*;
+import java.util.regex.*;
+
+import org.codehaus.plexus.util.*;
+
+try
+{
+ File depsDir = new File( basedir, "target/dependencies" );
+ File antJar = new File( depsDir, "ant-1.7.1.jar" );
+ File junitJar = new File ( depsDir, "junit-3.8.2.jar" );
+
+ if ( ! antJar.exists() || antJar.isDirectory() )
+ {
+ System.out.println( "Ant jar file does not exist: " + antJar );
+ return false;
+ }
+ if ( ! junitJar.exists() || junitJar.isDirectory() )
+ {
+ System.out.println( "Junit jar file does not exist: " + junitJar );
+ return false;
+ }
+
+ File deps2Dir = new File( basedir, "target/dependencies2" );
+ antJar = new File( deps2Dir, "ant-1.7.1.jar" );
+ junitJar = new File ( deps2Dir, "junit-3.8.2.jar" );
+
+ if ( ! antJar.exists() || antJar.isDirectory() )
+ {
+ System.out.println( "Ant jar file does not exist: " + antJar );
+ return false;
+ }
+ if ( ! junitJar.exists() || junitJar.isDirectory() )
+ {
+ System.out.println( "Junit jar file does not exist: " + junitJar );
+ return false;
+ }
+}
+catch( Throwable t )
+{
+ t.printStackTrace();
+ return false;
+}
+
+return true;
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/verify.bsh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/it/filesets-test/verify.bsh
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: 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=925310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java Fri Mar 19 16:26:21 2010
@@ -0,0 +1,215 @@
+package org.apache.maven.ant.tasks;
+
+/*
+ * 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.
+ */
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import org.apache.maven.ant.tasks.support.SpecificScopesArtifactFilter;
+import org.apache.maven.ant.tasks.support.TypesArtifactFilter;
+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.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.
+ *
+ * @author pgier
+ */
+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;
+
+ /**
+ * The id to store the dependencies fileset.
+ */
+ private String projectDependenciesId = DEFAULT_PROJECT_DEPENDENCIES_ID;
+
+ public String getProjectDependenciesId()
+ {
+ return projectDependenciesId;
+ }
+
+ public void setProjectDependenciesId( String projectDependenciesId )
+ {
+ this.projectDependenciesId = projectDependenciesId;
+ }
+
+ /**
+ * The string to prepend to all dependency filesets.
+ */
+ private String prefix = "";
+
+ /**
+ * A comma separated list of artifact types to include.
+ */
+ private String types = "";
+
+ /**
+ * A comma separated list of dependency scopes to include.
+ */
+ private String scopes = "";
+
+ public DependencyFilesetsTask()
+ {
+
+ }
+
+ public void execute()
+ {
+ if ( this.getProject().getReference( mavenProjectId ) == null )
+ {
+ throw new BuildException( "Maven project reference not found: " + mavenProjectId );
+ }
+
+ MavenProject mavenProject = (MavenProject) this.getProject().getReference( "maven.project" );
+
+ // Add filesets for depenedency artifacts
+ Set depArtifacts = filterArtifacts( mavenProject.getDependencyArtifacts() );
+
+ FileSet dependenciesFileSet = new FileSet();
+ dependenciesFileSet.setProject( getProject() );
+ ArtifactRepository localRepository = (ArtifactRepository) getProject().getReference( "maven.local.repository" );
+ dependenciesFileSet.setDir( new File( localRepository.getBasedir() ) );
+
+ for ( Iterator it = depArtifacts.iterator(); it.hasNext(); )
+ {
+ Artifact artifact = (Artifact) it.next();
+
+ String relativeArtifactPath = localRepository.pathOf( artifact );
+ dependenciesFileSet.createInclude().setName( relativeArtifactPath );
+
+ String fileSetName = getPrefix() + artifact.getDependencyConflictId();
+
+ FileSet singleArtifactFileSet = new FileSet();
+ singleArtifactFileSet.setProject( getProject() );
+ singleArtifactFileSet.setFile( artifact.getFile() );
+ getProject().addReference( fileSetName, singleArtifactFileSet );
+ }
+
+ getProject().addReference( ( getPrefix() + projectDependenciesId ), dependenciesFileSet );
+ }
+
+ public String getMavenProjectId()
+ {
+ return mavenProjectId;
+ }
+
+ public void setMavenProjectId( String mavenProjectId )
+ {
+ this.mavenProjectId = mavenProjectId;
+ }
+
+ public String getPrefix()
+ {
+ if ( prefix == null )
+ {
+ prefix = "";
+ }
+ return prefix;
+ }
+
+ /**
+ * Prefix to be added to each of the dependency filesets. Default is empty string.
+ */
+ public void setPrefix( String prefix )
+ {
+ this.prefix = prefix;
+ }
+
+ public String getTypes()
+ {
+ return types;
+ }
+
+ public void setTypes( String types )
+ {
+ this.types = types;
+ }
+
+ public String getScopes()
+ {
+ return scopes;
+ }
+
+ public void setScopes( String scopes )
+ {
+ this.scopes = scopes;
+ }
+
+ /**
+ * Filter a set of artifacts using the scopes and type filters.
+ *
+ * @param artifacts
+ * @return
+ */
+ public Set filterArtifacts( Set artifacts )
+ {
+ if ( scopes == null )
+ {
+ scopes = "";
+ }
+ if ( types == null )
+ {
+ types = "";
+ }
+
+ if ( scopes.equals( "" ) && types.equals( "" ) )
+ {
+ return artifacts;
+ }
+
+ AndArtifactFilter filter = new AndArtifactFilter();
+ if ( !scopes.equals( "" ) )
+ {
+ filter.add( new SpecificScopesArtifactFilter( getScopes() ) );
+ }
+ if ( !types.equals( "" ) )
+ {
+ filter.add( new TypesArtifactFilter( getTypes() ) );
+ }
+
+ Set artifactsResult = new HashSet();
+ for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
+ {
+ Artifact artifact = (Artifact) iter.next();
+ if ( filter.include( artifact ) )
+ {
+ artifactsResult.add( artifact );
+ }
+ }
+ return artifactsResult;
+ }
+}
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/SpecificScopesArtifactFilter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/SpecificScopesArtifactFilter.java?rev=925310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/SpecificScopesArtifactFilter.java (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/SpecificScopesArtifactFilter.java Fri Mar 19 16:26:21 2010
@@ -0,0 +1,106 @@
+package org.apache.maven.ant.tasks.support;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+
+/**
+ * Filter to only retain objects in the given scope(s).
+ *
+ * @author pgier
+ * @version $Id$
+ */
+public class SpecificScopesArtifactFilter
+ implements ArtifactFilter
+{
+ private boolean compileScope;
+
+ private boolean runtimeScope;
+
+ private boolean testScope;
+
+ private boolean providedScope;
+
+ private boolean systemScope;
+
+ /**
+ * Takes a comma separated list of scopes to include.
+ *
+ * @param scopes A comma separated list of scopes
+ */
+ public SpecificScopesArtifactFilter( String scopes )
+ {
+ String [] scopeList = scopes.split( "," );
+
+ for ( int i=0; i<scopeList.length; ++i )
+ {
+ if ( scopeList[i].trim().equals( DefaultArtifact.SCOPE_COMPILE) )
+ {
+ compileScope = true;
+ }
+ else if ( scopeList[i].trim().equals( DefaultArtifact.SCOPE_PROVIDED) )
+ {
+ providedScope = true;
+ }
+ else if ( scopeList[i].trim().equals( DefaultArtifact.SCOPE_RUNTIME) )
+ {
+ runtimeScope = true;
+ }
+ else if ( scopeList[i].trim().equals( DefaultArtifact.SCOPE_SYSTEM) )
+ {
+ systemScope = true;
+ }
+ else if ( scopeList[i].trim().equals( DefaultArtifact.SCOPE_TEST) )
+ {
+ testScope = true;
+ }
+ }
+ }
+
+ public boolean include( Artifact artifact )
+ {
+ if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) )
+ {
+ return compileScope;
+ }
+ else if ( Artifact.SCOPE_RUNTIME.equals( artifact.getScope() ) )
+ {
+ return runtimeScope;
+ }
+ else if ( Artifact.SCOPE_TEST.equals( artifact.getScope() ) )
+ {
+ return testScope;
+ }
+ else if ( Artifact.SCOPE_PROVIDED.equals( artifact.getScope() ) )
+ {
+ return providedScope;
+ }
+ else if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
+ {
+ return systemScope;
+ }
+ else
+ {
+ return true;
+ }
+ }
+}
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/SpecificScopesArtifactFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/SpecificScopesArtifactFilter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/TypesArtifactFilter.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/TypesArtifactFilter.java?rev=925310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/TypesArtifactFilter.java (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/TypesArtifactFilter.java Fri Mar 19 16:26:21 2010
@@ -0,0 +1,63 @@
+package org.apache.maven.ant.tasks.support;
+
+/*
+ * 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.
+ */
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Artifact Filter which filters on artifact types.
+ *
+ */
+public class TypesArtifactFilter
+ implements ArtifactFilter
+{
+ private List types = new ArrayList();
+
+ /**
+ * Accepts a comma separated list of types
+ *
+ * @param types
+ */
+ public TypesArtifactFilter( String types )
+ {
+ if ( !types.trim().equals( "" ) )
+ {
+ String[] typesArray = types.split( "," );
+ for ( int i = 0; i < typesArray.length; ++i )
+ {
+ this.types.add( typesArray[i].trim() );
+ }
+ }
+ }
+
+ public boolean include( Artifact artifact )
+ {
+ String artifactType = artifact.getType();
+ if ( artifactType == null || artifactType.equals( "" ) )
+ {
+ artifactType = "jar";
+ }
+ return types.contains( artifactType );
+ }
+}
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/TypesArtifactFilter.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/ant/tasks/support/TypesArtifactFilter.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
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=925310&r1=925309&r2=925310&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 Mar 19 16:26:21 2010
@@ -29,6 +29,7 @@ import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.antrun.components.AntTargetConverter;
@@ -38,6 +39,7 @@ import org.apache.tools.ant.DefaultLogge
import org.apache.tools.ant.Project;
import org.apache.tools.ant.PropertyHelper;
import org.apache.tools.ant.Target;
+import org.apache.tools.ant.taskdefs.Typedef;
import org.apache.tools.ant.types.Path;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
import org.codehaus.plexus.util.StringUtils;
@@ -52,38 +54,73 @@ import org.codehaus.plexus.util.StringUt
public abstract class AbstractAntMojo
extends AbstractMojo
{
+
+ /**
+ * 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";
+
+ /**
+ * The URI which defines the built in Ant tasks
+ */
+ public final static String TASK_URI = "antlib:org.apache.maven.ant.tasks";
+
/**
* The Maven project object
*
* @parameter expression="${project}"
- * @required
* @readonly
*/
private MavenProject project;
/**
+ * The plugin dependencies.
+ *
+ * @parameter expression="${plugin.artifacts}"
+ * @required
+ * @readonly
+ */
+ private List pluginArtifacts;
+
+ /**
+ * The local Maven repository
+ *
+ * @parameter expression="${localRepository}"
+ * @readonly
+ */
+ protected ArtifactRepository localRepository;
+
+ /**
* String to prepend to project and dependency property names.
* @parameter default-value=""
*/
private String propertyPrefix;
/**
+ * The xml namespace to use for the built in Ant tasks.
+ * @parameter default-value="mvn"
+ */
+ private String taskNamespace;
+
+ /**
* @deprecated use {@link AbstractAntMojo#executeTasks(Target,MavenProject,List)}.
*/
- protected void executeTasks( Target antTasks, MavenProject mavenProject )
+ /*protected void executeTasks( Target antTasks, MavenProject mavenProject )
throws MojoExecutionException
{
- executeTasks( antTasks, mavenProject, null );
- }
+ executeTasks( antTasks, null );
+ }*/
/**
* @param antTasks
* @param mavenProject
* @throws MojoExecutionException
*/
- protected void executeTasks( Target antTasks, MavenProject mavenProject, List pluginArtifacts )
+ protected void executeTasks( Target antTasks )
throws MojoExecutionException
{
+ MavenProject mavenProject = getMavenProject();
+
if ( antTasks == null )
{
getLog().info( "No ant tasks defined - SKIPPED" );
@@ -132,6 +169,10 @@ 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( "maven.local.repository", localRepository );
+ initMavenTasks( antProject );
+
// The ant project needs actual properties vs. using expression evaluator when calling an external build file.
copyProperties( mavenProject, antProject );
@@ -255,4 +296,14 @@ public abstract class AbstractAntMojo
{
return this.project;
}
+
+ public void initMavenTasks( Project antProject )
+ {
+ getLog().debug( "Initialize Maven Ant Tasks" );
+ Typedef typedef = new Typedef();
+ typedef.setProject( antProject );
+ typedef.setResource( ANTLIB );
+ //typedef.setURI( TASK_URI );
+ typedef.execute();
+ }
}
Modified: maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java?rev=925310&r1=925309&r2=925310&view=diff
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java (original)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/java/org/apache/maven/plugin/antrun/AntRunMojo.java Fri Mar 19 16:26:21 2010
@@ -20,10 +20,8 @@ package org.apache.maven.plugin.antrun;
*/
import java.io.File;
-import java.util.List;
import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
import org.apache.tools.ant.Target;
/**
@@ -46,15 +44,6 @@ public class AntRunMojo
extends AbstractAntMojo
{
/**
- * The plugin dependencies.
- *
- * @parameter expression="${plugin.artifacts}"
- * @required
- * @readonly
- */
- private List pluginArtifacts;
-
- /**
* The XML for the Ant task. You can add anything you can add
* between <target> and </target> in a build.xml.
*
@@ -88,7 +77,7 @@ public class AntRunMojo
public void execute()
throws MojoExecutionException
{
- executeTasks( tasks, getMavenProject(), pluginArtifacts );
+ executeTasks( tasks );
if ( sourceRoot != null )
{
Added: 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=925310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/ant/tasks/antlib.xml (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/ant/tasks/antlib.xml Fri Mar 19 16:26:21 2010
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<antlib>
+
+ <taskdef name="dependencyfilesets" classname="org.apache.maven.ant.tasks.DependencyFilesetsTask"/>
+
+</antlib>
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/ant/tasks/antlib.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/main/resources/org/apache/maven/ant/tasks/antlib.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-antrun-plugin/src/site/apt/examples/classpaths.apt.vm
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/site/apt/examples/classpaths.apt.vm?rev=925310&r1=925309&r2=925310&view=diff
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/site/apt/examples/classpaths.apt.vm (original)
+++ maven/plugins/trunk/maven-antrun-plugin/src/site/apt/examples/classpaths.apt.vm Fri Mar 19 16:26:21 2010
@@ -33,7 +33,7 @@ Referencing the Maven Classpaths
to a dependency with groupId "org.apache" and artifactId "common-util", the following could be used.
------
-<echo message="Dependency JAR Path: ${org.apache:common-util:jar}"/>
+<echo message="Dependency JAR Path: ${org.apache.common-util.jar}"/>
------
Note that the old format "maven.dependency.groupId.artifactId[.classifier].type.path" has been deprecated
Added: 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=925310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/dependencyFilesets.apt.vm (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/dependencyFilesets.apt.vm Fri Mar 19 16:26:21 2010
@@ -0,0 +1,78 @@
+ ------
+ DependencyFileSets Task
+ ------
+ Paul Gier
+ ------
+ March 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
+
+DependencyFilesets Task
+
+ This task will create fileset objects containing the Maven project dependencies. This can be used access
+ specific dependency artifacts, or to operate on a set of dependency artifacts. Each artifact will be assigned
+ a fileset ID in the form <<<[prefix]groupId:artifactId:[classifier]:type>>>. A dependency on a junit jar would be
+ given a fileset ID of <<<junit:junit:jar>>>.
+
+ In addition, a single fileset containing all the project dependencies will be created using the default ID
+ maven.project.dependencies
+
+* Task Parameters
+
+*---------------+--------------------------------------------------------+-----------------------------------*
+|| Attribute || Description || Required |
+*---------------+--------------------------------------------------------+-----------------------------------*
+| prefix | String to prepend to all fileset IDs | No, defaults to empty string |
+*---------------+--------------------------------------------------------+-----------------------------------*
+| projectDependenciesId | RefId for the fileset containing all project dependencies | No, defaults to "maven.project.dependencies |
+*---------------+--------------------------------------------------------+-----------------------------------*
+| scopes | Comma separated list of artifact scopes to include | No, defaults to all artifacts |
+*---------------+--------------------------------------------------------+-----------------------------------*
+| types | Comma separated list of artifact types to include | No, defaults to all artifacts |
+*---------------+--------------------------------------------------------+-----------------------------------*
+
+
+* Example
+
+ 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>
+
+ <mkdir dir="target/dependencies2"/>
+ <copy todir="target/dependencies2" flatten="true">
+ <fileset refid="mydeps.maven.project.dependencies"/>
+ </copy>
+
+ </tasks>
+ </configuration>
+
+------
+
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/dependencyFilesets.apt.vm
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/dependencyFilesets.apt.vm
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: 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=925310&view=auto
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/tasks.apt.vm (added)
+++ maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/tasks.apt.vm Fri Mar 19 16:26:21 2010
@@ -0,0 +1,43 @@
+ ------
+ Ant Tasks
+ ------
+ Paul Gier
+ ------
+ March 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
+
+Ant Tasks
+
+ The Maven Antrun Plugin includes some custom Ant tasks which can be used to better integrate with the
+ Maven build. This page provides an overview of these tasks. Click on the task name for more information
+ and examples.
+
+*-----------------------------------------------------+--------------------------------------------------------+
+|| Task || Description |
+*---------------+--------------------------------------------------------+
+| {{{./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
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/tasks.apt.vm
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/plugins/trunk/maven-antrun-plugin/src/site/apt/tasks/tasks.apt.vm
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Modified: maven/plugins/trunk/maven-antrun-plugin/src/site/site.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antrun-plugin/src/site/site.xml?rev=925310&r1=925309&r2=925310&view=diff
==============================================================================
--- maven/plugins/trunk/maven-antrun-plugin/src/site/site.xml (original)
+++ maven/plugins/trunk/maven-antrun-plugin/src/site/site.xml Fri Mar 19 16:26:21 2010
@@ -31,6 +31,7 @@ under the License.
<menu name="Overview">
<item name="Introduction" href="index.html"/>
<item name="Goals" href="plugin-info.html"/>
+ <item name="Ant Tasks" href="tasks/tasks.html"/>
<item name="Usage" href="usage.html"/>
<item name="FAQ" href="faq.html"/>
</menu>