1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.creadur.whisker.plugin.maven;
20
21 import java.io.File;
22
23 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.creadur.whisker.app.Act;
26 import org.apache.creadur.whisker.app.Whisker;
27 import org.apache.creadur.whisker.app.load.StreamableResourceFactory;
28 import org.apache.creadur.whisker.app.out.WriteResultsIntoDirectoryFactory;
29 import org.apache.creadur.whisker.out.velocity.VelocityEngine;
30
31
32
33
34
35
36
37 public class GenerateMojo extends AbstractMojo {
38
39
40
41
42
43
44 private File outputDirectory;
45
46
47
48
49
50 private String outputEncoding;
51
52
53
54
55
56
57
58
59 private File descriptor;
60
61
62
63
64
65
66
67 public void execute() throws MojoExecutionException {
68 if (descriptor.exists()) {
69 if (descriptor.canRead()) {
70 try {
71 new Whisker().setLicenseDescriptor(new StreamableResourceFactory().streamFromFileResource(descriptor))
72 .setEngine(new VelocityEngine(new MojoToJCLLog(getLog())))
73 .setWriterFactory(new WriteResultsIntoDirectoryFactory(outputDirectory, outputEncoding))
74 .setAct(Act.GENERATE).act();
75 } catch (Exception e) {
76 throw new MojoExecutionException("Whisker failed to generate materials: " + e.getMessage(), e);
77 }
78 } else {
79 throw new MojoExecutionException("Read permission requires on Whisker descriptor file: " + descriptor);
80 }
81 } else {
82 throw new MojoExecutionException("Whisker descriptor file is missing: " + descriptor);
83 }
84 }
85
86 }