1 | |
package org.apache.maven.report.projectinfo; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.util.ArrayList; |
23 | |
import java.util.Collections; |
24 | |
import java.util.Comparator; |
25 | |
import java.util.Iterator; |
26 | |
import java.util.List; |
27 | |
import java.util.Locale; |
28 | |
import java.util.Set; |
29 | |
|
30 | |
import org.apache.maven.artifact.Artifact; |
31 | |
import org.apache.maven.artifact.factory.ArtifactFactory; |
32 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
33 | |
import org.apache.maven.artifact.versioning.VersionRange; |
34 | |
import org.apache.maven.doxia.sink.Sink; |
35 | |
import org.apache.maven.plugin.logging.Log; |
36 | |
import org.apache.maven.project.MavenProject; |
37 | |
import org.apache.maven.project.MavenProjectBuilder; |
38 | |
import org.apache.maven.project.ProjectBuildingException; |
39 | |
import org.codehaus.plexus.i18n.I18N; |
40 | |
import org.codehaus.plexus.util.StringUtils; |
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | 0 | public class PluginsReport |
52 | |
extends AbstractProjectInfoReport |
53 | |
{ |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
private MavenProjectBuilder mavenProjectBuilder; |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
private ArtifactFactory artifactFactory; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
public void executeReport( Locale locale ) |
78 | |
{ |
79 | 0 | PluginsRenderer r = new PluginsRenderer( getLog(), getSink(), locale, i18n, project.getPluginArtifacts(), |
80 | |
project.getReportArtifacts(), project, mavenProjectBuilder, |
81 | |
artifactFactory, localRepository ); |
82 | 0 | r.render(); |
83 | 0 | } |
84 | |
|
85 | |
|
86 | |
public String getOutputName() |
87 | |
{ |
88 | 0 | return "plugins"; |
89 | |
} |
90 | |
|
91 | |
protected String getI18Nsection() |
92 | |
{ |
93 | 0 | return "plugins"; |
94 | |
} |
95 | |
|
96 | |
|
97 | |
public boolean canGenerateReport() |
98 | |
{ |
99 | 0 | return ( project.getPluginArtifacts() != null && !project.getPluginArtifacts().isEmpty() ) |
100 | |
|| ( project.getReportArtifacts() != null && !project.getReportArtifacts().isEmpty() ); |
101 | |
} |
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | 0 | protected static class PluginsRenderer |
111 | |
extends AbstractProjectInfoRenderer |
112 | |
{ |
113 | |
private final Log log; |
114 | |
|
115 | |
private final List plugins; |
116 | |
|
117 | |
private final List reports; |
118 | |
|
119 | |
private final MavenProject project; |
120 | |
|
121 | |
private final MavenProjectBuilder mavenProjectBuilder; |
122 | |
|
123 | |
private final ArtifactFactory artifactFactory; |
124 | |
|
125 | |
private final ArtifactRepository localRepository; |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
|
138 | |
|
139 | |
public PluginsRenderer( Log log, Sink sink, Locale locale, I18N i18n, Set plugins, Set reports, |
140 | |
MavenProject project, MavenProjectBuilder mavenProjectBuilder, |
141 | |
ArtifactFactory artifactFactory, ArtifactRepository localRepository ) |
142 | |
{ |
143 | 0 | super( sink, i18n, locale ); |
144 | |
|
145 | 0 | this.log = log; |
146 | |
|
147 | 0 | this.plugins = new ArrayList( plugins ); |
148 | |
|
149 | 0 | this.reports = new ArrayList( reports ); |
150 | |
|
151 | 0 | this.project = project; |
152 | |
|
153 | 0 | this.mavenProjectBuilder = mavenProjectBuilder; |
154 | |
|
155 | 0 | this.artifactFactory = artifactFactory; |
156 | |
|
157 | 0 | this.localRepository = localRepository; |
158 | 0 | } |
159 | |
|
160 | |
protected String getI18Nsection() |
161 | |
{ |
162 | 0 | return "plugins"; |
163 | |
} |
164 | |
|
165 | |
|
166 | |
public void renderBody() |
167 | |
{ |
168 | |
|
169 | 0 | renderSectionPlugins( true ); |
170 | |
|
171 | |
|
172 | 0 | renderSectionPlugins( false ); |
173 | 0 | } |
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
private void renderSectionPlugins( boolean isPlugins ) |
180 | |
{ |
181 | 0 | List list = ( isPlugins ? plugins : reports ); |
182 | 0 | String[] tableHeader = getPluginTableHeader(); |
183 | |
|
184 | 0 | startSection( ( isPlugins ? getI18nString( "title" ) |
185 | |
: getI18nString( "report.title" ) ) ); |
186 | |
|
187 | 0 | if ( list == null || list.isEmpty() ) |
188 | |
{ |
189 | |
|
190 | 0 | paragraph( ( isPlugins ? getI18nString( "nolist" ) |
191 | |
: getI18nString( "report.nolist" ) ) ); |
192 | |
|
193 | 0 | endSection(); |
194 | |
|
195 | 0 | return; |
196 | |
} |
197 | |
|
198 | 0 | Collections.sort( list, getArtifactComparator() ); |
199 | |
|
200 | 0 | startTable(); |
201 | 0 | tableHeader( tableHeader ); |
202 | |
|
203 | 0 | for ( Iterator iterator = list.iterator(); iterator.hasNext(); ) |
204 | |
{ |
205 | 0 | Artifact artifact = (Artifact) iterator.next(); |
206 | |
|
207 | |
VersionRange versionRange; |
208 | 0 | if ( StringUtils.isEmpty( artifact.getVersion() ) ) |
209 | |
{ |
210 | 0 | versionRange = VersionRange.createFromVersion( Artifact.RELEASE_VERSION ); |
211 | |
} |
212 | |
else |
213 | |
{ |
214 | 0 | versionRange = VersionRange.createFromVersion( artifact.getVersion() ); |
215 | |
} |
216 | |
|
217 | 0 | Artifact pluginArtifact = artifactFactory.createParentArtifact( artifact.getGroupId(), artifact |
218 | |
.getArtifactId(), versionRange.toString() ); |
219 | 0 | List artifactRepositories = project.getPluginArtifactRepositories(); |
220 | 0 | if ( artifactRepositories == null ) |
221 | |
{ |
222 | 0 | artifactRepositories = new ArrayList(); |
223 | |
} |
224 | |
try |
225 | |
{ |
226 | 0 | MavenProject pluginProject = mavenProjectBuilder.buildFromRepository( pluginArtifact, |
227 | |
artifactRepositories, |
228 | |
localRepository ); |
229 | 0 | tableRow( getPluginRow( pluginProject.getGroupId(), pluginProject.getArtifactId(), pluginProject |
230 | |
.getVersion(), pluginProject.getUrl() ) ); |
231 | |
} |
232 | 0 | catch ( ProjectBuildingException e ) |
233 | |
{ |
234 | 0 | log.info( "Could not build project for: " + artifact.getArtifactId() + ":" + e.getMessage(), e ); |
235 | 0 | tableRow( getPluginRow( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), |
236 | |
null ) ); |
237 | 0 | } |
238 | |
|
239 | 0 | } |
240 | 0 | endTable(); |
241 | |
|
242 | 0 | endSection(); |
243 | 0 | } |
244 | |
|
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
private String[] getPluginTableHeader() |
250 | |
{ |
251 | |
|
252 | 0 | String groupId = getI18nString( "dependencyManagement", "column.groupId" ); |
253 | 0 | String artifactId = getI18nString( "dependencyManagement", "column.artifactId" ); |
254 | 0 | String version = getI18nString( "dependencyManagement", "column.version" ); |
255 | 0 | return new String[] { groupId, artifactId, version }; |
256 | |
} |
257 | |
|
258 | |
private String[] getPluginRow( String groupId, String artifactId, String version, String link ) |
259 | |
{ |
260 | 0 | artifactId = ProjectInfoReportUtils.getArtifactIdCell( artifactId, link ); |
261 | 0 | return new String[] { groupId, artifactId, version }; |
262 | |
} |
263 | |
|
264 | |
private Comparator getArtifactComparator() |
265 | |
{ |
266 | 0 | return new Comparator() |
267 | 0 | { |
268 | |
|
269 | |
public int compare( Object o1, Object o2 ) |
270 | |
{ |
271 | 0 | Artifact a1 = (Artifact) o1; |
272 | 0 | Artifact a2 = (Artifact) o2; |
273 | |
|
274 | 0 | int result = a1.getGroupId().compareTo( a2.getGroupId() ); |
275 | 0 | if ( result == 0 ) |
276 | |
{ |
277 | 0 | result = a1.getArtifactId().compareTo( a2.getArtifactId() ); |
278 | |
} |
279 | 0 | return result; |
280 | |
} |
281 | |
}; |
282 | |
} |
283 | |
} |
284 | |
} |