commit cb72cd197413fb633ed18c1ffccf996d0f769810 Author: wangbing Date: Mon Dec 14 21:50:37 2020 +0800 备份 diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9709af9 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +```java + + xyz.wbsite + optimizer-maven-plugin + 1.0-SNAPSHOT + + + + run + + compile + + + + + + COMPRESS_CSS + src/main/resources/static/css/ + target/classes/static/css/ + **/*.css + **/*.min.css + + + + +``` \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..cb206fb --- /dev/null +++ b/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + xyz.wbsite + optimizer-maven-plugin + 1.0-SNAPSHOT + maven-plugin + optimizer + + + UTF-8 + UTF-8 + 1.8 + true + + + + + + central + Central Repository + default + https://maven.aliyun.com/repository/public + + + + + + + central + Central Repository + https://maven.aliyun.com/repository/public + default + + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + + org.apache.ant + ant + 1.9.7 + + + + + com.yahoo.platform.yui + yuicompressor + 2.4.8 + + + + + com.googlecode.htmlcompressor + htmlcompressor + 1.5.2 + + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.2 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/src/main/java/xyz/wbsite/optimizer/Compressor.java b/src/main/java/xyz/wbsite/optimizer/Compressor.java new file mode 100644 index 0000000..d2bcac2 --- /dev/null +++ b/src/main/java/xyz/wbsite/optimizer/Compressor.java @@ -0,0 +1,10 @@ +package xyz.wbsite.optimizer; + +/** + * Created by LiuFa on 2017/10/14. + * xyz.wbsite.optimizer + * greatapp + */ +public interface Compressor { + void compress(String fileName, T config); +} diff --git a/src/main/java/xyz/wbsite/optimizer/Optimizer.java b/src/main/java/xyz/wbsite/optimizer/Optimizer.java new file mode 100644 index 0000000..0a6e603 --- /dev/null +++ b/src/main/java/xyz/wbsite/optimizer/Optimizer.java @@ -0,0 +1,174 @@ +package xyz.wbsite.optimizer; + +import com.googlecode.htmlcompressor.compressor.HtmlCompressor; +import com.googlecode.htmlcompressor.compressor.XmlCompressor; +import com.googlecode.htmlcompressor.compressor.YuiCssCompressor; +import com.googlecode.htmlcompressor.compressor.YuiJavaScriptCompressor; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.codehaus.plexus.util.FileUtils; +import xyz.wbsite.optimizer.compressor.SimpleJavaScriptCompressor; +import xyz.wbsite.optimizer.task.Task; +import xyz.wbsite.optimizer.util.FileUtil; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +/** + * @goal run + * @phase compile + * @execute phase="compile" + */ +public class Optimizer extends AbstractMojo { + + /** + * @parameter + */ + private Task[] tasks; + + public void execute() throws MojoExecutionException { + getLog().info("------------------------------------------------------------------------"); + for (Task task : tasks) { + try { + File directory = task.getDirectory(); + File targetPath = task.getTargetPath(); + String include = task.getInclude(); + String exclude = task.getExclude(); + + List fileList = FileUtils.getFiles(directory, include, exclude); + for (Object o : fileList) { + if (o instanceof File) { + File sourceFile = (File) o; + File targetFile = new File(targetPath, sourceFile.getAbsolutePath().substring(directory.getAbsolutePath().length())); + switch (task.getTaskType()) { + case COMPRESS_PLAIN: + compressPLAIN(sourceFile, targetFile); + break; + case COMPRESS_CSS: + compressCSS(sourceFile, targetFile); + break; + case COMPRESS_JS: + compressJS(sourceFile, targetFile); + break; + case COMPRESS_HTML: + compressHTML(sourceFile, targetFile); + break; + case COMPRESS_XML: + compressXML(sourceFile, targetFile); + break; + } + } + } + } catch (IOException e) { +// e.printStackTrace(); + } + } + getLog().info("------------------------------------------------------------------------"); + getLog().info("The optimization task has been completed."); + } + + public void compressPLAIN(File sourceFile, File targetFile) { + try { + // 源文件大小 + long sourceLength = sourceFile.length(); + // 从源文件向目标复制文件 + FileUtils.copyFile(sourceFile, targetFile); + // 对目标文件进行压缩 + String string = FileUtil.readFileToString(sourceFile); + String targetString = FileUtil.trim(string); + FileUtil.writeStringToFile(targetString, targetFile, false, false); + // 目标文件压缩后的大小 + long targetLength = targetFile.length(); + // 打印压缩信息 + getLog().info(targetFile.getName() + FileUtil.compressorInfo(sourceLength, targetLength)); + } catch (Exception e) { + e.printStackTrace(); + getLog().info(sourceFile.getAbsolutePath() + " compress failed"); + } + } + + public void compressCSS(File sourceFile, File targetFile) { + try { + // 源文件大小 + long sourceLength = sourceFile.length(); + // 从源文件向目标复制文件 + FileUtils.copyFile(sourceFile, targetFile); + // 对目标文件进行压缩 + YuiCssCompressor compressor = new YuiCssCompressor(); + String compress = compressor.compress(FileUtil.readFileToString(sourceFile)); + FileUtil.writeStringToFile(compress, targetFile, false, false); + // 目标文件压缩后的大小 + long targetLength = targetFile.length(); + // 打印压缩信息 + getLog().info(targetFile.getName() + FileUtil.compressorInfo(sourceLength, targetLength)); + } catch (Exception e) { + e.printStackTrace(); + getLog().info(sourceFile.getAbsolutePath() + " compress failed"); + } + } + + public void compressJS(File sourceFile, File targetFile) { + try { + // 源文件大小 + long sourceLength = sourceFile.length(); + // 从源文件向目标复制文件 + FileUtils.copyFile(sourceFile, targetFile); + // 对目标文件进行压缩 + YuiJavaScriptCompressor compressor = new YuiJavaScriptCompressor(); + String compress = compressor.compress(FileUtil.readFileToString(sourceFile)); + FileUtil.writeStringToFile(compress, targetFile, false, false); + // 目标文件压缩后的大小 + long targetLength = targetFile.length(); + // 打印压缩信息 + getLog().info(targetFile.getName() + FileUtil.compressorInfo(sourceLength, targetLength)); + } catch (Exception e) { + e.printStackTrace(); + getLog().info(sourceFile.getAbsolutePath() + " compress failed"); + } + } + + public void compressHTML(File sourceFile, File targetFile) { + try { + // 源文件大小 + long sourceLength = sourceFile.length(); + // 从源文件向目标复制文件 + FileUtils.copyFile(sourceFile, targetFile); + // 对目标文件进行压缩 + HtmlCompressor compressor = new HtmlCompressor(); + compressor.setRemoveIntertagSpaces(true); + compressor.setCompressJavaScript(true); + compressor.setJavaScriptCompressor(new SimpleJavaScriptCompressor()); + compressor.setCompressCss(true); + String compress = compressor.compress(FileUtil.readFileToString(sourceFile)); + FileUtil.writeStringToFile(compress, targetFile, false, false); + // 目标文件压缩后的大小 + long targetLength = targetFile.length(); + // 打印压缩信息 + getLog().info(targetFile.getName() + FileUtil.compressorInfo(sourceLength, targetLength)); + } catch (Exception e) { + e.printStackTrace(); + getLog().info(sourceFile.getAbsolutePath() + " compress failed"); + } + } + + public void compressXML(File sourceFile, File targetFile) { + try { + // 源文件大小 + long sourceLength = sourceFile.length(); + // 从源文件向目标复制文件 + FileUtils.copyFile(sourceFile, targetFile); + // 对目标文件进行压缩 + XmlCompressor compressor = new XmlCompressor(); + String compress = compressor.compress(FileUtil.readFileToString(sourceFile)); + FileUtil.writeStringToFile(compress, targetFile, false, false); + // 目标文件压缩后的大小 + long targetLength = targetFile.length(); + // 打印压缩信息 + getLog().info(targetFile.getName() + FileUtil.compressorInfo(sourceLength, targetLength)); + } catch (Exception e) { + e.printStackTrace(); + getLog().info(sourceFile.getAbsolutePath() + " compress failed"); + } + } +} diff --git a/src/main/java/xyz/wbsite/optimizer/TaskType.java b/src/main/java/xyz/wbsite/optimizer/TaskType.java new file mode 100644 index 0000000..7b3da4a --- /dev/null +++ b/src/main/java/xyz/wbsite/optimizer/TaskType.java @@ -0,0 +1,10 @@ +package xyz.wbsite.optimizer; + + +public enum TaskType { + COMPRESS_PLAIN,//一般压缩(去除换行多余空格) + COMPRESS_CSS, + COMPRESS_JS, + COMPRESS_HTML, + COMPRESS_XML +} diff --git a/src/main/java/xyz/wbsite/optimizer/compressor/SimpleJavaScriptCompressor.java b/src/main/java/xyz/wbsite/optimizer/compressor/SimpleJavaScriptCompressor.java new file mode 100644 index 0000000..2085608 --- /dev/null +++ b/src/main/java/xyz/wbsite/optimizer/compressor/SimpleJavaScriptCompressor.java @@ -0,0 +1,20 @@ +package xyz.wbsite.optimizer.compressor; + + +import com.googlecode.htmlcompressor.compressor.Compressor; + +import java.util.regex.Pattern; + +public class SimpleJavaScriptCompressor implements Compressor { + @Override + public String compress(String source) { + if (source == null || "".equals(source)) { + return source; + } + String result = source; + // 将空格、制表符、回车、换行符替换为空字符 + result = Pattern.compile("//.*|\\s+|\t+|\r+|\n+").matcher(result).replaceAll(" "); + result = Pattern.compile("\\s?(=|:|;|,|:\\{|\\{|}|\\(|\\))\\s?").matcher(result).replaceAll("$1"); + return result; + } +} diff --git a/src/main/java/xyz/wbsite/optimizer/task/Task.java b/src/main/java/xyz/wbsite/optimizer/task/Task.java new file mode 100644 index 0000000..6c5f92c --- /dev/null +++ b/src/main/java/xyz/wbsite/optimizer/task/Task.java @@ -0,0 +1,117 @@ +package xyz.wbsite.optimizer.task; + +import xyz.wbsite.optimizer.TaskType; + +import java.io.File; + +public class Task { + /** + * @parameter + */ + private TaskType taskType; + /** + * @parameter + */ + private File directory; + /** + * @parameter defaultValue="${project.basedir}/target" + */ + private File targetPath; + /** + * @parameter + */ + private String include; + /** + * @parameter + */ + private String exclude; + + /** + * @parameter :是否只压缩, 不对局部变量进行混淆 + */ + private boolean JsConfigMunge = false; + /** + * @parameter :是否显示info和warn级别的信息 + */ + private boolean JsConfigVerbose = false; + /** + * @parameter :是否保留所有的分号 + */ + private boolean JsConfigPreserveAllSemiColons = false; + /** + * @parameter :是否禁用自带的所有优化措施 + */ + private boolean JsConfigDisableOptimizations = false; + + public TaskType getTaskType() { + return taskType; + } + + public void setTaskType(TaskType taskType) { + this.taskType = taskType; + } + + public File getDirectory() { + return directory; + } + + public void setDirectory(File directory) { + this.directory = directory; + } + + public File getTargetPath() { + return targetPath; + } + + public void setTargetPath(File targetPath) { + this.targetPath = targetPath; + } + + public String getInclude() { + return include; + } + + public void setInclude(String include) { + this.include = include; + } + + public String getExclude() { + return exclude; + } + + public void setExclude(String exclude) { + this.exclude = exclude; + } + + public boolean isJsConfigMunge() { + return JsConfigMunge; + } + + public void setJsConfigMunge(boolean jsConfigMunge) { + JsConfigMunge = jsConfigMunge; + } + + public boolean isJsConfigVerbose() { + return JsConfigVerbose; + } + + public void setJsConfigVerbose(boolean jsConfigVerbose) { + JsConfigVerbose = jsConfigVerbose; + } + + public boolean isJsConfigPreserveAllSemiColons() { + return JsConfigPreserveAllSemiColons; + } + + public void setJsConfigPreserveAllSemiColons(boolean jsConfigPreserveAllSemiColons) { + JsConfigPreserveAllSemiColons = jsConfigPreserveAllSemiColons; + } + + public boolean isJsConfigDisableOptimizations() { + return JsConfigDisableOptimizations; + } + + public void setJsConfigDisableOptimizations(boolean jsConfigDisableOptimizations) { + JsConfigDisableOptimizations = jsConfigDisableOptimizations; + } +} diff --git a/src/main/java/xyz/wbsite/optimizer/util/FileInfo.java b/src/main/java/xyz/wbsite/optimizer/util/FileInfo.java new file mode 100644 index 0000000..9756cdb --- /dev/null +++ b/src/main/java/xyz/wbsite/optimizer/util/FileInfo.java @@ -0,0 +1,36 @@ +package xyz.wbsite.optimizer.util; + +/** + * Created by LiuFa on 2017/10/14. + * xyz.wbsite.optimizer.config + * greatapp + */ +public class FileInfo { + private String fileName; + private long fileLength; + private String fileSize; + + public String getFileName() { + return fileName; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public long getFileLength() { + return fileLength; + } + + public void setFileLength(long fileLength) { + this.fileLength = fileLength; + } + + public String getFileSize() { + return fileSize; + } + + public void setFileSize(String fileSize) { + this.fileSize = fileSize; + } +} diff --git a/src/main/java/xyz/wbsite/optimizer/util/FileUtil.java b/src/main/java/xyz/wbsite/optimizer/util/FileUtil.java new file mode 100644 index 0000000..d4f47c1 --- /dev/null +++ b/src/main/java/xyz/wbsite/optimizer/util/FileUtil.java @@ -0,0 +1,386 @@ +package xyz.wbsite.optimizer.util; + +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.net.MalformedURLException; +import java.net.URL; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.regex.Pattern; + +public class FileUtil { + private static DecimalFormat df = new DecimalFormat("#.00"); + + /** + * 获取文件大小信息 + * + * @param sourceLength 文件长度 + * @return FileInfo + */ + private static String getFileSize(long sourceLength) { + if (sourceLength < 1024) { + return df.format((double) sourceLength) + "BT"; + } else if (sourceLength < 1048576) { + return df.format((double) sourceLength / 1024) + "KB"; + } else if (sourceLength < 1073741824) { + return df.format((double) sourceLength / 1048576) + "MB"; + } else { + return df.format((double) sourceLength / 1073741824) + "GB"; + } + } + + /** + * 压缩信息 + * + * @param sourceLength 源文件 + * @param targetLength 压缩文件 + * @return 压缩信息 + */ + public static String compressorInfo(long sourceLength, long targetLength) { + long compressorLength = sourceLength - targetLength; + String rate = df.format((float) compressorLength / sourceLength * 100); + return String.format(Locale.getDefault(), " %s==>%s,%s%%", getFileSize(sourceLength), getFileSize(targetLength), rate); + } + + + public static String trim(String source) { + if (source == null || "".equals(source)) { + return source; + } + String result; + Pattern s = Pattern.compile("\\s{2,}"); + result = s.matcher(source).replaceAll("\\s"); + Pattern p = Pattern.compile("\t*|\r*|\n*"); + result = p.matcher(result).replaceAll(""); + return result; + } + + public static List readFileToLines(File filePath) { + return readFileToLines(filePath.getAbsolutePath()); + } + + public static List readFileToLines(String fileName) { + List returnString = new ArrayList(); + File file = new File(fileName); + BufferedReader reader = null; + try { + reader = new BufferedReader(new FileReader(file)); + String tempString = null; + int line = 1; + // 一次读入一行,直到读入null为文件结束 + while ((tempString = reader.readLine()) != null) { + // 显示行号 + returnString.add(tempString); + line++; + } + reader.close(); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (reader != null) { + try { + reader.close(); + } catch (IOException e1) { + } + } + } + return returnString; + } + + public static String readFileToString(File file) throws IOException { + byte[] bytes = readFileToByteArray(file); + return new String(bytes, "UTF-8"); + } + + public static byte[] readFileToByteArray(File file) throws IOException { + InputStream in = openInputStream(file); + Throwable var2 = null; + + byte[] var5; + try { + long fileLength = file.length(); + var5 = fileLength > 0L ? toByteArray(in, fileLength) : toByteArray(in); + } catch (Throwable var14) { + var2 = var14; + throw var14; + } finally { + if (in != null) { + if (var2 != null) { + try { + in.close(); + } catch (Throwable var13) { + var2.addSuppressed(var13); + } + } else { + in.close(); + } + } + + } + + return var5; + } + + public static void writeBytesToFile(byte[] buffer, final File file) { + OutputStream output = null; + BufferedOutputStream bufferedOutput = null; + try { + output = new FileOutputStream(file); + bufferedOutput = new BufferedOutputStream(output); + bufferedOutput.write(buffer); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (null != bufferedOutput) { + try { + bufferedOutput.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (null != output) { + try { + output.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + public static boolean writeStringToFile(String data, File file, boolean isNewLine, boolean isAppend) { + PrintWriter printWriter = null; + try { + printWriter = openPrintWriter(file); + if (isNewLine && isAppend) {// 换行追加 + printWriter.println(); + printWriter.append(data); + } else if (!isNewLine && isAppend) {// 不换行追加 + printWriter.append(data); + } else {// 直接写入 + printWriter.print(data); + } + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } finally { + if (printWriter != null) printWriter.close(); + } + } + + public static PrintWriter openPrintWriter(File file) { + try { + return new PrintWriter(new FileOutputStream(file)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + return null; + } + } + + public static FileInputStream openInputStream(File file) throws IOException { + if (file.exists()) { + if (file.isDirectory()) { + throw new IOException("File '" + file + "' exists but is a directory"); + } else if (!file.canRead()) { + throw new IOException("File '" + file + "' cannot be read"); + } else { + return new FileInputStream(file); + } + } else { + throw new FileNotFoundException("File '" + file + "' does not exist"); + } + } + + public static FileOutputStream openOutputStream(File file) throws IOException { + if (file.exists()) { + if (file.isDirectory()) { + throw new IOException("File '" + file + "' exists but is a directory"); + } else if (!file.canRead()) { + throw new IOException("File '" + file + "' cannot be read"); + } else { + return new FileOutputStream(file); + } + } else { + throw new FileNotFoundException("File '" + file + "' does not exist"); + } + } + + /** + * @param fileLocation 文件路径 + * @return URL + */ + public static URL getURL(String fileLocation) { + try { + return new URL(fileLocation); + } catch (MalformedURLException var6) { + try { + return (new File(fileLocation)).toURI().toURL(); + } catch (MalformedURLException var5) { + var5.printStackTrace(); + } + } + return null; + } + + public static byte[] toByteArray(InputStream input, long size) throws IOException { + if (size > 2147483647L) { + throw new IllegalArgumentException("Size cannot be greater than Integer max value: " + size); + } else { + return toByteArray(input, (int) size); + } + } + + public static byte[] toByteArray(InputStream input, int size) throws IOException { + if (size < 0) { + throw new IllegalArgumentException("Size must be equal or greater than zero: " + size); + } else if (size == 0) { + return new byte[0]; + } else { + byte[] data = new byte[size]; + + int offset; + int read; + for (offset = 0; offset < size && (read = input.read(data, offset, size - offset)) != -1; offset += read) { + ; + } + + if (offset != size) { + throw new IOException("Unexpected read size. current: " + offset + ", expected: " + size); + } else { + return data; + } + } + } + + public static byte[] toByteArray(InputStream input) throws IOException { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + Throwable var2 = null; + + byte[] var3; + try { + copy((InputStream) input, (OutputStream) output); + var3 = output.toByteArray(); + } catch (Throwable var12) { + var2 = var12; + throw var12; + } finally { + if (output != null) { + if (var2 != null) { + try { + output.close(); + } catch (Throwable var11) { + var2.addSuppressed(var11); + } + } else { + output.close(); + } + } + + } + + return var3; + } + + public static int copy(InputStream input, OutputStream output) throws IOException { + long count = copyLarge(input, output); + return count > 2147483647L ? -1 : (int) count; + } + + public static boolean copy(File in, File out) throws Exception { + try { + FileInputStream input = new FileInputStream(in); + FileOutputStream output = new FileOutputStream(out); + copy(input, output); + input.close(); + output.close(); + return true; + } catch (IOException ie) { + return false; + } + } + + public static long copyLarge(InputStream input, OutputStream output) throws IOException { + return copy(input, output, 4096); + } + + public static long copy(InputStream input, OutputStream output, int bufferSize) throws IOException { + return copyLarge(input, output, new byte[bufferSize]); + } + + public static long copyLarge(InputStream input, OutputStream output, byte[] buffer) throws IOException { + long count; + int n; + for (count = 0L; -1 != (n = input.read(buffer)); count += (long) n) { + output.write(buffer, 0, n); + } + + return count; + } + + public static boolean clearDirectory(File dir) { + if ((dir == null) || !dir.isDirectory()) { + throw new IllegalArgumentException("Argument " + dir + + " is not a directory. "); + } + + File[] entries = dir.listFiles(); + int sz = entries.length; + + for (int i = 0; i < sz; i++) { + if (entries[i].isDirectory()) { + if (!clearDirectory(entries[i])) { + return false; + } + } else { + if (!entries[i].delete()) { + return false; + } + } + } + + if (!dir.delete()) { + return false; + } + return true; + } + + /** + * 将DOS/Windows格式的路径转换为UNIX/Linux格式的路径。 + * 其实就是将路径中的"\"全部换为"/",因为在某些情况下我们转换为这种方式比较方便, + * 某中程度上说"/"比"\"更适合作为路径分隔符,而且DOS/Windows也将它当作路径分隔符。 + */ + public static String toUNIXpath(String filePath) { + return filePath.replace('\\', '/'); + } + + public static void inputStream2File(InputStream is, File target) { + try { + if (!target.exists() && !target.createNewFile()) { + throw new RuntimeException(target.getName() + "not exists"); + } + OutputStream outStream = new FileOutputStream(target); + byte[] buffer = new byte[8 * 1024]; + int bytesRead; + while ((bytesRead = is.read(buffer)) != -1) { + outStream.write(buffer, 0, bytesRead); + } + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/src/test/java/xyz/wbsite/TaskTest.java b/src/test/java/xyz/wbsite/TaskTest.java new file mode 100644 index 0000000..08cacef --- /dev/null +++ b/src/test/java/xyz/wbsite/TaskTest.java @@ -0,0 +1,67 @@ +package xyz.wbsite; + +import org.codehaus.plexus.util.FileUtils; +import xyz.wbsite.optimizer.Optimizer; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +public class TaskTest { + + public static void main(String[] args) throws IOException { + { + System.out.println("=================================================CSS"); + File directory = new File("E:\\workspace\\dbtool\\target\\project\\wadmin\\src\\main\\resources\\static"); + File targetPath = new File("E:\\workspace\\dbtool\\target\\project\\wadmin\\target\\classes\\static"); + String include = "**/*.css"; + String exclude = ""; + Optimizer optimizer = new Optimizer(); + + List fileList = FileUtils.getFiles(directory, include, exclude); + for (Object o : fileList) { + if (o instanceof File) { + File sourceFile = (File) o; + File targetFile = new File(targetPath, sourceFile.getAbsolutePath().substring(directory.getAbsolutePath().length())); + optimizer.compressCSS(sourceFile, targetFile); + } + } + } + + { + System.out.println("=================================================JS"); + File directory = new File("E:\\workspace\\dbtool\\target\\project\\wadmin\\src\\main\\resources\\static"); + File targetPath = new File("E:\\workspace\\dbtool\\target\\project\\wadmin\\target\\classes\\static"); + String include = "**/*.js"; + String exclude = "**/*.min.js"; + Optimizer optimizer = new Optimizer(); + + List fileList = FileUtils.getFiles(directory, include, exclude); + for (Object o : fileList) { + if (o instanceof File) { + File sourceFile = (File) o; + File targetFile = new File(targetPath, sourceFile.getAbsolutePath().substring(directory.getAbsolutePath().length())); + optimizer.compressJS(sourceFile, targetFile); + } + } + } + + { + System.out.println("=================================================COMPRESS_HTML"); + File directory = new File("E:\\workspace\\dbtool\\target\\project\\wadmin\\src\\main\\resources\\static"); + File targetPath = new File("E:\\workspace\\dbtool\\target\\project\\wadmin\\target\\classes\\static"); + String include = "**/*.ftl"; + String exclude = ""; + Optimizer optimizer = new Optimizer(); + + List fileList = FileUtils.getFiles(directory, include, exclude); + for (Object o : fileList) { + if (o instanceof File) { + File sourceFile = (File) o; + File targetFile = new File(targetPath, sourceFile.getAbsolutePath().substring(directory.getAbsolutePath().length())); + optimizer.compressHTML(sourceFile, targetFile); + } + } + } + } +}