From 2af4531f5ac99925dad3d1ee2dd61a0bb1a1bda0 Mon Sep 17 00:00:00 2001 From: Samuel Santos Date: Fri, 23 Aug 2013 01:29:21 +0100 Subject: [PATCH] Preserve sub-directory structure when only minifying Merge changes in ProcessFilesTask.java from commit 924a23a373e6b9aa841af6b9e4300c670eb602aa. Fix formatting in CHANGELOG.md. Update version in docs. Add license to README.md. --- CHANGELOG.md | 55 +++++++++++-------- README.md | 8 ++- demo/pom.xml | 6 +- .../main/webapp/js/{ => ext}/samaxesjs.toc.js | 0 pom.xml | 2 +- .../maven/minify/plugin/ProcessFilesTask.java | 37 ++++++++----- src/site/apt/examples/basic.apt | 2 +- src/site/apt/examples/exclude.apt | 2 +- src/site/apt/examples/patterns.apt | 2 +- src/site/apt/usage.apt | 2 +- 10 files changed, 69 insertions(+), 47 deletions(-) rename demo/src/main/webapp/js/{ => ext}/samaxesjs.toc.js (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7bc2c3fa..cd7c75be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,26 +1,30 @@ # Minify Maven Plugin +## 1.6.1 + +* Preserve sub-directory structure when only minifying (#29). + ## 1.6 -* [MINIFY-14] Added support for Google Closure Compiler for JavaScript compression. +* Add support for [Google Closure Compiler](https://developers.google.com/closure/compiler/) for JavaScript compression (#14). ## 1.5.2 -* [MINIFY-5] New goal parameter to log full source file paths and new FAQ entry pointing to the plugin goal parameters. -* [MINIFY-11] Option to skip the minify step. -* [MINIFY-13] Option to skip the merge step. +* New goal parameter to log full source file paths and new FAQ entry pointing to the plugin goal parameters (#5). +* Option to skip the minify step (#11). +* Option to skip the merge step (#13). ## 1.5.1 -* [MINIFY-2] Cannot process the same filename of files in different directories. -* [MINIFY-3] CSS minification fails for base64 encoded background images. +* Cannot process the same filename of files in different directories (#2). +* CSS minification fails for base64 encoded background images (#3). ## 1.5 -* [MINIFY-1] Fixed charset issue. -* Updated Maven site skin. +* Fix charset issue (#1). +* Update Maven site skin. * Use `ExecutorService` to wait for all tasks to finish. -* Added support for CLI-based configuration and Maven 2.2.1. From [Configuring Plugin Goals in Maven 3](http://www.sonatype.com/people/2011/03/configuring-plugin-goals-in-maven-3/): +* Add support for CLI-based configuration and Maven 2.2.1. From [Configuring Plugin Goals in Maven 3](http://www.sonatype.com/people/2011/03/configuring-plugin-goals-in-maven-3/): > For many plugin parameters it is occasionally convenient to specify their values from the command line via system properties. In the past, this was limited to parameters of simple types like `String` or `Boolean`. The latest Maven release finally allows plugin users to configure collections or arrays from the command line via comma-separated strings. Take for example a plugin parameter like this: > @@ -35,45 +39,50 @@ ## 1.4 -* Moved from http://code.google.com/p/maven-samaxes-plugin/ to https://github.com/samaxes/minify-maven-plugin. -* Renamed project from Maven Minify Plugin to Minify Maven Plugin. -* Added Maven Integration for Eclipse (M2E) lifecycle mapping metadata. +* Move from http://code.google.com/p/maven-samaxes-plugin/ to https://github.com/samaxes/minify-maven-plugin. +* Add Maven Integration for Eclipse (M2E) lifecycle mapping metadata. +* Rename project from Maven Minify Plugin to Minify Maven Plugin: + + > Artifact Ids of the format maven-___-plugin are reserved for + > plugins in the Group Id org.apache.maven.plugins + > Please change your artifactId to the format ___-maven-plugin + > In the future this error will break the build. ## 1.3.5 -* Lifted restriction that prevented the final filename to be the same as an existing source filename. +* Lift restriction that prevented the final filename to be the same as an existing source filename. ## 1.3.4 -* Updated YUI Compressor to version 2.4.6. +* Update YUI Compressor to version 2.4.6. ## 1.3.3 -* Added debug messages for wrong source file names and source directory paths. +* Add debug messages for wrong source file names and source directory paths. ## 1.3.2 -* Added cssTargetDir, jsTargetDir, suffix, and charset parameters. +* Add `cssTargetDir`, `jsTargetDir`, `suffix`, and `charset` parameters. ## 1.3.1 -* Class 'java.util.List' cannot be instantiated while running minify goal with Maven versions before 3. +* Class `java.util.List` cannot be instantiated while running Maven minify goal with versions previous to 3.0. ## 1.3 -* Exclude/include patterns changed from a comma separated String to List. Also included a custom file comparator that only compares the file name instead of the full file path. -* Updated YUI Compressor dependency to version 2.4.2. +* Change exclude/include patterns from a comma separated `String` to `List`. Also included a custom file comparator that only compares the file name instead of the full file path. +* Update [YUI Compressor](http://developer.yahoo.com/yui/compressor/) dependency to version 2.4.2. ## 1.2.1 -* Doesn't crash anymore with an IndexOutOfBoundsException when a source file does not exist. +* Don't crash with an `IndexOutOfBoundsException` when a source file does not exist. * More accurate logging. * Configure POM to inherit from Sonatype OSS Parent POM. ## 1.2 -* Exclude/include patterns added, with the caveat that the developer must name their source files so their lexicographical order is correct for minifying. +* Add exclude/include patterns, with the caveat that the developer must name their source files so their lexicographical order is correct for minifying. * Don't minify a file type if the list of files to process is empty. * Make JavaScript minify error messages clearer. -* Make file extensions configurable (e.g. it's now possible to save a JavaScript file as *.jsp or *.php). -* Compiled against JDK 1.5 instead of JDK 1.6. +* Make file extensions configurable (e.g. it's now possible to save a JavaScript file as `*.jsp` or `*.php`). +* Compile against JDK 1.5 instead of JDK 1.6. diff --git a/README.md b/README.md index de68a310..b4b4f565 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ Configure your project's `pom.xml` to run the plugin during the project's build com.samaxes.maven minify-maven-plugin - 1.6 + 1.6.1 default-minify @@ -60,4 +60,8 @@ Configure your project's `pom.xml` to run the plugin during the project's build ``` -For more information, check the plugin [documentation](http://samaxes.github.com/minify-maven-plugin/) and the [demo application](https://github.com/downloads/samaxes/minify-maven-plugin/minify-maven-plugin-demo-1.6-src.zip). +For more information, check the plugin [documentation](http://samaxes.github.com/minify-maven-plugin/) and the [demo application](https://github.com/downloads/samaxes/minify-maven-plugin/minify-maven-plugin-demo-1.6.1-src.zip). + +## License + +This distribution is licensed under the terms of the Apache License, Version 2.0 (see LICENSE.txt). diff --git a/demo/pom.xml b/demo/pom.xml index 9792ebfd..92edd9bd 100644 --- a/demo/pom.xml +++ b/demo/pom.xml @@ -7,7 +7,7 @@ com.samaxes.maven minify-maven-plugin-demo - 1.6 + 1.6.1 war Minify Maven Plugin Demo @@ -74,7 +74,7 @@ com.samaxes.maven minify-maven-plugin - 1.6 + 1.6.1 default-minify @@ -90,7 +90,7 @@ samaxesjs.core.js - samaxesjs.toc.js + ext/samaxesjs.toc.js diff --git a/demo/src/main/webapp/js/samaxesjs.toc.js b/demo/src/main/webapp/js/ext/samaxesjs.toc.js similarity index 100% rename from demo/src/main/webapp/js/samaxesjs.toc.js rename to demo/src/main/webapp/js/ext/samaxesjs.toc.js diff --git a/pom.xml b/pom.xml index f4870a5e..7af33aad 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ com.samaxes.maven minify-maven-plugin - 1.6 + 1.6.1-SNAPSHOT maven-plugin Minify Maven Plugin diff --git a/src/main/java/com/samaxes/maven/minify/plugin/ProcessFilesTask.java b/src/main/java/com/samaxes/maven/minify/plugin/ProcessFilesTask.java index 3159b68f..c72bc869 100644 --- a/src/main/java/com/samaxes/maven/minify/plugin/ProcessFilesTask.java +++ b/src/main/java/com/samaxes/maven/minify/plugin/ProcessFilesTask.java @@ -64,6 +64,8 @@ public abstract class ProcessFilesTask implements Callable { protected int linebreak; + private File sourceDir; + private File targetDir; private String extension; @@ -109,13 +111,13 @@ public ProcessFilesTask(Log log, Integer bufferSize, boolean debug, boolean skip this.charset = charset; this.linebreak = linebreak; - File sourceDir = new File(webappSourceDir + File.separator + inputDir); + this.sourceDir = new File(webappSourceDir + File.separator + inputDir); for (String sourceFilename : sourceFiles) { - addNewSourceFile(mergedFilename, sourceDir, sourceFilename); + addNewSourceFile(mergedFilename, sourceFilename); } - for (File sourceInclude : getFilesToInclude(sourceDir, sourceIncludes, sourceExcludes)) { + for (File sourceInclude : getFilesToInclude(sourceIncludes, sourceExcludes)) { if (!files.contains(sourceInclude)) { - addNewSourceFile(mergedFilename, sourceDir, sourceInclude); + addNewSourceFile(mergedFilename, sourceInclude); } } @@ -132,8 +134,18 @@ public Object call() { if (!files.isEmpty() && (targetDir.exists() || targetDir.mkdirs())) { if (skipMerge) { log.info("Skipping merge step."); + String sourceBasePath = sourceDir.getAbsolutePath(); + for (File mergedFile : files) { - File minifiedFile = new File(targetDir, mergedFile.getName().replace(extension, suffix + extension)); + // Create folders to preserve sub-directory structure when only minifying + String originalPath = mergedFile.getAbsolutePath(); + String subPath = originalPath.substring(sourceBasePath.length(), + originalPath.lastIndexOf(File.separator)); + File targetPath = new File(targetDir.getAbsolutePath() + subPath); + targetPath.mkdirs(); + + File minifiedFile = new File(targetPath, mergedFile.getName() + .replace(extension, suffix + extension)); minify(mergedFile, minifiedFile); } } else if (skipMinify) { @@ -200,23 +212,21 @@ private void merge(File mergedFile) { * Logs an addition of a new source file. * * @param finalFilename the final file name - * @param sourceDir the sources directory * @param sourceFilename the source file name */ - private void addNewSourceFile(String finalFilename, File sourceDir, String sourceFilename) { + private void addNewSourceFile(String finalFilename, String sourceFilename) { File sourceFile = new File(sourceDir, sourceFilename); - addNewSourceFile(finalFilename, sourceDir, sourceFile); + addNewSourceFile(finalFilename, sourceFile); } /** * Logs an addition of a new source file. * * @param finalFilename the final file name - * @param sourceDir the sources directory * @param sourceFile the source file */ - private void addNewSourceFile(String finalFilename, File sourceDir, File sourceFile) { + private void addNewSourceFile(String finalFilename, File sourceFile) { if (sourceFile.exists()) { if (finalFilename.equalsIgnoreCase(sourceFile.getName())) { log.warn("Source file [" + sourceFile.getName() + "] has the same name as the final file."); @@ -231,12 +241,11 @@ private void addNewSourceFile(String finalFilename, File sourceDir, File sourceF /** * Returns the files to copy. Default exclusions are used when the excludes list is empty. * - * @param baseDir the base directory to start from * @param includes list of source files to include * @param excludes list of source files to exclude * @return the files to copy */ - private List getFilesToInclude(File baseDir, List includes, List excludes) { + private List getFilesToInclude(List includes, List excludes) { List includedFiles = new ArrayList(); if (includes != null && !includes.isEmpty()) { @@ -245,11 +254,11 @@ private List getFilesToInclude(File baseDir, List includes, List com.samaxes.maven minify-maven-plugin - 1.6 + 1.6.1 file-1.css diff --git a/src/site/apt/examples/exclude.apt b/src/site/apt/examples/exclude.apt index cd6c4716..8df51d15 100644 --- a/src/site/apt/examples/exclude.apt +++ b/src/site/apt/examples/exclude.apt @@ -36,7 +36,7 @@ Exclude source files from WAR package com.samaxes.maven minify-maven-plugin - 1.6 + 1.6.1 default-minify diff --git a/src/site/apt/examples/patterns.apt b/src/site/apt/examples/patterns.apt index 5d7c8f51..1097f1a7 100644 --- a/src/site/apt/examples/patterns.apt +++ b/src/site/apt/examples/patterns.apt @@ -21,7 +21,7 @@ Lexicographical ordering (include/exclude patterns) com.samaxes.maven minify-maven-plugin - 1.6 + 1.6.1 default-minify diff --git a/src/site/apt/usage.apt b/src/site/apt/usage.apt index 28682db3..161ed0db 100644 --- a/src/site/apt/usage.apt +++ b/src/site/apt/usage.apt @@ -35,7 +35,7 @@ Usage com.samaxes.maven minify-maven-plugin - 1.6 + 1.6.1 default-minify