Skip to content

Commit

Permalink
Revert last change for pull request on issue samaxes#29
Browse files Browse the repository at this point in the history
This reverts commit f74b642.
  • Loading branch information
AFaust committed Jul 12, 2013
1 parent f74b642 commit 4515d82
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 188 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@

<properties>
<github.global.server>github</github.global.server>
<project.build.resourceEncoding>UTF-8</project.build.resourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<project.build.resourceEncoding>ISO-8859-1</project.build.resourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.plugin.version>2.9</maven.plugin.version>
</properties>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public class ProcessCSSFilesTask extends ProcessFilesTask {
* Otherwise, only byte-to-byte operations are used
* @param linebreak split long lines after a specific column
*/
public ProcessCSSFilesTask(final Log log, final Integer bufferSize, final boolean debug, final boolean skipMerge, final boolean skipMinify,
final String webappSourceDir, final String webappTargetDir, final String inputDir, final List<String> sourceFiles,
final List<String> sourceIncludes, final List<String> sourceExcludes, final String outputDir, final String outputFilename,
final String suffix, final boolean nosuffix, final String charset, final int linebreak) {
public ProcessCSSFilesTask(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) {
super(log, bufferSize, debug, skipMerge, skipMinify, webappSourceDir, webappTargetDir, inputDir, sourceFiles,
sourceIncludes, sourceExcludes, outputDir, outputFilename, suffix, nosuffix, charset, linebreak);
}
Expand All @@ -77,53 +77,21 @@ public ProcessCSSFilesTask(final Log log, final Integer bufferSize, final boolea
* @throws IOException when the minify step fails
*/
@Override
protected void minify(final File mergedFile, final File minifiedFile) throws IOException {
try
{
final InputStream in = new FileInputStream(mergedFile);
try
{
final OutputStream out = new FileOutputStream(minifiedFile);
try
{
final InputStreamReader reader = new InputStreamReader(in, this.charset);
try
{
final OutputStreamWriter writer = new OutputStreamWriter(out, this.charset);
try
{
this.log.info("Creating the minified file [" + ((this.debug) ? minifiedFile.getPath() : minifiedFile.getName())
+ "].");
protected void minify(File mergedFile, File minifiedFile) throws IOException {
try (InputStream in = new FileInputStream(mergedFile);
OutputStream out = new FileOutputStream(minifiedFile);
InputStreamReader reader = new InputStreamReader(in, charset);
OutputStreamWriter writer = new OutputStreamWriter(out, charset)) {
log.info("Creating the minified file [" + ((debug) ? minifiedFile.getPath() : minifiedFile.getName())
+ "].");

final CssCompressor compressor = new CssCompressor(reader);
compressor.compress(writer, this.linebreak);
}
finally
{
writer.close();
}
}
finally
{
reader.close();
}
}
finally
{
// may already be closed but make sure
out.close();
}
}
finally
{
// may already be closed but make sure
in.close();
}
} catch (final IOException e) {
this.log.error("Failed to compress the CSS file [" + mergedFile.getName() + "].", e);
CssCompressor compressor = new CssCompressor(reader);
compressor.compress(writer, linebreak);
} catch (IOException e) {
log.error("Failed to compress the CSS file [" + mergedFile.getName() + "].", e);
throw e;
}

this.logCompressionGains(mergedFile, minifiedFile);
logCompressionGains(mergedFile, minifiedFile);
}
}
74 changes: 10 additions & 64 deletions src/main/java/com/samaxes/maven/minify/plugin/ProcessFilesTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,46 +213,13 @@ public Object call() throws IOException {
* @throws IOException when the merge step fails
*/
protected void merge(final File mergedFile) throws IOException {
try
{
final InputStream sequence = new SequenceInputStream(new ListOfFiles(this.log, this.files, this.debug));
try
{
final OutputStream out = new FileOutputStream(mergedFile);
try
{
final InputStreamReader sequenceReader = new InputStreamReader(sequence, this.charset);
try
{
final OutputStreamWriter outWriter = new OutputStreamWriter(out, this.charset);
try
{
this.log.info("Creating the merged file [" + ((this.debug) ? mergedFile.getPath() : mergedFile.getName())
+ "].");
try (InputStream sequence = new SequenceInputStream(new ListOfFiles(this.log, this.files, this.debug));
OutputStream out = new FileOutputStream(mergedFile);
InputStreamReader sequenceReader = new InputStreamReader(sequence, this.charset);
OutputStreamWriter outWriter = new OutputStreamWriter(out, this.charset)) {
this.log.info("Creating the merged file [" + ((this.debug) ? mergedFile.getPath() : mergedFile.getName()) + "].");

IOUtil.copy(sequenceReader, outWriter, this.bufferSize);
}
finally
{
outWriter.close();
}
}
finally
{
sequenceReader.close();
}
}
finally
{
// may already be closed but make sure
out.close();
}
}
finally
{
// may already be closed but make sure
sequence.close();
}
IOUtil.copy(sequenceReader, outWriter, this.bufferSize);
} catch (final IOException e) {
this.log.error("Failed to concatenate files.", e);
throw e;
Expand All @@ -278,31 +245,10 @@ void logCompressionGains(final File mergedFile, final File minifiedFile) {
try {
final File temp = File.createTempFile(minifiedFile.getName(), ".gz");

final InputStream in = new FileInputStream(minifiedFile);
try
{
final OutputStream out = new FileOutputStream(temp);
try
{
final GZIPOutputStream outGZIP = new GZIPOutputStream(out);
try
{
IOUtil.copy(in, outGZIP, this.bufferSize);
}
finally
{
outGZIP.close();
}
}
finally
{
// may already be closed but make sure
out.close();
}
}
finally
{
in.close();
try (InputStream in = new FileInputStream(minifiedFile);
OutputStream out = new FileOutputStream(temp);
GZIPOutputStream outGZIP = new GZIPOutputStream(out)) {
IOUtil.copy(in, outGZIP, this.bufferSize);
}

this.log.info("Uncompressed size: " + mergedFile.length() + " bytes.");
Expand Down
109 changes: 36 additions & 73 deletions src/main/java/com/samaxes/maven/minify/plugin/ProcessJSFilesTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ public class ProcessJSFilesTask extends ProcessFilesTask {
* @param preserveAllSemiColons preserve unnecessary semicolons
* @param disableOptimizations disable all the built-in micro optimizations
*/
public ProcessJSFilesTask(final Log log, final Integer bufferSize, final boolean debug, final boolean skipMerge, final boolean skipMinify,
final String webappSourceDir, final String webappTargetDir, final String inputDir, final List<String> sourceFiles,
final List<String> sourceIncludes, final List<String> sourceExcludes, final String outputDir, final String outputFilename,
final String suffix, final boolean nosuffix, final String charset, final int linebreak, final String jsEngine, final boolean munge,
final boolean verbose, final boolean preserveAllSemiColons, final boolean disableOptimizations) {
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) {
super(log, bufferSize, debug, skipMerge, skipMinify, webappSourceDir, webappTargetDir, inputDir, sourceFiles,
sourceIncludes, sourceExcludes, outputDir, outputFilename, suffix, nosuffix, charset, linebreak);

Expand All @@ -106,77 +106,40 @@ public ProcessJSFilesTask(final Log log, final Integer bufferSize, final boolean
* @throws IOException when the minify step fails
*/
@Override
protected void minify(final File mergedFile, final File minifiedFile) throws IOException {
try
{
final InputStream in = new FileInputStream(mergedFile);
try
{
final OutputStream out = new FileOutputStream(minifiedFile);
try
{
final InputStreamReader reader = new InputStreamReader(in, this.charset);
try
{
final OutputStreamWriter writer = new OutputStreamWriter(out, this.charset);
try
{

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

if ("closure".equals(this.jsEngine))
{
this.log.debug("Using Google Closure Compiler engine.");

final CompilerOptions options = new CompilerOptions();
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setOutputCharset(this.charset);

final SourceFile input = SourceFile.fromInputStream(mergedFile.getName(), in);
final List<SourceFile> externs = Collections.emptyList();

final Compiler compiler = new Compiler();
compiler.compile(externs, Arrays.asList(new SourceFile[] { input }), options);

writer.append(compiler.toSource());
}
else
{
this.log.debug("Using YUI Compressor engine.");

final JavaScriptCompressor compressor = new JavaScriptCompressor(reader, new JavaScriptErrorReporter(
this.log, mergedFile.getName()));
compressor.compress(writer, this.linebreak, this.munge, this.verbose, this.preserveAllSemiColons,
this.disableOptimizations);
}
}
finally
{
writer.close();
}
}
finally
{
reader.close();
}
}
finally
{
// may already be closed but make sure
out.close();
}
protected void minify(File mergedFile, File minifiedFile) throws IOException {
try (InputStream in = new FileInputStream(mergedFile);
OutputStream out = new FileOutputStream(minifiedFile);
InputStreamReader reader = new InputStreamReader(in, charset);
OutputStreamWriter writer = new OutputStreamWriter(out, charset)) {
log.info("Creating the minified file [" + ((debug) ? minifiedFile.getPath() : minifiedFile.getName())
+ "].");

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

CompilerOptions options = new CompilerOptions();
CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
options.setOutputCharset(charset);

SourceFile input = SourceFile.fromInputStream(mergedFile.getName(), in);
List<SourceFile> externs = Collections.emptyList();

Compiler compiler = new Compiler();
compiler.compile(externs, Arrays.asList(new SourceFile[] { input }), options);

writer.append(compiler.toSource());
} else {
log.debug("Using YUI Compressor engine.");

JavaScriptCompressor compressor = new JavaScriptCompressor(reader, new JavaScriptErrorReporter(log,
mergedFile.getName()));
compressor.compress(writer, linebreak, munge, verbose, preserveAllSemiColons, disableOptimizations);
}
finally
{
// may already be closed but make sure
in.close();
}
} catch (final IOException e) {
this.log.error("Failed to compress the JavaScript file [" + mergedFile.getName() + "].", e);
} catch (IOException e) {
log.error("Failed to compress the JavaScript file [" + mergedFile.getName() + "].", e);
throw e;
}

this.logCompressionGains(mergedFile, minifiedFile);
logCompressionGains(mergedFile, minifiedFile);
}
}

0 comments on commit 4515d82

Please sign in to comment.