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