}
}
public void minify() {
MinifyProperty minifyProperty = MinifyProperty.getInstance();
InputOutput io = IOProvider.getDefault().getIO(Bundle.CTL_Minify(), false);
MinifyUtil util = new MinifyUtil();
try {
long startTime = new Date().getTime();
FileObject source = context.getPrimaryFile();
FileObject target = null;
if (minifyProperty.isSeparatBuild()) {
File sourceFile = FileUtil.toFile(source);
File targetFile = getTargetFolder(new File(sourceFile.getParentFile().getPath() + File.separator + sourceFile.getName() + "_BUILD"));
FileUtils.copyDirectory(sourceFile, targetFile);
target = FileUtil.toFileObject(targetFile);
} else {
target = source;
}
MinifyResult minifyResult = util.minify(target, minifyProperty);
long endTime = new Date().getTime();
long totalTime = endTime - startTime;
minifyResult.setDirectories(minifyResult.getDirectories() + 1);
float jsSpaceSaved = (1 - ((float) minifyResult.getOutputJsFilesSize() / (float) minifyResult.getInputJsFilesSize())) * 100;
float cssSpaceSaved = (1 - ((float) minifyResult.getOutputCssFilesSize() / (float) minifyResult.getInputCssFilesSize())) * 100;
float htmlSpaceSaved = (1 - ((float) minifyResult.getOutputHtmlFilesSize() / (float) minifyResult.getInputHtmlFilesSize())) * 100;
float xmlSpaceSaved = (1 - ((float) minifyResult.getOutputXmlFilesSize() / (float) minifyResult.getInputXmlFilesSize())) * 100;
float jsonSpaceSaved = (1 - ((float) minifyResult.getOutputJsonFilesSize() / (float) minifyResult.getInputJsonFilesSize())) * 100;
String cssEval = "", jsEval = "", htmlEval = "", xmlEval = "", jsonEval = "";
if (!Float.isNaN(jsSpaceSaved)) {
jsEval = "Input JS Files Size : " + minifyResult.getInputJsFilesSize() + " Bytes \n"
+ "After Minifying JS Files Size : " + minifyResult.getOutputJsFilesSize() + " Bytes \n"
+ "JS Space Saved " + jsSpaceSaved + "% \n";
}
if (!Float.isNaN(cssSpaceSaved)) {
cssEval = "Input CSS Files Size : " + minifyResult.getInputCssFilesSize() + " Bytes \n"
+ "After Minifying CSS Files Size : " + minifyResult.getOutputCssFilesSize() + " Bytes \n"
+ "CSS Space Saved " + cssSpaceSaved + "% \n";
}
if (!Float.isNaN(htmlSpaceSaved)) {
htmlEval = "Input HTML Files Size : " + minifyResult.getInputHtmlFilesSize() + " Bytes \n"
+ "After Minifying HTML Files Size : " + minifyResult.getOutputHtmlFilesSize() + " Bytes \n"
+ "HTML Space Saved " + htmlSpaceSaved + "% \n";
}
if (!Float.isNaN(xmlSpaceSaved)) {
xmlEval = "Input XML Files Size : " + minifyResult.getInputXmlFilesSize() + " Bytes \n"
+ "After Minifying XML Files Size : " + minifyResult.getOutputXmlFilesSize() + " Bytes \n"
+ "XML Space Saved " + xmlSpaceSaved + "% \n";
}
if (!Float.isNaN(jsonSpaceSaved)) {
jsonEval = "Input JSON Files Size : " + minifyResult.getInputJsonFilesSize() + " Bytes \n"
+ "After Minifying JSON Files Size : " + minifyResult.getOutputJsonFilesSize() + " Bytes \n"
+ "JSON Space Saved " + jsonSpaceSaved + "% \n";
}
if (minifyProperty.isEnableOutputLogAlert()) {
JOptionPane.showMessageDialog(null, "Js Css Minified Completed Successfully \n Logs - \n"
+ minifyResult.getDirectories() + " Directories Found \n"
+ minifyResult.getJsFiles() + " JS Files Minified \n"
+ minifyResult.getCssFiles() + " CSS Files Minified \n"
+ minifyResult.getHtmlFiles() + " HTML Files Minified \n"
+ minifyResult.getXmlFiles() + " XML Files Minified \n"
+ minifyResult.getJsonFiles() + " JSON Files Minified \n"
+ jsEval + cssEval + htmlEval + xmlEval + jsonEval
+ "Total Time - " + totalTime + "ms");
}
} catch (Exception ex) {
io.getOut().println("Exception: " + ex.toString());
}
}