1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.forgerock.maven.plugins.xcite;
18
19 import org.apache.maven.plugin.AbstractMojo;
20 import org.apache.maven.plugin.MojoExecutionException;
21 import org.apache.maven.plugin.MojoFailureException;
22 import org.apache.maven.plugins.annotations.LifecyclePhase;
23 import org.apache.maven.plugins.annotations.Mojo;
24 import org.apache.maven.plugins.annotations.Parameter;
25 import org.forgerock.maven.plugins.xcite.utils.FileUtils;
26
27 import java.io.File;
28 import java.io.IOException;
29
30
31
32
33 @Mojo(name = "cite", defaultPhase = LifecyclePhase.PROCESS_SOURCES)
34 public class XCiteMojo extends AbstractMojo {
35
36
37
38
39 @Parameter (defaultValue = "false")
40 private boolean escapeXml;
41
42
43
44
45 @Parameter
46 private String[] includes;
47
48
49
50
51 @Parameter
52 private String[] excludes;
53
54
55
56
57 @Parameter (defaultValue = "0")
58 private int reindent;
59
60
61
62
63 @Parameter (defaultValue = "${project.build.directory}/xcite")
64 private File outputDirectory;
65
66
67
68
69 @Parameter (defaultValue = "${basedir}/src/main")
70 private File sourceDirectory;
71
72
73
74
75
76
77
78
79 @Override
80 public void execute() throws MojoExecutionException, MojoFailureException {
81
82 if (!outputDirectory.exists()) {
83 if (!outputDirectory.mkdirs()) {
84 throw new MojoExecutionException(
85 "Failed to create output directory: "
86 + outputDirectory.getPath());
87 }
88 }
89
90 String[] files = FileUtils.getIncludedFiles(sourceDirectory, includes, excludes);
91 Resolver resolver =
92 new Resolver(outputDirectory, escapeXml, reindent, true);
93 try {
94 resolver.resolve(sourceDirectory, files);
95 } catch (IOException e) {
96 throw new MojoFailureException(e.getMessage());
97 }
98 }
99 }