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