1 | |
package org.apache.maven.plugins.site; |
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.doxia.siterenderer.RendererException; |
23 | |
import org.apache.maven.doxia.siterenderer.SiteRenderingContext; |
24 | |
import org.apache.maven.plugin.MojoExecutionException; |
25 | |
import org.apache.maven.plugin.MojoFailureException; |
26 | |
import org.apache.maven.reporting.MavenReport; |
27 | |
|
28 | |
import java.io.File; |
29 | |
import java.io.IOException; |
30 | |
import java.util.Collections; |
31 | |
import java.util.Iterator; |
32 | |
import java.util.List; |
33 | |
import java.util.Locale; |
34 | |
import java.util.Map; |
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | 2 | public class SiteMojo |
50 | |
extends AbstractSiteRenderingMojo |
51 | |
{ |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
protected File outputDirectory; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
private boolean generateReports; |
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
public void execute() |
76 | |
throws MojoExecutionException, MojoFailureException |
77 | |
{ |
78 | |
List filteredReports; |
79 | 0 | if ( generateReports ) |
80 | |
{ |
81 | 0 | filteredReports = filterReports( reports ); |
82 | |
} |
83 | |
else |
84 | |
{ |
85 | 0 | filteredReports = Collections.EMPTY_LIST; |
86 | |
} |
87 | |
|
88 | |
try |
89 | |
{ |
90 | 0 | List localesList = siteTool.getAvailableLocales( locales ); |
91 | |
|
92 | |
|
93 | 0 | Locale defaultLocale = (Locale) localesList.get( 0 ); |
94 | 0 | Locale.setDefault( defaultLocale ); |
95 | |
|
96 | 0 | for ( Iterator iterator = localesList.iterator(); iterator.hasNext(); ) |
97 | |
{ |
98 | 0 | Locale locale = (Locale) iterator.next(); |
99 | |
|
100 | 0 | renderLocale( locale, filteredReports ); |
101 | |
} |
102 | |
} |
103 | 0 | catch ( RendererException e ) |
104 | |
{ |
105 | 0 | throw new MojoExecutionException( "Error during page generation", e ); |
106 | |
} |
107 | 0 | catch ( IOException e ) |
108 | |
{ |
109 | 0 | throw new MojoExecutionException( "Error during site generation", e ); |
110 | 0 | } |
111 | 0 | } |
112 | |
|
113 | |
private void renderLocale( Locale locale, |
114 | |
List reports ) |
115 | |
throws IOException, RendererException, MojoFailureException, MojoExecutionException |
116 | |
{ |
117 | 0 | SiteRenderingContext context = createSiteRenderingContext( locale ); |
118 | |
|
119 | 0 | context.setInputEncoding( getInputEncoding() ); |
120 | 0 | context.setOutputEncoding( getOutputEncoding() ); |
121 | |
|
122 | 0 | Map documents = locateDocuments( context, reports, locale ); |
123 | |
|
124 | 0 | File outputDirectory = getOutputDirectory( locale ); |
125 | |
|
126 | |
|
127 | 0 | for ( Iterator i = reports.iterator(); i.hasNext(); ) |
128 | |
{ |
129 | 0 | MavenReport report = (MavenReport) i.next(); |
130 | 0 | report.setReportOutputDirectory( outputDirectory ); |
131 | |
} |
132 | |
|
133 | 0 | siteRenderer.render( documents.values(), context, outputDirectory ); |
134 | |
|
135 | |
|
136 | 0 | context.getSiteDirectories().clear(); |
137 | 0 | context.addSiteDirectory( generatedSiteDirectory ); |
138 | |
|
139 | 0 | documents = siteRenderer.locateDocumentFiles( context ); |
140 | |
|
141 | 0 | siteRenderer.render( documents.values(), context, outputDirectory ); |
142 | 0 | } |
143 | |
|
144 | |
private File getOutputDirectory( Locale locale ) |
145 | |
{ |
146 | |
File file; |
147 | 0 | if ( locale.getLanguage().equals( Locale.getDefault().getLanguage() ) ) |
148 | |
{ |
149 | 0 | file = outputDirectory; |
150 | |
} |
151 | |
else |
152 | |
{ |
153 | 0 | file = new File( outputDirectory, locale.getLanguage() ); |
154 | |
} |
155 | |
|
156 | |
|
157 | 0 | if ( !file.exists() ) |
158 | |
{ |
159 | 0 | file.mkdirs(); |
160 | |
} |
161 | |
|
162 | 0 | return file; |
163 | |
} |
164 | |
} |