You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/10/28 18:09:20 UTC

svn commit: r1190418 - in /tapestry/tapestry5/trunk: tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/ tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/ tapestry-yuicompressor/src/test/groovy/org...

Author: hlship
Date: Fri Oct 28 16:09:18 2011
New Revision: 1190418

URL: http://svn.apache.org/viewvc?rev=1190418&view=rev
Log:
TAP5-1726: JavaScript Assets fail to load for already-minified JS assets in Production mode

Added:
    tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/java/yuicompressor/testapp/pages/BadJavaScript.java
    tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/BadJavaScript.tml
    tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/bad.js
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
    tapestry/tapestry5/trunk/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java
    tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/groovy/org/apache/tapestry5/yuicompressor/itest/YUICompressorIntegrationTests.groovy
    tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/java/yuicompressor/testapp/pages/Index.java
    tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/Index.tml

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java?rev=1190418&r1=1190417&r2=1190418&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/StackAssetRequestHandler.java Fri Oct 28 16:09:18 2011
@@ -182,7 +182,7 @@ public class StackAssetRequestHandler im
         PrintWriter writer = new PrintWriter(osw, true);
         long lastModified = 0;
 
-        StringBuilder description = new StringBuilder(String.format("stack=%s, locale=%s, resources=[", stackName, localeName));
+        StringBuilder description = new StringBuilder(String.format("'%s' JavaScript stack, for locale %s, resources=", stackName, localeName));
         String sep = "";
 
         JSONArray paths = new JSONArray();
@@ -211,7 +211,7 @@ public class StackAssetRequestHandler im
         writer.close();
 
         return new StreamableResourceImpl(
-                description.append("]").toString(),
+                description.toString(),
                 JAVASCRIPT_CONTENT_TYPE, CompressionStatus.COMPRESSABLE, lastModified,
                 new BytestreamCache(stream));
     }

Modified: tapestry/tapestry5/trunk/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java?rev=1190418&r1=1190417&r2=1190418&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java (original)
+++ tapestry/tapestry5/trunk/tapestry-yuicompressor/src/main/java/org/apache/tapestry5/internal/yuicompressor/JavaScriptResourceMinimizer.java Fri Oct 28 16:09:18 2011
@@ -101,17 +101,23 @@ public class JavaScriptResourceMinimizer
         {
             logInputLines(resource, errorLines);
 
-            throw ex;
+            recoverFromException(ex, resource, output);
+
         } catch (Exception ex)
         {
-            logger.error(String.format("Exception minimizing %s: %s", resource, InternalUtils.toMessage(ex), ex));
-
-            streamUnminimized(resource, output);
+            recoverFromException(ex, resource, output);
         }
 
         reader.close();
     }
 
+    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));
+
+        streamUnminimized(resource, output);
+    }
+
     private void streamUnminimized(StreamableResource resource, Writer output) throws IOException
     {
         Reader reader = toReader(resource);
@@ -140,6 +146,8 @@ public class JavaScriptResourceMinimizer
 
     private void logInputLines(StreamableResource resource, Set<Integer> lines)
     {
+        logger.error(String.format("Errors in resource %s:", resource.getDescription()));
+
         int last = -1;
 
         try

Modified: tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/groovy/org/apache/tapestry5/yuicompressor/itest/YUICompressorIntegrationTests.groovy
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/groovy/org/apache/tapestry5/yuicompressor/itest/YUICompressorIntegrationTests.groovy?rev=1190418&r1=1190417&r2=1190418&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/groovy/org/apache/tapestry5/yuicompressor/itest/YUICompressorIntegrationTests.groovy (original)
+++ tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/groovy/org/apache/tapestry5/yuicompressor/itest/YUICompressorIntegrationTests.groovy Fri Oct 28 16:09:18 2011
@@ -34,4 +34,13 @@ class YUICompressorIntegrationTests exte
 
         assertText "selected", "CLOJURE, JAVA"
     }
+
+    @Test
+    void bad_js_is_reported() {
+        openLinks "Bad JavaScript Demo"
+
+        // We still get there, no the exception page.
+
+        assertTitle "Tapestry 5: Bad JavaScript Demo"
+    }
 }

