Skip to content

Commit

Permalink
Fix nosuffix support
Browse files Browse the repository at this point in the history
  • Loading branch information
samaxes committed Feb 22, 2014
1 parent bb10d41 commit 581266c
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 76 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Minify Maven Plugin

## 1.6.2

* Cherry picked from commit 31fe5c91bf2d24c29251595206c3c4ebada1c712: [MINIFY-16] Added nosuffix option to avoid the suffix (.min) on the minified output filename.

## 1.6.1

* Preserve sub-directory structure when only minifying (#29).
* Cherry picked from commit 924a23a373e6b9aa841af6b9e4300c670eb602aa: Preserve sub-directory structure when only minifying (#29).

## 1.6

Expand Down
4 changes: 2 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.1</version>
<version>1.6.2</version>
<executions>
<execution>
<id>default-minify</id>
Expand Down Expand Up @@ -60,7 +60,7 @@ 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/samaxes/minify-maven-plugin/releases/download/minify-maven-plugin-1.6.1/minify-maven-plugin-demo-1.6.1-src.zip).
For more information, check the [plugin documentation](http://samaxes.github.com/minify-maven-plugin/) or the [demo application](https://github.com/samaxes/minify-maven-plugin/releases/download/minify-maven-plugin-1.6.2/minify-maven-plugin-demo-1.6.2-src.zip).

## License

Expand Down
4 changes: 2 additions & 2 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.1</version>
<version>1.6.2</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.1</version>
<version>1.6.2</version>
<executions>
<execution>
<id>default-minify</id>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/samaxes/maven/minify/plugin/MinifyMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ public class MinifyMojo extends AbstractMojo {
private String suffix;

/**
* Do not append a suffix to the minified output file name, independently of the value in the {@code suffix}
* Do not append a suffix to the minified output filename, independently of the value in the <code>suffix</code>
* parameter.
*
* @parameter expression="${nosuffix}" default-value="false"
* @since 1.6.2
*/
private boolean nosuffix;

/**
* <p>
* If a supported character set is specified, it will be used to read the input file. Otherwise, it will assume that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public class ProcessCSSFilesTask extends ProcessFilesTask {
* @param outputDir directory to write the final file
* @param outputFilename the output file name
* @param suffix final filename suffix
* @param nosuffix whether to use a suffix for the minified file name or not
* @param nosuffix whether to use a suffix for the minified filename or not
* @param charset if a character set is specified, a byte-to-char variant allows the encoding to be selected.
* Otherwise, only byte-to-byte operations are used
* Otherwise, only byte-to-byte operations are used
* @param linebreak split long lines after a specific column
*/
public ProcessCSSFilesTask(Log log, Integer bufferSize, boolean debug, boolean skipMerge, boolean skipMinify,
Expand All @@ -77,10 +77,12 @@ public ProcessCSSFilesTask(Log log, Integer bufferSize, boolean debug, boolean s
* @param minifiedFile output file resulting from the minify step
*/
@Override
protected void minify(File mergedFile, File minifiedFile) {
void minify(File mergedFile, File minifiedFile) {
if (minifiedFile != null) {
try {

log.info("Creating minified file [" + ((debug) ? minifiedFile.getPath() : minifiedFile.getName())
+ "].");

InputStream in = new FileInputStream(mergedFile);
OutputStream out = new FileOutputStream(minifiedFile);
InputStreamReader reader;
Expand All @@ -93,13 +95,6 @@ protected void minify(File mergedFile, File minifiedFile) {
writer = new OutputStreamWriter(out, charset);
}

if (debug) {
log.info("Creating minified file [" + minifiedFile.getPath() + "].");
} else {
File temp = (nosuffix) ? mergedFile : minifiedFile;
log.info("Creating minified file [" + temp.getName() + "].");
}

CssCompressor compressor = new CssCompressor(reader);
compressor.compress(writer, linebreak);

Expand All @@ -110,8 +105,6 @@ protected void minify(File mergedFile, File minifiedFile) {
} catch (IOException e) {
log.error(e.getMessage(), e);
}

cleanupFiles(mergedFile, minifiedFile);
}
}
}
50 changes: 13 additions & 37 deletions src/main/java/com/samaxes/maven/minify/plugin/ProcessFilesTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.SequenceInputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -51,23 +50,23 @@ public abstract class ProcessFilesTask implements Callable<Object> {

protected Log log;

protected Integer bufferSize;

protected boolean debug;

protected Integer bufferSize;

protected boolean skipMerge;

protected boolean skipMinify;

private String mergedFilename;
protected String charset;

private String suffix;
protected int linebreak;

protected boolean nosuffix;
private String suffix;

protected String charset;
private boolean nosuffix;

protected int linebreak;
private String mergedFilename;

private File sourceDir;

Expand Down Expand Up @@ -98,18 +97,18 @@ public abstract class ProcessFilesTask implements Callable<Object> {
* @param outputDir directory to write the final file
* @param outputFilename the output file name
* @param suffix final filename suffix
* @param nosuffix whether to use a suffix for the minified file name or not
* @param nosuffix whether to use a suffix for the minified filename or not
* @param charset if a character set is specified, a byte-to-char variant allows the encoding to be selected.
* Otherwise, only byte-to-byte operations are used
* Otherwise, only byte-to-byte operations are used
* @param linebreak split long lines after a specific column
*/
public ProcessFilesTask(Log log, Integer bufferSize, boolean debug, boolean skipMerge, boolean skipMinify,
String webappSourceDir, String webappTargetDir, String inputDir, List<String> sourceFiles,
List<String> sourceIncludes, List<String> sourceExcludes, String outputDir, String outputFilename,
String suffix, boolean nosuffix, String charset, int linebreak) {
this.log = log;
this.bufferSize = bufferSize;
this.debug = debug;
this.bufferSize = bufferSize;
this.skipMerge = skipMerge;
this.skipMinify = skipMinify;
this.mergedFilename = outputFilename;
Expand Down Expand Up @@ -150,11 +149,9 @@ public Object call() {
originalPath.lastIndexOf(File.separator));
File targetPath = new File(targetDir.getAbsolutePath() + subPath);
targetPath.mkdirs();
log.info("nosuffix?" + nosuffix);

File minifiedFile = new File(targetPath, (nosuffix) ? mergedFile.getName() : mergedFile.getName()
.replace(extension, suffix + extension));
log.info("Calling minify on: " + minifiedFile.getName());
minify(mergedFile, minifiedFile);
}
} else if (skipMinify) {
Expand All @@ -163,9 +160,9 @@ public Object call() {
log.info("Skipping minify step.");
} else {
File mergedFile = new File(targetDir, (nosuffix) ? mergedFilename + TEMP_SUFFIX : mergedFilename);
File minifiedFile = new File(targetDir, (nosuffix) ? mergedFilename
: mergedFile.getName().replace(extension, suffix + extension));
merge(mergedFile);
File minifiedFile = new File(targetDir, (nosuffix) ? mergedFilename : mergedFile.getName().replace(
extension, suffix + extension));
minify(mergedFile, minifiedFile);
if (nosuffix) {
if (!mergedFile.delete()) {
Expand Down Expand Up @@ -221,7 +218,7 @@ private void merge(File mergedFile) {
* @param mergedFile input file resulting from the merged step
* @param minifiedFile output file resulting from the minify step
*/
abstract void minify(File file, File minifiedFile);
abstract void minify(File mergedFile, File minifiedFile);

/**
* Logs an addition of a new source file.
Expand All @@ -235,27 +232,6 @@ private void addNewSourceFile(String finalFilename, String sourceFilename) {
addNewSourceFile(finalFilename, sourceFile);
}

/**
* Cleanup files. Remove merged file is nosuffix parameter was set to true.
*
* @param mergedFile input file resulting from the merged step
* @param minifiedFile output file resulting from the minify step
*/
void cleanupFiles(File mergedFile, File minifiedFile) {
if (nosuffix) {
String mergedFilename = mergedFile.getName();
URI mergedFileURI = mergedFile.toURI();
if (debug) {
log.info("Deleting the file [" + mergedFilename + "].");
}
mergedFile.delete();
if (debug) {
log.info("Renaming the file [" + minifiedFile.getName() + "] to [" + mergedFilename + "].");
}
minifiedFile.renameTo(new File(mergedFileURI));
}
}

/**
* Logs an addition of a new source file.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class ProcessJSFilesTask extends ProcessFilesTask {
* @param outputDir directory to write the final file
* @param outputFilename the output file name
* @param suffix final filename suffix
* @param nosuffix whether to use a suffix for the minified file name or not
* @param nosuffix whether to use a suffix for the minified filename or not
* @param charset if a character set is specified, a byte-to-char variant allows the encoding to be selected.
* Otherwise, only byte-to-byte operations are used
* @param linebreak split long lines after a specific column
Expand All @@ -87,8 +87,8 @@ public class ProcessJSFilesTask extends ProcessFilesTask {
public ProcessJSFilesTask(Log log, Integer bufferSize, boolean debug, boolean skipMerge, boolean skipMinify,
String webappSourceDir, String webappTargetDir, String inputDir, List<String> sourceFiles,
List<String> sourceIncludes, List<String> sourceExcludes, String outputDir, String outputFilename,
String suffix, boolean nosuffix, String charset, int linebreak, String jsEngine, boolean munge, boolean verbose,
boolean preserveAllSemiColons, boolean disableOptimizations) {
String suffix, boolean nosuffix, String charset, int linebreak, String jsEngine, boolean munge,
boolean verbose, boolean preserveAllSemiColons, boolean disableOptimizations) {
super(log, bufferSize, debug, skipMerge, skipMinify, webappSourceDir, webappTargetDir, inputDir, sourceFiles,
sourceIncludes, sourceExcludes, outputDir, outputFilename, suffix, nosuffix, charset, linebreak);

Expand All @@ -106,9 +106,12 @@ public ProcessJSFilesTask(Log log, Integer bufferSize, boolean debug, boolean sk
* @param minifiedFile output file resulting from the minify step
*/
@Override
protected void minify(File mergedFile, File minifiedFile) {
void minify(File mergedFile, File minifiedFile) {
if (minifiedFile != null) {
try {
log.info("Creating minified file [" + ((debug) ? minifiedFile.getPath() : minifiedFile.getName())
+ "].");

InputStream in = new FileInputStream(mergedFile);
OutputStream out = new FileOutputStream(minifiedFile);
InputStreamReader reader;
Expand All @@ -120,14 +123,7 @@ protected void minify(File mergedFile, File minifiedFile) {
reader = new InputStreamReader(in, charset);
writer = new OutputStreamWriter(out, charset);
}

if (debug) {
log.info("Creating minified file [" + minifiedFile.getPath() + "].");
} else {
File temp = (nosuffix) ? mergedFile : minifiedFile;
log.info("Creating minified file [" + temp.getName() + "].");
}


if ("closure".equals(jsEngine)) {
log.debug("Using JavaScript compressor engine [Google Closure Compiler].");

Expand Down Expand Up @@ -157,9 +153,6 @@ protected void minify(File mergedFile, File minifiedFile) {
} catch (IOException e) {
log.error(e.getMessage(), e);
}

cleanupFiles(mergedFile, minifiedFile);

}
}
}
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.1</version>
<version>1.6.2</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.1</version>
<version>1.6.2</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.1</version>
<version>1.6.2</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.1</version>
<version>1.6.2</version>
<executions>
<execution>
<id>default-minify</id>
Expand Down

0 comments on commit 581266c

Please sign in to comment.