You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by bl...@apache.org on 2016/07/16 14:36:03 UTC

groovy git commit: mostly javac setup fixes for jdk9

Repository: groovy
Updated Branches:
  refs/heads/master 375407573 -> 9efebf173


mostly javac setup fixes for jdk9


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

Branch: refs/heads/master
Commit: 9efebf1738805eb2c5a42bace2eaa571e2499db2
Parents: 3754075
Author: Jochen Theodorou <bl...@gmx.org>
Authored: Sat Jul 16 16:28:07 2016 +0200
Committer: Jochen Theodorou <bl...@gmx.org>
Committed: Sat Jul 16 16:32:15 2016 +0200

----------------------------------------------------------------------
 gradle.properties                               |  3 +++
 .../groovy/tools/javac/JavacJavaCompiler.java   | 24 +++++++++++++++++---
 .../org/codehaus/groovy/vmplugin/v5/Java5.java  |  7 ++++--
 .../test/gdk/WorkingWithCollectionsTest.groovy  |  2 +-
 .../GroovyTestCaseExampleTests.groovy           |  2 +-
 src/test/groovy/bugs/Groovy5150Bug.groovy       |  9 ++++++++
 .../ast/decompiled/AsmDecompilerTest.groovy     |  8 +++++--
 .../m12n/ExtensionModuleHelperForTests.groovy   |  2 +-
 .../tools/stubgenerator/StubTestCase.groovy     |  9 ++++++++
 .../TransformsAndCustomClassLoadersTest.groovy  | 14 +++++++++++-
 10 files changed, 69 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/9efebf17/gradle.properties
----------------------------------------------------------------------
diff --git a/gradle.properties b/gradle.properties
index 3f96e55..c745a6f 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -29,6 +29,9 @@ groovycExamples_mx = 384m
 
 javaDoc_mx = 640m
 
+# jdk 9
+#org.gradle.jvmargs=-ea -Xmx1G
+# jdk 6-8
 org.gradle.jvmargs=-Xmx1G -XX:MaxPermSize=384m -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled
 
 # Property below not currently used for gradle build. It was used in the Ant build by forking a JVM instance using

http://git-wip-us.apache.org/repos/asf/groovy/blob/9efebf17/src/main/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java b/src/main/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
index 873b7e6..c300959 100644
--- a/src/main/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
+++ b/src/main/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
@@ -25,11 +25,15 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.lang.reflect.Method;
 import java.lang.reflect.InvocationTargetException;
+import java.security.AccessController;
+import java.security.CodeSource;
+import java.security.PrivilegedAction;
 import java.util.*;
 import java.net.URLClassLoader;
 import java.net.URL;
 import java.net.URISyntaxException;
 
+import groovy.lang.GroovyObject;
 import org.codehaus.groovy.control.CompilationUnit;
 import org.codehaus.groovy.control.CompilerConfiguration;
 import org.codehaus.groovy.control.messages.ExceptionMessage;
