View Javadoc
1   package org.apache.maven.plugins.dependency;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.Artifact;
23  import org.apache.maven.plugins.dependency.resolvers.CollectDependenciesMojo;
24  import org.apache.maven.plugins.dependency.utils.DependencyStatusSets;
25  import org.apache.maven.plugin.testing.SilentLog;
26  import org.apache.maven.project.MavenProject;
27  
28  import java.io.File;
29  import java.util.Set;
30  
31  public class TestCollectMojo
32      extends AbstractDependencyMojoTestCase
33  {
34  
35      protected void setUp()
36          throws Exception
37      {
38          // required for mojo lookups to work
39          super.setUp( "markers", false );
40      }
41  
42      /**
43       * tests the proper discovery and configuration of the mojo
44       * 
45       * @throws Exception if a problem occurs
46       */
47      public void testCollectTestEnvironment()
48          throws Exception
49      {
50          File testPom = new File( getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml" );
51          CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo( "collect", testPom );
52  
53          assertNotNull( mojo );
54          assertNotNull( mojo.getProject() );
55          MavenProject project = mojo.getProject();
56  
57          mojo.setSilent( true );
58          Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
59          Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
60          artifacts.addAll( directArtifacts );
61  
62          project.setArtifacts( artifacts );
63          project.setDependencyArtifacts( directArtifacts );
64  
65          mojo.execute();
66          DependencyStatusSets results = mojo.getResults();
67          assertNotNull( results );
68          assertEquals( artifacts.size(), results.getResolvedDependencies().size() );
69      }
70  
71      /**
72       * tests the proper discovery and configuration of the mojo
73       *
74       * @throws Exception if a problem occurs
75       */
76      public void testCollectTestEnvironment_excludeTransitive()
77          throws Exception
78      {
79          File testPom = new File( getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml" );
80          CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo( "collect", testPom );
81  
82          assertNotNull( mojo );
83          assertNotNull( mojo.getProject() );
84          MavenProject project = mojo.getProject();
85  
86          mojo.setSilent( true );
87          Set<Artifact> artifacts = this.stubFactory.getScopedArtifacts();
88          Set<Artifact> directArtifacts = this.stubFactory.getReleaseAndSnapshotArtifacts();
89          artifacts.addAll( directArtifacts );
90  
91          project.setArtifacts( artifacts );
92          project.setDependencyArtifacts( directArtifacts );
93  
94          setVariableValueToObject( mojo, "excludeTransitive", Boolean.TRUE );
95  
96          mojo.execute();
97          DependencyStatusSets results = mojo.getResults();
98          assertNotNull( results );
99          assertEquals( directArtifacts.size(), results.getResolvedDependencies().size() );
100     }
101 
102     public void testSilent()
103         throws Exception
104     {
105         File testPom = new File( getBasedir(), "target/test-classes/unit/collect-test/plugin-config.xml" );
106         CollectDependenciesMojo mojo = (CollectDependenciesMojo) lookupMojo( "collect", testPom );
107         mojo.setSilent( false );
108 
109         assertFalse( mojo.getLog() instanceof SilentLog );
110     } // TODO: Test skipping artifacts.
111 }