1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.tunyk.mvn.plugins.htmlcompressor;
20
21 import java.nio.charset.Charset;
22
23 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugins.annotations.LifecyclePhase;
26 import org.apache.maven.plugins.annotations.Mojo;
27 import org.apache.maven.plugins.annotations.Parameter;
28
29
30
31
32 @Mojo(name = "xml", defaultPhase = LifecyclePhase.COMPILE, requiresProject = false, threadSafe = true)
33 public class XmlCompressorMojo extends AbstractMojo {
34
35
36
37
38
39
40 @Deprecated
41 @Parameter(property = "htmlcompressor.fileExt")
42 private String[] fileExt;
43
44
45 @Parameter(property = "htmlcompressor.fileExtensions")
46 private String[] fileExtensions;
47
48
49 @Parameter(property = "htmlcompressor.enabled", defaultValue = "true")
50 private boolean enabled = true;
51
52
53 @Parameter(defaultValue = "false", alias = "skip", property = "skip")
54 private boolean skip;
55
56
57 @Parameter(property = "htmlcompressor.removeComments", defaultValue = "true")
58 private boolean removeComments = true;
59
60
61 @Parameter(property = "htmlcompressor.removeIntertagSpaces", defaultValue = "true")
62 private boolean removeIntertagSpaces = true;
63
64
65
66
67 @Parameter(property = "htmlcompressor.srcFolder", defaultValue = "${project.basedir}/src/main/resources")
68 private String srcFolder = "src/main/resources";
69
70
71
72
73 @Parameter(property = "htmlcompressor.targetFolder", defaultValue = "${project.build.directory}/classes")
74 private String targetFolder = "target/classes";
75
76
77 @Parameter(property = "htmlcompressor.encoding", defaultValue = "UTF-8")
78 private String encoding = "UTF-8";
79
80 @Override
81 public void execute() throws MojoExecutionException {
82
83 if (this.skip) {
84 getLog().info("XMLCompressor is skipped");
85 return;
86 }
87
88 if (!enabled) {
89 getLog().info("XML compression was turned off.");
90 return;
91 }
92
93
94 if (fileExt != null && fileExtensions == null) {
95 fileExtensions = fileExt;
96 }
97
98 getLog().info("Compressing " + srcFolder);
99 XmlCompressor xmlCompressor = new XmlCompressor(srcFolder, targetFolder);
100 xmlCompressor.setFileExtensions(fileExtensions);
101 xmlCompressor.setFileEncoding(Charset.forName(encoding));
102
103 com.googlecode.htmlcompressor.compressor.XmlCompressor xmlCompressorHandler = new com.googlecode.htmlcompressor.compressor.XmlCompressor();
104 xmlCompressorHandler.setEnabled(enabled);
105 xmlCompressorHandler.setRemoveComments(removeComments);
106 xmlCompressorHandler.setRemoveIntertagSpaces(removeIntertagSpaces);
107 xmlCompressor.setXmlCompressor(xmlCompressorHandler);
108
109 try {
110 xmlCompressor.compress();
111 } catch (Exception e) {
112 throw new MojoExecutionException(e.getMessage());
113 }
114
115 getLog().info("XML compression completed.");
116 }
117
118
119
120
121
122
123
124
125 @Deprecated
126 public String[] getFileExt() {
127 return fileExt;
128 }
129
130
131
132
133
134
135
136
137
138 @Deprecated
139 public void setFileExt(String[] fileExt) {
140 this.fileExt = fileExt;
141 }
142
143
144
145
146
147
148 public String[] getFileExtensions() {
149 return fileExtensions;
150 }
151
152
153
154
155
156
157
158 public void setFileExtensions(String[] fileExtensions) {
159 this.fileExtensions = fileExtensions;
160 }
161
162
163
164
165
166
167 public Boolean getEnabled() {
168 return enabled;
169 }
170
171
172
173
174
175
176
177 public void setEnabled(Boolean enabled) {
178 this.enabled = enabled;
179 }
180
181
182
183
184
185
186 public Boolean getRemoveComments() {
187 return removeComments;
188 }
189
190
191
192
193
194
195
196 public void setRemoveComments(Boolean removeComments) {
197 this.removeComments = removeComments;
198 }
199
200
201
202
203
204
205 public Boolean getRemoveIntertagSpaces() {
206 return removeIntertagSpaces;
207 }
208
209
210
211
212
213
214
215 public void setRemoveIntertagSpaces(Boolean removeIntertagSpaces) {
216 this.removeIntertagSpaces = removeIntertagSpaces;
217 }
218
219
220
221
222
223
224 public String getSrcFolder() {
225 return srcFolder;
226 }
227
228
229
230
231
232
233
234 public void setSrcFolder(String srcFolder) {
235 this.srcFolder = srcFolder;
236 }
237
238
239
240
241
242
243 public String getTargetFolder() {
244 return targetFolder;
245 }
246
247
248
249
250
251
252
253 public void setTargetFolder(String targetFolder) {
254 this.targetFolder = targetFolder;
255 }
256 }