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