You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by mi...@apache.org on 2016/11/08 19:51:56 UTC

svn commit: r1768770 - in /maven/plugins/trunk/maven-dependency-plugin: main/ main/java/ main/java/org/ main/java/org/apache/ main/java/org/apache/maven/ main/java/org/apache/maven/plugins/ main/java/org/apache/maven/plugins/dependency/ main/java/org/a...

Author: michaelo
Date: Tue Nov  8 19:51:56 2016
New Revision: 1768770

URL: http://svn.apache.org/viewvc?rev=1768770&view=rev
Log:
[MDEP-410] Add dependency:collect goal which prints the dependency list by resolving the POMs only

Submitted by: Eric Pabst <pa...@familysearch.org>

This closes #19

Added:
    maven/plugins/trunk/maven-dependency-plugin/main/
    maven/plugins/trunk/maven-dependency-plugin/main/java/
    maven/plugins/trunk/maven-dependency-plugin/main/java/org/
    maven/plugins/trunk/maven-dependency-plugin/main/java/org/apache/
    maven/plugins/trunk/maven-dependency-plugin/main/java/org/apache/maven/
    maven/plugins/trunk/maven-dependency-plugin/main/java/org/apache/maven/plugins/
    maven/plugins/trunk/maven-dependency-plugin/main/java/org/apache/maven/plugins/dependency/
    maven/plugins/trunk/maven-dependency-plugin/main/java/org/apache/maven/plugins/dependency/resolvers/
    maven/plugins/trunk/maven-dependency-plugin/main/java/org/apache/maven/plugins/dependency/resolvers/CollectDependenciesMojo.java
    maven/plugins/trunk/maven-dependency-plugin/test/
    maven/plugins/trunk/maven-dependency-plugin/test/java/
    maven/plugins/trunk/maven-dependency-plugin/test/java/org/
    maven/plugins/trunk/maven-dependency-plugin/test/java/org/apache/
    maven/plugins/trunk/maven-dependency-plugin/test/java/org/apache/maven/
    maven/plugins/trunk/maven-dependency-plugin/test/java/org/apache/maven/plugins/
    maven/plugins/trunk/maven-dependency-plugin/test/java/org/apache/maven/plugins/dependency/
    maven/plugins/trunk/maven-dependency-plugin/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java
    maven/plugins/trunk/maven-dependency-plugin/test/resources/
    maven/plugins/trunk/maven-dependency-plugin/test/resources/its/
    maven/plugins/trunk/maven-dependency-plugin/test/resources/its/collect/
    maven/plugins/trunk/maven-dependency-plugin/test/resources/its/collect/pom.xml
    maven/plugins/trunk/maven-dependency-plugin/test/resources/unit/
    maven/plugins/trunk/maven-dependency-plugin/test/resources/unit/collect-test/
    maven/plugins/trunk/maven-dependency-plugin/test/resources/unit/collect-test/plugin-config.xml

Added: maven/plugins/trunk/maven-dependency-plugin/main/java/org/apache/maven/plugins/dependency/resolvers/CollectDependenciesMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/main/java/org/apache/maven/plugins/dependency/resolvers/CollectDependenciesMojo.java?rev=1768770&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/main/java/org/apache/maven/plugins/dependency/resolvers/CollectDependenciesMojo.java (added)
+++ maven/plugins/trunk/maven-dependency-plugin/main/java/org/apache/maven/plugins/dependency/resolvers/CollectDependenciesMojo.java Tue Nov  8 19:51:56 2016
@@ -0,0 +1,45 @@
+package org.apache.maven.plugins.dependency.resolvers;
+
+/*
+ * 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.plugins.annotations.LifecyclePhase;
+import org.apache.maven.plugins.annotations.Mojo;
+import org.apache.maven.plugins.annotations.ResolutionScope;
+
+/**
+ * Goal that collects the project dependencies from the repository.
+ * This goal requires Maven 3.0 or higher to function because it uses "requiresDependencyCollection".
+ * This means that it lists the groupId:artifactId:version information by downloading the pom files
+ * without downloading the actual artifacts such as jar files.
+ * This is very useful when full dependency resolution might fail due to projects which haven't been built yet.
+ * <p/>
+ * It is identical to {@link ResolveDependenciesMojo} except for using the requiresDependencyCollection annotation
+ * attribute instead of requiresDependencyResolution.
+ *
+ * @author <a href="mailto:epabst@gmail.com">Eric Pabst</a>
+ * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
+ * @version $Id$
+ * @since 3.0
+ */
+@Mojo( name = "collect", requiresDependencyCollection = ResolutionScope.TEST,
+       defaultPhase = LifecyclePhase.GENERATE_SOURCES, threadSafe = true )
+public class CollectDependenciesMojo extends ResolveDependenciesMojo
+{
+}

