tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject git commit: TAP5-1952: Improve logging of warnings for YUICompressor
Date Thu, 07 Jun 2012 22:44:19 GMT
Updated Branches:
  refs/heads/master 1ca36dc67 -> bfe1a19c3


TAP5-1952: Improve logging of warnings for YUICompressor


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/bfe1a19c
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/bfe1a19c
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/bfe1a19c

Branch: refs/heads/master
Commit: bfe1a19c3e56ea57f37ec2b65a8bdc94ef292abb
Parents: 1ca36dc
Author: Howard M. Lewis Ship <hlship@apache.org>
Authored: Thu Jun 7 15:43:12 2012 -0700
Committer: Howard M. Lewis Ship <hlship@apache.org>
Committed: Thu Jun 7 15:44:12 2012 -0700

----------------------------------------------------------------------
 .../yuicompressor/JavaScriptResourceMinimizer.java |   62 +++++++++++++--
 .../src/test/resources/log4j.properties            |    1 +
 2 files changed, 55 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bfe1a19c/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 8a873f5..4a3a999 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
@@ -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.
@@ -28,6 +28,7 @@ import java.io.LineNumberReader;
 import java.io.Reader;
 import java.io.Writer;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * JavaScript resource minimizer based on the YUI {@link JavaScriptCompressor}.
@@ -52,10 +53,41 @@ public class JavaScriptResourceMinimizer extends AbstractMinimizer
         this.logger = logger;
     }
 
-    protected void doMinimize(StreamableResource resource, Writer output) throws IOException
+    protected void doMinimize(final StreamableResource resource, Writer output) throws IOException
     {
         final Set<Integer> errorLines = CollectionFactory.newSet();
 
+        final Runnable identifySource = new Runnable()
+        {
+            boolean sourceIdentified = false;
+
+            @Override
+            public void run()
+            {
+                if (!sourceIdentified)
+                {
+                    logger.error(String.format("JavaScript compression problems for resource
%s:",
+                            resource.getDescription()));
+                    sourceIdentified = true;
+                }
+            }
+        };
+
+        final AtomicInteger warningCount = new AtomicInteger();
+
+        Runnable identifyWarnings = new Runnable() {
+            @Override
+            public void run()
+            {
+                if (warningCount.get() > 0)
+                {
+                    logger.error(String.format("%,d compression warnings; enable warning
logging of %s to see details.",
+                            warningCount.get(),
+                            logger.getName()));
+                }
+            }
+        };
+
         ErrorReporter errorReporter = new ErrorReporter()
         {
             private String format(String message, int line, int lineOffset)
@@ -68,9 +100,17 @@ public class JavaScriptResourceMinimizer extends AbstractMinimizer
 
             public void warning(String message, String sourceName, int line, String lineSource,
int lineOffset)
             {
+                identifySource.run();
+
                 errorLines.add(line);
 
-                logger.warn(format(message, line, lineOffset));
+                if (logger.isWarnEnabled())
+                {
+                    logger.warn(format(message, line, lineOffset));
+                } else
+                {
+                    warningCount.incrementAndGet();
+                }
             }
 
             public EvaluatorException runtimeError(String message, String sourceName, int
line, String lineSource,
@@ -83,6 +123,8 @@ public class JavaScriptResourceMinimizer extends AbstractMinimizer
 
             public void error(String message, String sourceName, int line, String lineSource,
int lineOffset)
             {
+                identifySource.run();
+
                 errorLines.add(line);
 
                 logger.error(format(message, line, lineOffset));
@@ -90,21 +132,27 @@ public class JavaScriptResourceMinimizer extends AbstractMinimizer
 
         };
 
-
         Reader reader = toReader(resource);
 
         try
         {
             JavaScriptCompressor compressor = new JavaScriptCompressor(reader, errorReporter);
-            compressor.compress(output, -1, true, false, false, false);
+            compressor.compress(output, -1, true, true, false, false);
+
+            identifyWarnings.run();
+
         } catch (EvaluatorException ex)
         {
+            identifySource.run();
+
             logInputLines(resource, errorLines);
 
             recoverFromException(ex, resource, output);
 
         } catch (Exception ex)
         {
+            identifySource.run();
+
             recoverFromException(ex, resource, output);
         }
 
@@ -113,7 +161,7 @@ public class JavaScriptResourceMinimizer extends AbstractMinimizer
 
     private void recoverFromException(Exception ex, StreamableResource resource, Writer output)
throws IOException
     {
-        logger.error(String.format("Exception minimizing %s: %s", resource.getDescription(),
InternalUtils.toMessage(ex)), ex);
+        logger.error(InternalUtils.toMessage(ex), ex);
 
         streamUnminimized(resource, output);
     }
@@ -146,8 +194,6 @@ public class JavaScriptResourceMinimizer extends AbstractMinimizer
 
     private void logInputLines(StreamableResource resource, Set<Integer> lines)
     {
-        logger.error(String.format("Errors in resource %s:", resource.getDescription()));
-
         int last = -1;
 
         try

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/bfe1a19c/tapestry-yuicompressor/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/tapestry-yuicompressor/src/test/resources/log4j.properties b/tapestry-yuicompressor/src/test/resources/log4j.properties
index 8ae8390..e659dc0 100644
--- a/tapestry-yuicompressor/src/test/resources/log4j.properties
+++ b/tapestry-yuicompressor/src/test/resources/log4j.properties
@@ -10,6 +10,7 @@ log4j.appender.A1.layout.ConversionPattern=[%p] %c{1} %m%n
 # log4j.category.tapestry.render=debug
 
 log4j.category.org.apache.tapestry5.services.assets.AssetsModule.ResourceMinimizer=debug
+#log4j.category.org.apache.tapestry5.services.assets.AssetsModule.ResourceMinimizer=error
 log4j.category.org.apache.tapestry5.yuicompressor=debug
 log4j.category.org.apache.tapestry5.internal.yuicompressor=debug
 


Mime
View raw message