1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.report.projectinfo;
20
21 import java.util.Locale;
22
23 import org.apache.maven.doxia.sink.Sink;
24 import org.apache.maven.model.DistributionManagement;
25 import org.apache.maven.plugins.annotations.Mojo;
26 import org.apache.maven.project.MavenProject;
27 import org.apache.maven.reporting.MavenReportException;
28 import org.codehaus.plexus.i18n.I18N;
29 import org.codehaus.plexus.util.StringUtils;
30
31
32
33
34
35
36
37 @Mojo(name = "distribution-management")
38 public class DistributionManagementReport extends AbstractProjectInfoReport {
39
40
41
42
43 @Override
44 public boolean canGenerateReport() throws MavenReportException {
45 boolean result = super.canGenerateReport();
46 if (result && skipEmptyReport) {
47 result = getProject().getDistributionManagement() != null;
48 }
49
50 return result;
51 }
52
53 @Override
54 public void executeReport(Locale locale) {
55 DistributionManagementRenderer r =
56 new DistributionManagementRenderer(getSink(), getProject(), getI18N(locale), locale);
57
58 r.render();
59 }
60
61
62 public String getOutputName() {
63 return "distribution-management";
64 }
65
66 @Override
67 protected String getI18Nsection() {
68 return "distribution-management";
69 }
70
71
72
73
74
75
76
77
78 private static class DistributionManagementRenderer extends AbstractProjectInfoRenderer {
79 private final MavenProject project;
80
81 DistributionManagementRenderer(Sink sink, MavenProject project, I18N i18n, Locale locale) {
82 super(sink, i18n, locale);
83
84 this.project = project;
85 }
86
87 @Override
88 protected String getI18Nsection() {
89 return "distribution-management";
90 }
91
92 @Override
93 protected void renderBody() {
94 DistributionManagement distributionManagement = project.getDistributionManagement();
95 if (distributionManagement == null) {
96 startSection(getI18nString("overview.title"));
97
98 paragraph(getI18nString("nodistributionmanagement"));
99
100 endSection();
101
102 return;
103 }
104
105 startSection(getI18nString("overview.title"));
106 paragraph(getI18nString("overview.intro"));
107
108 if (StringUtils.isNotEmpty(distributionManagement.getDownloadUrl())) {
109 startSection(getI18nString("downloadURL"));
110 internalLink(distributionManagement.getDownloadUrl());
111 endSection();
112 }
113
114 if (distributionManagement.getRelocation() != null) {
115 startSection(getI18nString("relocation"));
116 startTable();
117 tableHeader(new String[] {getI18nString("field"), getI18nString("value")});
118 tableRow(new String[] {
119 getI18nString("relocation.groupid"),
120 distributionManagement.getRelocation().getGroupId()
121 });
122 tableRow(new String[] {
123 getI18nString("relocation.artifactid"),
124 distributionManagement.getRelocation().getArtifactId()
125 });
126 tableRow(new String[] {
127 getI18nString("relocation.version"),
128 distributionManagement.getRelocation().getVersion()
129 });
130 tableRow(new String[] {
131 getI18nString("relocation.message"),
132 distributionManagement.getRelocation().getMessage()
133 });
134 endTable();
135 endSection();
136 }
137
138 if (distributionManagement.getRepository() != null
139 && StringUtils.isNotEmpty(
140 distributionManagement.getRepository().getUrl())) {
141 startSection(getI18nString("repository")
142 + getRepoName(distributionManagement.getRepository().getId()));
143 internalLink(distributionManagement.getRepository().getUrl());
144 endSection();
145 }
146
147 if (distributionManagement.getSnapshotRepository() != null
148 && StringUtils.isNotEmpty(
149 distributionManagement.getSnapshotRepository().getUrl())) {
150 startSection(getI18nString("snapshotRepository")
151 + getRepoName(
152 distributionManagement.getSnapshotRepository().getId()));
153 internalLink(distributionManagement.getSnapshotRepository().getUrl());
154 endSection();
155 }
156
157 if (distributionManagement.getSite() != null
158 && StringUtils.isNotEmpty(distributionManagement.getSite().getUrl())) {
159 startSection(getI18nString("site")
160 + getRepoName(distributionManagement.getSite().getId()));
161 internalLink(distributionManagement.getSite().getUrl());
162 endSection();
163 }
164
165 endSection();
166 }
167
168 private void internalLink(String url) {
169 if (url == null || url.isEmpty()) {
170 return;
171 }
172
173 String urlLowerCase = url.trim().toLowerCase(Locale.ENGLISH);
174 if (urlLowerCase.startsWith("http") || urlLowerCase.startsWith("https") || urlLowerCase.startsWith("ftp")) {
175 link(url, url);
176 } else {
177 paragraph(url);
178 }
179 }
180
181 private String getRepoName(String name) {
182 if (name != null && !name.isEmpty()) {
183 return " - " + name;
184 }
185
186 return "";
187 }
188 }
189 }