Skip to content

Commit

Permalink
Preserve sub-directory structure when only minifying
Browse files Browse the repository at this point in the history
Merge changes in ProcessFilesTask.java from commit 924a23a.
Fix formatting in CHANGELOG.md.
Update version in docs.
Add license to README.md.
  • Loading branch information
samaxes committed Aug 23, 2013
1 parent 9b2e886 commit 2af4531
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 47 deletions.
55 changes: 32 additions & 23 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
>
Expand All @@ -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<String>. 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<String>`. 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.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Configure your project's `pom.xml` to run the plugin during the project's build
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.6</version>
<version>1.6.1</version>
<executions>
<execution>
<id>default-minify</id>
Expand Down Expand Up @@ -60,4 +60,8 @@ Configure your project's `pom.xml` to run the plugin during the project's build
</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).
6 changes: 3 additions & 3 deletions demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin-demo</artifactId>
<version>1.6</version>
<version>1.6.1</version>
<packaging>war</packaging>

<name>Minify Maven Plugin Demo</name>
Expand Down Expand Up @@ -74,7 +74,7 @@
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.6</version>
<version>1.6.1</version>
<executions>
<execution>
<id>default-minify</id>
Expand All @@ -90,7 +90,7 @@
</cssSourceFiles>
<jsSourceFiles>
<jsSourceFile>samaxesjs.core.js</jsSourceFile>
<jsSourceFile>samaxesjs.toc.js</jsSourceFile>
<jsSourceFile>ext/samaxesjs.toc.js</jsSourceFile>
</jsSourceFiles>
</configuration>
<goals>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.6</version>
<version>1.6.1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>

<name>Minify Maven Plugin</name>
Expand Down
37 changes: 23 additions & 14 deletions src/main/java/com/samaxes/maven/minify/plugin/ProcessFilesTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public abstract class ProcessFilesTask implements Callable<Object> {

protected int linebreak;

private File sourceDir;

private File targetDir;

private String extension;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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.");
Expand All @@ -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<File> getFilesToInclude(File baseDir, List<String> includes, List<String> excludes) {
private List<File> getFilesToInclude(List<String> includes, List<String> excludes) {
List<File> includedFiles = new ArrayList<File>();

if (includes != null && !includes.isEmpty()) {
Expand All @@ -245,11 +254,11 @@ private List<File> getFilesToInclude(File baseDir, List<String> includes, List<S
scanner.setIncludes(includes.toArray(new String[0]));
scanner.setExcludes(excludes.toArray(new String[0]));
scanner.addDefaultExcludes();
scanner.setBasedir(baseDir);
scanner.setBasedir(sourceDir);
scanner.scan();

for (String includedFilename : scanner.getIncludedFiles()) {
includedFiles.add(new File(baseDir, includedFilename));
includedFiles.add(new File(sourceDir, includedFilename));
}

Collections.sort(includedFiles, new FilenameComparator());
Expand Down
2 changes: 1 addition & 1 deletion src/site/apt/examples/basic.apt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Basic Configuration
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.6</version>
<version>1.6.1</version>
<configuration>
<cssSourceFiles>
<cssSourceFile>file-1.css</cssSourceFile>
Expand Down
2 changes: 1 addition & 1 deletion src/site/apt/examples/exclude.apt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Exclude source files from WAR package
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.6</version>
<version>1.6.1</version>
<executions>
<execution>
<id>default-minify</id>
Expand Down
2 changes: 1 addition & 1 deletion src/site/apt/examples/patterns.apt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Lexicographical ordering (include/exclude patterns)
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.6</version>
<version>1.6.1</version>
<executions>
<execution>
<id>default-minify</id>
Expand Down
2 changes: 1 addition & 1 deletion src/site/apt/usage.apt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Usage
<plugin>
<groupId>com.samaxes.maven</groupId>
<artifactId>minify-maven-plugin</artifactId>
<version>1.6</version>
<version>1.6.1</version>
<executions>
<execution>
<id>default-minify</id>
Expand Down

0 comments on commit 2af4531

Please sign in to comment.