Added: tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/java/yuicompressor/testapp/pages/BadJavaScript.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/java/yuicompressor/testapp/pages/BadJavaScript.java?rev=1190418&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/java/yuicompressor/testapp/pages/BadJavaScript.java (added)
+++ tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/java/yuicompressor/testapp/pages/BadJavaScript.java Fri Oct 28 16:09:18 2011
@@ -0,0 +1,9 @@
+package yuicompressor.testapp.pages;
+
+
+import org.apache.tapestry5.annotations.Import;
+
+@Import(library = "bad.js")
+public class BadJavaScript
+{
+}

Modified: tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/java/yuicompressor/testapp/pages/Index.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/java/yuicompressor/testapp/pages/Index.java?rev=1190418&r1=1190417&r2=1190418&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/java/yuicompressor/testapp/pages/Index.java (original)
+++ tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/java/yuicompressor/testapp/pages/Index.java Fri Oct 28 16:09:18 2011
@@ -1,17 +1,18 @@
 package yuicompressor.testapp.pages;
 
-import java.util.List;
-
 import org.apache.tapestry5.SelectModel;
 import org.apache.tapestry5.ValueEncoder;
 import org.apache.tapestry5.annotations.Persist;
 import org.apache.tapestry5.annotations.Property;
 import org.apache.tapestry5.ioc.Messages;
 import org.apache.tapestry5.ioc.annotations.Inject;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.services.ValueEncoderSource;
 import org.apache.tapestry5.util.EnumSelectModel;
 
+import java.util.List;
+
 public class Index
 {
     static enum Languages
@@ -26,6 +27,14 @@ public class Index
     @Inject
     private Messages messages;
 
+    void onActivate()
+    {
+        if (languages == null)
+        {
+            languages = CollectionFactory.newList();
+        }
+    }
+
     @Inject
     private ValueEncoderSource vec;
 

Added: tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/BadJavaScript.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/BadJavaScript.tml?rev=1190418&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/BadJavaScript.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/BadJavaScript.tml Fri Oct 28 16:09:18 2011
@@ -0,0 +1,6 @@
+<i:internallayout title="Bad JavaScript Demo" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
+                  xmlns:p="tapestry:parameter" xmlns:i="tapestry-library:t5internal">
+
+
+
+</i:internallayout>
\ No newline at end of file

Modified: tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/Index.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/Index.tml?rev=1190418&r1=1190417&r2=1190418&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/Index.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/Index.tml Fri Oct 28 16:09:18 2011
@@ -1,25 +1,26 @@
-<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd" xmlns:p="tapestry:parameter">
-  <head>
-    <title>YUICompressor Test</title>
-  </head>
-  <body>
+<i:internallayout title="YUICompressor Test" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
+                  xmlns:p="tapestry:parameter" xmlns:i="tapestry-library:t5internal">
+
+    <p:leftnav>
+        <t:pagelink page="badJavaScript">Bad JavaScript Demo</t:pagelink>
+    </p:leftnav>
 
     <t:form>
-      <t:errors/>
-      <t:palette t:id="languages" selected="languages" model="languagesModel" encoder="languagesEncoder" reorder="true"/>
-      <br/>
-      <input type="submit"/>
+        <t:errors/>
+        <t:palette t:id="languages" selected="languages" model="languagesModel" encoder="languagesEncoder"
+                   reorder="true"/>
+        <br/>
+        <input type="submit"/>
     </t:form>
 
     <hr/>
 
     <t:if test="languages">
-      <p>
-        Selected languages:
-        <span id="selected">${selectedLanguages}</span>
-      </p>
+        <p>
+            Selected languages:
+            <span id="selected">${selectedLanguages}</span>
+        </p>
     </t:if>
 
 
-  </body>
-</html>
\ No newline at end of file
+</i:internallayout>
\ No newline at end of file

Added: tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/bad.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/bad.js?rev=1190418&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/bad.js (added)
+++ tapestry/tapestry5/trunk/tapestry-yuicompressor/src/test/resources/yuicompressor/testapp/pages/bad.js Fri Oct 28 16:09:18 2011
@@ -0,0 +1,30 @@
+/**
+ * This file contains bad JavaScript.
+ */
+
+function ok() { return null; }
+
+
+
+// Lots of space here, to exercise the code that shows only
+// a snippet
+// of the source
+// around the failed code.
+
+
+
+
+
+// Ok, back to where we put the syntax error.
+
+function name with spaces() { this.will not.compile(); }
+
+
+
+// Meanwhile, down here,
+// we have code that is OK again.
+
+
+function also_ok() {
+    return "no worries, mate!";
+}