You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by th...@apache.org on 2022/02/05 19:35:55 UTC

[tapestry-5] 01/02: TAP5-2700: allowing module classes written in Groovy again

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

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

commit 64f3fb46c41a98b6000d1bbe94d9f972e14578cd
Author: Thiago H. de Paula Figueiredo <th...@arsmachina.com.br>
AuthorDate: Sat Feb 5 16:31:55 2022 -0300

    TAP5-2700: allowing module classes written in Groovy again
    
    This fixes GridSymbolDemoTests
---
 .../ioc/internal/DefaultModuleDefImpl.java         | 67 +++++++++++++++++-----
 1 file changed, 52 insertions(+), 15 deletions(-)

diff --git a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
index adbd8e0..b444a69 100644
--- a/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
+++ b/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/DefaultModuleDefImpl.java
@@ -14,7 +14,22 @@
 
 package org.apache.tapestry5.ioc.internal;
 
-import org.apache.tapestry5.commons.*;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tapestry5.commons.Configuration;
+import org.apache.tapestry5.commons.MappedConfiguration;
+import org.apache.tapestry5.commons.ObjectCreator;
+import org.apache.tapestry5.commons.OrderedConfiguration;
 import org.apache.tapestry5.commons.internal.util.TapestryException;
 import org.apache.tapestry5.commons.services.PlasticProxyFactory;
 import org.apache.tapestry5.commons.util.CollectionFactory;
@@ -26,23 +41,26 @@ import org.apache.tapestry5.ioc.MethodAdviceReceiver;
 import org.apache.tapestry5.ioc.ScopeConstants;
 import org.apache.tapestry5.ioc.ServiceBinder;
 import org.apache.tapestry5.ioc.ServiceBuilderResources;
-import org.apache.tapestry5.ioc.annotations.*;
-import org.apache.tapestry5.ioc.def.*;
+import org.apache.tapestry5.ioc.annotations.Advise;
+import org.apache.tapestry5.ioc.annotations.Contribute;
+import org.apache.tapestry5.ioc.annotations.Decorate;
+import org.apache.tapestry5.ioc.annotations.EagerLoad;
+import org.apache.tapestry5.ioc.annotations.Marker;
+import org.apache.tapestry5.ioc.annotations.Match;
+import org.apache.tapestry5.ioc.annotations.Optional;
+import org.apache.tapestry5.ioc.annotations.Order;
+import org.apache.tapestry5.ioc.annotations.PreventServiceDecoration;
+import org.apache.tapestry5.ioc.annotations.Scope;
+import org.apache.tapestry5.ioc.annotations.Startup;
+import org.apache.tapestry5.ioc.def.ContributionDef;
+import org.apache.tapestry5.ioc.def.ContributionDef3;
+import org.apache.tapestry5.ioc.def.DecoratorDef;
+import org.apache.tapestry5.ioc.def.ModuleDef2;
+import org.apache.tapestry5.ioc.def.ServiceDef;
+import org.apache.tapestry5.ioc.def.StartupDef;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.slf4j.Logger;
 
-import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
 /**
  * Starting from the Class for a module, identifies all the services (service builder methods),
  * decorators (service
@@ -157,6 +175,7 @@ public class DefaultModuleDefImpl implements ModuleDef2, ServiceDefAccumulator
         }
 
         removeSyntheticMethods(methods);
+        removeGroovyObjectMethods(methods);
 
         boolean modulePreventsServiceDecoration = moduleClass.getAnnotation(PreventServiceDecoration.class) != null;
 
@@ -215,6 +234,24 @@ public class DefaultModuleDefImpl implements ModuleDef2, ServiceDefAccumulator
     {
         return serviceDefs.get(serviceId);
     }
+    
+    private void removeGroovyObjectMethods(Set<Method> methods)
+    {
+        Iterator<Method> iterator = methods.iterator();
+
+        while (iterator.hasNext())
+        {
+            Method m = iterator.next();
+            final String name = m.getName();
+
+            if (m.getDeclaringClass().getName().equals("groovy.lang.GroovyObject")
+                    || (name.equals("getMetaClass") && m.getReturnType().getName().equals("groovy.lang.MetaClass"))
+                || (m.getParameterCount() == 1 && m.getParameterTypes()[0].getName().equals("groovy.lang.MetaClass")))
+            {
+                iterator.remove();
+            }
+        }
+    }
 
     private void removeSyntheticMethods(Set<Method> methods)
     {