/
HtmlCompressorMojo.java
1226 lines (1080 loc) · 40.8 KB
/
HtmlCompressorMojo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2011-2024 Alex Tunyk <alex at tunyk.com>.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*/
package com.tunyk.mvn.plugins.htmlcompressor;
import com.google.javascript.jscomp.CompilationLevel;
import com.google.javascript.jscomp.SourceFile;
import com.googlecode.htmlcompressor.compressor.ClosureJavaScriptCompressor;
import com.googlecode.htmlcompressor.compressor.Compressor;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
/**
* Compress HTML files.
*/
@Mojo(name = "html", defaultPhase = LifecyclePhase.COMPILE, requiresProject = false, threadSafe = true)
public class HtmlCompressorMojo extends AbstractMojo {
/** file where statistics of html compression is stored. */
@Parameter(property = "htmlcompressor.htmlCompressionStatistics", defaultValue = "${project.build.directory}/htmlcompressor/html-compression-statistics.txt")
private String htmlCompressionStatistics = "target/htmlcompressor/html-compression-statistics.txt";
/**
* file types to be processed.
*
* @deprecated use fileExtensions
*/
@Deprecated
@Parameter(property = "htmlcompressor.fileExt")
private String[] fileExt;
/**
* File extensions to be processed.
*/
@Parameter(property = "htmlcompressor.fileExtensions")
private String[] fileExtensions;
/** if false all compression is off (default is true). */
@Parameter(property = "htmlcompressor.enabled", defaultValue = "true")
private boolean enabled = true;
/** Skip run of plugin. */
@Parameter(defaultValue = "false", alias = "skip", property = "skip")
private boolean skip;
/** if false keeps HTML comments (default is true). */
@Parameter(property = "htmlcompressor.removeComments", defaultValue = "true")
private boolean removeComments = true;
/** if false keeps multiple whitespace characters (default is true). */
@Parameter(property = "htmlcompressor.removeMultiSpaces", defaultValue = "true")
private boolean removeMultiSpaces = true;
/** removes iter-tag whitespace characters. */
@Parameter(property = "htmlcompressor.removeIntertagSpaces", defaultValue = "false")
private boolean removeIntertagSpaces;
/** removes unnecessary tag attribute quotes. */
@Parameter(property = "htmlcompressor.removeQuotes", defaultValue = "false")
private boolean removeQuotes;
/** simplify existing doctype. */
@Parameter(property = "htmlcompressor.simpleDoctype", defaultValue = "false")
private boolean simpleDoctype;
/** remove optional attributes from script tags. */
@Parameter(property = "htmlcompressor.removeScriptAttributes", defaultValue = "false")
private boolean removeScriptAttributes;
/** remove optional attributes from style tags. */
@Parameter(property = "htmlcompressor.removeStyleAttributes", defaultValue = "false")
private boolean removeStyleAttributes;
/** remove optional attributes from link tags. */
@Parameter(property = "htmlcompressor.removeLinkAttributes", defaultValue = "false")
private boolean removeLinkAttributes;
/** remove optional attributes from form tags. */
@Parameter(property = "htmlcompressor.removeFormAttributes", defaultValue = "false")
private boolean removeFormAttributes;
/** remove optional attributes from input tags. */
@Parameter(property = "htmlcompressor.removeInputAttributes", defaultValue = "false")
private boolean removeInputAttributes;
/** remove values from boolean tag attributes. */
@Parameter(property = "htmlcompressor.simpleBooleanAttributes", defaultValue = "false")
private boolean simpleBooleanAttributes;
/** remove "javascript:" from inline event handlers. */
@Parameter(property = "htmlcompressor.removeJavaScriptProtocol", defaultValue = "false")
private boolean removeJavaScriptProtocol;
/** replace "http://" with "//" inside tag attributes. */
@Parameter(property = "htmlcompressor.removeHttpProtocol", defaultValue = "false")
private boolean removeHttpProtocol;
/** replace "https://" with "//" inside tag attributes. */
@Parameter(property = "htmlcompressor.removeHttpsProtocol", defaultValue = "false")
private boolean removeHttpsProtocol;
/** compress inline css. */
@Parameter(property = "htmlcompressor.compressCss", defaultValue = "false")
private boolean compressCss;
/** preserves original line breaks. */
@Parameter(property = "htmlcompressor.preserveLineBreaks", defaultValue = "false")
private boolean preserveLineBreaks;
/** --line-break param for Yahoo YUI Compressor. */
@Parameter(property = "htmlcompressor.yuiCssLineBreak", defaultValue = "-1")
private int yuiCssLineBreak = -1;
/** css compressor. */
// TODO JWL 4/22/2023 Unsupported
@SuppressWarnings("unused")
@Parameter(property = "htmlcompressor.cssCompressor", defaultValue = "")
private Compressor cssCompressor;
/** compress inline javascript. */
@Parameter(property = "htmlcompressor.compressJavaScript", defaultValue = "false")
private boolean compressJavaScript;
/** javascript compression: "yui" or "closure". */
@Parameter(property = "htmlcompressor.jsCompressor", defaultValue = "yui")
private String jsCompressor = "yui";
/** javascript compression. */
// TODO JWL 4/22/2023Unsupported
@SuppressWarnings("unused")
@Parameter(property = "htmlcompressor.javaScriptCompressor", defaultValue = "")
private Compressor javaScriptCompressor;
/** --nomunge param for Yahoo YUI Compressor. */
@Parameter(property = "htmlcompressor.yuiJsNoMunge", defaultValue = "false")
private boolean yuiJsNoMunge;
/** --preserve-semi param for Yahoo YUI Compressor. */
@Parameter(property = "htmlcompressor.yuiJsPreserveAllSemiColons", defaultValue = "false")
private boolean yuiJsPreserveAllSemiColons;
/** --line-break param for Yahoo YUI Compressor. */
@Parameter(property = "htmlcompressor.yuiJsLineBreak", defaultValue = "-1")
private int yuiJsLineBreak = -1;
/** closureOptLevel = "simple", "advanced" or "whitespace". */
@Parameter(property = "htmlcompressor.closureOptLevel", defaultValue = "simple")
private String closureOptLevel = "simple";
/** --disable-optimizations param for Yahoo YUI Compressor. */
@Parameter(property = "htmlcompressor.yuiJsDisableOptimizations", defaultValue = "false")
private boolean yuiJsDisableOptimizations;
/**
* predefined patterns for most often used custom preservation rules: PHP_TAG_PATTERN and SERVER_SCRIPT_TAG_PATTERN.
*/
@Parameter(property = "htmlcompressor.predefinedPreservePatterns")
private String[] predefinedPreservePatterns;
/** preserve patterns. */
@Parameter(property = "htmlcompressor.preservePatterns")
private String[] preservePatterns;
/** list of files containing preserve patterns. */
@Parameter(property = "htmlcompressor.preservePatternFiles")
private File[] preservePatternFiles;
/** HTML compression statistics. */
@Parameter(property = "htmlcompressor.generateStatistics", defaultValue = "true")
private boolean generateStatistics = true;
/**
* source folder where html files are located.
*/
@Parameter(property = "htmlcompressor.srcFolder", defaultValue = "${basedir}/src/main/resources")
private String srcFolder = "src/main/resources";
/**
* target folder where compressed html files will be placed.
*/
@Parameter(property = "htmlcompressor.targetFolder", defaultValue = "${project.build.directory}/classes")
private String targetFolder = "target/classes";
/**
* Create javascript file which includes all compressed html files as json object. If set to true then
* javascriptHtmlSpriteIntegrationFile param is required, otherwise it will throw exception.
*/
@Parameter(property = "htmlcompressor.javascriptHtmlSprite", defaultValue = "true")
private boolean javascriptHtmlSprite = true;
/**
* JavaScript sprite integration file (first occurrence of "%s" will be substituted by json with all compressed html
* strings).
*/
@Parameter(property = "htmlcompressor.javascriptHtmlSpriteIntegrationFile", defaultValue = "${basedir}/src/main/resources/html/integration.js")
private String javascriptHtmlSpriteIntegrationFile = "src/main/resources/html/integration.js";
/**
* The target JavaScript sprite file with compressed html files as json object.
*/
@Parameter(property = "htmlcompressor.javascriptHtmlSpriteTargetFile", defaultValue = "${project.build.directory}/htmlcompressor/html/integration.js")
private String javascriptHtmlSpriteTargetFile = "target/htmlcompressor/html/integration.js";
/** Charset encoding for files to read and create. */
@Parameter(property = "htmlcompressor.encoding", defaultValue = "UTF-8")
private String encoding = "UTF-8";
/**
* Disable default built-in closure externs.
*/
@Parameter(property = "htmlcompressor.closureCustomExternsOnly", defaultValue = "false")
private boolean closureCustomExternsOnly;
/**
* Sets custom closure externs file list.
*/
@Parameter(property = "htmlcompressor.closureExterns")
private String[] closureExterns;
@Override
public void execute() throws MojoExecutionException {
// Check if plugin run should be skipped
if (this.skip) {
getLog().info("HtmlCompressor is skipped");
return;
}
if (!enabled) {
getLog().info("HTML compression was turned off.");
return;
}
if (!new File(srcFolder).exists()) {
getLog().warn("Compressor folder does not exist, skipping compression of " + srcFolder);
return;
}
getLog().info("Compressing " + srcFolder);
HtmlCompressor htmlCompressor = new HtmlCompressor(srcFolder, targetFolder);
// Deprecated
if (fileExt != null && fileExtensions == null) {
fileExtensions = fileExt;
}
htmlCompressor.setFileExtensions(fileExtensions);
htmlCompressor.setFileEncoding(Charset.forName(encoding));
htmlCompressor.setCreateJsonFile(javascriptHtmlSprite);
htmlCompressor.setJsonIntegrationFilePath(javascriptHtmlSpriteIntegrationFile);
htmlCompressor.setTargetJsonFilePath(javascriptHtmlSpriteTargetFile);
com.googlecode.htmlcompressor.compressor.HtmlCompressor htmlCompressorHandler = new com.googlecode.htmlcompressor.compressor.HtmlCompressor();
htmlCompressorHandler.setEnabled(enabled);
htmlCompressorHandler.setRemoveComments(removeComments);
htmlCompressorHandler.setRemoveMultiSpaces(removeMultiSpaces);
htmlCompressorHandler.setRemoveIntertagSpaces(removeIntertagSpaces);
htmlCompressorHandler.setRemoveQuotes(removeQuotes);
htmlCompressorHandler.setSimpleDoctype(simpleDoctype);
htmlCompressorHandler.setRemoveScriptAttributes(removeScriptAttributes);
htmlCompressorHandler.setRemoveStyleAttributes(removeStyleAttributes);
htmlCompressorHandler.setRemoveLinkAttributes(removeLinkAttributes);
htmlCompressorHandler.setRemoveFormAttributes(removeFormAttributes);
htmlCompressorHandler.setRemoveInputAttributes(removeInputAttributes);
htmlCompressorHandler.setSimpleBooleanAttributes(simpleBooleanAttributes);
htmlCompressorHandler.setRemoveJavaScriptProtocol(removeJavaScriptProtocol);
htmlCompressorHandler.setRemoveHttpProtocol(removeHttpProtocol);
htmlCompressorHandler.setRemoveHttpsProtocol(removeHttpsProtocol);
htmlCompressorHandler.setCompressCss(compressCss);
htmlCompressorHandler.setPreserveLineBreaks(preserveLineBreaks);
htmlCompressorHandler.setYuiCssLineBreak(yuiCssLineBreak);
htmlCompressorHandler.setCompressJavaScript(compressJavaScript);
htmlCompressorHandler.setYuiJsNoMunge(yuiJsNoMunge);
htmlCompressorHandler.setYuiJsPreserveAllSemiColons(yuiJsPreserveAllSemiColons);
htmlCompressorHandler.setYuiJsLineBreak(yuiJsLineBreak);
htmlCompressorHandler.setYuiJsDisableOptimizations(yuiJsDisableOptimizations);
htmlCompressorHandler.setGenerateStatistics(generateStatistics);
if (jsCompressor.equalsIgnoreCase("closure")) {
ClosureJavaScriptCompressor closureCompressor = new ClosureJavaScriptCompressor();
if (closureOptLevel != null
&& closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_ADVANCED)) {
closureCompressor.setCompilationLevel(CompilationLevel.ADVANCED_OPTIMIZATIONS);
closureCompressor.setCustomExternsOnly(closureCustomExternsOnly);
if (closureExterns.length > 0) {
List<SourceFile> externs = new ArrayList<>();
for (String externFile : closureExterns) {
externs.add(SourceFile.fromFile(externFile));
}
closureCompressor.setExterns(externs);
}
} else if (closureOptLevel != null
&& closureOptLevel.equalsIgnoreCase(ClosureJavaScriptCompressor.COMPILATION_LEVEL_WHITESPACE)) {
closureCompressor.setCompilationLevel(CompilationLevel.WHITESPACE_ONLY);
} else {
closureCompressor.setCompilationLevel(CompilationLevel.SIMPLE_OPTIMIZATIONS);
}
htmlCompressorHandler.setJavaScriptCompressor(closureCompressor);
}
List<Pattern> preservePatternList = new ArrayList<>();
boolean phpTagPatternAdded = false;
boolean serverScriptTagPatternAdded = false;
if (predefinedPreservePatterns != null) {
for (String pattern : predefinedPreservePatterns) {
if (!phpTagPatternAdded && pattern.equalsIgnoreCase("PHP_TAG_PATTERN")) {
preservePatternList.add(com.googlecode.htmlcompressor.compressor.HtmlCompressor.PHP_TAG_PATTERN);
phpTagPatternAdded = true;
} else if (!serverScriptTagPatternAdded && pattern.equalsIgnoreCase("SERVER_SCRIPT_TAG_PATTERN")) {
preservePatternList
.add(com.googlecode.htmlcompressor.compressor.HtmlCompressor.SERVER_SCRIPT_TAG_PATTERN);
serverScriptTagPatternAdded = true;
}
}
}
if (preservePatterns != null) {
for (String preservePatternString : preservePatterns) {
if (!preservePatternString.isEmpty()) {
try {
preservePatternList.add(Pattern.compile(preservePatternString));
} catch (PatternSyntaxException e) {
throw new MojoExecutionException(e.getMessage());
}
}
}
}
if (preservePatternFiles != null) {
for (File file : preservePatternFiles) {
try {
List<String> fileLines = Files.readAllLines(file.toPath(), Charset.forName(encoding));
for (String line : fileLines) {
if (!line.isEmpty()) {
preservePatternList.add(Pattern.compile(line));
}
}
} catch (IOException | PatternSyntaxException e) {
throw new MojoExecutionException(e.getMessage());
}
}
}
htmlCompressorHandler.setPreservePatterns(preservePatternList);
htmlCompressor.setHtmlCompressor(htmlCompressorHandler);
try {
htmlCompressor.compress();
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage());
}
// The system of units (SI) as 1000 rather than 1024
boolean systemOfUnits = true;
int origFilesizeBytes = -1;
try {
origFilesizeBytes = htmlCompressor.getHtmlCompressor().getStatistics().getOriginalMetrics().getFilesize();
} catch (NullPointerException e) {
getLog().info("No files found to compress, HTML compression completed.");
return;
}
String origFilesize = FileTool.humanReadableByteCount(origFilesizeBytes, systemOfUnits);
String origEmptyChars = String
.valueOf(htmlCompressor.getHtmlCompressor().getStatistics().getOriginalMetrics().getEmptyChars());
String origInlineEventSize = FileTool.humanReadableByteCount(
htmlCompressor.getHtmlCompressor().getStatistics().getOriginalMetrics().getInlineEventSize(),
systemOfUnits);
String origInlineScriptSize = FileTool.humanReadableByteCount(
htmlCompressor.getHtmlCompressor().getStatistics().getOriginalMetrics().getInlineScriptSize(),
systemOfUnits);
String origInlineStyleSize = FileTool.humanReadableByteCount(
htmlCompressor.getHtmlCompressor().getStatistics().getOriginalMetrics().getInlineStyleSize(),
systemOfUnits);
int compFilesizeBytes = htmlCompressor.getHtmlCompressor().getStatistics().getCompressedMetrics().getFilesize();
String compFilesize = FileTool.humanReadableByteCount(compFilesizeBytes, systemOfUnits);
String compEmptyChars = String
.valueOf(htmlCompressor.getHtmlCompressor().getStatistics().getCompressedMetrics().getEmptyChars());
String compInlineEventSize = FileTool.humanReadableByteCount(
htmlCompressor.getHtmlCompressor().getStatistics().getCompressedMetrics().getInlineEventSize(),
systemOfUnits);
String compInlineScriptSize = FileTool.humanReadableByteCount(
htmlCompressor.getHtmlCompressor().getStatistics().getCompressedMetrics().getInlineScriptSize(),
systemOfUnits);
String compInlineStyleSize = FileTool.humanReadableByteCount(
htmlCompressor.getHtmlCompressor().getStatistics().getCompressedMetrics().getInlineStyleSize(),
systemOfUnits);
String elapsedTime = FileTool.getElapsedHMSTime(htmlCompressor.getHtmlCompressor().getStatistics().getTime());
String preservedSize = FileTool.humanReadableByteCount(
htmlCompressor.getHtmlCompressor().getStatistics().getPreservedSize(), systemOfUnits);
Float compressionRatio = Float.valueOf(compFilesizeBytes) / Float.valueOf(origFilesizeBytes);
Float spaceSavings = Float.valueOf(1) - compressionRatio;
String format = "%-30s%-30s%-30s%-2s";
NumberFormat formatter = new DecimalFormat("#0.00");
String eol = "\n";
String hr = "+-----------------------------+-----------------------------+-----------------------------+";
StringBuilder sb = new StringBuilder("HTML compression statistics:").append(eol);
sb.append(hr).append(eol);
sb.append(String.format(format, "| Category", "| Original", "| Compressed", "|")).append(eol);
sb.append(hr).append(eol);
sb.append(String.format(format, "| Filesize", "| " + origFilesize, "| " + compFilesize, "|")).append(eol);
sb.append(String.format(format, "| Empty Chars", "| " + origEmptyChars, "| " + compEmptyChars, "|"))
.append(eol);
sb.append(String.format(format, "| Script Size", "| " + origInlineScriptSize, "| " + compInlineScriptSize, "|"))
.append(eol);
sb.append(String.format(format, "| Style Size", "| " + origInlineStyleSize, "| " + compInlineStyleSize, "|"))
.append(eol);
sb.append(String.format(format, "| Event Handler Size", "| " + origInlineEventSize, "| " + compInlineEventSize,
"|")).append(eol);
sb.append(hr).append(eol);
sb.append(String.format("%-90s%-2s",
String.format("| Time: %s, Preserved: %s, Compression Ratio: %s, Savings: %s%%", elapsedTime,
preservedSize, formatter.format(compressionRatio), formatter.format(spaceSavings * 100)),
"|")).append(eol);
sb.append(hr).append(eol);
String statistics = sb.toString();
getLog().info(statistics);
try {
Files.createDirectories(Path.of(htmlCompressionStatistics).getParent());
Files.writeString(Path.of(htmlCompressionStatistics), statistics, Charset.forName(encoding));
} catch (IOException e) {
throw new MojoExecutionException(e.getMessage());
}
getLog().info("HTML compression completed.");
}
/**
* Gets the html compression statistics.
*
* @return the html compression statistics
*/
public String getHtmlCompressionStatistics() {
return htmlCompressionStatistics;
}
/**
* Sets the html compression statistics.
*
* @param htmlCompressionStatistics
* the new html compression statistics
*/
public void setHtmlCompressionStatistics(String htmlCompressionStatistics) {
this.htmlCompressionStatistics = htmlCompressionStatistics;
}
/**
* Gets the file ext.
*
* @return the file ext
*
* @deprecated use getFileExtensions
*/
@Deprecated
public String[] getFileExt() {
return fileExt;
}
/**
* Sets the file ext.
*
* @param fileExt
* the new file ext
*
* @deprecated use setFileExtensions
*/
@Deprecated
public void setFileExt(String[] fileExt) {
this.fileExt = fileExt;
}
/**
* Gets the file ext.
*
* @return the file extensions
*/
public String[] getFileExtensions() {
return fileExtensions;
}
/**
* Sets the file ext.
*
* @param fileExtensions
* the new file ext
*/
public void setFileExtensions(String[] fileExtensions) {
this.fileExtensions = fileExtensions;
}
/**
* Gets the enabled.
*
* @return the enabled
*/
public Boolean getEnabled() {
return enabled;
}
/**
* Sets the enabled.
*
* @param enabled
* the new enabled
*/
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
/**
* Gets the removes the comments.
*
* @return the removes the comments
*/
public Boolean getRemoveComments() {
return removeComments;
}
/**
* Sets the removes the comments.
*
* @param removeComments
* the new removes the comments
*/
public void setRemoveComments(Boolean removeComments) {
this.removeComments = removeComments;
}
/**
* Gets the removes the multi spaces.
*
* @return the removes the multi spaces
*/
public Boolean getRemoveMultiSpaces() {
return removeMultiSpaces;
}
/**
* Sets the removes the multi spaces.
*
* @param removeMultiSpaces
* the new removes the multi spaces
*/
public void setRemoveMultiSpaces(Boolean removeMultiSpaces) {
this.removeMultiSpaces = removeMultiSpaces;
}
/**
* Gets the removes the intertag spaces.
*
* @return the removes the intertag spaces
*/
public Boolean getRemoveIntertagSpaces() {
return removeIntertagSpaces;
}
/**
* Sets the removes the intertag spaces.
*
* @param removeIntertagSpaces
* the new removes the intertag spaces
*/
public void setRemoveIntertagSpaces(Boolean removeIntertagSpaces) {
this.removeIntertagSpaces = removeIntertagSpaces;
}
/**
* Gets the removes the quotes.
*
* @return the removes the quotes
*/
public Boolean getRemoveQuotes() {
return removeQuotes;
}
/**
* Sets the removes the quotes.
*
* @param removeQuotes
* the new removes the quotes
*/
public void setRemoveQuotes(Boolean removeQuotes) {
this.removeQuotes = removeQuotes;
}
/**
* Gets the simple doctype.
*
* @return the simple doctype
*/
public Boolean getSimpleDoctype() {
return simpleDoctype;
}
/**
* Sets the simple doctype.
*
* @param simpleDoctype
* the new simple doctype
*/
public void setSimpleDoctype(Boolean simpleDoctype) {
this.simpleDoctype = simpleDoctype;
}
/**
* Gets the removes the script attributes.
*
* @return the removes the script attributes
*/
public Boolean getRemoveScriptAttributes() {
return removeScriptAttributes;
}
/**
* Sets the removes the script attributes.
*
* @param removeScriptAttributes
* the new removes the script attributes
*/
public void setRemoveScriptAttributes(Boolean removeScriptAttributes) {
this.removeScriptAttributes = removeScriptAttributes;
}
/**
* Gets the removes the style attributes.
*
* @return the removes the style attributes
*/
public Boolean getRemoveStyleAttributes() {
return removeStyleAttributes;
}
/**
* Sets the removes the style attributes.
*
* @param removeStyleAttributes
* the new removes the style attributes
*/
public void setRemoveStyleAttributes(Boolean removeStyleAttributes) {
this.removeStyleAttributes = removeStyleAttributes;
}
/**
* Gets the removes the link attributes.
*
* @return the removes the link attributes
*/
public Boolean getRemoveLinkAttributes() {
return removeLinkAttributes;
}
/**
* Sets the removes the link attributes.
*
* @param removeLinkAttributes
* the new removes the link attributes
*/
public void setRemoveLinkAttributes(Boolean removeLinkAttributes) {
this.removeLinkAttributes = removeLinkAttributes;
}
/**
* Gets the removes the form attributes.
*
* @return the removes the form attributes
*/
public Boolean getRemoveFormAttributes() {
return removeFormAttributes;
}
/**
* Sets the removes the form attributes.
*
* @param removeFormAttributes
* the new removes the form attributes
*/
public void setRemoveFormAttributes(Boolean removeFormAttributes) {
this.removeFormAttributes = removeFormAttributes;
}
/**
* Gets the removes the input attributes.
*
* @return the removes the input attributes
*/
public Boolean getRemoveInputAttributes() {
return removeInputAttributes;
}
/**
* Sets the removes the input attributes.
*
* @param removeInputAttributes
* the new removes the input attributes
*/
public void setRemoveInputAttributes(Boolean removeInputAttributes) {
this.removeInputAttributes = removeInputAttributes;
}
/**
* Gets the simple boolean attributes.
*
* @return the simple boolean attributes
*/
public Boolean getSimpleBooleanAttributes() {
return simpleBooleanAttributes;
}
/**
* Sets the simple boolean attributes.
*
* @param simpleBooleanAttributes
* the new simple boolean attributes
*/
public void setSimpleBooleanAttributes(Boolean simpleBooleanAttributes) {
this.simpleBooleanAttributes = simpleBooleanAttributes;
}
/**
* Gets the removes the java script protocol.
*
* @return the removes the java script protocol
*/
public Boolean getRemoveJavaScriptProtocol() {
return removeJavaScriptProtocol;
}
/**
* Sets the removes the java script protocol.
*
* @param removeJavaScriptProtocol
* the new removes the java script protocol
*/
public void setRemoveJavaScriptProtocol(Boolean removeJavaScriptProtocol) {
this.removeJavaScriptProtocol = removeJavaScriptProtocol;
}
/**
* Gets the removes the http protocol.
*
* @return the removes the http protocol
*/
public Boolean getRemoveHttpProtocol() {
return removeHttpProtocol;
}
/**
* Sets the removes the http protocol.
*
* @param removeHttpProtocol
* the new removes the http protocol
*/
public void setRemoveHttpProtocol(Boolean removeHttpProtocol) {
this.removeHttpProtocol = removeHttpProtocol;
}
/**
* Gets the removes the https protocol.
*
* @return the removes the https protocol
*/
public Boolean getRemoveHttpsProtocol() {
return removeHttpsProtocol;
}
/**
* Sets the removes the https protocol.
*
* @param removeHttpsProtocol
* the new removes the https protocol
*/
public void setRemoveHttpsProtocol(Boolean removeHttpsProtocol) {
this.removeHttpsProtocol = removeHttpsProtocol;
}
/**
* Gets the compress css.
*
* @return the compress css
*/
public Boolean getCompressCss() {
return compressCss;
}
/**
* Sets the compress css.
*
* @param compressCss
* the new compress css
*/
public void setCompressCss(Boolean compressCss) {
this.compressCss = compressCss;
}
/**
* Gets the preserve line breaks.
*
* @return the preserve line breaks
*/
public Boolean getPreserveLineBreaks() {
return preserveLineBreaks;
}
/**
* Sets the preserve line breaks.
*
* @param preserveLineBreaks
* the new preserve line breaks
*/
public void setPreserveLineBreaks(Boolean preserveLineBreaks) {
this.preserveLineBreaks = preserveLineBreaks;
}
/**
* Gets the yui css line break.
*
* @return the yui css line break
*/
public Integer getYuiCssLineBreak() {
return yuiCssLineBreak;
}
/**
* Sets the yui css line break.
*
* @param yuiCssLineBreak
* the new yui css line break
*/
public void setYuiCssLineBreak(Integer yuiCssLineBreak) {
this.yuiCssLineBreak = yuiCssLineBreak;
}
/**
* Gets the compress java script.
*
* @return the compress java script
*/
public Boolean getCompressJavaScript() {
return compressJavaScript;
}
/**
* Sets the compress java script.
*
* @param compressJavaScript
* the new compress java script
*/
public void setCompressJavaScript(Boolean compressJavaScript) {
this.compressJavaScript = compressJavaScript;
}
/**
* Gets the js compressor.
*
* @return the js compressor
*/
public String getJsCompressor() {
return jsCompressor;
}
/**
* Sets the js compressor.
*
* @param jsCompressor
* the new js compressor
*/
public void setJsCompressor(String jsCompressor) {
this.jsCompressor = jsCompressor;
}
/**
* Gets the yui js no munge.
*
* @return the yui js no munge
*/
public Boolean getYuiJsNoMunge() {
return yuiJsNoMunge;
}
/**
* Sets the yui js no munge.
*
* @param yuiJsNoMunge
* the new yui js no munge
*/
public void setYuiJsNoMunge(Boolean yuiJsNoMunge) {
this.yuiJsNoMunge = yuiJsNoMunge;
}
/**
* Gets the yui js preserve all semi colons.
*
* @return the yui js preserve all semi colons
*/
public Boolean getYuiJsPreserveAllSemiColons() {
return yuiJsPreserveAllSemiColons;
}
/**
* Sets the yui js preserve all semi colons.
*
* @param yuiJsPreserveAllSemiColons
* the new yui js preserve all semi colons
*/
public void setYuiJsPreserveAllSemiColons(Boolean yuiJsPreserveAllSemiColons) {
this.yuiJsPreserveAllSemiColons = yuiJsPreserveAllSemiColons;
}
/**
* Gets the yui js line break.
*
* @return the yui js line break
*/
public Integer getYuiJsLineBreak() {
return yuiJsLineBreak;
}
/**
* Sets the yui js line break.
*
* @param yuiJsLineBreak
* the new yui js line break
*/
public void setYuiJsLineBreak(Integer yuiJsLineBreak) {
this.yuiJsLineBreak = yuiJsLineBreak;
}
/**
* Gets the closure opt level.
*
* @return the closure opt level
*/
public String getClosureOptLevel() {
return closureOptLevel;
}
/**
* Sets the closure opt level.
*
* @param closureOptLevel
* the new closure opt level
*/
public void setClosureOptLevel(String closureOptLevel) {
this.closureOptLevel = closureOptLevel;
}
/**
* Gets the yui js disable optimizations.
*
* @return the yui js disable optimizations
*/
public Boolean getYuiJsDisableOptimizations() {
return yuiJsDisableOptimizations;
}
/**
* Sets the yui js disable optimizations.
*
* @param yuiJsDisableOptimizations
* the new yui js disable optimizations
*/
public void setYuiJsDisableOptimizations(Boolean yuiJsDisableOptimizations) {
this.yuiJsDisableOptimizations = yuiJsDisableOptimizations;
}
/**
* Gets the predefined preserve patterns.