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 2020/05/16 09:14:28 UTC

[groovy] branch master updated (767cd44 -> e5e9a0f)

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

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


    from 767cd44  Update README.adoc (closes #1247)
     new d1a02a6  GROOVY-9556: Stub generated without the effect of AST transformation makes joint compilation fail (closes #1248)
     new e5e9a0f  GROOVY-9506: Joint compilation is broken (add test case)

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:
 .../tools/javac/JavaAwareCompilationUnit.java      |  1 +
 .../groovy/tools/javac/JavacJavaCompiler.java      | 16 ++++++
 .../bugs/{Groovy9245.groovy => Groovy9556.groovy}  | 62 +++++++++++++---------
 ...vy => AutoImplementWithJointCompilation.groovy} | 29 +++++-----
 4 files changed, 71 insertions(+), 37 deletions(-)
 copy src/test/groovy/bugs/{Groovy9245.groovy => Groovy9556.groovy} (54%)
 copy src/test/org/codehaus/groovy/tools/stubgenerator/{VarargsMethodParamsStubTest.groovy => AutoImplementWithJointCompilation.groovy} (58%)


[groovy] 01/02: GROOVY-9556: Stub generated without the effect of AST transformation makes joint compilation fail (closes #1248)

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

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

commit d1a02a6713ae21c49b867a638b0632eae7bf8a57
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat May 16 16:13:45 2020 +0800

    GROOVY-9556: Stub generated without the effect of AST transformation makes joint compilation fail (closes #1248)
---
 .../tools/javac/JavaAwareCompilationUnit.java      |  1 +
 .../groovy/tools/javac/JavacJavaCompiler.java      | 16 +++++
 src/test/groovy/bugs/Groovy9556.groovy             | 84 ++++++++++++++++++++++
 3 files changed, 101 insertions(+)

diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavaAwareCompilationUnit.java b/src/main/java/org/codehaus/groovy/tools/javac/JavaAwareCompilationUnit.java
index d2b7800..cce5faf 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaAwareCompilationUnit.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaAwareCompilationUnit.java
@@ -74,6 +74,7 @@ public class JavaAwareCompilationUnit extends CompilationUnit {
             Object memStub = options.get(CompilerConfiguration.MEM_STUB);
             if (memStub == null) {
                 memStub = SystemUtil.getSystemPropertySafe("groovy.generate.stub.in.memory", "false");
+                options.put(CompilerConfiguration.MEM_STUB, Boolean.parseBoolean((String) memStub));
             }
 
             this.keepStubs = Boolean.TRUE.equals(options.get("keepStubs"));
diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java b/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
index cb35ad2..a31fe2d 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavacJavaCompiler.java
@@ -21,6 +21,7 @@ package org.codehaus.groovy.tools.javac;
 import groovy.lang.GroovyClassLoader;
 import groovy.lang.GroovyObject;
 import org.apache.groovy.io.StringBuilderWriter;
+import org.codehaus.groovy.GroovyBugError;
 import org.codehaus.groovy.control.CompilationUnit;
 import org.codehaus.groovy.control.CompilerConfiguration;
 import org.codehaus.groovy.control.messages.ExceptionMessage;
@@ -38,6 +39,7 @@ import java.security.CodeSource;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -93,6 +95,20 @@ public class JavacJavaCompiler implements JavaCompiler {
         try (javax.tools.StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, DEFAULT_LOCALE, charset)) {
             Set<javax.tools.JavaFileObject> compilationUnitSet = cu.getJavaCompilationUnitSet(); // java stubs already added
 
+            Map<String, Object> options = this.config.getJointCompilationOptions();
+            if (!Boolean.parseBoolean(options.get(CompilerConfiguration.MEM_STUB).toString())) {
+                // clear the java stubs in the source set of Java compilation
+                compilationUnitSet = new HashSet<>();
+
+                // use sourcepath to specify the root directory of java stubs
+                javacParameters.add("-sourcepath");
+                final File stubDir = (File) options.get("stubDir");
+                if (null == stubDir) {
+                    throw new GroovyBugError("stubDir is not specified");
+                }
+                javacParameters.add(stubDir.getAbsolutePath());
+            }
+
             // add java source files to compile
             fileManager.getJavaFileObjectsFromFiles(
                     files.stream().map(File::new).collect(Collectors.toList())
diff --git a/src/test/groovy/bugs/Groovy9556.groovy b/src/test/groovy/bugs/Groovy9556.groovy
new file mode 100644
index 0000000..978c1d6
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy9556.groovy
@@ -0,0 +1,84 @@
+/*
+ *  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 groovy.bugs
+
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
+import org.junit.Test
+
+final class Groovy9556 {
+// .\gradlew --no-daemon --max-workers 2 :test --tests groovy.bugs.Groovy9556 --debug-jvm
+    @Test
+    void testInheritConstructors() {
+        def config = new CompilerConfiguration(
+            targetDirectory: File.createTempDir(),
+            jointCompilationOptions: [memStub: false]
+        )
+
+        def parentDir = File.createTempDir()
+        config.jointCompilationOptions.stubDir = parentDir
+
+        try {
+            def a = new File(parentDir, 'CreateSignatureBase.java')
+            a.write '''
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+
+public abstract class CreateSignatureBase implements SignatureInterface
+{
+    public CreateSignatureBase(KeyStore keystore, char[] pin)
+            throws KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, IOException, CertificateException
+    { }
+    @Override
+    public byte[] sign(InputStream content) throws IOException
+    {
+        return null;
+    }
+}
+
+interface SignatureInterface {
+    byte[] sign(InputStream content) throws IOException;
+}
+            '''
+            def b = new File(parentDir, 'B.groovy')
+            b.write '''
+import groovy.transform.*
+
+@InheritConstructors class CreateSignature extends CreateSignatureBase {
+    void signPDF(String pdDocument, String out) {
+
+    }
+}
+            '''
+
+            def loader = new GroovyClassLoader(this.class.classLoader)
+            def cu = new JavaAwareCompilationUnit(config, loader)
+            cu.addSources(a, b)
+            cu.compile()
+        } finally {
+            parentDir.deleteDir()
+            config.targetDirectory.deleteDir()
+        }
+    }
+}


[groovy] 02/02: GROOVY-9506: Joint compilation is broken (add test case)

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

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

commit e5e9a0f48125855d76dc79929caf4e895ffe3952
Author: Paul King <pa...@asert.com.au>
AuthorDate: Sat May 16 19:14:06 2020 +1000

    GROOVY-9506: Joint compilation is broken (add test case)
---
 .../AutoImplementWithJointCompilation.groovy       | 50 ++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/src/test/org/codehaus/groovy/tools/stubgenerator/AutoImplementWithJointCompilation.groovy b/src/test/org/codehaus/groovy/tools/stubgenerator/AutoImplementWithJointCompilation.groovy
new file mode 100644
index 0000000..9cbefa6
--- /dev/null
+++ b/src/test/org/codehaus/groovy/tools/stubgenerator/AutoImplementWithJointCompilation.groovy
@@ -0,0 +1,50 @@
+/*
+ *  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.tools.stubgenerator
+
+/**
+ * Checks that {@code @AutoImplement} annotated classes work correctly with stubs.
+ */
+class AutoImplementWithJointCompilation extends StringSourcesStubTestCase {
+
+    Map<String, String> provideSources() {
+        [
+                'foo/JavaI.java': '''package foo;
+                    public interface JavaI {}
+                ''',
+                'foo/GroovyClass.groovy': '''package foo
+                    @groovy.transform.AutoImplement
+                    class GroovyClass implements Runnable {}
+                ''',
+                'foo/Main.groovy': '''package foo
+                    class Main {
+                        boolean runGroovyClass() {
+                            new GroovyClass().run()
+                            return true
+                        }
+                    }
+                '''
+        ]
+    }
+
+    void verifyStubs() {
+        def main = loader.loadClass('foo.Main').newInstance()
+        assert main.runGroovyClass()
+    }
+}