1 package org.codehaus.mojo.webstart;
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.Renderer;
23 import org.apache.maven.plugins.annotations.Component;
24 import org.apache.maven.plugins.annotations.LifecyclePhase;
25 import org.apache.maven.plugins.annotations.Mojo;
26 import org.apache.maven.plugins.annotations.Parameter;
27 import org.apache.maven.project.MavenProject;
28 import org.apache.maven.reporting.AbstractMavenReport;
29 import org.apache.maven.reporting.MavenReportException;
30 import org.codehaus.plexus.util.FileUtils;
31
32 import java.io.File;
33 import java.io.IOException;
34 import java.util.List;
35 import java.util.Locale;
36 import java.util.ResourceBundle;
37
38
39
40
41
42
43 @Mojo( name = "report", defaultPhase = LifecyclePhase.SITE, requiresReports = true )
44 public class JnlpReportMojo
45 extends AbstractMavenReport
46 {
47
48
49
50
51
52
53
54 @Parameter( property = "jnlp.outputDirectory", defaultValue = "${project.reporting.outputDirectory}" )
55 private File outputDirectory;
56
57
58
59
60 @Parameter( property = "jnlp.jnlpSourceDirectory", defaultValue = "${project.build.directory}/jnlp", required = true )
61 private File jnlpSourceDirectory;
62
63
64
65
66 @Parameter( property = "jnlp.siteJnlpDirectory", defaultValue = "jnlp", required = true )
67 private String siteJnlpDirectory;
68
69
70
71
72 @Parameter( property = "jnlp.siteJnlpFile", defaultValue = "launch.jnlp", required = true )
73 private String siteJnlpFile;
74
75
76
77
78 @Parameter( property = "outputName", defaultValue = "jnlp-report", required = true )
79 private String outputName;
80
81
82
83
84
85
86 @Parameter( property = "jnlp.codebase", defaultValue = "${project.url}/jnlp" )
87 private String codebase;
88
89
90
91
92
93
94
95
96 @Component
97 private MavenProject project;
98
99
100
101
102 @Component
103 private Renderer siteRenderer;
104
105
106
107
108
109
110
111
112 public void executeReport( Locale locale )
113 throws MavenReportException
114 {
115 copyJnlpFiles();
116 fillReport( locale );
117 }
118
119
120
121
122 public String getName( Locale locale )
123 {
124 return getBundle( locale ).getString( "report.jnlp-report.name" );
125 }
126
127
128
129
130 public String getDescription( Locale locale )
131 {
132 return getBundle( locale ).getString( "report.jnlp-report.description" );
133 }
134
135
136
137
138
139
140
141
142 protected Renderer getSiteRenderer()
143 {
144 return siteRenderer;
145 }
146
147
148
149
150 protected MavenProject getProject()
151 {
152 return project;
153 }
154
155
156
157
158 public String getOutputName()
159 {
160 return outputName;
161 }
162
163
164
165
166 protected String getOutputDirectory()
167 {
168 return outputDirectory.getPath();
169 }
170
171
172
173
174
175 private void copyJnlpFiles()
176 throws MavenReportException
177 {
178 if ( !jnlpSourceDirectory.exists() )
179 {
180 throw new MavenReportException( "jnlpSourceDirectory does not exist" );
181 }
182 try
183 {
184 File destinationDirectory = new File( outputDirectory, siteJnlpDirectory );
185 List<File> files = FileUtils.getFiles( jnlpSourceDirectory, "**/*", "" );
186 for ( File file : files )
187 {
188 getLog().debug( "Copying " + file + " to " + destinationDirectory );
189 String path = file.getAbsolutePath().substring( jnlpSourceDirectory.getAbsolutePath().length() + 1 );
190 File destDir = new File( destinationDirectory, path );
191 getLog().debug( "Copying " + file + " to " + destDir );
192 if ( file.isDirectory() )
193 {
194 destDir.mkdirs();
195 }
196 else
197 {
198 FileUtils.copyFileToDirectory( file, destDir.getParentFile() );
199 }
200 }
201 }
202 catch ( IOException e )
203 {
204 throw new MavenReportException( "Failed to copy jnlp files", e );
205 }
206 }
207
208 private void fillReport( Locale locale )
209 {
210 ResourceBundle bundle = getBundle( locale );
211 getSink().head();
212 getSink().text( bundle.getString( "report.jnlp-report.description" ) );
213 getSink().head_();
214 getSink().body();
215 getSink().sectionTitle1();
216 getSink().text( bundle.getString( "report.jnlp-report.label.installation.header" ) );
217 getSink().sectionTitle1_();
218 getSink().paragraph();
219 getSink().text( bundle.getString( "report.jnlp-report.label.installation.description" ) );
220 getSink().paragraph_();
221 getSink().paragraph();
222 if ( codebase.startsWith( "file://" ) )
223 {
224 if ( !codebase.endsWith( File.separator ) )
225 {
226 codebase += File.separator;
227 }
228 }
229 else
230 {
231 if ( !codebase.endsWith( "/" ) )
232 {
233 codebase += "/";
234 }
235 }
236 getSink().link( codebase + siteJnlpFile );
237
238 getSink().text( bundle.getString( "report.jnlp-report.label.installation.webStartMeNow" ) );
239 getSink().link_();
240 getSink().paragraph_();
241 getSink().paragraph();
242 getSink().text( bundle.getString( "report.jnlp-report.label.installation.getJava" ) + " " );
243 getSink().link( "http://java.com" );
244 getSink().text( "http://java.com" );
245 getSink().link_();
246 getSink().paragraph_();
247 getSink().sectionTitle1();
248 getSink().text( bundle.getString( "report.jnlp-report.label.uninstallation.header" ) );
249 getSink().sectionTitle1_();
250 getSink().paragraph();
251 getSink().text( bundle.getString( "report.jnlp-report.label.uninstallation.description" ) );
252 getSink().paragraph_();
253 getSink().body_();
254 getSink().flush();
255 getSink().close();
256 }
257
258 private ResourceBundle getBundle( Locale locale )
259 {
260 return ResourceBundle.getBundle( "jnlp-report", locale, this.getClass().getClassLoader() );
261 }
262
263 }