1 | |
package org.apache.maven.plugin.docck; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import org.apache.maven.model.ReportPlugin; |
23 | |
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException; |
24 | |
import org.apache.maven.plugin.descriptor.MojoDescriptor; |
25 | |
import org.apache.maven.plugin.descriptor.Parameter; |
26 | |
import org.apache.maven.plugin.descriptor.PluginDescriptor; |
27 | |
import org.apache.maven.plugin.docck.reports.DocumentationReporter; |
28 | |
import org.apache.maven.project.MavenProject; |
29 | |
import org.apache.maven.tools.plugin.extractor.ExtractionException; |
30 | |
import org.apache.maven.tools.plugin.scanner.MojoScanner; |
31 | |
import org.codehaus.plexus.util.IOUtil; |
32 | |
import org.codehaus.plexus.util.ReaderFactory; |
33 | |
|
34 | |
import java.io.File; |
35 | |
import java.io.IOException; |
36 | |
import java.io.Reader; |
37 | |
import java.util.ArrayList; |
38 | |
import java.util.Iterator; |
39 | |
import java.util.List; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | 0 | public class CheckPluginDocumentationMojo |
50 | |
extends AbstractCheckDocumentationMojo |
51 | |
{ |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
protected MojoScanner mojoScanner; |
59 | |
|
60 | |
|
61 | |
private static final int MIN_DESCRIPTION_LENGTH = 1; |
62 | |
|
63 | |
protected void checkPackagingSpecificDocumentation( MavenProject project, DocumentationReporter reporter ) |
64 | |
{ |
65 | 0 | PluginDescriptor descriptor = new PluginDescriptor(); |
66 | |
|
67 | |
try |
68 | |
{ |
69 | 0 | mojoScanner.populatePluginDescriptor( project, descriptor ); |
70 | |
} |
71 | 0 | catch ( InvalidPluginDescriptorException e ) |
72 | |
{ |
73 | 0 | reporter.error( "Failed to parse mojo descriptors.\nError: " + e.getMessage() ); |
74 | 0 | descriptor = null; |
75 | |
} |
76 | 0 | catch ( ExtractionException e ) |
77 | |
{ |
78 | 0 | reporter.error( "Failed to parse mojo descriptors.\nError: " + e.getMessage() ); |
79 | 0 | descriptor = null; |
80 | 0 | } |
81 | |
|
82 | 0 | if ( descriptor != null ) |
83 | |
{ |
84 | 0 | List mojos = descriptor.getMojos(); |
85 | |
|
86 | |
|
87 | 0 | if ( mojos != null && !mojos.isEmpty() ) |
88 | |
{ |
89 | 0 | for ( Iterator it = mojos.iterator(); it.hasNext(); ) |
90 | |
{ |
91 | 0 | MojoDescriptor mojo = (MojoDescriptor) it.next(); |
92 | |
|
93 | 0 | String mojoDescription = mojo.getDescription(); |
94 | |
|
95 | 0 | if ( mojoDescription == null || mojoDescription.trim().length() < MIN_DESCRIPTION_LENGTH ) |
96 | |
{ |
97 | 0 | reporter.error( "Mojo: \'" + mojo.getGoal() + "\' is missing a description." ); |
98 | |
} |
99 | |
|
100 | 0 | List params = mojo.getParameters(); |
101 | |
|
102 | |
|
103 | 0 | if ( params != null && !params.isEmpty() ) |
104 | |
{ |
105 | 0 | for ( Iterator paramIterator = params.iterator(); paramIterator.hasNext(); ) |
106 | |
{ |
107 | 0 | Parameter param = (Parameter) paramIterator.next(); |
108 | |
|
109 | 0 | if ( param.getRequirement() == null && param.isEditable() ) |
110 | |
{ |
111 | 0 | String paramDescription = param.getDescription(); |
112 | |
|
113 | 0 | if ( paramDescription == null |
114 | |
|| paramDescription.trim().length() < MIN_DESCRIPTION_LENGTH ) |
115 | |
{ |
116 | 0 | reporter.error( "Parameter: \'" + param.getName() + "\' in mojo: \'" |
117 | |
+ mojo.getGoal() + "\' is missing a description." ); |
118 | |
} |
119 | |
} |
120 | |
} |
121 | |
} |
122 | |
} |
123 | |
} |
124 | |
} |
125 | |
|
126 | 0 | checkConfiguredReportPlugins( project, reporter ); |
127 | |
|
128 | 0 | checkProjectSite( project, reporter ); |
129 | 0 | } |
130 | |
|
131 | |
protected boolean approveProjectPackaging( String packaging ) |
132 | |
{ |
133 | 0 | return "maven-plugin".equals( packaging ); |
134 | |
} |
135 | |
|
136 | |
private void checkProjectSite( MavenProject project, DocumentationReporter reporter ) |
137 | |
{ |
138 | 0 | File projectSiteDirectory = new File( project.getBasedir(), siteDirectory ); |
139 | |
|
140 | |
|
141 | 0 | File siteXml = new File( projectSiteDirectory, "site.xml" ); |
142 | |
|
143 | 0 | if ( !siteXml.exists() ) |
144 | |
{ |
145 | 0 | reporter.error( "site.xml is missing." ); |
146 | |
} |
147 | |
else |
148 | |
{ |
149 | 0 | Reader streamReader = null; |
150 | |
try |
151 | |
{ |
152 | 0 | streamReader = ReaderFactory.newXmlReader( siteXml ); |
153 | |
|
154 | 0 | String siteHtml = IOUtil.toString( streamReader ); |
155 | |
|
156 | 0 | if ( siteHtml.indexOf( "href=\"index.html\"" ) < 0 ) |
157 | |
{ |
158 | 0 | reporter.error( "site.xml is missing the link to: index.html \"Introduction\"." ); |
159 | |
} |
160 | |
|
161 | 0 | if ( siteHtml.indexOf( "href=\"usage.html\"" ) < 0 ) |
162 | |
{ |
163 | 0 | reporter.error( "site.xml is missing the link to: usage.html \"Usage\"." ); |
164 | |
} |
165 | |
|
166 | 0 | if ( siteHtml.indexOf( "href=\"plugin-info.html\"" ) < 0 ) |
167 | |
{ |
168 | 0 | reporter.error( "site.xml is missing the link to: plugin-info.html \"Goals\"." ); |
169 | |
} |
170 | |
|
171 | 0 | if ( siteHtml.indexOf( "href=\"faq.html\"" ) < 0 ) |
172 | |
{ |
173 | 0 | reporter.error( "site.xml is missing the link to: faq.html \"FAQ\"." ); |
174 | |
} |
175 | |
} |
176 | 0 | catch ( IOException e ) |
177 | |
{ |
178 | 0 | reporter.error( "Unable to read site.xml file: \'" + siteXml.getAbsolutePath() |
179 | |
+ "\'.\nError: " + e.getMessage() ); |
180 | |
} |
181 | |
finally |
182 | |
{ |
183 | 0 | IOUtil.close( streamReader ); |
184 | 0 | } |
185 | |
} |
186 | |
|
187 | |
|
188 | 0 | if ( !findFiles( projectSiteDirectory, "index" ) ) |
189 | |
{ |
190 | 0 | reporter.error( "There is no \'index\' file in your site directory (in apt|html|xml[.vm] format)." ); |
191 | |
} |
192 | |
|
193 | |
|
194 | 0 | if ( !findFiles( projectSiteDirectory, "usage" ) ) |
195 | |
{ |
196 | 0 | reporter.error( "There is no \'usage\' file in your site directory (in apt|html|xml[.vm] format)." ); |
197 | |
} |
198 | |
|
199 | |
|
200 | 0 | if ( !findFiles( projectSiteDirectory, "**/examples/*" ) |
201 | |
&& !findFiles( projectSiteDirectory, "**/example*" ) ) |
202 | |
{ |
203 | 0 | reporter.error( "There are no example files in your site directory (in apt|html|xml[.vm] format)." |
204 | |
+ " They should either be called \'example*.(apt|html|xml)[.vm]\'" |
205 | |
+ " or they should be located in the \'examples\' directory." ); |
206 | |
} |
207 | |
|
208 | 0 | if ( !findFiles( projectSiteDirectory, "faq" ) ) |
209 | |
{ |
210 | 0 | reporter.error( "There is no \'faq\' file in your site directory (in apt|fml|html|xml[.vm] format)." ); |
211 | |
} |
212 | 0 | } |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
private void checkConfiguredReportPlugins( MavenProject project, DocumentationReporter reporter ) |
222 | |
{ |
223 | 0 | List expectedPlugins = getRequiredPlugins(); |
224 | |
|
225 | 0 | List reportPlugins = project.getReportPlugins(); |
226 | 0 | if ( reportPlugins != null && reportPlugins.size() > 0 ) |
227 | |
{ |
228 | 0 | for ( Iterator plugins = reportPlugins.iterator(); plugins.hasNext(); ) |
229 | |
{ |
230 | 0 | ReportPlugin plugin = (ReportPlugin) plugins.next(); |
231 | |
|
232 | 0 | expectedPlugins.remove( plugin.getArtifactId() ); |
233 | |
} |
234 | |
} |
235 | |
else |
236 | |
{ |
237 | 0 | reporter.error( "pom.xml has no report plugins configured." ); |
238 | |
} |
239 | |
|
240 | 0 | for ( Iterator plugins = expectedPlugins.iterator(); plugins.hasNext(); ) |
241 | |
{ |
242 | 0 | reporter.error( "pom.xml is missing the report plugin: " + plugins.next().toString() + "." ); |
243 | |
} |
244 | 0 | } |
245 | |
|
246 | |
|
247 | |
|
248 | |
|
249 | |
|
250 | |
|
251 | |
private List getRequiredPlugins() |
252 | |
{ |
253 | 0 | List list = new ArrayList(); |
254 | |
|
255 | 0 | list.add( "maven-javadoc-plugin" ); |
256 | 0 | list.add( "maven-jxr-plugin" ); |
257 | |
|
258 | 0 | return list; |
259 | |
} |
260 | |
} |