@@ -129,14 +133,13 @@ public class JavacJavaCompiler implements JavaCompiler {
         // append classpath if not already defined
         if (!hadClasspath) {
             // add all classpaths that compilation unit sees
-            StringBuilder resultPath = new StringBuilder(DefaultGroovyMethods.join((Iterable)config.getClasspath(), File.pathSeparator));
+            List<String> paths = new ArrayList<String>(config.getClasspath());
             ClassLoader cl = parentClassLoader;
             while (cl != null) {
                 if (cl instanceof URLClassLoader) {
                     for (URL u : ((URLClassLoader) cl).getURLs()) {
                         try {
-                            resultPath.append(File.pathSeparator);
-                            resultPath.append(new File(u.toURI()).getPath());
+                            paths.add(new File(u.toURI()).getPath());
                         } catch (URISyntaxException e) {
                             // ignore it
                         }
@@ -145,6 +148,21 @@ public class JavacJavaCompiler implements JavaCompiler {
                 cl = cl.getParent();
             }
 
+            try {
+                CodeSource codeSource =AccessController.doPrivileged(new PrivilegedAction<CodeSource>() {
+                    @Override
+                    public CodeSource run() {
+                        return GroovyObject.class.getProtectionDomain().getCodeSource();
+                    }
+                });
+                if (codeSource != null) {
+                    paths.add(new File(codeSource.getLocation().toURI()).getPath());
+                }
+            } catch (URISyntaxException e) {
+                // ignore it
+            }
+
+            StringBuilder resultPath = new StringBuilder(DefaultGroovyMethods.join((Iterable) paths, File.pathSeparator));
             paras.add("-classpath");
             paras.add(resultPath.toString());
         }

http://git-wip-us.apache.org/repos/asf/groovy/blob/9efebf17/src/main/org/codehaus/groovy/vmplugin/v5/Java5.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/vmplugin/v5/Java5.java b/src/main/org/codehaus/groovy/vmplugin/v5/Java5.java
index 17d7794..9e4ccc9 100644
--- a/src/main/org/codehaus/groovy/vmplugin/v5/Java5.java
+++ b/src/main/org/codehaus/groovy/vmplugin/v5/Java5.java
@@ -336,8 +336,11 @@ public class Java5 implements VMPlugin {
                 return AnnotationNode.ANNOTATION_TARGET;
             case PACKAGE:
                 return AnnotationNode.PACKAGE_TARGET;
-            default:
-                throw new GroovyBugError("unsupported Target " + value);
+        }
+        if ("MODULE".equals(value.name())) {
+            return AnnotationNode.TYPE_TARGET;
+        } else {
+            throw new GroovyBugError("unsupported Target " + value);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/9efebf17/src/spec/test/gdk/WorkingWithCollectionsTest.groovy
----------------------------------------------------------------------
diff --git a/src/spec/test/gdk/WorkingWithCollectionsTest.groovy b/src/spec/test/gdk/WorkingWithCollectionsTest.groovy
index 5d22dd8..9dc1ff3 100644
--- a/src/spec/test/gdk/WorkingWithCollectionsTest.groovy
+++ b/src/spec/test/gdk/WorkingWithCollectionsTest.groovy
@@ -61,7 +61,7 @@ class WorkingWithCollectionsTest extends GroovyTestCase {
             [1, 2, 3, 4, 5].get(-2)                 // but negative index not allowed with get()
             assert false
         } catch (e) {
-            assert e instanceof ArrayIndexOutOfBoundsException
+            assert e instanceof IndexOutOfBoundsException
         }
         // end::list_usecases[]
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/9efebf17/src/spec/test/testingguide/GroovyTestCaseExampleTests.groovy
----------------------------------------------------------------------
diff --git a/src/spec/test/testingguide/GroovyTestCaseExampleTests.groovy b/src/spec/test/testingguide/GroovyTestCaseExampleTests.groovy
index c1d1fd1..5db90a8 100644
--- a/src/spec/test/testingguide/GroovyTestCaseExampleTests.groovy
+++ b/src/spec/test/testingguide/GroovyTestCaseExampleTests.groovy
@@ -81,7 +81,7 @@ class MyTestCase extends GroovyTestCase {
         def msg = shouldFail IndexOutOfBoundsException, {
             numbers.get(4)
         }
-        assert msg.contains('Index: 4, Size: 4')
+        assert msg.contains('Index: 4, Size: 4') || msg.contains('Index 4 out-of-bounds for length 4')
     }
     // end::should_fail_with_msg[]
 

http://git-wip-us.apache.org/repos/asf/groovy/blob/9efebf17/src/test/groovy/bugs/Groovy5150Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy5150Bug.groovy b/src/test/groovy/bugs/Groovy5150Bug.groovy
index 3195b0c..0a676d3 100644
--- a/src/test/groovy/bugs/Groovy5150Bug.groovy
+++ b/src/test/groovy/bugs/Groovy5150Bug.groovy
@@ -18,6 +18,7 @@
  */
 package groovy.bugs
 
+import junit.framework.TestCase
 import org.codehaus.groovy.control.CompilerConfiguration
 import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
 
@@ -47,6 +48,7 @@ class Groovy5150Bug extends GroovyTestCase {
             }
         '''
             def loader = new GroovyClassLoader(this.class.classLoader)
+            addToClassPath(loader)
             def cu = new JavaAwareCompilationUnit(config, loader)
             cu.addSources([b] as File[])
             cu.compile()
@@ -84,6 +86,7 @@ class Groovy5150Bug extends GroovyTestCase {
             }
         '''
             def loader = new GroovyClassLoader(this.class.classLoader)
+            addToClassPath(loader)
             def cu = new JavaAwareCompilationUnit(config, loader)
             cu.addSources([a,b] as File[])
             cu.compile()
@@ -94,6 +97,12 @@ class Groovy5150Bug extends GroovyTestCase {
         }
     }
 
+    static addToClassPath(GroovyClassLoader loader) {
+        loader.addURL(this.getProtectionDomain().getCodeSource().getLocation())
+        loader.addURL(GroovyTestCase.class.getProtectionDomain().getCodeSource().getLocation())
+        loader.addURL(TestCase.class.getProtectionDomain().getCodeSource().getLocation())
+    }
+
     void testShouldAllowCharConstantInSwitchWithoutStubs() {
         def config = new CompilerConfiguration()
         config.with {

http://git-wip-us.apache.org/repos/asf/groovy/blob/9efebf17/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTest.groovy b/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTest.groovy
index bec2b6d..7a27998 100644
--- a/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTest.groovy
+++ b/src/test/org/codehaus/groovy/ast/decompiled/AsmDecompilerTest.groovy
@@ -201,8 +201,10 @@ class AsmDecompilerTest extends TestCase {
         assert !anno.isTargetAllowed(AnnotationNode.LOCAL_VARIABLE_TARGET)
     }
 
+    public static enum TestEnum { SOURCE, CLASS, RUNTIME }
+
     void "test enum field"() {
-        def node = decompile(RetentionPolicy.name).plainNodeReference
+        def node = decompile(TestEnum.name).plainNodeReference
         for (s in ['SOURCE', 'CLASS', 'RUNTIME']) {
             def field = node.getDeclaredField(s)
             assert field
@@ -276,8 +278,10 @@ class AsmDecompilerTest extends TestCase {
         assert field.type.toString() == 'V -> java.lang.RuntimeException'
     }
 
+    public static class SomeInnerclass{}
+
     void "test static inner class"() {
-        assert (decompile(Attributes.Name.name).modifiers & Opcodes.ACC_STATIC) != 0
+        assert (decompile(SomeInnerclass.name).modifiers & Opcodes.ACC_STATIC) != 0
     }
 
     void "test static inner with dollar"() {

http://git-wip-us.apache.org/repos/asf/groovy/blob/9efebf17/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
index b2cb542..1cdeb7a 100644
--- a/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
+++ b/src/test/org/codehaus/groovy/runtime/m12n/ExtensionModuleHelperForTests.groovy
@@ -44,7 +44,7 @@ public class ExtensionModuleHelperForTests {
                 throw new RuntimeException("Unable to find class loader")
             }
         }
-        Set<String> cp = ((URLClassLoader)cl).URLs.collect{ new File(it.toURI()).absolutePath}
+        Set<String> cp = System.getProperty("java.class.path").split(File.pathSeparator) as Set
         cp << baseDir.absolutePath
 
         def ant = new AntBuilder()

http://git-wip-us.apache.org/repos/asf/groovy/blob/9efebf17/src/test/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy b/src/test/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy
index 31d7c18..2ecbef5 100644
--- a/src/test/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy
+++ b/src/test/org/codehaus/groovy/tools/stubgenerator/StubTestCase.groovy
@@ -18,6 +18,8 @@
  */
 package org.codehaus.groovy.tools.stubgenerator
 
+import junit.framework.TestCase
+
 import static groovy.io.FileType.*
 
 import org.codehaus.groovy.control.CompilerConfiguration
@@ -209,6 +211,12 @@ abstract class StubTestCase extends GroovyTestCase {
         return sources
     }
 
+    private static addToClassPath(GroovyClassLoader loader) {
+        loader.addURL(this.getProtectionDomain().getCodeSource().getLocation())
+        loader.addURL(GroovyTestCase.class.getProtectionDomain().getCodeSource().getLocation())
+        loader.addURL(TestCase.class.getProtectionDomain().getCodeSource().getLocation())
+    }
+
     /**
      * Launch the actual compilation -- hence launching the stub generator as well.
      *
@@ -216,6 +224,7 @@ abstract class StubTestCase extends GroovyTestCase {
      */
     protected void compile(List<File> sources) {
         loader = new GroovyClassLoader(this.class.classLoader)
+        addToClassPath(loader)
         def cu = new JavaAwareCompilationUnit(config, loader)
         cu.addSources(sources as File[])
         try {

http://git-wip-us.apache.org/repos/asf/groovy/blob/9efebf17/src/test/org/codehaus/groovy/transform/classloading/TransformsAndCustomClassLoadersTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/transform/classloading/TransformsAndCustomClassLoadersTest.groovy b/src/test/org/codehaus/groovy/transform/classloading/TransformsAndCustomClassLoadersTest.groovy
index 72e3337..66bf434 100644
--- a/src/test/org/codehaus/groovy/transform/classloading/TransformsAndCustomClassLoadersTest.groovy
+++ b/src/test/org/codehaus/groovy/transform/classloading/TransformsAndCustomClassLoadersTest.groovy
@@ -18,6 +18,7 @@
  */
 package org.codehaus.groovy.transform.classloading
 
+import junit.framework.TestCase
 import org.codehaus.groovy.ast.ASTNode
 import org.codehaus.groovy.ast.ModuleNode
 import org.codehaus.groovy.ast.ClassNode
@@ -28,6 +29,7 @@ import org.codehaus.groovy.transform.GroovyASTTransformationClass
 import org.codehaus.groovy.transform.ASTTransformation
 import org.codehaus.groovy.transform.GroovyASTTransformation
 import org.codehaus.groovy.transform.GlobalTestTransformClassLoader
+import org.objectweb.asm.ClassVisitor
 
 import java.lang.annotation.Retention
 import java.lang.annotation.RetentionPolicy
@@ -42,10 +44,20 @@ import java.lang.annotation.ElementType
  * @author Peter Niederwieser
  */
 class TransformsAndCustomClassLoadersTest extends GroovyTestCase {
-    URL[] urls = collectUrls(getClass().classLoader)
+    URL[] urls = collectUrls(getClass().classLoader) + addGroovyUrls()
     GroovyClassLoader dependencyLoader = new GroovyClassLoader(new URLClassLoader(urls, (ClassLoader)null))
     GroovyClassLoader transformLoader = new GroovyClassLoader(new URLClassLoader(urls, new GroovyOnlyClassLoader()))
 
+    private static addGroovyUrls() {
+       [
+           GroovyObject.class.protectionDomain.codeSource.location.toURI().toURL(),    // load Groovy runtime
+           ClassVisitor.class.protectionDomain.codeSource.location.toURI().toURL(),    // load asm
+           GroovyTestCase.class.protectionDomain.codeSource.location.toURI().toURL(),  // load Groovy test module
+           TestCase.class.protectionDomain.codeSource.location.toURI().toURL(),        // -"-
+           this.protectionDomain.codeSource.location.toURI().toURL(),                  // load test as well
+       ]
+    }
+
     void setUp() {
         assert dependencyLoader.loadClass(CompilationUnit.class.name) != CompilationUnit
         assert dependencyLoader.loadClass(getClass().name) != getClass()