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 2018/03/22 17:07:01 UTC

groovy git commit: GROOVY-8494: Calling Stream.of from groovy class in JDK 9 fails

Repository: groovy
Updated Branches:
  refs/heads/GROOVY_2_4_X 44c9ee998 -> 00af138c0


GROOVY-8494: Calling Stream.of from groovy class in JDK 9 fails


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/00af138c
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/00af138c
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/00af138c

Branch: refs/heads/GROOVY_2_4_X
Commit: 00af138c0b0d6a9a06cf7f87d654ef7fb9505d60
Parents: 44c9ee9
Author: paulk <pa...@asert.com.au>
Authored: Fri Mar 23 03:06:24 2018 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Fri Mar 23 03:06:52 2018 +1000

----------------------------------------------------------------------
 build.gradle                                    |  4 +-
 .../groovy/vmplugin/VMPluginFactory.java        |  7 ++-
 .../org/codehaus/groovy/vmplugin/v8/Java8.java  | 37 +++++++++++++++
 .../v8/InterfaceStaticMethodCallTest.groovy     | 36 ---------------
 .../vm8/InterfaceStaticMethodCallTest.groovy    | 48 ++++++++++++++++++++
 5 files changed, 93 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/00af138c/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index 0341615..a1ac1df 100644
--- a/build.gradle
+++ b/build.gradle
@@ -148,7 +148,7 @@ configurations {
 
 ext {
     antVersion = '1.9.4'
-    asmVersion = '5.0.3'
+    asmVersion = '6.0'
     antlrVersion = '2.7.7'
     coberturaVersion = '1.9.4.1'
     commonsCliVersion = '1.2'
@@ -213,7 +213,7 @@ dependencies {
         exclude(module: 'asm')
         exclude(module: 'ant')
     }
-    tools "org.ow2.asm:asm-all:$asmVersion"
+    tools "org.ow2.asm:asm:$asmVersion"
     tools "com.thoughtworks.qdox:qdox:$qdoxVersion"
 
     examplesCompile project(':groovy-test')

http://git-wip-us.apache.org/repos/asf/groovy/blob/00af138c/src/main/org/codehaus/groovy/vmplugin/VMPluginFactory.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/vmplugin/VMPluginFactory.java b/src/main/org/codehaus/groovy/vmplugin/VMPluginFactory.java
index 127f65e..c9b36f6 100644
--- a/src/main/org/codehaus/groovy/vmplugin/VMPluginFactory.java
+++ b/src/main/org/codehaus/groovy/vmplugin/VMPluginFactory.java
@@ -29,15 +29,20 @@ public class VMPluginFactory {
     private static final String JDK5_CLASSNAME_CHECK = "java.lang.annotation.Annotation";
     private static final String JDK6_CLASSNAME_CHECK = "javax.script.ScriptEngine";
     private static final String JDK7_CLASSNAME_CHECK = "java.util.Objects";
+    private static final String JDK8_CLASSNAME_CHECK = "java.util.Optional";
 
     private static final String JDK5_PLUGIN_NAME = "org.codehaus.groovy.vmplugin.v5.Java5";
     private static final String JDK6_PLUGIN_NAME = "org.codehaus.groovy.vmplugin.v6.Java6";
     private static final String JDK7_PLUGIN_NAME = "org.codehaus.groovy.vmplugin.v7.Java7";
+    private static final String JDK8_PLUGIN_NAME = "org.codehaus.groovy.vmplugin.v8.Java8";
 
     private static VMPlugin plugin;
 
     static {
-        plugin = createPlugin(JDK7_CLASSNAME_CHECK, JDK7_PLUGIN_NAME);
+        plugin = createPlugin(JDK8_CLASSNAME_CHECK, JDK8_PLUGIN_NAME);
+        if (plugin == null) {
+            plugin = createPlugin(JDK7_CLASSNAME_CHECK, JDK7_PLUGIN_NAME);
+        }
         if (plugin == null) {
             // v6 plugin is the same as v5 but with some scripting stuff
             // so check below is good enough for now (can be true for JVM 5)

http://git-wip-us.apache.org/repos/asf/groovy/blob/00af138c/src/main/org/codehaus/groovy/vmplugin/v8/Java8.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/vmplugin/v8/Java8.java b/src/main/org/codehaus/groovy/vmplugin/v8/Java8.java
new file mode 100644
index 0000000..7a0142a
--- /dev/null
+++ b/src/main/org/codehaus/groovy/vmplugin/v8/Java8.java
@@ -0,0 +1,37 @@
+/*
+ *  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.vmplugin.v8;
+
+import org.codehaus.groovy.ast.AnnotationNode;
+import org.codehaus.groovy.vmplugin.v7.Java7;
+
+import java.lang.annotation.ElementType;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * No additional Java 8 based functionality in 2_4_X
+ */
+public class Java8 extends Java7 {
+    @Override
+    public int getVersion() {
+        return 8;
+    }
+}

http://git-wip-us.apache.org/repos/asf/groovy/blob/00af138c/src/test/org/codehaus/groovy/vmplugin/v8/InterfaceStaticMethodCallTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/vmplugin/v8/InterfaceStaticMethodCallTest.groovy b/src/test/org/codehaus/groovy/vmplugin/v8/InterfaceStaticMethodCallTest.groovy
deleted file mode 100644
index ee2c88c..0000000
--- a/src/test/org/codehaus/groovy/vmplugin/v8/InterfaceStaticMethodCallTest.groovy
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- *  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.vmplugin.v8
-
-import org.codehaus.groovy.vmplugin.VMPluginFactory
-
-class InterfaceStaticMethodCallTest extends GroovyTestCase {
-    void testStreamOf() {
-        if (VMPluginFactory.getPlugin().getVersion() < 8) {
-            return
-        }
-
-        // "of" is a static method declared on the interface, we only want to be sure we can call the method
-        assertScript '''
-            import java.util.stream.Stream
-
-            assert Stream.of("1") instanceof Stream
-        '''
-    }
-}

http://git-wip-us.apache.org/repos/asf/groovy/blob/00af138c/subprojects/tests-vm8/src/test/groovy/org/codehaus/groovy/runtime/vm8/InterfaceStaticMethodCallTest.groovy
----------------------------------------------------------------------
diff --git a/subprojects/tests-vm8/src/test/groovy/org/codehaus/groovy/runtime/vm8/InterfaceStaticMethodCallTest.groovy b/subprojects/tests-vm8/src/test/groovy/org/codehaus/groovy/runtime/vm8/InterfaceStaticMethodCallTest.groovy
new file mode 100644
index 0000000..6a62260
--- /dev/null
+++ b/subprojects/tests-vm8/src/test/groovy/org/codehaus/groovy/runtime/vm8/InterfaceStaticMethodCallTest.groovy
@@ -0,0 +1,48 @@
+/*
+ *  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.runtime.vm8
+
+class InterfaceStaticMethodCallTest extends GroovyTestCase {
+    void testStreamOf() {
+        // "of" is a static method declared on the interface, we only want to be sure we can call the method
+        assertScript '''
+            import java.util.stream.Stream
+            assert Stream.of("1") instanceof Stream
+        '''
+    }
+
+    // GROOVY-8494
+    void testComparatorNaturalOrder() {
+        assertScript '''
+            def no = Comparator.naturalOrder()
+            assert -1 == no.compare(42, 52)
+            assert  0 == no.compare(42, 42)
+            assert  1 == no.compare(42, 32)
+        '''
+    }
+
+    // GROOVY-8494
+    void testFunctionIdentity() {
+        assertScript '''
+            import java.util.function.Function
+            Function<Integer, Integer> function = Function.identity()
+            assert 42 == function.apply(42)
+        '''
+    }
+}