View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.report.projectinfo;
20  
21  import java.util.Locale;
22  
23  import org.apache.maven.artifact.metadata.ArtifactMetadataSource;
24  import org.apache.maven.artifact.repository.metadata.RepositoryMetadataManager;
25  import org.apache.maven.plugins.annotations.Component;
26  import org.apache.maven.plugins.annotations.Mojo;
27  import org.apache.maven.plugins.annotations.ResolutionScope;
28  import org.apache.maven.project.DefaultProjectBuildingRequest;
29  import org.apache.maven.project.ProjectBuildingRequest;
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  import org.apache.maven.reporting.MavenReportException;
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 extends AbstractProjectInfoReport {
43      // ----------------------------------------------------------------------
44      // Mojo components
45      // ----------------------------------------------------------------------
46  
47      /**
48       * Artifact metadata source component.
49       *
50       * @since 2.4
51       */
52      @Component
53      protected ArtifactMetadataSource artifactMetadataSource;
54  
55      /**
56       * Repository metadata component.
57       *
58       * @since 2.3
59       */
60      @Component
61      private RepositoryMetadataManager repositoryMetadataManager;
62  
63      // ----------------------------------------------------------------------
64      // Mojo parameters
65      // ----------------------------------------------------------------------
66  
67      /**
68       * Lazy instantiation for management dependencies.
69       */
70      private ManagementDependencies managementDependencies;
71  
72      // ----------------------------------------------------------------------
73      // Public methods
74      // ----------------------------------------------------------------------
75  
76      @Override
77      public boolean canGenerateReport() throws MavenReportException {
78          boolean result = super.canGenerateReport();
79          if (result && skipEmptyReport) {
80              result = getManagementDependencies().hasDependencies();
81          }
82  
83          return result;
84      }
85  
86      @Override
87      public void executeReport(Locale locale) {
88          ProjectBuildingRequest buildingRequest =
89                  new DefaultProjectBuildingRequest(getSession().getProjectBuildingRequest());
90          buildingRequest.setLocalRepository(localRepository);
91          buildingRequest.setRemoteRepositories(remoteRepositories);
92          buildingRequest.setPluginArtifactRepositories(pluginRepositories);
93          buildingRequest.setProcessPlugins(false);
94  
95          RepositoryUtils repoUtils = new RepositoryUtils(
96                  getLog(),
97                  projectBuilder,
98                  repositorySystem,
99                  resolver,
100                 remoteRepositories,
101                 pluginRepositories,
102                 buildingRequest,
103                 repositoryMetadataManager);
104 
105         DependencyManagementRenderer r = new DependencyManagementRenderer(
106                 getSink(),
107                 locale,
108                 getI18N(locale),
109                 getLog(),
110                 getManagementDependencies(),
111                 artifactMetadataSource,
112                 repositorySystem,
113                 projectBuilder,
114                 buildingRequest,
115                 repoUtils,
116                 getLicenseMappings());
117         r.render();
118     }
119 
120     /**
121      * {@inheritDoc}
122      */
123     public String getOutputName() {
124         return "dependency-management";
125     }
126 
127     @Override
128     protected String getI18Nsection() {
129         return "dependency-management";
130     }
131 
132     // ----------------------------------------------------------------------
133     // Private methods
134     // ----------------------------------------------------------------------
135 
136     private ManagementDependencies getManagementDependencies() {
137         if (managementDependencies != null) {
138             return managementDependencies;
139         }
140 
141         if (project.getDependencyManagement() == null) {
142             managementDependencies = new ManagementDependencies(null);
143         } else {
144             managementDependencies =
145                     new ManagementDependencies(project.getDependencyManagement().getDependencies());
146         }
147 
148         return managementDependencies;
149     }
150 }