This is an automated email from the ASF dual-hosted git repository.

thiagohp pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tapestry-5.git

commit 166ade9bcf0bbc231c1c8b080167483f4e323047
Author: Thiago H. de Paula Figueiredo <thi...@arsmachina.com.br>
AuthorDate: Wed Jul 12 19:12:48 2023 -0300

    TAP5-1733: some adjustments to avoid tapestry-core stuff in tapestry-ioc
---
 .../tapestry5/commons/util/ExceptionUtils.java     | 31 +++++++++++++++++++++-
 .../apache/tapestry5/corelib/components/Form.java  |  2 +-
 .../internal}/FormsRequirePostException.java       |  4 ++-
 .../FormsRequirePostExceptionHandlerAssistant.java |  2 +-
 .../apache/tapestry5/modules/TapestryModule.java   |  2 +-
 ...msRequirePostExceptionHandlerAssistantTest.java |  4 +--
 .../org/apache/tapestry5/ioc/OperationTracker.java | 16 +++++++++++
 .../ioc/internal/OperationTrackerImpl.java         |  3 +--
 8 files changed, 55 insertions(+), 9 deletions(-)

diff --git 
a/commons/src/main/java/org/apache/tapestry5/commons/util/ExceptionUtils.java 
b/commons/src/main/java/org/apache/tapestry5/commons/util/ExceptionUtils.java
index 164c7cf8b..bf704023a 100644
--- 
a/commons/src/main/java/org/apache/tapestry5/commons/util/ExceptionUtils.java
+++ 
b/commons/src/main/java/org/apache/tapestry5/commons/util/ExceptionUtils.java
@@ -1,4 +1,4 @@
-// Copyright 2008-2013 The Apache Software Foundation
+// Copyright 2008-2013, 2023 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.
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry5.commons.util;
 
+import java.lang.annotation.Annotation;
+
 import org.apache.tapestry5.commons.services.ClassPropertyAdapter;
 import org.apache.tapestry5.commons.services.PropertyAccess;
 
@@ -112,4 +114,31 @@ public class ExceptionUtils
 
         return exception.getClass().getName();
     }
+    
+    /**
+     * Tells whether an exception annotated with a given annotation is found 
in the stack
+     * trace.
+     * @return <code>true</code> or </code>false</code>
+     * @since 5.8.3
+     */
+    public static boolean isAnnotationInStackTrace(Throwable t, Class<? 
extends Annotation> annotationClass)
+    {
+        boolean answer = false;
+        Throwable current = t;
+
+        while (current != null)
+        {
+            if (current.getClass().isAnnotationPresent(annotationClass))
+            {
+                answer = true;
+                break;
+            }
+
+            // Not a match, work down.
+
+            current = current.getCause();
+        }
+
+        return answer;
+    }
 }
diff --git 
a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java 
b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
index 90f20ede7..3d0fe289b 100644
--- 
a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
+++ 
b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/Form.java
@@ -20,7 +20,6 @@ import org.apache.tapestry5.commons.Messages;
 import org.apache.tapestry5.commons.internal.util.TapestryException;
 import org.apache.tapestry5.commons.services.PropertyAccess;
 import org.apache.tapestry5.commons.util.ExceptionUtils;
-import org.apache.tapestry5.commons.util.FormsRequirePostException;
 import org.apache.tapestry5.corelib.ClientValidation;
 import org.apache.tapestry5.corelib.internal.ComponentActionSink;
 import org.apache.tapestry5.corelib.internal.FormSupportImpl;
@@ -30,6 +29,7 @@ import org.apache.tapestry5.http.Link;
 import org.apache.tapestry5.http.services.Request;
 import org.apache.tapestry5.internal.BeanValidationContext;
 import org.apache.tapestry5.internal.BeanValidationContextImpl;
+import org.apache.tapestry5.internal.FormsRequirePostException;
 import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.internal.services.FormControlNameManager;
 import org.apache.tapestry5.internal.services.HeartbeatImpl;
diff --git 
a/commons/src/main/java/org/apache/tapestry5/commons/util/FormsRequirePostException.java
 
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/FormsRequirePostException.java
similarity index 90%
rename from 
commons/src/main/java/org/apache/tapestry5/commons/util/FormsRequirePostException.java
rename to 
tapestry-core/src/main/java/org/apache/tapestry5/internal/FormsRequirePostException.java
index 892eb226c..47ed942c4 100644
--- 
a/commons/src/main/java/org/apache/tapestry5/commons/util/FormsRequirePostException.java
+++ 
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/FormsRequirePostException.java
@@ -12,9 +12,10 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-package org.apache.tapestry5.commons.util;
+package org.apache.tapestry5.internal;
 
 import org.apache.tapestry5.commons.internal.util.TapestryException;
+import org.apache.tapestry5.ioc.OperationTracker.NonLoggableException;
 
 /**
  * Exception thrown by Tapestry's {@link 
org.apache.tapestry5.corelib.components.Form} component
@@ -25,6 +26,7 @@ import 
org.apache.tapestry5.commons.internal.util.TapestryException;
  * 
  * @since 5.8.3
  */
