View Javadoc

1   package org.apache.maven.report.projectinfo;
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.factory.ArtifactFactory;
23  import org.apache.maven.artifact.manager.WagonManager;
24  import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
25  import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
26  import org.apache.maven.plugins.annotations.Component;
27  import org.apache.maven.plugins.annotations.Mojo;
28  import org.apache.maven.plugins.annotations.ResolutionScope;
29  import org.apache.maven.project.MavenProjectBuilder;
30  import org.apache.maven.report.projectinfo.dependencies.ManagementDependencies;
31  import org.apache.maven.report.projectinfo.dependencies.RepositoryUtils;
32  import org.apache.maven.report.projectinfo.dependencies.renderer.DependencyManagementRenderer;
33  
34  import java.util.Locale;
35  
36  /**
37   * Generates the Project Dependency Management report.
38   *
39   * @author Nick Stolwijk
40   * @version $Id: DependencyManagementReport.java 1359783 2012-07-10 16:57:48Z tchemit $
41   * @since 2.1
42   */
43  @Mojo( name = "dependency-management", requiresDependencyResolution = ResolutionScope.TEST )
44  public class DependencyManagementReport
45      extends AbstractProjectInfoReport
46  {
47      // ----------------------------------------------------------------------
48      // Mojo components
49      // ----------------------------------------------------------------------
50  
51      /**
52       * Maven Project Builder component.
53       */
54      @Component
55      private MavenProjectBuilder mavenProjectBuilder;
56  
57      /**
58       * Artifact metadata source component.
59       *
60       * @since 2.4
61       */
62      @Component
63      protected ArtifactMetadataSource artifactMetadataSource;
64  
65      /**
66       * Maven Artifact Factory component.
67       */
68      @Component
69      private ArtifactFactory artifactFactory;
70  
71      /**
72       * Wagon manager component.
73       *
74       * @since 2.3
75       */
76      @Component
77      private WagonManager wagonManager;
78  
79      /**
80       * Repository metadata component.
81       *
82       * @since 2.3
83       */
84      @Component
85      private RepositoryMetadataManager repositoryMetadataManager;
86  
87      // ----------------------------------------------------------------------
88      // Mojo parameters
89      // ----------------------------------------------------------------------
90  
91      /**
92       * Lazy instantiation for management dependencies.
93       */
94      private ManagementDependencies managementDependencies;
95  
96      // ----------------------------------------------------------------------
97      // Public methods
98      // ----------------------------------------------------------------------
99  
100     @Override
101     public void executeReport( Locale locale )
102     {
103         @SuppressWarnings( "unchecked" ) RepositoryUtils repoUtils =
104             new RepositoryUtils( getLog(), wagonManager, settings, mavenProjectBuilder, factory, resolver,
105                                  project.getRemoteArtifactRepositories(), project.getPluginArtifactRepositories(),
106                                  localRepository, repositoryMetadataManager );
107 
108         DependencyManagementRenderer r =
109             new DependencyManagementRenderer( getSink(), locale, getI18N( locale ), getLog(),
110                                               getManagementDependencies(), artifactMetadataSource, artifactFactory,
111                                               mavenProjectBuilder, remoteRepositories, localRepository, repoUtils );
112         r.render();
113     }
114 
115     /**
116      * {@inheritDoc}
117      */
118     public String getOutputName()
119     {
120         return "dependency-management";
121     }
122 
123     @Override
124     protected String getI18Nsection()
125     {
126         return "dependencyManagement";
127     }
128 
129     @Override
130     public boolean canGenerateReport()
131     {
132         return getManagementDependencies().hasDependencies();
133     }
134 
135     // ----------------------------------------------------------------------
136     // Private methods
137     // ----------------------------------------------------------------------
138 
139     private ManagementDependencies getManagementDependencies()
140     {
141         if ( managementDependencies != null )
142         {
143             return managementDependencies;
144         }
145 
146         if ( project.getDependencyManagement() == null )
147         {
148             managementDependencies = new ManagementDependencies( null );
149         }
150         else
151         {
152             managementDependencies = new ManagementDependencies( project.getDependencyManagement().getDependencies() );
153         }
154 
155         return managementDependencies;
156     }
157 }