• 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

77.27
/src/main/java/com/tunyk/mvn/plugins/htmlcompressor/HtmlCompressor.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.io.IOException;
23
import java.nio.charset.Charset;
24
import java.nio.file.Files;
25
import java.nio.file.Path;
26
import java.util.Map.Entry;
27
import java.util.concurrent.ConcurrentMap;
28

29
/**
30
 * The Class HtmlCompressor.
31
 */
32
public class HtmlCompressor {
33

34
    /** The Constant FILE_EXT. */
35
    private static final String[] FILE_EXT = { "htm", "html" };
1✔
36

37
    /** The file extensions. */
38
    private String[] fileExtensions;
39

40
    /** The src dir path. */
41
    private String srcDirPath;
42

43
    /** The target dir path. */
44
    private String targetDirPath;
45

46
    /** The file encoding. */
47
    private Charset fileEncoding;
48

49
    /** The create json file. */
50
    private boolean createJsonFile;
51

52
    /** The target json file path. */
53
    private String targetJsonFilePath;
54

55
    /** The json integration file path. */
56
    private String jsonIntegrationFilePath;
57

58
    /** The html compressor. */
59
    private com.googlecode.htmlcompressor.compressor.HtmlCompressor htmlCompressor;
60

61
    /**
62
     * Instantiates a new html compressor.
63
     *
64
     * @param srcDirPath
65
     *            the src dir path
66
     * @param targetDirPath
67
     *            the target dir path
68
     */
69
    public HtmlCompressor(String srcDirPath, String targetDirPath) {
1✔
70
        this.srcDirPath = srcDirPath;
1✔
71
        this.targetDirPath = targetDirPath;
1✔
72
    }
1✔
73

74
    /**
75
     * Instantiates a new html compressor.
76
     *
77
     * @param srcDirPath
78
     *            the src dir path
79
     * @param targetDirPath
80
     *            the target dir path
81
     * @param createJsonFile
82
     *            the create json file
83
     * @param targetJsonFilePath
84
     *            the target json file path
85
     * @param jsonIntegrationFilePath
86
     *            the json integration file path
87
     */
88
    public HtmlCompressor(String srcDirPath, String targetDirPath, boolean createJsonFile, String targetJsonFilePath,
89
            String jsonIntegrationFilePath) {
1✔
90
        this.srcDirPath = srcDirPath;
1✔
91
        this.targetDirPath = targetDirPath;
1✔
92
        this.createJsonFile = createJsonFile;
1✔
93
        this.targetJsonFilePath = targetJsonFilePath;
1✔
94
        this.jsonIntegrationFilePath = jsonIntegrationFilePath;
1✔
95
    }
1✔
96

97
    /**
98
     * Compress.
99
     *
100
     * @throws IOException
101
     *             Signals that an I/O exception has occurred.
102
     */
103
    public void compress() throws IOException {
104
        if (fileExtensions == null || fileExtensions.length == 0) {
1!
105
            fileExtensions = FILE_EXT;
1✔
106
        }
107

108
        FileTool fileTool = new FileTool(srcDirPath, fileExtensions, true);
1✔
109
        fileTool.setFileEncoding(fileEncoding);
1✔
110
        ConcurrentMap<String, String> map = fileTool.getFiles();
1✔
111

112
        if (htmlCompressor == null) {
1✔
113
            htmlCompressor = new com.googlecode.htmlcompressor.compressor.HtmlCompressor();
1✔
114
        }
115

116
        for (Entry<String, String> key : map.entrySet()) {
1✔
117
            map.put(key.getKey(), htmlCompressor.compress(key.getValue()));
1✔
118
        }
1✔
119

120
        fileTool.writeFiles(map, targetDirPath);
1✔
121
        if (createJsonFile) {
1✔
122
            String jsonIntegrationCode = Files.readString(Path.of(jsonIntegrationFilePath),
1✔
123
                    fileEncoding == null ? Charset.defaultCharset() : fileEncoding);
1✔
124
            fileTool.writeToJsonFile(map, targetJsonFilePath, jsonIntegrationCode);
1✔
125
        }
126
    }
1✔
127

128
    /**
129
     * Gets the file extensions.
130
     *
131
     * @return the file extensions
132
     */
133
    public String[] getFileExtensions() {
UNCOV
134
        return fileExtensions;
×
135
    }
136

137
    /**
138
     * Sets the file extensions.
139
     *
140
     * @param fileExtensions
141
     *            the new file extensions
142
     */
143
    public void setFileExtensions(String[] fileExtensions) {
144
        this.fileExtensions = fileExtensions;
1✔
145
    }
1✔
146

147
    /**
148
     * Gets the src dir path.
149
     *
150
     * @return the src dir path
151
     */
152
    public String getSrcDirPath() {
UNCOV
153
        return srcDirPath;
×
154
    }
155

156
    /**
157
     * Sets the src dir path.
158
     *
159
     * @param srcDirPath
160
     *            the new src dir path
161
     */
162
    public void setSrcDirPath(String srcDirPath) {
163
        this.srcDirPath = srcDirPath;
×
UNCOV
164
    }
×
165

166
    /**
167
     * Gets the target dir path.
168
     *
169
     * @return the target dir path
170
     */
171
    public String getTargetDirPath() {
UNCOV
172
        return targetDirPath;
×
173
    }
174

175
    /**
176
     * Sets the target dir path.
177
     *
178
     * @param targetDirPath
179
     *            the new target dir path
180
     */
181
    public void setTargetDirPath(String targetDirPath) {
182
        this.targetDirPath = targetDirPath;
×
UNCOV
183
    }
×
184

185
    /**
186
     * Gets the file encoding.
187
     *
188
     * @return the file encoding
189
     */
190
    public Charset getFileEncoding() {
UNCOV
191
        return fileEncoding;
×
192
    }
193

194
    /**
195
     * Sets the file encoding.
196
     *
197
     * @param fileEncoding
198
     *            the new file encoding
199
     */
200
    public void setFileEncoding(Charset fileEncoding) {
201
        this.fileEncoding = fileEncoding == null ? Charset.defaultCharset() : fileEncoding;
1!
202
    }
1✔
203

204
    /**
205
     * Checks if is creates the json file.
206
     *
207
     * @return true, if is creates the json file
208
     */
209
    public boolean isCreateJsonFile() {
UNCOV
210
        return createJsonFile;
×
211
    }
212

213
    /**
214
     * Sets the creates the json file.
215
     *
216
     * @param createJsonFile
217
     *            the new creates the json file
218
     */
219
    public void setCreateJsonFile(boolean createJsonFile) {
220
        this.createJsonFile = createJsonFile;
1✔
221
    }
1✔
222

223
    /**
224
     * Gets the target json file path.
225
     *
226
     * @return the target json file path
227
     */
228
    public String getTargetJsonFilePath() {
UNCOV
229
        return targetJsonFilePath;
×
230
    }
231

232
    /**
233
     * Sets the target json file path.
234
     *
235
     * @param targetJsonFilePath
236
     *            the new target json file path
237
     */
238
    public void setTargetJsonFilePath(String targetJsonFilePath) {
239
        this.targetJsonFilePath = targetJsonFilePath;
1✔
240
    }
1✔
241

242
    /**
243
     * Gets the json integration file path.
244
     *
245
     * @return the json integration file path
246
     */
247
    public String getJsonIntegrationFilePath() {
UNCOV
248
        return jsonIntegrationFilePath;
×
249
    }
250

251
    /**
252
     * Sets the json integration file path.
253
     *
254
     * @param jsonIntegrationFilePath
255
     *            the new json integration file path
256
     */
257
    public void setJsonIntegrationFilePath(String jsonIntegrationFilePath) {
258
        this.jsonIntegrationFilePath = jsonIntegrationFilePath;
1✔
259
    }
1✔
260

261
    /**
262
     * Gets the html compressor.
263
     *
264
     * @return the html compressor
265
     */
266
    public com.googlecode.htmlcompressor.compressor.HtmlCompressor getHtmlCompressor() {
267
        return htmlCompressor;
1✔
268
    }
269

270
    /**
271
     * Sets the html compressor.
272
     *
273
     * @param htmlCompressor
274
     *            the new html compressor
275
     */
276
    public void setHtmlCompressor(com.googlecode.htmlcompressor.compressor.HtmlCompressor htmlCompressor) {
277
        this.htmlCompressor = htmlCompressor;
1✔
278
    }
1✔
279
}
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