• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / htmlcompressor-maven-plugin / 75

20 Apr 2025 06:38PM UTC coverage: 36.479% (+0.2%) from 36.249%
75

push

github

hazendaz
Change %s injector to be quoted "%s" instead

the underlying code with %s is invalid javascript.  By doing it this way, its now compliant.  The result is the same.  This is a breaking change for those using this.

44 of 218 branches covered (20.18%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

133 existing lines in 5 files now uncovered.

273 of 651 relevant lines covered (41.94%)

0.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.85
/src/main/java/com/tunyk/mvn/plugins/htmlcompressor/XmlCompressorMojo.java
1
/*
2
 * Copyright (c) 2011-2025 Alex Tunyk <alex at tunyk.com>.
3
 * Copyright (c) 2011-2025 Hazendaz <github.com/hazendaz>.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *   https://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 * See the NOTICE file distributed with this work for additional information
18
 * regarding copyright ownership.
19
 */
20
package com.tunyk.mvn.plugins.htmlcompressor;
21

22
import java.nio.charset.Charset;
23

24
import org.apache.maven.plugin.AbstractMojo;
25
import org.apache.maven.plugin.MojoExecutionException;
26
import org.apache.maven.plugins.annotations.LifecyclePhase;
27
import org.apache.maven.plugins.annotations.Mojo;
28
import org.apache.maven.plugins.annotations.Parameter;
29

30
/**
31
 * Compress XML files.
32
 */
33
@Mojo(name = "xml", defaultPhase = LifecyclePhase.COMPILE, requiresProject = false, threadSafe = true)
34
public class XmlCompressorMojo extends AbstractMojo {
1✔
35

36
    /**
37
     * File extensions to be processed.
38
     *
39
     * @deprecated use fileExtensions
40
     */
41
    @Deprecated
42
    @Parameter(property = "htmlcompressor.fileExt")
43
    private String[] fileExt;
44

45
    /** file extensions to be processed. */
46
    @Parameter(property = "htmlcompressor.fileExtensions")
47
    private String[] fileExtensions;
48

49
    /** if false all compression is off (default is true). */
50
    @Parameter(property = "htmlcompressor.enabled", defaultValue = "true")
1✔
51
    private boolean enabled = true;
52

53
    /** Skip run of plugin. */
54
    @Parameter(defaultValue = "false", alias = "skip", property = "skip")
55
    private boolean skip;
56

57
    /** if false keeps XML comments (default is true). */
58
    @Parameter(property = "htmlcompressor.removeComments", defaultValue = "true")
1✔
59
    private boolean removeComments = true;
60

61
    /** removes iter-tag whitespace characters (default is true). */
62
    @Parameter(property = "htmlcompressor.removeIntertagSpaces", defaultValue = "true")
1✔
63
    private boolean removeIntertagSpaces = true;
64

65
    /**
66
     * source folder where xml files are located.
67
     */
68
    @Parameter(property = "htmlcompressor.srcFolder", defaultValue = "${project.basedir}/src/main/resources")
1✔
69
    private String srcFolder = "src/main/resources";
70

71
    /**
72
     * target folder where compressed xml files will be placed.
73
     */
74
    @Parameter(property = "htmlcompressor.targetFolder", defaultValue = "${project.build.directory}/classes")
1✔
75
    private String targetFolder = "target/classes";
76

77
    /** Charset encoding for files to read and create. */
78
    @Parameter(property = "htmlcompressor.encoding", defaultValue = "UTF-8")
1✔
79
    private String encoding = "UTF-8";
80

81
    @Override
82
    public void execute() throws MojoExecutionException {
83
        // Check if plugin run should be skipped
84
        if (this.skip) {
1!
85
            getLog().info("XMLCompressor is skipped");
×
UNCOV
86
            return;
×
87
        }
88

89
        if (!enabled) {
1!
90
            getLog().info("XML compression was turned off.");
×
UNCOV
91
            return;
×
92
        }
93

94
        // Deprecated
95
        if (fileExt != null && fileExtensions == null) {
1!
UNCOV
96
            fileExtensions = fileExt;
×
97
        }
98

99
        getLog().info("Compressing " + srcFolder);
1✔
100
        XmlCompressor xmlCompressor = new XmlCompressor(srcFolder, targetFolder);
1✔
101
        xmlCompressor.setFileExtensions(fileExtensions);
1✔
102
        xmlCompressor.setFileEncoding(Charset.forName(encoding));
1✔
103

104
        com.googlecode.htmlcompressor.compressor.XmlCompressor xmlCompressorHandler = new com.googlecode.htmlcompressor.compressor.XmlCompressor();
1✔
105
        xmlCompressorHandler.setEnabled(enabled);
1✔
106
        xmlCompressorHandler.setRemoveComments(removeComments);
1✔
107
        xmlCompressorHandler.setRemoveIntertagSpaces(removeIntertagSpaces);
1✔
108
        xmlCompressor.setXmlCompressor(xmlCompressorHandler);
1✔
109

110
        try {
111
            xmlCompressor.compress();
1✔
112
        } catch (Exception e) {
×
UNCOV
113
            throw new MojoExecutionException(e.getMessage());
×
114
        }
1✔
115

116
        getLog().info("XML compression completed.");
1✔
117
    }
1✔
118

119
    /**
120
     * Gets the file ext.
121
     *
122
     * @return the file ext
123
     *
124
     * @deprecated use getFileExtensions
125
     */
126
    @Deprecated
127
    public String[] getFileExt() {
UNCOV
128
        return fileExt;
×
129
    }
130

131
    /**
132
     * Sets the file ext.
133
     *
134
     * @param fileExt
135
     *            the new file ext
136
     *
137
     * @deprecated use setFileExtensions
138
     */
139
    @Deprecated
140
    public void setFileExt(String[] fileExt) {
141
        this.fileExt = fileExt;
×
UNCOV
142
    }
×
143

144
    /**
145
     * Gets the file extensions.
146
     *
147
     * @return the file extensions
148
     */
149
    public String[] getFileExtensions() {
UNCOV
150
        return fileExtensions;
×
151
    }
152

153
    /**
154
     * Sets the file ext.
155
     *
156
     * @param fileExtensions
157
     *            the new file extensions
158
     */
159
    public void setFileExtensions(String[] fileExtensions) {
160
        this.fileExtensions = fileExtensions;
×
UNCOV
161
    }
×
162

163
    /**
164
     * Gets the enabled.
165
     *
166
     * @return the enabled
167
     */
168
    public Boolean getEnabled() {
UNCOV
169
        return enabled;
×
170
    }
171

172
    /**
173
     * Sets the enabled.
174
     *
175
     * @param enabled
176
     *            the new enabled
177
     */
178
    public void setEnabled(Boolean enabled) {
179
        this.enabled = enabled;
×
UNCOV
180
    }
×
181

182
    /**
183
     * Gets the removes the comments.
184
     *
185
     * @return the removes the comments
186
     */
187
    public Boolean getRemoveComments() {
UNCOV
188
        return removeComments;
×
189
    }
190

191
    /**
192
     * Sets the removes the comments.
193
     *
194
     * @param removeComments
195
     *            the new removes the comments
196
     */
197
    public void setRemoveComments(Boolean removeComments) {
198
        this.removeComments = removeComments;
×
UNCOV
199
    }
×
200

201
    /**
202
     * Gets the removes the intertag spaces.
203
     *
204
     * @return the removes the intertag spaces
205
     */
206
    public Boolean getRemoveIntertagSpaces() {
UNCOV
207
        return removeIntertagSpaces;
×
208
    }
209

210
    /**
211
     * Sets the removes the intertag spaces.
212
     *
213
     * @param removeIntertagSpaces
214
     *            the new removes the intertag spaces
215
     */
216
    public void setRemoveIntertagSpaces(Boolean removeIntertagSpaces) {
217
        this.removeIntertagSpaces = removeIntertagSpaces;
×
UNCOV
218
    }
×
219

220
    /**
221
     * Gets the src folder.
222
     *
223
     * @return the src folder
224
     */
225
    public String getSrcFolder() {
UNCOV
226
        return srcFolder;
×
227
    }
228

229
    /**
230
     * Sets the src folder.
231
     *
232
     * @param srcFolder
233
     *            the new src folder
234
     */
235
    public void setSrcFolder(String srcFolder) {
236
        this.srcFolder = srcFolder;
1✔
237
    }
1✔
238

239
    /**
240
     * Gets the target folder.
241
     *
242
     * @return the target folder
243
     */
244
    public String getTargetFolder() {
UNCOV
245
        return targetFolder;
×
246
    }
247

248
    /**
249
     * Sets the target folder.
250
     *
251
     * @param targetFolder
252
     *            the new target folder
253
     */
254
    public void setTargetFolder(String targetFolder) {
255
        this.targetFolder = targetFolder;
1✔
256
    }
1✔
257
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc