Permalink
Browse files

mostly javac setup fixes for jdk9

  • Loading branch information...
1 parent 3754075 commit 9efebf1738805eb2c5a42bace2eaa571e2499db2 @blackdrag blackdrag committed Jul 16, 2016
View
@@ -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
@@ -25,11 +25,15 @@
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 @@ private static void addJavacError(String header, CompilationUnit cu, StringWrite
// 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 @@ private static void addJavacError(String header, CompilationUnit cu, StringWrite
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());
}
@@ -336,8 +336,11 @@ private static int getElementCode(ElementType value) {
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);
}
}
@@ -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[]
}
@@ -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[]
@@ -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 {
@@ -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"() {
@@ -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()
@@ -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,13 +211,20 @@ 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.
*
* @param sources the sources to be compiled
*/
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 {
@@ -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()

0 comments on commit 9efebf1

Please sign in to comment.