View Javadoc

1   package org.apache.maven.plugin.dependency.resolvers;
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.plugin.MojoExecutionException;
23  import org.apache.maven.plugin.dependency.AbstractResolveMojo;
24  import org.apache.maven.plugin.dependency.utils.DependencyStatusSets;
25  import org.apache.maven.plugin.dependency.utils.DependencyUtil;
26  import org.apache.maven.plugin.dependency.utils.filters.ResolveFileFilter;
27  import org.apache.maven.plugin.dependency.utils.markers.SourcesFileMarkerHandler;
28  import org.apache.maven.plugins.annotations.LifecyclePhase;
29  import org.apache.maven.plugins.annotations.Mojo;
30  import org.apache.maven.plugins.annotations.Parameter;
31  import org.apache.maven.plugins.annotations.ResolutionScope;
32  import org.apache.maven.shared.artifact.filter.collection.ArtifactsFilter;
33  
34  import java.io.IOException;
35  
36  /**
37   * Goal that resolves the project dependencies from the repository.
38   *
39   * @author <a href="mailto:brianf@apache.org">Brian Fox</a>
40   * @version $Id: ResolveDependenciesMojo.java 1357251 2012-07-04 13:28:33Z olamy $
41   * @since 2.0
42   */
43  @Mojo( name = "resolve", requiresDependencyResolution = ResolutionScope.TEST,
44         defaultPhase = LifecyclePhase.GENERATE_SOURCES )
45  public class ResolveDependenciesMojo
46      extends AbstractResolveMojo
47  {
48  
49      /**
50       * If we should display the scope when resolving
51       *
52       * @since 2.0-alpha-2
53       */
54      @Parameter( property = "mdep.outputScope", defaultValue = "true" )
55      protected boolean outputScope;
56  
57      /**
58       * Only used to store results for integration test validation
59       */
60      DependencyStatusSets results;
61  
62      /**
63       * Main entry into mojo. Gets the list of dependencies and iterates through displaying the resolved version.
64       *
65       * @throws MojoExecutionException with a message if an error occurs.
66       */
67      public void execute()
68          throws MojoExecutionException
69      {
70          // get sets of dependencies
71          results = this.getDependencySets( false );
72  
73          String output = results.getOutput( outputAbsoluteArtifactFilename, outputScope );
74          try
75          {
76              if ( outputFile == null )
77              {
78                  DependencyUtil.log( output, getLog() );
79              }
80              else
81              {
82                  DependencyUtil.write( output, outputFile, appendOutput, getLog() );
83              }
84          }
85          catch ( IOException e )
86          {
87              throw new MojoExecutionException( e.getMessage(), e );
88          }
89      }
90  
91      /**
92       * @return Returns the results.
93       */
94      public DependencyStatusSets getResults()
95      {
96          return this.results;
97      }
98  
99      protected ArtifactsFilter getMarkedArtifactFilter()
100     {
101         return new ResolveFileFilter( new SourcesFileMarkerHandler( this.markersDirectory ) );
102     }
103 }