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 java.util.Locale;
23  
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.DefaultProjectBuildingRequest;
30  import org.apache.maven.project.ProjectBuildingRequest;
31  import org.apache.maven.report.projectinfo.dependencies.ManagementDependencies;
32  import org.apache.maven.report.projectinfo.dependencies.RepositoryUtils;
33  import org.apache.maven.report.projectinfo.dependencies.renderer.DependencyManagementRenderer;
34  
35  /**
36   * Generates the Project Dependency Management report.
37   *
38   * @author Nick Stolwijk
39   * @since 2.1
40   */
41  @Mojo( name = "dependency-management", requiresDependencyResolution = ResolutionScope.TEST )
42  public class DependencyManagementReport
43      extends AbstractProjectInfoReport
44  {
45      // ----------------------------------------------------------------------
46      // Mojo components
47      // ----------------------------------------------------------------------
48  
49      /**
50       * Artifact metadata source component.
51       *
52       * @since 2.4
53       */
54      @Component
55      protected ArtifactMetadataSource artifactMetadataSource;
56  
57      /**
58       * Repository metadata component.
59       *
60       * @since 2.3
61       */
62      @Component
63      private RepositoryMetadataManager repositoryMetadataManager;
64  
65      // ----------------------------------------------------------------------
66      // Mojo parameters
67      // ----------------------------------------------------------------------
68  
69      /**
70       * Lazy instantiation for management dependencies.
71       */
72      private ManagementDependencies managementDependencies;
73  
74      // ----------------------------------------------------------------------
75      // Public methods
76      // ----------------------------------------------------------------------
77  
78      @Override
79      public boolean canGenerateReport()
80      {
81          boolean result = super.canGenerateReport();
82          if ( result && skipEmptyReport )
83          {
84              result = getManagementDependencies().hasDependencies();
85          }
86  
87          return result;
88      }
89  
90      @Override
91      public void executeReport( Locale locale )
92      {
93          ProjectBuildingRequest buildingRequest =
94              new DefaultProjectBuildingRequest( getSession().getProjectBuildingRequest() );
95          buildingRequest.setLocalRepository( localRepository );
96          buildingRequest.setRemoteRepositories( remoteRepositories );
97          buildingRequest.setPluginArtifactRepositories( pluginRepositories );
98          
99          RepositoryUtils repoUtils =
100             new RepositoryUtils( getLog(), projectBuilder, repositorySystem, resolver,
101                                  project.getRemoteArtifactRepositories(), project.getPluginArtifactRepositories(),
102                                  buildingRequest, repositoryMetadataManager );
103 
104         DependencyManagementRenderer r =
105             new DependencyManagementRenderer( getSink(), locale, getI18N( locale ), getLog(),
106                                               getManagementDependencies(), artifactMetadataSource, repositorySystem,
107                                               projectBuilder, buildingRequest, repoUtils, getLicenseMappings() );
108         r.render();
109     }
110 
111     /**
112      * {@inheritDoc}
113      */
114     public String getOutputName()
115     {
116         return "dependency-management";
117     }
118 
119     @Override
120     protected String getI18Nsection()
121     {
122         return "dependency-management";
123     }
124 
125     // ----------------------------------------------------------------------
126     // Private methods
127     // ----------------------------------------------------------------------
128 
129     private ManagementDependencies getManagementDependencies()
130     {
131         if ( managementDependencies != null )
132         {
133             return managementDependencies;
134         }
135 
136         if ( project.getDependencyManagement() == null )
137         {
138             managementDependencies = new ManagementDependencies( null );
139         }
140         else
141         {
142             managementDependencies = new ManagementDependencies( project.getDependencyManagement().getDependencies() );
143         }
144 
145         return managementDependencies;
146     }
147 }