You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/03/31 13:44:14 UTC

[groovy] branch GROOVY_2_5_X updated (8016bb0 -> 5c3159f)

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

paulk pushed a change to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from 8016bb0  fix some tests for JDK12
     new ba71131  GROOVY-9061: Tests containing @Grab statements within nested scripts fail in JDK12
     new 5c3159f  fix test for JDK12

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../groovy/reflection/ReflectionUtils.java         | 281 +++++++++++----------
 .../groovy/ast/tools/WideningCategoriesTest.groovy |  14 +-
 2 files changed, 148 insertions(+), 147 deletions(-)


[groovy] 02/02: fix test for JDK12

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 5c3159fac63de793ae8e2f2c17c022d747c6dac8
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Mar 31 23:39:34 2019 +1000

    fix test for JDK12
---
 .../groovy/ast/tools/WideningCategoriesTest.groovy         | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/test/org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy b/src/test/org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy
index 28ba1de..63b72d6 100644
--- a/src/test/org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy
+++ b/src/test/org/codehaus/groovy/ast/tools/WideningCategoriesTest.groovy
@@ -91,7 +91,7 @@ class WideningCategoriesTest extends GenericsTestCase {
     void testBuildCommonTypeWithTwoClassesWithoutSuperClass() {
         ClassNode a = make(ClassA)
         ClassNode b = make(ClassB)
-        assert lowestUpperBound(a,b) == make(GroovyObject) // GroovyObject because Groovy classes implicitely implement GroovyObject
+        assert lowestUpperBound(a,b) == make(GroovyObject) // GroovyObject because Groovy classes implicitly implement GroovyObject
         assert lowestUpperBound(b,a) == make(GroovyObject)
     }
 
@@ -213,7 +213,7 @@ class WideningCategoriesTest extends GenericsTestCase {
         assert lub.genericsTypes.length == 1
         assert lub.genericsTypes[0].wildcard
         assert lub.genericsTypes[0].upperBounds[0].superClass == Number_TYPE
-        assert lub.genericsTypes[0].upperBounds[0].interfaces == [ make(Comparable) ]
+        assert make(Comparable) in lub.genericsTypes[0].upperBounds[0].interfaces
     }
 
     void testLUBWithTwoInterfacesAndSingleCommonInterface() {
@@ -242,7 +242,7 @@ class WideningCategoriesTest extends GenericsTestCase {
     void testLUBWithTwoArgumentTypesSharingOneInterfaceNotImplementedBySuperClass() {
         // BottomA extends Top implements Serializable
         // BottomB extends Top implements Serializable
-        // Top does not implement Serialiazable
+        // Top does not implement Serializable
         ClassNode a = extractTypesFromCode('List<org.codehaus.groovy.ast.tools.WideningCategoriesTest.BottomA> type').type
         ClassNode b = extractTypesFromCode('List<org.codehaus.groovy.ast.tools.WideningCategoriesTest.BottomB> type').type
         ClassNode lub = lowestUpperBound(a,b)
@@ -258,7 +258,7 @@ class WideningCategoriesTest extends GenericsTestCase {
     void testLUBWithTwoParameterizedTypesSharingOneInterfaceNotImplementedBySuperClass() {
         // PTopInt extends PTop<Integer> implements Serializable
         // PTopLong extends PTop<Long> implements Serializable
-        // PTop<E> does not implement Serialiazable
+        // PTop<E> does not implement Serializable
         ClassNode a = extractTypesFromCode('org.codehaus.groovy.ast.tools.WideningCategoriesTest.PTopInt type').type
         ClassNode b = extractTypesFromCode('org.codehaus.groovy.ast.tools.WideningCategoriesTest.PTopLong type').type
         ClassNode lub = lowestUpperBound(a,b)
@@ -324,9 +324,9 @@ class WideningCategoriesTest extends GenericsTestCase {
         def type = superType.genericsTypes[0]
         assert type.wildcard
         assert type.upperBounds[0] instanceof LowestUpperBoundClassNode
-        assert type.upperBounds[0].interfaces as Set == [make(Serializable), make(Comparable)] as Set
-
-
+        [Comparable, Serializable].each {
+            assert make(it) in type.upperBounds[0].interfaces
+        }
     }
 
     void testLUBOfArrayTypes() {


[groovy] 01/02: GROOVY-9061: Tests containing @Grab statements within nested scripts fail in JDK12

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit ba71131b75a1c54a2c949156a1cfbffeb213ebb5
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sun Mar 31 22:55:40 2019 +1000

    GROOVY-9061: Tests containing @Grab statements within nested scripts fail in JDK12
---
 .../groovy/reflection/ReflectionUtils.java         | 281 +++++++++++----------
 1 file changed, 141 insertions(+), 140 deletions(-)

diff --git a/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java b/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
index e621729..a4fd735 100644
--- a/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
+++ b/src/main/java/org/codehaus/groovy/reflection/ReflectionUtils.java
@@ -1,140 +1,141 @@
-/*
- *  Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you 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.codehaus.groovy.reflection;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * This class contains utility methods to determine which class called the
- * current class to multiple levels of depth.  Calls used to handle the
- * groovy MOP are excluded from the level counting.
- */
-public class ReflectionUtils {
-
-    // these are packages in the call stack that are only part of the groovy MOP
-    private static final Set<String> IGNORED_PACKAGES = new HashSet<String>();
-
-    static {
-        //IGNORED_PACKAGES.add("java.lang.reflect");
-        IGNORED_PACKAGES.add("groovy.lang");
-        IGNORED_PACKAGES.add("org.codehaus.groovy.reflection");
-        IGNORED_PACKAGES.add("org.codehaus.groovy.runtime.callsite");
-        IGNORED_PACKAGES.add("org.codehaus.groovy.runtime.metaclass");
-        IGNORED_PACKAGES.add("org.codehaus.groovy.runtime");
-        IGNORED_PACKAGES.add("sun.reflect");
-        IGNORED_PACKAGES.add("java.lang.invoke");
-        IGNORED_PACKAGES.add("org.codehaus.groovy.vmplugin.v7");
-    }
-
-    private static final ClassContextHelper HELPER = new ClassContextHelper();
-
-    /**
-     * Determine whether or not the getCallingClass methods will return
-     * any sensible results.  On JVMs that are not Sun derived i.e.
-     * (gcj, Harmony) this will likely return false.  When not available
-     * all getCallingClass methods will return null.
-     *
-     * @return true if getCallingClass can return anything but null, false if
-     *         it will only return null.
-     */
-    public static boolean isCallingClassReflectionAvailable() {
-        return true;
-    }
-
-    /**
-     * Get the immediate calling class, ignoring MOP frames.
-     *
-     * @return The Class of the caller
-     */
-    public static Class getCallingClass() {
-        return getCallingClass(1);
-    }
-
-    /**
-     * Get the called that is matchLevel stack frames before the call,
-     * ignoring MOP frames.
-     *
-     * @param matchLevel how may call stacks down to look.
-     *                   If it is less than 1 it is treated as though it was 1.
-     * @return The Class of the matched caller, or null if there aren't
-     *         enough stackframes to satisfy matchLevel
-     */
-    public static Class getCallingClass(int matchLevel) {
-        return getCallingClass(matchLevel, Collections.EMPTY_SET);
-    }
-
-    /**
-     * Get the called that is matchLevel stack frames before the call,
-     * ignoring MOP frames and desired exclude packages.
-     *
-     * @param matchLevel           how may call stacks down to look.
-     *                             If it is less than 1 it is treated as though it was 1.
-     * @param extraIgnoredPackages A collection of string names of packages to exclude
-     *                             in addition to the MOP packages when counting stack frames.
-     * @return The Class of the matched caller, or null if there aren't
-     *         enough stackframes to satisfy matchLevel
-     */
-    public static Class getCallingClass(int matchLevel, Collection<String> extraIgnoredPackages) {
-        Class[] classContext = HELPER.getClassContext();
-
-        int depth = 0;
-        try {
-            Class c;
-            // this super class stuff is for Java 1.4 support only
-            // it isn't needed on a 5.0 VM
-            Class sc;
-            do {
-                do {
-                    c = classContext[depth++];
-                    if (c != null) {
-                        sc = c.getSuperclass();
-                    } else {
-                        sc = null;
-                    }
-                } while (classShouldBeIgnored(c, extraIgnoredPackages)
-                        || superClassShouldBeIgnored(sc));
-            } while (c != null && matchLevel-- > 0 && depth<classContext.length);
-            return c;
-        } catch (Throwable t) {
-            return null;
-        }
-    }
-
-    private static boolean superClassShouldBeIgnored(Class sc) {
-        return ((sc != null) && (sc.getPackage() != null) && "org.codehaus.groovy.runtime.callsite".equals(sc.getPackage().getName()));
-    }
-
-    private static boolean classShouldBeIgnored(Class c, Collection<String> extraIgnoredPackages) {
-        return ((c != null)
-                && (c.isSynthetic()
-                    || (c.getPackage() != null
-                        && (IGNORED_PACKAGES.contains(c.getPackage().getName())
-                          || extraIgnoredPackages.contains(c.getPackage().getName())))));
-    }
-
-    private static class ClassContextHelper extends SecurityManager {
-        @Override
-        public Class[] getClassContext() {
-            return super.getClassContext();
-        }
-    }
-}
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.codehaus.groovy.reflection;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * This class contains utility methods to determine which class called the
+ * current class to multiple levels of depth.  Calls used to handle the
+ * groovy MOP are excluded from the level counting.
+ */
+public class ReflectionUtils {
+
+    // these are packages in the call stack that are only part of the groovy MOP
+    private static final Set<String> IGNORED_PACKAGES = new HashSet<String>();
+
+    static {
+        //IGNORED_PACKAGES.add("java.lang.reflect");
+        IGNORED_PACKAGES.add("groovy.lang");
+        IGNORED_PACKAGES.add("org.codehaus.groovy.reflection");
+        IGNORED_PACKAGES.add("org.codehaus.groovy.runtime.callsite");
+        IGNORED_PACKAGES.add("org.codehaus.groovy.runtime.metaclass");
+        IGNORED_PACKAGES.add("org.codehaus.groovy.runtime");
+        IGNORED_PACKAGES.add("sun.reflect");
+        IGNORED_PACKAGES.add("java.security");
+        IGNORED_PACKAGES.add("java.lang.invoke");
+        IGNORED_PACKAGES.add("org.codehaus.groovy.vmplugin.v7");
+    }
+
+    private static final ClassContextHelper HELPER = new ClassContextHelper();
+
+    /**
+     * Determine whether or not the getCallingClass methods will return
+     * any sensible results.  On JVMs that are not Sun derived i.e.
+     * (gcj, Harmony) this will likely return false.  When not available
+     * all getCallingClass methods will return null.
+     *
+     * @return true if getCallingClass can return anything but null, false if
+     *         it will only return null.
+     */
+    public static boolean isCallingClassReflectionAvailable() {
+        return true;
+    }
+
+    /**
+     * Get the immediate calling class, ignoring MOP frames.
+     *
+     * @return The Class of the caller
+     */
+    public static Class getCallingClass() {
+        return getCallingClass(1);
+    }
+
+    /**
+     * Get the called that is matchLevel stack frames before the call,
+     * ignoring MOP frames.
+     *
+     * @param matchLevel how may call stacks down to look.
+     *                   If it is less than 1 it is treated as though it was 1.
+     * @return The Class of the matched caller, or null if there aren't
+     *         enough stackframes to satisfy matchLevel
+     */
+    public static Class getCallingClass(int matchLevel) {
+        return getCallingClass(matchLevel, Collections.EMPTY_SET);
+    }
+
+    /**
+     * Get the called that is matchLevel stack frames before the call,
+     * ignoring MOP frames and desired exclude packages.
+     *
+     * @param matchLevel           how may call stacks down to look.
+     *                             If it is less than 1 it is treated as though it was 1.
+     * @param extraIgnoredPackages A collection of string names of packages to exclude
+     *                             in addition to the MOP packages when counting stack frames.
+     * @return The Class of the matched caller, or null if there aren't
+     *         enough stackframes to satisfy matchLevel
+     */
+    public static Class getCallingClass(int matchLevel, Collection<String> extraIgnoredPackages) {
+        Class[] classContext = HELPER.getClassContext();
+
+        int depth = 0;
+        try {
+            Class c;
+            // this super class stuff is for Java 1.4 support only
+            // it isn't needed on a 5.0 VM
+            Class sc;
+            do {
+                do {
+                    c = classContext[depth++];
+                    if (c != null) {
+                        sc = c.getSuperclass();
+                    } else {
+                        sc = null;
+                    }
+                } while (classShouldBeIgnored(c, extraIgnoredPackages)
+                        || superClassShouldBeIgnored(sc));
+            } while (c != null && matchLevel-- > 0 && depth<classContext.length);
+            return c;
+        } catch (Throwable t) {
+            return null;
+        }
+    }
+
+    private static boolean superClassShouldBeIgnored(Class sc) {
+        return ((sc != null) && (sc.getPackage() != null) && "org.codehaus.groovy.runtime.callsite".equals(sc.getPackage().getName()));
+    }
+
+    private static boolean classShouldBeIgnored(Class c, Collection<String> extraIgnoredPackages) {
+        return ((c != null)
+                && (c.isSynthetic()
+                    || (c.getPackage() != null
+                        && (IGNORED_PACKAGES.contains(c.getPackage().getName())
+                          || extraIgnoredPackages.contains(c.getPackage().getName())))));
+    }
+
+    private static class ClassContextHelper extends SecurityManager {
+        @Override
+        public Class[] getClassContext() {
+            return super.getClassContext();
+        }
+    }
+}