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.LoggingVelocityEngine;
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 getLog().info("Reading descriptor from " + descriptor);
67 if (descriptor.canRead()) {
68 try {
69 new Whisker().setLicenseDescriptor(new StreamableResourceFactory().streamFromFileResource(descriptor))
70 .setEngine(new LoggingVelocityEngine())
71 .setWriterFactory(new WriteResultsIntoDirectoryFactory(outputDirectory, outputEncoding))
72 .setAct(Act.GENERATE).act();
73 } catch (Exception e) {
74 throw new MojoExecutionException("Whisker failed to generate materials: " + e.getMessage(), e);
75 }
76 } else {
77 throw new MojoExecutionException("Read permission required on Whisker descriptor file: " + descriptor);
78 }
79 } else {
80 getLog().error("No descriptor found " + descriptor);
81 throw new MojoExecutionException("Whisker descriptor file is missing: " + descriptor);
82 }
83 }
84
85 }