Updated Branches: refs/heads/5.3 4fbe60b8c -> 0fb8abd7f
TAP5-1991: Make YUICompressor less verbose about common warnings Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/0fb8abd7 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/0fb8abd7 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/0fb8abd7 Branch: refs/heads/5.3 Commit: 0fb8abd7f718f2d839fa1b0ef6c5a31003859415 Parents: d6ec62c Author: Howard M. Lewis Ship <hls...@apache.org> Authored: Mon Aug 20 11:20:23 2012 -0700 Committer: Howard M. Lewis Ship <hls...@apache.org> Committed: Mon Aug 20 11:21:00 2012 -0700 ---------------------------------------------------------------------- .../internal/yuicompressor/AbstractMinimizer.java | 17 ++++++++++---- .../yuicompressor/JavaScriptResourceMinimizer.java | 17 ++++++++++++++- 2 files changed, 28 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/0fb8abd7/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/AbstractMinimizer.java ---------------------------------------------------------------------- diff --git a/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/AbstractMinimizer.java b/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/AbstractMinimizer.java index 51d7024..bb4b243 100644 --- a/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/AbstractMinimizer.java +++ b/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/AbstractMinimizer.java @@ -1,4 +1,4 @@ -// Copyright 2011 The Apache Software Foundation +// Copyright 2011-2012 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -86,10 +86,15 @@ public abstract class AbstractMinimizer implements ResourceMinimizer if (logger.isDebugEnabled()) { + int inputSize = input.getSize(); + int outputSize = output.getSize(); + double elapsedMillis = ((double) elapsedNanos) * NANOS_TO_MILLIS; + // e.g., reducing 100 bytes to 25 would be a (100-25)/100 reduction, or 75% + double reduction = 100d * ((double) (inputSize - outputSize)) / ((double) inputSize); - logger.debug(String.format("Minimized %s (%,d input bytes of %s to %,d output bytes in %.2f ms)", - input.getDescription(), input.getSize(), resourceType, output.getSize(), elapsedMillis)); + logger.debug(String.format("Minimized %s (%,d input bytes of %s to %,d output bytes in %.2f ms, %.2f%% reduction)", + input.getDescription(), inputSize, resourceType, outputSize, elapsedMillis, reduction)); } return output; @@ -105,8 +110,10 @@ public abstract class AbstractMinimizer implements ResourceMinimizer /** * Implemented in subclasses to do the actual work. * - * @param resource content to minimize - * @param output writer for minimized version of input + * @param resource + * content to minimize + * @param output + * writer for minimized version of input */ protected abstract void doMinimize(StreamableResource resource, Writer output) throws IOException; } http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/0fb8abd7/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java ---------------------------------------------------------------------- diff --git a/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java b/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java index 4a3a999..598f977 100644 --- a/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java +++ b/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java @@ -46,6 +46,12 @@ public class JavaScriptResourceMinimizer extends AbstractMinimizer EXACT, NEAR, FAR } + private static final String[] IGNORED_WARNINGS = { + "Try to use a single 'var' statement per scope.", + "Using 'eval' is not recommended", + "has already been declared in the same scope" + }; + public JavaScriptResourceMinimizer(final Logger logger, OperationTracker tracker) { super(logger, tracker, "JavaScript"); @@ -75,7 +81,8 @@ public class JavaScriptResourceMinimizer extends AbstractMinimizer final AtomicInteger warningCount = new AtomicInteger(); - Runnable identifyWarnings = new Runnable() { + Runnable identifyWarnings = new Runnable() + { @Override public void run() { @@ -100,6 +107,14 @@ public class JavaScriptResourceMinimizer extends AbstractMinimizer public void warning(String message, String sourceName, int line, String lineSource, int lineOffset) { + for (String ignored : IGNORED_WARNINGS) + { + if (message.contains(ignored)) + { + return; + } + } + identifySource.run(); errorLines.add(line);