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 org.apache.maven.artifact.Artifact; |
23 | |
import org.apache.maven.artifact.factory.ArtifactFactory; |
24 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
25 | |
import org.apache.maven.artifact.resolver.ArtifactResolver; |
26 | |
import org.apache.maven.doxia.module.xhtml.decoration.render.RenderingContext; |
27 | |
import org.apache.maven.doxia.site.decoration.Body; |
28 | |
import org.apache.maven.doxia.site.decoration.DecorationModel; |
29 | |
import org.apache.maven.doxia.siterenderer.Renderer; |
30 | |
import org.apache.maven.doxia.siterenderer.RendererException; |
31 | |
import org.apache.maven.doxia.siterenderer.SiteRenderingContext; |
32 | |
import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink; |
33 | |
import org.apache.maven.doxia.tools.SiteTool; |
34 | |
import org.apache.maven.doxia.tools.SiteToolException; |
35 | |
import org.apache.maven.plugin.MojoExecutionException; |
36 | |
import org.apache.maven.project.MavenProject; |
37 | |
import org.apache.maven.reporting.AbstractMavenReport; |
38 | |
import org.apache.maven.reporting.MavenReportException; |
39 | |
import org.codehaus.plexus.i18n.I18N; |
40 | |
|
41 | |
import java.io.File; |
42 | |
import java.io.FileOutputStream; |
43 | |
import java.io.IOException; |
44 | |
import java.io.OutputStreamWriter; |
45 | |
import java.io.Writer; |
46 | |
import java.util.HashMap; |
47 | |
import java.util.Locale; |
48 | |
import java.util.Map; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | 16 | public abstract class AbstractProjectInfoReport |
58 | |
extends AbstractMavenReport |
59 | |
{ |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
protected SiteTool siteTool; |
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
protected Renderer siteRenderer; |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
protected ArtifactResolver resolver; |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | |
protected ArtifactFactory factory; |
92 | |
|
93 | |
|
94 | |
|
95 | |
|
96 | |
|
97 | |
|
98 | |
protected I18N i18n; |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
protected File outputDirectory; |
113 | |
|
114 | |
|
115 | |
|
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
protected MavenProject project; |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
protected ArtifactRepository localRepository; |
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
public void execute() |
138 | |
throws MojoExecutionException |
139 | |
{ |
140 | 16 | if ( !canGenerateReport() ) |
141 | |
{ |
142 | 0 | return; |
143 | |
} |
144 | |
|
145 | |
|
146 | |
try |
147 | |
{ |
148 | 16 | DecorationModel model = new DecorationModel(); |
149 | 16 | model.setBody( new Body() ); |
150 | 16 | Map attributes = new HashMap(); |
151 | 16 | attributes.put( "outputEncoding", "UTF-8" ); |
152 | 16 | attributes.put( "project", project ); |
153 | 16 | Locale locale = Locale.getDefault(); |
154 | 16 | Artifact defaultSkin = |
155 | |
siteTool.getDefaultSkinArtifact( localRepository, project.getRemoteArtifactRepositories() ); |
156 | 16 | SiteRenderingContext siteContext = siteRenderer.createContextForSkin( defaultSkin.getFile(), attributes, |
157 | |
model, getName( locale ), locale ); |
158 | |
|
159 | 16 | RenderingContext context = new RenderingContext( outputDirectory, getOutputName() + ".html" ); |
160 | |
|
161 | 16 | SiteRendererSink sink = new SiteRendererSink( context ); |
162 | 16 | generate( sink, locale ); |
163 | |
|
164 | 13 | outputDirectory.mkdirs(); |
165 | |
|
166 | 13 | Writer writer = |
167 | |
new OutputStreamWriter( new FileOutputStream( new File( outputDirectory, getOutputName() + ".html" ) ), |
168 | |
"UTF-8" ); |
169 | |
|
170 | 13 | siteRenderer.generateDocument( writer, sink, siteContext ); |
171 | |
|
172 | 13 | siteRenderer.copyResources( siteContext, new File( project.getBasedir(), "src/site/resources" ), |
173 | |
outputDirectory ); |
174 | |
} |
175 | 0 | catch ( RendererException e ) |
176 | |
{ |
177 | 0 | throw new MojoExecutionException( |
178 | |
"An error has occurred in " + getName( Locale.ENGLISH ) + " report generation.", e ); |
179 | |
} |
180 | 0 | catch ( IOException e ) |
181 | |
{ |
182 | 0 | throw new MojoExecutionException( |
183 | |
"An error has occurred in " + getName( Locale.ENGLISH ) + " report generation.", e ); |
184 | |
} |
185 | 0 | catch ( SiteToolException e ) |
186 | |
{ |
187 | 0 | throw new MojoExecutionException( |
188 | |
"An error has occurred in " + getName( Locale.ENGLISH ) + " report generation.", e ); |
189 | |
} |
190 | 0 | catch ( MavenReportException e ) |
191 | |
{ |
192 | 0 | throw new MojoExecutionException( |
193 | |
"An error has occurred in " + getName( Locale.ENGLISH ) + " report generation.", e ); |
194 | 13 | } |
195 | 13 | } |
196 | |
|
197 | |
|
198 | |
public String getCategoryName() |
199 | |
{ |
200 | 0 | return CATEGORY_PROJECT_INFORMATION; |
201 | |
} |
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
protected String getOutputDirectory() |
209 | |
{ |
210 | 1 | return outputDirectory.getAbsolutePath(); |
211 | |
} |
212 | |
|
213 | |
|
214 | |
public File getReportOutputDirectory() |
215 | |
{ |
216 | 13 | return outputDirectory; |
217 | |
} |
218 | |
|
219 | |
|
220 | |
public void setReportOutputDirectory( File reportOutputDirectory ) |
221 | |
{ |
222 | 0 | this.outputDirectory = reportOutputDirectory; |
223 | 0 | } |
224 | |
|
225 | |
|
226 | |
protected MavenProject getProject() |
227 | |
{ |
228 | 9 | return project; |
229 | |
} |
230 | |
|
231 | |
|
232 | |
protected Renderer getSiteRenderer() |
233 | |
{ |
234 | 0 | return siteRenderer; |
235 | |
} |
236 | |
} |