You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by be...@apache.org on 2025/09/13 15:01:03 UTC
(tapestry-5) 03/12: Improving handling of resource minimization exceptions
This is an automated email from the ASF dual-hosted git repository.
benw pushed a commit to branch gradle-improvements-javax
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git
commit 4098b2df2352f0dae994985cf40603316f36f314
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Sun Aug 24 11:14:57 2025 -0300
Improving handling of resource minimization exceptions
---
.../assets/JavaScriptStackMinimizeDisabler.java | 32 ++++++++++++++++++++--
.../webresources/GoogleClosureMinimizer.java | 2 +-
.../ResourceMinimizationException.java | 32 ++++++++++++++++++++++
3 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/JavaScriptStackMinimizeDisabler.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/JavaScriptStackMinimizeDisabler.java
index 9bca3fa0f..fe475efb2 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/JavaScriptStackMinimizeDisabler.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/assets/JavaScriptStackMinimizeDisabler.java
@@ -12,6 +12,8 @@
package org.apache.tapestry5.internal.services.assets;
+import java.io.IOException;
+
import org.apache.tapestry5.TapestryConstants;
import org.apache.tapestry5.commons.Resource;
import org.apache.tapestry5.http.services.Request;
@@ -21,8 +23,8 @@ import org.apache.tapestry5.services.assets.StreamableResourceProcessing;
import org.apache.tapestry5.services.assets.StreamableResourceSource;
import org.apache.tapestry5.services.javascript.JavaScriptStack;
import org.apache.tapestry5.services.javascript.JavaScriptStackSource;
-
-import java.io.IOException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Attempts to match resources against a {@link org.apache.tapestry5.services.javascript.JavaScriptStack}, and
@@ -33,6 +35,8 @@ import java.io.IOException;
public class JavaScriptStackMinimizeDisabler extends DelegatingSRS
{
+ private static final Logger LOGGER = LoggerFactory.getLogger(JavaScriptStackMinimizeDisabler.class);
+
private final JavaScriptStackSource javaScriptStackSource;
private final Request request;
@@ -59,7 +63,29 @@ public class JavaScriptStackMinimizeDisabler extends DelegatingSRS
try
{
return delegate.getStreamableResource(baseResource, processing, dependencies);
- } finally
+ }
+ catch (RuntimeException e)
+ {
+ if (processing != StreamableResourceProcessing.FOR_AGGREGATION)
+ {
+ // We know our current minimizer, Google Closure Compiler,
+ // doesn't support ES modules
+ if (LOGGER.isWarnEnabled() &&
+ !baseResource.toString().contains("/es-modules/") &&
+ !baseResource.toString().toLowerCase().contains("es module wrapper"))
+ {
+ LOGGER.warn("Exception happened while processing " + baseResource +
+ "Trying again without compression nor minification.", e);
+ }
+ request.setAttribute(TapestryConstants.DISABLE_JAVASCRIPT_MINIMIZATION, true);
+ return delegate.getStreamableResource(baseResource, StreamableResourceProcessing.FOR_AGGREGATION, dependencies);
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ finally
{
request.setAttribute(TapestryConstants.DISABLE_JAVASCRIPT_MINIMIZATION, null);
}
diff --git a/tapestry-webresources/src/main/java/org/apache/tapestry5/internal/webresources/GoogleClosureMinimizer.java b/tapestry-webresources/src/main/java/org/apache/tapestry5/internal/webresources/GoogleClosureMinimizer.java
index b134b2bad..f2385dccd 100644
--- a/tapestry-webresources/src/main/java/org/apache/tapestry5/internal/webresources/GoogleClosureMinimizer.java
+++ b/tapestry-webresources/src/main/java/org/apache/tapestry5/internal/webresources/GoogleClosureMinimizer.java
@@ -106,7 +106,7 @@ public class GoogleClosureMinimizer extends AbstractMinimizer
return IOUtils.toInputStream(compiler.toSource(), StandardCharsets.UTF_8);
}
- throw new RuntimeException(String.format("Compilation failed for %s. Errors: %s.",
+ throw new ResourceMinimizationException(String.format("Compilation failed for %s. Errors: %s.",
resource,
InternalUtils.join(CollectionFactory.newList(result.errors), ";")));
}
diff --git a/tapestry-webresources/src/main/java/org/apache/tapestry5/internal/webresources/ResourceMinimizationException.java b/tapestry-webresources/src/main/java/org/apache/tapestry5/internal/webresources/ResourceMinimizationException.java
new file mode 100644
index 000000000..e4df96ba7
--- /dev/null
+++ b/tapestry-webresources/src/main/java/org/apache/tapestry5/internal/webresources/ResourceMinimizationException.java
@@ -0,0 +1,32 @@
+// Copyright 2015 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.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package org.apache.tapestry5.internal.webresources;
+
+/**
+ * Manages a collection of Resources and can check to see if any resource's actual content has changed.
+ *
+ * @since 5.10.0
+ */
+public class ResourceMinimizationException extends RuntimeException
+{
+
+ private static final long serialVersionUID = 1L;
+
+ public ResourceMinimizationException(String message)
+ {
+ super(message);
+ }
+
+}