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.creadur.whisker.app.Act;
24 import org.apache.creadur.whisker.app.Whisker;
25 import org.apache.creadur.whisker.app.load.StreamableResourceFactory;
26 import org.apache.creadur.whisker.app.out.WriteResultsIntoDirectoryFactory;
27 import org.apache.creadur.whisker.out.velocity.VelocityEngine;
28 import org.apache.maven.plugin.AbstractMojo;
29 import org.apache.maven.plugin.MojoExecutionException;
30 import org.apache.maven.plugins.annotations.*;
31
32
33
34
35
36 @Mojo(name = "generate", requiresProject = false)
37 public class GenerateMojo extends AbstractMojo {
38
39
40
41
42 @Parameter(defaultValue = "${project.build.directory}")
43 private File outputDirectory;
44
45
46
47
48 @Parameter(property = "outputEncoding", defaultValue = "${project.build.sourceEncoding}")
49 private String outputEncoding;
50
51
52
53
54
55 @Parameter(property = "apacheWhiskerDescriptor", required = true)
56 private File descriptor;
57
58
59
60
61
62
63
64 public void execute() throws MojoExecutionException {
65 if (descriptor.exists()) {
66 if (descriptor.canRead()) {
67 try {
68 new Whisker().setLicenseDescriptor(new StreamableResourceFactory().streamFromFileResource(descriptor))
69 .setEngine(new VelocityEngine(new MojoToJCLLog(getLog())))
70 .setWriterFactory(new WriteResultsIntoDirectoryFactory(outputDirectory, outputEncoding))
71 .setAct(Act.GENERATE).act();
72 } catch (Exception e) {
73 throw new MojoExecutionException("Whisker failed to generate materials: " + e.getMessage(), e);
74 }
75 } else {
76 throw new MojoExecutionException("Read permission requires on Whisker descriptor file: " + descriptor);
77 }
78 } else {
79 throw new MojoExecutionException("Whisker descriptor file is missing: " + descriptor);
80 }
81 }
82
83 }