Added: maven/plugins/trunk/maven-dependency-plugin/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java?rev=1768770&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java (added)
+++ maven/plugins/trunk/maven-dependency-plugin/test/java/org/apache/maven/plugins/dependency/TestCollectMojo.java Tue Nov  8 19:51:56 2016
@@ -0,0 +1,111 @@
+package org.apache.maven.plugins.dependency;
+
+/*
+ * 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.plugins.dependency.resolvers.CollectDependenciesMojo;
+import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
+import org.apache.maven.plugin.testing.SilentLog;
+import org.apache.maven.project.MavenProject;
+
+import java.io.File;
+import java.util.Set;
+
+public class TestCollectMojo
+    extends AbstractDependencyMojoTestCase
+{
+
+    protected void setUp()
+        throws Exception
+    {
+        // required for mojo lookups to work
+        super.setUp( "markers", false );
+    }
+
+    /**
+     * tests the proper discovery and configuration of the mojo
+     * 
+     * @throws Exception if a problem occurs
+     */
+    public void testCollectTestEnvironment()
+        throws Exception
+    {
+        File testPom = new File( getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml" );
+        CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo( "collect", testPom );
+
+        assertNotNull( mojo );
+        assertNotNull( mojo.getProject() );
+        MavenProject project = mojo.getProject();
+
+        mojo.setSilent( true );
+        Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
+        Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
+        artifacts.addAll( directArtifacts );
+
+        project.setArtifacts( artifacts );
+        project.setDependencyArtifacts( directArtifacts );
+
+        mojo.execute();
+        DependencyStatusSets results = mojo.getResults();
+        assertNotNull( results );
+        assertEquals( artifacts.size(), results.getResolvedDependencies().size() );
+    }
+
+    /**
+     * tests the proper discovery and configuration of the mojo
+     *
+     * @throws Exception if a problem occurs
+     */
+    public void testCollectTestEnvironment_excludeTransitive()
+        throws Exception
+    {
+        File testPom = new File( getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml" );
+        CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo( "collect", testPom );
+
+        assertNotNull( mojo );
+        assertNotNull( mojo.getProject() );
+        MavenProject project = mojo.getProject();
+
+        mojo.setSilent( true );
+        Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
+        Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
+        artifacts.addAll( directArtifacts );
+
+        project.setArtifacts( artifacts );
+        project.setDependencyArtifacts( directArtifacts );
+
+        setVariableValueToObject( mojo, "excludeTransitive", Boolean.TRUE );
+
+        mojo.execute();
+        DependencyStatusSets results = mojo.getResults();
+        assertNotNull( results );
+        assertEquals( directArtifacts.size(), results.getResolvedDependencies().size() );
+    }
+
+    public void testSilent()
+        throws Exception
+    {
+        File testPom = new File( getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml" );
+        CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo( "collect", testPom );
+        mojo.setSilent( false );
+
+        assertFalse( mojo.getLog() instanceof SilentLog );
+    } // TODO: Test skipping artifacts.
+}

Added: maven/plugins/trunk/maven-dependency-plugin/test/resources/its/collect/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/test/resources/its/collect/pom.xml?rev=1768770&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/test/resources/its/collect/pom.xml (added)
+++ maven/plugins/trunk/maven-dependency-plugin/test/resources/its/collect/pom.xml Tue Nov  8 19:51:56 2016
@@ -0,0 +1,55 @@
+<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/xsd/maven-4.0.0.xsd">
+<!--
+ * 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.
+ *
+-->
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>test</groupId>
+    <artifactId>maven-dependency-plugin-it-parent</artifactId>
+    <version>1</version>
+  </parent>
+
+  <artifactId>maven-dependency-plugin-it-collect</artifactId>
+  <packaging>pom</packaging>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>2.0.6</version>
+    </dependency>
+  </dependencies>
+  <!--This must be set so the correct version is used for the IT test-->
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <executions>
+          <execution>
+            <id>collect</id>
+            <goals>
+              <goal>collect</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Added: maven/plugins/trunk/maven-dependency-plugin/test/resources/unit/collect-test/plugin-config.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-dependency-plugin/test/resources/unit/collect-test/plugin-config.xml?rev=1768770&view=auto
==============================================================================
--- maven/plugins/trunk/maven-dependency-plugin/test/resources/unit/collect-test/plugin-config.xml (added)
+++ maven/plugins/trunk/maven-dependency-plugin/test/resources/unit/collect-test/plugin-config.xml Tue Nov  8 19:51:56 2016
@@ -0,0 +1,38 @@
+<!--
+ * 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>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-dependency-plugin</artifactId>
+        <configuration>
+          <project implementation="org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub"/>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>2.0.4</version>
+    </dependency>
+  </dependencies>
+</project>