Author: pgier Date: Thu May 7 16:17:01 2009 New Revision: 772694 URL: http://svn.apache.org/viewvc?rev=772694&view=rev Log: [MANTTASKS-147] Make scope filtering more intuitive for ant users.
Added: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/SpecificScopesArtifactFilter.java (with props) maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/pom-with-scopes.xml (with props) Modified: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/sample.build.xml maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/examples/dependencies.apt maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/reference.apt maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/site.xml Modified: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/sample.build.xml URL: http://svn.apache.org/viewvc/maven/ant-tasks/branches/maven-ant-tasks-2.0.x/sample.build.xml?rev=772694&r1=772693&r2=772694&view=diff ============================================================================== --- maven/ant-tasks/branches/maven-ant-tasks-2.0.x/sample.build.xml (original) +++ maven/ant-tasks/branches/maven-ant-tasks-2.0.x/sample.build.xml Thu May 7 16:17:01 2009 @@ -63,7 +63,7 @@ </target> <target name="test-all-deps" description="All dependencies tests" - depends="test-pom, test-pom-profiles, test-pom-with-parent,test-no-deps,test-pom-deps,test-deps-two-repos,test-deps,test-legacy-pom,test-deps-mirror,test-deps-order,test-deps-sources,test-deps-sources-empty,test-deps-profile"> + depends="test-pom, test-pom-profiles, test-pom-with-parent,test-no-deps,test-pom-deps,test-deps-two-repos,test-deps,test-legacy-pom,test-deps-mirror,test-deps-order,test-deps-sources,test-deps-sources-empty,test-deps-profile,test-deps-scopes"> <echo>test-bad-dep and test-invalid-pom-ref must be run manually, since they are intended to fail</echo> </target> @@ -579,11 +579,29 @@ <target name="test-mvn" depends="initTaskDefs"> <artifact:mvn pom="src/test/pom.xml" mavenVersion="2.1.0" fork="true"> - <arg value="package"/> + <arg value="test"/> <localRepository path="${basedir}/target/tmp"/> </artifact:mvn> </target> + <target name="test-deps-scopes" depends="initTaskDefs"> + <artifact:dependencies filesetId="dependency.scopes.fileset" useScope=" provided , test "> + <pom file="src/test/pom-with-scopes.xml"/> + </artifact:dependencies> + + <delete dir="target/files/scopes-test"/> + <mkdir dir="target/files/scopes-test"/> + <copy todir="target/files/scopes-test"> + <fileset refid="dependency.scopes.fileset"/> + </copy> + + <!-- excluded dependency junit:junit --> + <check.file.exists file="target/files/scopes-test/commons-lang/commons-lang" type="dir"/> + <check.file.exists file="target/files/scopes-test/commons-collections/commons-collections" type="dir"/> + <check.file.not.exists file="target/files/scopes-test/org/apache/commons/commons-io" type="dir"/> + <check.file.not.exists file="target/files/scopes-test/commons-logging/commons-logging" type="dir"/> + </target> + <macrodef name="check.file.exists"> <attribute name="file"/> <attribute name="type" default="file"/> Modified: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java URL: http://svn.apache.org/viewvc/maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java?rev=772694&r1=772693&r2=772694&view=diff ============================================================================== --- maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java (original) +++ maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java Thu May 7 16:17:01 2009 @@ -137,7 +137,7 @@ ArtifactFilter filter = null; if ( useScope != null ) { - filter = new ScopeArtifactFilter( useScope ); + filter = new SpecificScopesArtifactFilter( useScope ); } if ( type != null ) { Added: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/SpecificScopesArtifactFilter.java URL: http://svn.apache.org/viewvc/maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/SpecificScopesArtifactFilter.java?rev=772694&view=auto ============================================================================== --- maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/SpecificScopesArtifactFilter.java (added) +++ maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/SpecificScopesArtifactFilter.java Thu May 7 16:17:01 2009 @@ -0,0 +1,106 @@ +package org.apache.maven.artifact.ant; + +/* + * 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/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/SpecificScopesArtifactFilter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/main/java/org/apache/maven/artifact/ant/SpecificScopesArtifactFilter.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Modified: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/examples/dependencies.apt URL: http://svn.apache.org/viewvc/maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/examples/dependencies.apt?rev=772694&r1=772693&r2=772694&view=diff ============================================================================== --- maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/examples/dependencies.apt (original) +++ maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/examples/dependencies.apt Thu May 7 16:17:01 2009 @@ -131,3 +131,26 @@ <echo message="JUnit jar file downloaded to ${junit:junit:jar}"/> ----- +Filtering Dependencies by Scope + + Dependencies from a Pom file can be filtered by scope using the task attribute <<<useScope>>>. + <(since 2.0.10)> The <<<useScope>>> attribute accepts a comma separated list of scopes to + include in the filtering. If no value is specified, all scopes are included. The following + example includes only dependencies with a scope of either "provided" or "test". + +----- + <artifact:dependencies filesetId="deps.fileset" useScope="provided, test"> + <pom file="mypom.xml"/> + </artifact:dependencies> +----- + + Note: prior to version 2.0.10 of the ant tasks, only compile, runtime, and test scopes were supported + and they had the following behaviour. + + * compile - Includes scopes compile, system, and provided + + * runtime - Includes scopes compile and runtime + + * test - Includes scopes system, provided, compile, runtime, and test + + Modified: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/reference.apt URL: http://svn.apache.org/viewvc/maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/reference.apt?rev=772694&r1=772693&r2=772694&view=diff ============================================================================== --- maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/reference.apt (original) +++ maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/apt/reference.apt Thu May 7 16:17:01 2009 @@ -56,7 +56,7 @@ *-------------------------+---------------------------------------------------------------------------+--------------+-------------+ | <<<type>>> | The type of artifacts to be retrieved. The default is <<<jar>>>. | No | | *-------------------------+---------------------------------------------------------------------------+--------------+-------------+ -| <<<useScope>>> | The scope to be retrieved. | No | | +| <<<useScope>>> | A comma separated list of scopes to be retrieved. If no value is provided, all scopes will be included. | No | | *-------------------------+---------------------------------------------------------------------------+--------------+-------------+ | <<<verbose>>> | If <<<true>>> this displays the results of each dependency resolution and their relationships. Default is <false>. | No | | *-------------------------+---------------------------------------------------------------------------+--------------+-------------+ @@ -72,7 +72,7 @@ or a <<<pomRefId>>> attribute or one or more <<<dependency>>> elements. - If you have set a value for <<<versionsId>>>, you can later use {{{reference.html#VersionMapper} <<<VersionMapper>>>}}. + If you have set a value for <<<versionsId>>>, you can later use {{{reference.html#versionMapper} <<<VersionMapper>>>}}. <(since 2.0.8)> For each dependency resolved, the property <<<groupId:artifactId:type[:classifier]>>> is defined pointing to the corresponding file. Modified: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/site.xml URL: http://svn.apache.org/viewvc/maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/site.xml?rev=772694&r1=772693&r2=772694&view=diff ============================================================================== --- maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/site.xml (original) +++ maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/site/site.xml Thu May 7 16:17:01 2009 @@ -41,7 +41,7 @@ <item name="localRepository" href="reference.html#localRepository"/> <item name="remoteRepository" href="reference.html#remoteRepository"/> <item name="pom" href="reference.html#pom"/> - <item name="VersionMapper" href="reference.html#VersionMapper"/> + <item name="versionMapper" href="reference.html#versionMapper"/> </menu> </body> </project> Added: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/pom-with-scopes.xml URL: http://svn.apache.org/viewvc/maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/pom-with-scopes.xml?rev=772694&view=auto ============================================================================== --- maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/pom-with-scopes.xml (added) +++ maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/pom-with-scopes.xml Thu May 7 16:17:01 2009 @@ -0,0 +1,42 @@ +<?xml version="1.0"?> + +<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>it.ant-tasks</groupId> + <artifactId>scope-filtering</artifactId> + <packaging>jar</packaging> + + <name>Filter deps by scope</name> + <version>1.0-SNAPSHOT</version> + <description> + Check dependencies order after resolution. + </description> + <dependencies> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-io</artifactId> + <version>1.3.2</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.3</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + <version>1.1.1</version> + <scope>runtime</scope> + </dependency> + <dependency> + <groupId>commons-collections</groupId> + <artifactId>commons-collections</artifactId> + <version>3.2</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> Propchange: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/pom-with-scopes.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/pom-with-scopes.xml ------------------------------------------------------------------------------ svn:executable = * Propchange: maven/ant-tasks/branches/maven-ant-tasks-2.0.x/src/test/pom-with-scopes.xml ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision