1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugins.dependency.analyze;
20
21 import java.util.Collection;
22 import java.util.Locale;
23
24 import org.apache.maven.artifact.Artifact;
25 import org.apache.maven.doxia.sink.Sink;
26 import org.apache.maven.reporting.AbstractMavenReportRenderer;
27 import org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis;
28 import org.codehaus.plexus.i18n.I18N;
29
30
31
32
33
34 public class AnalyzeReportRenderer extends AbstractMavenReportRenderer {
35 private final I18N i18n;
36
37 private final Locale locale;
38
39 private final ProjectDependencyAnalysis analysis;
40
41 public AnalyzeReportRenderer(Sink sink, I18N i18n, Locale locale, ProjectDependencyAnalysis analysis) {
42 super(sink);
43 this.i18n = i18n;
44 this.locale = locale;
45 this.analysis = analysis;
46 }
47
48 @Override
49 public String getTitle() {
50 return getI18nString("title");
51 }
52
53
54
55
56
57 private String getI18nString(String key) {
58 return i18n.getString("analyze-report", locale, "report.analyze." + key);
59 }
60
61 protected void renderBody() {
62 startSection(getTitle());
63
64 boolean reported = false;
65
66
67 if (!analysis.getUsedDeclaredArtifacts().isEmpty()) {
68 startSection(getI18nString("UsedDeclaredDependencies"));
69 renderDependenciesTable(sink, analysis.getUsedDeclaredArtifacts());
70 endSection();
71 reported = true;
72 }
73
74
75
76 if (!analysis.getUsedUndeclaredArtifacts().isEmpty()) {
77 startSection(getI18nString("UsedUndeclaredDependencies"));
78 renderDependenciesTable(sink, analysis.getUsedUndeclaredArtifacts());
79 endSection();
80 reported = true;
81 }
82
83
84 if (!analysis.getUnusedDeclaredArtifacts().isEmpty()) {
85 startSection(getI18nString("UnusedDeclaredDependencies"));
86 renderDependenciesTable(sink, analysis.getUnusedDeclaredArtifacts());
87 endSection();
88 reported = true;
89 }
90
91
92 if (!analysis.getTestArtifactsWithNonTestScope().isEmpty()) {
93 startSection(getI18nString("CompileScopeTestOnlyDependencies"));
94 renderDependenciesTable(sink, analysis.getTestArtifactsWithNonTestScope());
95 endSection();
96 reported = true;
97 }
98
99 if (!reported) {
100 text(getI18nString("noDependencyProblems"));
101 }
102
103 endSection();
104 }
105
106 private void renderDependenciesTable(Sink sink, Collection<Artifact> artifacts) {
107 startTable();
108
109 tableHeader(new String[] {"GroupId", "ArtifactId", "Version", "Scope", "Classifier", "Type", "Optional"});
110
111 for (Artifact artifact : artifacts) {
112 tableRow(new String[] {
113 artifact.getGroupId(),
114 artifact.getArtifactId(),
115 artifact.getVersion(),
116 artifact.getScope(),
117 artifact.getClassifier(),
118 artifact.getType(),
119 artifact.isOptional() ? "" : "false"
120 });
121 }
122
123 endTable();
124 }
125 }