1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.forgerock.doc.maven.release;
18
19 import static org.twdata.maven.mojoexecutor.MojoExecutor.element;
20 import static org.twdata.maven.mojoexecutor.MojoExecutor.name;
21
22 import org.apache.commons.io.FileUtils;
23 import org.apache.maven.plugin.MojoExecutionException;
24 import org.forgerock.doc.maven.AbstractDocbkxMojo;
25 import org.forgerock.doc.maven.AbstractDocbkxMojo.Format;
26 import org.twdata.maven.mojoexecutor.MojoExecutor;
27
28 import java.io.File;
29 import java.io.IOException;
30 import java.util.ArrayList;
31 import java.util.List;
32
33
34
35
36
37
38
39
40
41 public class Layout {
42
43
44
45
46 private AbstractDocbkxMojo m;
47
48
49
50
51 private final Executor executor;
52
53
54
55
56
57
58 public Layout(final AbstractDocbkxMojo mojo) {
59 m = mojo;
60 this.executor = new Executor();
61 }
62
63
64
65
66
67
68 public void execute() throws MojoExecutionException {
69 executor.layout();
70 }
71
72
73
74
75
76
77
78
79
80
81
82 private MojoExecutor.Element getResources() throws MojoExecutionException {
83
84 ArrayList<MojoExecutor.Element> r = new ArrayList<MojoExecutor.Element>();
85 final List<Format> formats = m.getFormats();
86 final String outputDir = m.path(m.getDocbkxOutputDirectory());
87
88 if (formats.contains(Format.html)) {
89 r.add(element(name("resource"),
90 element(name("directory"), outputDir + "/html/")));
91 }
92
93 if (formats.contains(Format.pdf)) {
94 r.add(element(name("resource"),
95 element(name("directory"), outputDir + "/pdf/"),
96 element(name("includes"),
97 element(name("include"), "**/*.pdf"))));
98 }
99
100 return element("resources", r.toArray(new MojoExecutor.Element[r.size()]));
101 }
102
103
104
105
106 class Executor extends MojoExecutor {
107
108
109
110
111
112
113 public void layout() throws MojoExecutionException {
114 final File outputDir = new File(m.getReleaseDirectory(), m.getReleaseVersion());
115
116 executeMojo(
117 plugin(
118 groupId("org.apache.maven.plugins"),
119 artifactId("maven-resources-plugin"),
120 version(m.getMavenResourcesVersion())),
121 goal("copy-resources"),
122 configuration(
123 element(name("encoding"), "UTF-8"),
124 element(name("outputDirectory"), m.path(outputDir)),
125 getResources()),
126 executionEnvironment(m.getProject(), m.getSession(), m.getPluginManager()));
127
128
129
130 if (m.doCopyResourceFiles() && m.getResourcesDirectory().exists()) {
131 try {
132 FileUtils.copyDirectoryToDirectory(m.getResourcesDirectory(), outputDir);
133 } catch (IOException e) {
134 throw new MojoExecutionException("Failed to copy resources", e);
135 }
136 }
137 }
138 }
139 }