You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2010/07/17 18:07:19 UTC

svn commit: r965098 - in /maven/ant-tasks/trunk: build-tests.xml src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java src/site/apt/reference.apt

Author: hboutemy
Date: Sat Jul 17 16:07:18 2010
New Revision: 965098

URL: http://svn.apache.org/viewvc?rev=965098&view=rev
Log:
[MANTTASKS-190] added dependency scope validation

Modified:
    maven/ant-tasks/trunk/build-tests.xml
    maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java
    maven/ant-tasks/trunk/src/site/apt/reference.apt

Modified: maven/ant-tasks/trunk/build-tests.xml
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/build-tests.xml?rev=965098&r1=965097&r2=965098&view=diff
==============================================================================
--- maven/ant-tasks/trunk/build-tests.xml (original)
+++ maven/ant-tasks/trunk/build-tests.xml Sat Jul 17 16:07:18 2010
@@ -65,8 +65,12 @@
   <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,test-deps-scopes,test-system-scope">
-    <echo>test-bad-dep and test-invalid-pom-ref must be run manually, since they are intended to fail</echo>
+             test-deps-sources,test-deps-sources-empty,test-deps-profile,test-deps-scopes,test-system-scope,
+  	         test-bad-scope">
+    <echo>Some tests must be run manually, since they are intended to fail:
+        - test-bad-dep
+        - test-invalid-pom-ref
+    </echo>
   </target>
 
   <target name="test-all-pubs" description="All publication tests (install/deploy)"
@@ -93,11 +97,19 @@
   </target>
 
   <target name="test-bad-dep" depends="initTaskDefs">
+  	<echo>Expected failure because foo:foo:jar:1.0-alpha-2 artifact does not exist.</echo>
     <artifact:dependencies pathId="dependency.classpath" filesetId="dependency.fileset">
       <dependency groupId="foo" artifactId="foo" version="1.0-alpha-2"/>
     </artifact:dependencies>
   </target>
 
+  <target name="test-bad-scope" depends="initTaskDefs">
+  	<echo>Expected warning because 'bad-value' is not a valid scope. Error message must show official scopes. See MANTTASKS-190 for more information.</echo>
+    <artifact:dependencies>
+      <dependency groupId="commons-logging" artifactId="commons-logging" version="1.1.1" scope="bad-value"/>
+    </artifact:dependencies>
+  </target>
+
   <target name="test-pom" depends="initTaskDefs">
     <artifact:pom file="pom.xml" id="my.maven.project"/>
 

Modified: maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java?rev=965098&r1=965097&r2=965098&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java (original)
+++ maven/ant-tasks/trunk/src/main/java/org/apache/maven/artifact/ant/DependenciesTask.java Sat Jul 17 16:07:18 2010
@@ -44,6 +44,7 @@ import org.codehaus.plexus.util.StringUt
 
 import java.io.File;
 import java.io.IOException;
+import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
@@ -62,6 +63,14 @@ import java.util.Set;
 public class DependenciesTask
     extends AbstractArtifactWithRepositoryTask
 {
+    private static final String[] SCOPES = { Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_RUNTIME,
+        Artifact.SCOPE_TEST };
+
+    private static final Set<String> SCOPES_SET;
+    static
+    {
+        SCOPES_SET = new HashSet<String>( Arrays.asList( SCOPES ) );
+    }
 
     public static final String DEFAULT_ANT_BUILD_FILE = "target/build-dependencies.xml";
 
@@ -94,8 +103,8 @@ public class DependenciesTask
     private String versionsId;
 
     /**
-     * A specific maven scope used to determine which dependencies are resolved.
-     * This takes only a single scope and uses the standard maven ScopeArtifactFilter.
+     * A specific Maven scope used to determine which dependencies are resolved.
+     * This takes only a single scope and uses the standard Maven ScopeArtifactFilter.
      */
     private String useScope;
 
@@ -179,6 +188,21 @@ public class DependenciesTask
         {
             log( "There were no dependencies specified", Project.MSG_WARN );
         }
+        else
+        {
+            // check scopes
+            for ( Dependency dependency : dependencies )
+            {
+                String scope = dependency.getScope();
+
+                if ( ( scope != null ) && !SCOPES_SET.contains( scope ) )
+                {
+                    // see MANTTASKS-190
+                    log( "Unknown scope='" + scope + "' for " + dependency + ", supported scopes are: " + SCOPES_SET,
+                         Project.MSG_WARN );
+                }
+            }
+        }
 
         log( "Resolving dependencies...", Project.MSG_VERBOSE );
 
@@ -537,8 +561,8 @@ public class DependenciesTask
     }
 
     /**
-     * Use the maven artifact filtering for a particular scope.  This
-     * uses the standard maven ScopeArtifactFilter.
+     * Use the Maven artifact filtering for a particular scope.  This
+     * uses the standard Maven ScopeArtifactFilter.
      *
      * @param useScope
      */
@@ -573,7 +597,7 @@ public class DependenciesTask
      */
     public void setAddArtifactFileSetRefs( boolean addArtifactFileSetRefs )
     {
-        this.log( "Parameter addArtifactFileSetRefs is deprecated.  A fileset ref is always created" +
+        this.log( "Parameter addArtifactFileSetRefs is deprecated. A fileset ref is always created " +
         		"for each dependency.", Project.MSG_WARN );
     }
 

Modified: maven/ant-tasks/trunk/src/site/apt/reference.apt
URL: http://svn.apache.org/viewvc/maven/ant-tasks/trunk/src/site/apt/reference.apt?rev=965098&r1=965097&r2=965098&view=diff
==============================================================================
--- maven/ant-tasks/trunk/src/site/apt/reference.apt (original)
+++ maven/ant-tasks/trunk/src/site/apt/reference.apt Sat Jul 17 16:07:18 2010
@@ -102,7 +102,7 @@
 *------------------+--------------------------------------------------------+--------------+
 | <<<classifier>>> | The classifier of the dependency.                      | No           |
 *------------------+--------------------------------------------------------+--------------+
-| <<<scope>>>      | The scope of the usage of the dependency, which affects which of that dependency's own dependencies are also retrieved. This can be <<<compile>>>, <<<runtime>>>, <<<test>>>, <<<provided>>>. | No |
+| <<<scope>>>      | The scope of the usage of the dependency, which {{{http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Dependency_Scope}} affects which of that dependency's own dependencies are also retrieved}. This can be <<<compile>>> (default), <<<runtime>>>, <<<test>>>, <<<provided>>>. | No |
 *------------------+--------------------------------------------------------+--------------+
 
   The dependency can also nest multiple <<<exclusion>>> elements.