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/04/15 03:29:31 UTC

[groovy] branch master updated (0adc506 -> e1a5ff1)

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 0adc506  GROOVY-9508: groovyConsole CLI plumbing for --enable-preview command-line switch is missing one part
     new faf2997  GROOVY-9505: improve comment
     new e1a5ff1  GROOVY-9509: JavaShell should allow options to be passed

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:
 .../java/org/apache/groovy/util/JavaShell.java     | 56 +++++++++++++++++-----
 .../groovy/control/CompilerConfiguration.java      |  2 +-
 2 files changed, 44 insertions(+), 14 deletions(-)


[groovy] 02/02: GROOVY-9509: JavaShell should allow options to be passed

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 e1a5ff11b37b45af6ec4d0f3117f8235c29e6c92
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed Apr 15 13:29:23 2020 +1000

    GROOVY-9509: JavaShell should allow options to be passed
---
 .../java/org/apache/groovy/util/JavaShell.java     | 56 +++++++++++++++++-----
 1 file changed, 43 insertions(+), 13 deletions(-)

diff --git a/src/main/java/org/apache/groovy/util/JavaShell.java b/src/main/java/org/apache/groovy/util/JavaShell.java
index bf79d07..c192330 100644
--- a/src/main/java/org/apache/groovy/util/JavaShell.java
+++ b/src/main/java/org/apache/groovy/util/JavaShell.java
@@ -85,41 +85,60 @@ public class JavaShell {
      * Run main method
      *
      * @param className the main class name
+     * @param options compiler options
      * @param src the source code
      * @param args arguments for main method
-     * @throws Throwable
      */
-    public void run(String className, String src, String... args) throws Throwable {
-        Class<?> c = compile(className, src);
+    public void run(String className, Iterable<String> options, String src, String... args) throws Throwable {
+        Class<?> c = compile(className, options, src);
         Method mainMethod = c.getMethod(MAIN_METHOD_NAME, String[].class);
         mainMethod.invoke(null, (Object) args);
     }
 
     /**
+     * Run main method
+     *
+     * @param className the main class name
+     * @param src the source code
+     * @param args arguments for main method
+     */
+    public void run(String className, String src, String... args) throws Throwable {
+        run(className, Collections.emptyList(), src, args);
+    }
+
+    /**
      * Compile and return the main class
      * @param className the main class name
+     * @param options compiler options
      * @param src the source code
      * @return the main class
-     * @throws IOException
-     * @throws ClassNotFoundException
      */
-    public Class<?> compile(final String className, String src) throws IOException, ClassNotFoundException {
-        doCompile(className, src);
+    public Class<?> compile(final String className, Iterable<String> options, String src) throws IOException, ClassNotFoundException {
+        doCompile(className, src, options);
 
         return jscl.findClass(className);
     }
 
     /**
+     * Compile and return the main class
+     * @param className the main class name
+     * @param src the source code
+     * @return the main class
+     */
+    public Class<?> compile(final String className, String src) throws IOException, ClassNotFoundException {
+        return compile(className, Collections.emptyList(), src);
+    }
+
+    /**
      * Compile and return all classes
      *
      * @param className the main class name
+     * @param options compiler options
      * @param src the source code
      * @return all classes
-     * @throws IOException
-     * @throws ClassNotFoundException
      */
-    public Map<String, Class<?>> compileAll(final String className, String src) throws IOException, ClassNotFoundException {
-        doCompile(className, src);
+    public Map<String, Class<?>> compileAll(final String className, Iterable<String> options, String src) throws IOException, ClassNotFoundException {
+        doCompile(className, src, options);
 
         Map<String, Class<?>> classes = new LinkedHashMap<>();
         for (String cn : jscl.getClassMap().keySet()) {
@@ -130,7 +149,18 @@ public class JavaShell {
         return classes;
     }
 
-    private void doCompile(String className, String src) throws IOException {
+    /**
+     * Compile and return all classes
+     *
+     * @param className the main class name
+     * @param src the source code
+     * @return all classes
+     */
+    public Map<String, Class<?>> compileAll(final String className, String src) throws IOException, ClassNotFoundException {
+        return compileAll(className, Collections.emptyList(), src);
+    }
+
+    private void doCompile(String className, String src, Iterable<String> options) throws IOException {
         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
         try (BytesJavaFileManager bjfm = new BytesJavaFileManager(compiler.getStandardFileManager(null, locale, charset))) {
             StringBuilderWriter out = new StringBuilderWriter();
@@ -139,7 +169,7 @@ public class JavaShell {
                             out,
                             bjfm,
                             null,
-                            Collections.emptyList(),
+                            options,
                             Collections.emptyList(),
                             Collections.singletonList(
                                     new MemJavaFileObject(className, src)


[groovy] 01/02: GROOVY-9505: improve comment

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 faf2997d5e1095c9598abd2a504cbce64919cd82
Author: Paul King <pa...@asert.com.au>
AuthorDate: Wed Apr 15 13:26:44 2020 +1000

    GROOVY-9505: improve comment
---
 src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index da25138..bb08c63 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -123,7 +123,7 @@ public class CompilerConfiguration {
     public static final String[] ALLOWED_JDKS = JDK_TO_BYTECODE_VERSION_MAP.keySet().toArray(new String[JDK_TO_BYTECODE_VERSION_MAP.size()]);
 
     /**
-    * The valid instruction sets.
+    * The ASM api version to use when loading/parsing classes, and generating proxy adapter classes.
     */
     public static final int ASM_API_VERSION = Opcodes.ASM8;