1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package net.sf.jfxdplugin;
19
20 import java.io.File;
21 import java.io.IOException;
22 import org.apache.maven.archiver.MavenArchiveConfiguration;
23 import org.apache.maven.archiver.MavenArchiver;
24 import org.apache.maven.artifact.DependencyResolutionRequiredException;
25 import org.apache.maven.plugin.MojoExecutionException;
26 import org.apache.maven.plugin.MojoFailureException;
27 import org.apache.maven.reporting.MavenReportException;
28 import org.codehaus.plexus.archiver.ArchiverException;
29 import org.codehaus.plexus.archiver.jar.JarArchiver;
30 import org.codehaus.plexus.archiver.jar.ManifestException;
31 import org.codehaus.plexus.archiver.util.DefaultFileSet;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class JavafxdocJar extends AbstractJavafxdocMojo {
49
50
51
52
53 private static final String[] DEFAULT_INCLUDES = new String[]{"**/**"};
54
55
56
57
58
59
60
61 private static final String[] DEFAULT_EXCLUDES = new String[]{
62 DEBUG_JAVAFXDOC_SCRIPT_NAME, OPTIONS_FILE_NAME, FILES_FILE_NAME};
63
64
65
66
67
68
69
70
71 private JarArchiver jarArchiver;
72
73
74
75
76
77
78
79
80 private String jarOutputDirectory;
81
82
83
84
85
86
87
88 private String finalName;
89
90
91
92
93
94
95
96 private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
97
98
99
100
101
102
103
104
105 private File defaultManifestFile;
106
107
108
109
110
111
112 private boolean useDefaultManifestFile = false;
113
114
115
116
117
118
119
120
121 public void execute() throws MojoExecutionException, MojoFailureException {
122 try {
123 executeReport();
124
125 if (getOutputDirectory().exists()) {
126 generateArchive(getOutputDirectory(),
127 getFinalName() + "-" + "javafxdoc.jar");
128 } else {
129 getLog().warn(formatMessage("jar.nothing.to.generate"));
130 }
131 } catch (MavenReportException ex) {
132 String message = formatMessage("jar.error", ex.getMessage());
133 if (isFailOnError()) {
134 throw new MojoExecutionException(message, ex);
135 }
136 getLog().error(message, ex);
137 } catch (ArchiverException ex) {
138 String message = formatMessage("jar.error", ex.getMessage());
139 if (isFailOnError()) {
140 throw new MojoExecutionException(message, ex);
141 }
142 getLog().error(message, ex);
143 } catch (ManifestException ex) {
144 String message = formatMessage("jar.error", ex.getMessage());
145 if (isFailOnError()) {
146 throw new MojoExecutionException(message, ex);
147 }
148 getLog().error(message, ex);
149 } catch (IOException ex) {
150 String message = formatMessage("jar.error", ex.getMessage());
151 if (isFailOnError()) {
152 throw new MojoExecutionException(message, ex);
153 }
154 getLog().error(message, ex);
155 } catch (DependencyResolutionRequiredException ex) {
156 String message = formatMessage("jar.error", ex.getMessage());
157 if (isFailOnError()) {
158 throw new MojoExecutionException(message, ex);
159 }
160 getLog().error(message, ex);
161 }
162 }
163
164
165
166
167
168
169
170 public String getFinalName() {
171 return finalName;
172 }
173
174
175
176
177
178
179
180 public void setFinalName(String finalName) {
181 this.finalName = finalName;
182 }
183
184
185
186
187
188
189
190 public JarArchiver getJarArchiver() {
191 return jarArchiver;
192 }
193
194
195
196
197
198
199
200 public void setJarArchiver(JarArchiver jarArchiver) {
201 this.jarArchiver = jarArchiver;
202 }
203
204
205
206
207
208
209
210 public String getJarOutputDirectory() {
211 return jarOutputDirectory;
212 }
213
214
215
216
217
218
219
220 public void setJarOutputDirectory(String jarOutputDirectory) {
221 this.jarOutputDirectory = jarOutputDirectory;
222 }
223
224
225
226
227
228
229
230 public MavenArchiveConfiguration getArchive() {
231 return archive;
232 }
233
234
235
236
237
238
239
240 public void setArchive(MavenArchiveConfiguration archive) {
241 this.archive = archive;
242 }
243
244
245
246
247
248
249
250 public File getDefaultManifestFile() {
251 return defaultManifestFile;
252 }
253
254
255
256
257
258
259
260 public void setDefaultManifestFile(File defaultManifestFile) {
261 this.defaultManifestFile = defaultManifestFile;
262 }
263
264
265
266
267
268
269
270 public boolean isUseDefaultManifestFile() {
271 return useDefaultManifestFile;
272 }
273
274
275
276
277
278
279
280 public void setUseDefaultManifestFile(boolean useDefaultManifestFile) {
281 this.useDefaultManifestFile = useDefaultManifestFile;
282 }
283
284 private File generateArchive(File outputDir, String jarFileName) throws
285 ArchiverException, ManifestException, IOException,
286 DependencyResolutionRequiredException {
287
288 File jarFile = new File(getJarOutputDirectory(), jarFileName);
289
290 if (jarFile.exists()) {
291 jarFile.delete();
292 }
293
294 MavenArchiver archiver = new MavenArchiver();
295 archiver.setArchiver(getJarArchiver());
296 archiver.setOutputFile(jarFile);
297
298 DefaultFileSet fileSet = new DefaultFileSet();
299 fileSet.setDirectory(outputDir);
300 fileSet.setIncludes(DEFAULT_INCLUDES);
301 fileSet.setExcludes(DEFAULT_EXCLUDES);
302 archiver.getArchiver().addFileSet(fileSet);
303
304 if ((isUseDefaultManifestFile())
305 && (getDefaultManifestFile().exists())
306 && (null == getArchive().getManifestFile())) {
307 getLog().info(formatMessage("jar.existing.manifest",
308 getDefaultManifestFile().getPath()));
309 getArchive().setManifestFile(getDefaultManifestFile());
310 }
311
312 getArchive().setAddMavenDescriptor(false);
313 archiver.createArchive(getProject(), getArchive());
314
315 return jarFile;
316 }
317 }