View Javadoc

1   package org.apache.maven.plugin.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 java.io.File;
23  import java.util.Set;
24  
25  import org.apache.maven.artifact.Artifact;
26  import org.apache.maven.plugin.dependency.resolvers.ResolveDependenciesMojo;
27  import org.apache.maven.plugin.dependency.utils.DependencyStatusSets;
28  import org.apache.maven.plugin.testing.SilentLog;
29  import org.apache.maven.project.MavenProject;
30  
31  public class TestResolveMojo
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
46       */
47      public void testresolveTestEnvironment()
48          throws Exception
49      {
50          File testPom = new File( getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml" );
51          ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo( "resolve", testPom );
52  
53          assertNotNull( mojo );
54          assertNotNull( mojo.getProject() );
55          MavenProject project = mojo.getProject();
56  
57          mojo.silent = 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          setVariableValueToObject( mojo, "excludeTransitive", Boolean.TRUE );
71  
72          mojo.execute();
73          results = mojo.getResults();
74          assertNotNull( results );
75          assertEquals( directArtifacts.size(), results.getResolvedDependencies().size() );
76      }
77  
78      public void testSilent()
79          throws Exception
80      {
81          File testPom = new File( getBasedir(), "target/test-classes/unit/resolve-test/plugin-config.xml" );
82          ResolveDependenciesMojo mojo = (ResolveDependenciesMojo) lookupMojo( "resolve", testPom );
83          mojo.silent = false;
84  
85          assertFalse( mojo.getLog() instanceof SilentLog );
86      } // TODO: Test skipping artifacts.
87  }