+@NonLoggableException
 public class FormsRequirePostException extends TapestryException {
 
     private static final long serialVersionUID = 1L;
diff --git 
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/FormsRequirePostExceptionHandlerAssistant.java
 
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/FormsRequirePostExceptionHandlerAssistant.java
index 4ea0150e0..458980ad6 100644
--- 
a/tapestry-core/src/main/java/org/apache/tapestry5/internal/FormsRequirePostExceptionHandlerAssistant.java
+++ 
b/tapestry-core/src/main/java/org/apache/tapestry5/internal/FormsRequirePostExceptionHandlerAssistant.java
@@ -20,7 +20,6 @@ import java.util.List;
 import org.apache.tapestry5.ComponentResources;
 import org.apache.tapestry5.ExceptionHandlerAssistant;
 import org.apache.tapestry5.SymbolConstants;
-import org.apache.tapestry5.commons.util.FormsRequirePostException;
 import org.apache.tapestry5.corelib.components.Form;
 import org.apache.tapestry5.services.ComponentSource;
 import org.apache.tapestry5.services.PageRenderLinkSource;
@@ -36,6 +35,7 @@ import org.apache.tapestry5.services.RequestExceptionHandler;
  * @see ExceptionHandlerAssistant
  * @see RequestExceptionHandler
  * @see SymbolConstants#PRODUCTION_MODE
+ * @since 5.8.3
  */
 public class FormsRequirePostExceptionHandlerAssistant implements 
ExceptionHandlerAssistant
 {
diff --git 
a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java 
b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
index b9fc36e16..6dd4039ac 100644
--- 
a/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
+++ 
b/tapestry-core/src/main/java/org/apache/tapestry5/modules/TapestryModule.java
@@ -107,7 +107,6 @@ import org.apache.tapestry5.commons.services.PropertyAccess;
 import org.apache.tapestry5.commons.services.TypeCoercer;
 import org.apache.tapestry5.commons.util.AvailableValues;
 import org.apache.tapestry5.commons.util.CollectionFactory;
-import org.apache.tapestry5.commons.util.FormsRequirePostException;
 import org.apache.tapestry5.commons.util.StrategyRegistry;
 import org.apache.tapestry5.corelib.components.BeanEditor;
 import org.apache.tapestry5.corelib.components.PropertyDisplay;
@@ -137,6 +136,7 @@ import org.apache.tapestry5.http.services.Session;
 import org.apache.tapestry5.internal.ComponentOverrideImpl;
 import org.apache.tapestry5.internal.DefaultNullFieldStrategy;
 import org.apache.tapestry5.internal.DefaultValueLabelProvider;
+import org.apache.tapestry5.internal.FormsRequirePostException;
 import org.apache.tapestry5.internal.FormsRequirePostExceptionHandlerAssistant;
 import org.apache.tapestry5.internal.InternalConstants;
 import org.apache.tapestry5.internal.InternalSymbols;
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/internal/FormsRequirePostExceptionHandlerAssistantTest.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/internal/FormsRequirePostExceptionHandlerAssistantTest.java
index 40e7df6df..63f2c9974 100644
--- 
a/tapestry-core/src/test/java/org/apache/tapestry5/internal/FormsRequirePostExceptionHandlerAssistantTest.java
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/internal/FormsRequirePostExceptionHandlerAssistantTest.java
@@ -17,7 +17,6 @@ package org.apache.tapestry5.internal;
 import java.io.IOException;
 
 import org.apache.tapestry5.ComponentResources;
-import org.apache.tapestry5.commons.util.FormsRequirePostException;
 import org.apache.tapestry5.http.Link;
 import org.apache.tapestry5.runtime.Component;
 import org.apache.tapestry5.services.ComponentSource;
@@ -27,8 +26,9 @@ import org.testng.annotations.Test;
 
 public class FormsRequirePostExceptionHandlerAssistantTest extends 
TapestryTestCase
 {
+    @SuppressWarnings("deprecation")
     @Test
-    public void foo()
+    public void test()
     {
         ComponentSource componentSource = newMock(ComponentSource.class);
         Component page = newMock(Component.class);
diff --git 
a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OperationTracker.java 
b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OperationTracker.java
index f6b0f2b5e..8fe88b0ab 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OperationTracker.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/OperationTracker.java
@@ -15,6 +15,10 @@
 package org.apache.tapestry5.ioc;
 
 import java.io.IOException;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
 
 /**
  * Used to track some set of operations in such a way that a failure (a thrown 
RuntimeException) will be logged along
@@ -55,4 +59,16 @@ public interface OperationTracker
      * @since 5.4
      */
     <T> T perform(String description, IOOperation<T> operation) throws 
IOException;
+    
+    /**
+     * Annotation to be be used in exception classes whose instances are not 
meant to be 
+     * logged in  {@linkplain OperationTracker}.
+     * @since 5.8.3
+     */
+    @Retention(RetentionPolicy.RUNTIME)
+    @Target(ElementType.TYPE)
+    public static @interface NonLoggableException 
+    {
+    }
+    
 }
diff --git 
a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java
 
b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java
index 1170548b5..3be7e55a5 100644
--- 
a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java
+++ 
b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java
@@ -16,7 +16,6 @@ package org.apache.tapestry5.ioc.internal;
 
 import org.apache.tapestry5.commons.util.CollectionFactory;
 import org.apache.tapestry5.commons.util.ExceptionUtils;
-import org.apache.tapestry5.commons.util.FormsRequirePostException;
 import org.apache.tapestry5.commons.util.Stack;
 import org.apache.tapestry5.ioc.IOOperation;
 import org.apache.tapestry5.ioc.Invokable;
@@ -132,7 +131,7 @@ public class OperationTrackerImpl implements 
OperationTracker
     private <T> T handleRuntimeException(RuntimeException ex)
     {
         // This is to prevent the error level log messages
-        if (ExceptionUtils.findCause(ex, FormsRequirePostException.class) != 
null)
+        if (ExceptionUtils.isAnnotationInStackTrace(ex, 
NonLoggableException.class))
             // pass through without logging
             throw ex;
         else

Reply via email to