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 2019/04/25 10:13:10 UTC

[groovy] branch GROOVY_2_5_X updated (1875cf3 -> 4945a52)

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

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


    from 1875cf3  minor refactor: reduce some codenarc warnings
     new a299872  GROOVY-9073: added compiler option to enable preview features (JEP 12)
     new 9bcf4c7  GROOVY-9073: added compiler option to enable preview features (adjustments to startup scripts)
     new 4945a52  GROOVY-9073: added compiler option to enable preview features - fix typo (closes #906)

The 3 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:
 src/bin/groovyConsole_completion                   |  2 +-
 src/bin/groovy_completion                          |  2 +-
 src/bin/groovyc_completion                         |  2 +-
 src/bin/groovysh_completion                        |  2 +-
 src/bin/startGroovy                                | 10 +++++++-
 src/bin/startGroovy.bat                            | 26 +++++++++++++++++--
 src/main/groovy/groovy/ui/GroovyMain.java          |  4 +++
 .../groovy/classgen/AsmClassGenerator.java         |  2 +-
 .../groovy/classgen/asm/WriterController.java      |  7 ++---
 .../groovy/control/CompilerConfiguration.java      | 30 +++++++++++++++++++++-
 .../codehaus/groovy/tools/FileSystemCompiler.java  |  4 +++
 src/spec/doc/tools-groovy.adoc                     |  1 +
 src/spec/doc/tools-groovyc.adoc                    |  1 +
 .../main/java/org/codehaus/groovy/ant/Groovyc.java | 24 +++++++++++++++++
 .../groovy/cli/picocli/CliBuilderTest.groovy       | 19 ++++++++++++--
 .../src/spec/doc/groovy-console.adoc               |  3 ++-
 .../groovy-groovysh/src/spec/doc/groovysh.adoc     |  3 ++-
 17 files changed, 126 insertions(+), 16 deletions(-)


[groovy] 01/03: GROOVY-9073: added compiler option to enable preview features (JEP 12)

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

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

commit a2998728596430cce279e6a41e21bda434b2345e
Author: Keegan Witt <ke...@gmail.com>
AuthorDate: Mon Apr 8 14:36:09 2019 -0400

    GROOVY-9073: added compiler option to enable preview features (JEP 12)
---
 src/bin/groovyConsole_completion                   |  2 +-
 src/bin/groovy_completion                          |  2 +-
 src/bin/groovyc_completion                         |  2 +-
 src/bin/groovysh_completion                        |  2 +-
 src/main/groovy/groovy/ui/GroovyMain.java          |  4 +++
 .../groovy/classgen/AsmClassGenerator.java         |  2 +-
 .../groovy/classgen/asm/WriterController.java      |  7 ++---
 .../groovy/control/CompilerConfiguration.java      | 30 +++++++++++++++++++++-
 .../codehaus/groovy/tools/FileSystemCompiler.java  |  4 +++
 src/spec/doc/tools-groovy.adoc                     |  1 +
 src/spec/doc/tools-groovyc.adoc                    |  1 +
 .../main/java/org/codehaus/groovy/ant/Groovyc.java | 24 +++++++++++++++++
 .../groovy/cli/picocli/CliBuilderTest.groovy       | 24 +++++++++++++++--
 .../src/spec/doc/groovy-console.adoc               |  3 ++-
 .../groovy-groovysh/src/spec/doc/groovysh.adoc     |  3 ++-
 15 files changed, 98 insertions(+), 13 deletions(-)

diff --git a/src/bin/groovyConsole_completion b/src/bin/groovyConsole_completion
index 10c777c..9803661 100644
--- a/src/bin/groovyConsole_completion
+++ b/src/bin/groovyConsole_completion
@@ -90,7 +90,7 @@ function _picocli_groovyConsole() {
   PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
 
   COMMANDS=""
-  FLAG_OPTS="-cp -classpath --classpath -h --help -V --version -pa --parameters -i --indy"
+  FLAG_OPTS="-cp -classpath --classpath -h --help -V --version -pa --parameters -pr --enable-preview -i --indy"
   ARG_OPTS="-D --define --configscript"
 
   COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${COMMANDS}" -- ${CURR_WORD}) )
diff --git a/src/bin/groovy_completion b/src/bin/groovy_completion
index 13cd712..9fc1fa7 100644
--- a/src/bin/groovy_completion
+++ b/src/bin/groovy_completion
@@ -90,7 +90,7 @@ function _picocli_groovy() {
   PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
 
   COMMANDS=""
-  FLAG_OPTS="-d --debug -n -p -pa --parameters --indy -h --help -v --version"
+  FLAG_OPTS="-d --debug -n -p -pa --parameters -pr --enable-preview --indy -h --help -v --version"
   ARG_OPTS="-cp -classpath --classpath -D --define --disableopt -c --encoding -e -i -l -a --autosplit --configscript -b --basescript"
 
   COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${COMMANDS}" -- ${CURR_WORD}) )
diff --git a/src/bin/groovyc_completion b/src/bin/groovyc_completion
index ebb2a2a..d4591f1 100644
--- a/src/bin/groovyc_completion
+++ b/src/bin/groovyc_completion
@@ -90,7 +90,7 @@ function _picocli_groovyc() {
   PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
 
   COMMANDS=""
-  FLAG_OPTS="-e --exception -pa --parameters -j --jointCompilation --indy -h --help -v --version"
+  FLAG_OPTS="-e --exception -pa --parameters -pr --enable-preview -j --jointCompilation --indy -h --help -v --version"
   ARG_OPTS="-cp -classpath --classpath -sourcepath --sourcepath --temp --encoding -d -b --basescript -J -F --configscript"
 
   case ${CURR_WORD} in
diff --git a/src/bin/groovysh_completion b/src/bin/groovysh_completion
index 5b8869c..d3e4a8a 100644
--- a/src/bin/groovysh_completion
+++ b/src/bin/groovysh_completion
@@ -87,7 +87,7 @@ function _picocli_groovysh() {
   PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
 
   COMMANDS=""
-  FLAG_OPTS="-cp -classpath --classpath -h --help -V --version -v --verbose -q --quiet -d --debug -pa --parameters"
+  FLAG_OPTS="-cp -classpath --classpath -h --help -V --version -v --verbose -q --quiet -d --debug -pr --enable-preview -pr --parameters"
   ARG_OPTS="-e --evaluate -C --color -D --define -T --terminal"
 
   COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${COMMANDS}" -- ${CURR_WORD}) )
diff --git a/src/main/groovy/groovy/ui/GroovyMain.java b/src/main/groovy/groovy/ui/GroovyMain.java
index 54e1887..b1ea153 100644
--- a/src/main/groovy/groovy/ui/GroovyMain.java
+++ b/src/main/groovy/groovy/ui/GroovyMain.java
@@ -199,6 +199,9 @@ public class GroovyMain {
         @Option(names = {"-pa", "--parameters"}, description = "Generate metadata for reflection on method parameter names (jdk8+ only)")
         private boolean parameterMetadata;
 
+        @Option(names = {"-pr", "--enable-preview"}, description = "Enable preview Java features (JEP 12) (jdk12+ only)")
+        private boolean previewFeatures;
+
         @Option(names = "-l", arity = "0..1", paramLabel = "<port>", description = "Listen on a port and process inbound lines (default: 1960)")
         private String port;
 
@@ -241,6 +244,7 @@ public class GroovyMain {
             main.debug = debug;
             main.conf.setDebug(main.debug);
             main.conf.setParameters(parameterMetadata);
+            main.conf.setPreviewFeatures(previewFeatures);
             main.processFiles = lineByLine || lineByLinePrint;
             main.autoOutput = lineByLinePrint;
             main.editFiles = extension != null;
diff --git a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 6c7779c..8670c38 100644
--- a/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/java/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -219,7 +219,7 @@ public class AsmClassGenerator extends ClassGenerator {
             Object min = classNode.getNodeMetaData(MINIMUM_BYTECODE_VERSION);
             if (min instanceof Integer) {
                 int minVersion = (int) min;
-                if (bytecodeVersion < minVersion) {
+                if ((bytecodeVersion ^ Opcodes.V_PREVIEW) < minVersion) {
                     bytecodeVersion = minVersion;
                 }
             }
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
index b22c580..b39da3b 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/WriterController.java
@@ -95,7 +95,7 @@ public class WriterController {
         this.outermostClass = null;
         this.internalClassName = BytecodeHelper.getClassInternalName(classNode);
 
-        bytecodeVersion = chooseBytecodeVersion(invokedynamic, config.getTargetBytecode());
+        bytecodeVersion = chooseBytecodeVersion(invokedynamic, config.isPreviewFeatures(), config.getTargetBytecode());
 
         if (invokedynamic) {
             this.invocationWriter = new InvokeDynamicWriter(this);
@@ -143,14 +143,15 @@ public class WriterController {
         }
         return new LoggableClassVisitor(cv);
     }
-    private static int chooseBytecodeVersion(final boolean invokedynamic, final String targetBytecode) {
+
+    private static int chooseBytecodeVersion(final boolean invokedynamic, final boolean previewFeatures, final String targetBytecode) {
         Integer bytecodeVersion = CompilerConfiguration.JDK_TO_BYTECODE_VERSION_MAP.get(targetBytecode);
 
         if (invokedynamic && bytecodeVersion < Opcodes.V1_7) {
             return Opcodes.V1_7;
         } else {
             if (null != bytecodeVersion) {
-                return bytecodeVersion;
+                return previewFeatures ? bytecodeVersion | Opcodes.V_PREVIEW : bytecodeVersion;
             }
         }
 
diff --git a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
index 7d4d103..98ec14d 100644
--- a/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
+++ b/src/main/java/org/codehaus/groovy/control/CompilerConfiguration.java
@@ -204,6 +204,11 @@ public class CompilerConfiguration {
     private String targetBytecode;
 
     /**
+     * Whether the bytecode version has preview features enabled (JEP 12)
+     */
+    private boolean previewFeatures;
+
+    /**
      * options for joint compilation (null by default == no joint compilation)
      */
     private Map<String, Object> jointCompilationOptions;
@@ -230,7 +235,6 @@ public class CompilerConfiguration {
      * Sets the Flags to defaults.
      */
     public CompilerConfiguration() {
-        //
         // Set in safe defaults
 
         setWarningLevel(WarningMessage.LIKELY_ERRORS);
@@ -245,6 +249,7 @@ public class CompilerConfiguration {
         setRecompileGroovySource(false);
         setMinimumRecompilationInterval(100);
         setTargetBytecode(getSystemPropertySafe("groovy.target.bytecode", getMinBytecodeVersion()));
+        setPreviewFeatures(getSystemPropertySafe("groovy.preview.features") != null);
         setDefaultScriptExtension(getSystemPropertySafe("groovy.default.scriptExtension", ".groovy"));
 
         // Source file encoding
@@ -304,6 +309,7 @@ public class CompilerConfiguration {
         setRecompileGroovySource(configuration.getRecompileGroovySource());
         setMinimumRecompilationInterval(configuration.getMinimumRecompilationInterval());
         setTargetBytecode(configuration.getTargetBytecode());
+        setPreviewFeatures(configuration.isPreviewFeatures());
         setDefaultScriptExtension(configuration.getDefaultScriptExtension());
         setSourceEncoding(configuration.getSourceEncoding());
         setTargetDirectory(configuration.getTargetDirectory());
@@ -353,6 +359,7 @@ public class CompilerConfiguration {
      *      <tr><td><code>"groovy.source.encoding"</code></td><td>{@link #getSourceEncoding}</td></tr>
      *      <tr><td><code>"groovy.target.directory"</code></td><td>{@link #getTargetDirectory}</td></tr>
      *      <tr><td><code>"groovy.target.bytecode"</code></td><td>{@link #getTargetBytecode}</td></tr>
+     *      <tr><td><code>"groovy.preview.features"</code></td><td>{@link #isPreviewFeatures}</td></tr>
      *      <tr><td><code>"groovy.classpath"</code></td><td>{@link #getClasspath}</td></tr>
      *      <tr><td><code>"groovy.output.verbose"</code></td><td>{@link #getVerbose}</td></tr>
      *      <tr><td><code>"groovy.output.debug"</code></td><td>{@link #getDebug}</td></tr>
@@ -466,6 +473,9 @@ public class CompilerConfiguration {
         text = configuration.getProperty("groovy.target.bytecode");
         if (text != null) setTargetBytecode(text);
 
+        text = configuration.getProperty("groovy.preview.features");
+        if (text != null && text.equalsIgnoreCase("true")) setPreviewFeatures(true);
+
         //
         // Classpath
         //
@@ -799,6 +809,24 @@ public class CompilerConfiguration {
         return this.targetBytecode;
     }
 
+    /**
+     * Whether the bytecode version has preview features enabled (JEP 12)
+     *
+     * @return preview features
+     */
+    public boolean isPreviewFeatures() {
+        return previewFeatures;
+    }
+
+    /**
+     * Sets whether the bytecode version has preview features enabled (JEP 12).
+     *
+     * @param previewFeatures whether to support preview features
+     */
+    public void setPreviewFeatures(boolean previewFeatures) {
+        this.previewFeatures = previewFeatures;
+    }
+
     private static String getMinBytecodeVersion() {
         return JDK7;
     }
diff --git a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
index 8836f4b..d8be2f5 100644
--- a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
+++ b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
@@ -334,6 +334,9 @@ public class FileSystemCompiler {
         @Option(names = {"-pa", "--parameters"}, description = "Generate metadata for reflection on method parameter names (jdk8+ only)")
         private boolean parameterMetadata;
 
+        @Option(names = {"-pr", "--enable-preview"}, description = "Enable preview Java features (JEP 12) (jdk12+ only)")
+        private boolean previewFeatures;
+
         @Option(names = {"-j", "--jointCompilation"}, description = "Attach javac compiler to compile .java files")
         private boolean jointCompilation;
 
@@ -375,6 +378,7 @@ public class FileSystemCompiler {
             }
 
             configuration.setParameters(parameterMetadata);
+            configuration.setPreviewFeatures(previewFeatures);
             configuration.setSourceEncoding(encoding);
             configuration.setScriptBaseClass(scriptBaseClass);
 
diff --git a/src/spec/doc/tools-groovy.adoc b/src/spec/doc/tools-groovy.adoc
index 50f578d..caf202c 100644
--- a/src/spec/doc/tools-groovy.adoc
+++ b/src/spec/doc/tools-groovy.adoc
@@ -60,4 +60,5 @@ int (disable any int based optimizations) |
 | -p | | process files line by line and print result (see also -n) |
 | -v | --version | display the Groovy and JVM versions | groovy -v
 | -pa | --parameters | Generates metadata for reflection on method parameter names on JDK 8 and above. Defaults to false. | groovy --parameters Person.groovy
+| -pr | --enable-preview | Enable preview Java features (JEP 12) (jdk12+ only). | groovy --enable-preview Person.groovy
 |=======================================================================
diff --git a/src/spec/doc/tools-groovyc.adoc b/src/spec/doc/tools-groovyc.adoc
index db29911..7871561 100644
--- a/src/spec/doc/tools-groovyc.adoc
+++ b/src/spec/doc/tools-groovyc.adoc
@@ -52,6 +52,7 @@ a number of command line switches:
 | -Jproperty=value | | Properties to be passed to `javac` if joint compilation is enabled | groovyc -j -Jtarget=1.6 -Jsource=1.6 A.groovy B.java
 | -Fflag | | Flags to be passed to `javac` if joint compilation is enabled | groovyc -j -Fnowarn A.groovy B.java
 | -pa | --parameters | Generates metadata for reflection on method parameter names. Requires Java 8+. | groovyc --parameters Person.groovy
+| -pr | --enable-preview | Enable preview Java features (JEP 12) (jdk12+ only). | groovy --enable-preview Person.groovy
 | @argfile | | Read options and source files from specified file. | groovyc @conf/args
 |=======================================================================
 
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
index 9ab3dd7..899536d 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
@@ -217,6 +217,11 @@ public class Groovyc extends MatchingTask {
     private boolean parameters = false;
 
     /**
+     * If true, enable preview Java features (JEP 12) (jdk12+ only). Defaults to false.
+     */
+    private boolean previewFeatures = false;
+
+    /**
      * Adds a path for source compilation.
      *
      * @return a nested src element.
@@ -826,6 +831,22 @@ public class Groovyc extends MatchingTask {
     }
 
     /**
+     * If true, enable preview Java features (JEP 12) (jdk12+ only).
+     *
+     * @param previewFeatures set to true to enable preview features
+     */
+    public void setPreviewFeatures(boolean previewFeatures) {
+        this.previewFeatures = previewFeatures;
+    }
+
+    /**
+     * Returns true if preview features has been enabled.
+     */
+    public boolean getPreviewFeatures() {
+        return previewFeatures;
+    }
+
+    /**
      * Executes the task.
      *
      * @throws BuildException if an error occurs
@@ -1102,6 +1123,9 @@ public class Groovyc extends MatchingTask {
         if (parameters) {
             commandLineList.add("--parameters");
         }
+        if (previewFeatures) {
+            commandLineList.add("--enable-preview");
+        }
         if (useIndy) {
             commandLineList.add("--indy");
         }
diff --git a/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy b/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy
index 6849d3c..be164c4 100644
--- a/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy
+++ b/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy
@@ -896,6 +896,7 @@ class CliBuilderTest extends GroovyTestCase {
             h(longOpt: 'help', 'cli.option.help.description')
             V(longOpt: 'version', 'cli.option.version.description')
             pa(longOpt: 'parameters', 'cli.option.parameters.description')
+            pr(longOpt: 'preview', 'cli.option.preview.description')
             i(longOpt: 'indy', 'cli.option.indy.description')
             D(longOpt: 'define', args: 2, argName: 'name=value', valueSeparator: '=', 'cli.option.define.description')
             _(longOpt: 'configscript', args: 1, 'cli.option.configscript.description')
@@ -913,6 +914,14 @@ class CliBuilderTest extends GroovyTestCase {
         assert !options.pa
         assert options.arguments() == ['-parameters']
 
+        assert cli.parse(['--enable-preview']).preview
+        assert cli.parse(['--enable-preview']).pr
+
+        options = cli.parse(['-preview'])
+        assert !options.preview
+        assert !options.pr
+        assert options.arguments() == ['-preview']
+
         assert cli.parse(['--indy']).indy
         assert cli.parse(['--indy']).i
         resetPrintWriter()
@@ -951,6 +960,7 @@ class CliBuilderTest extends GroovyTestCase {
             h(longOpt: 'help', 'cli.option.help.description')
             V(longOpt: 'version', 'cli.option.version.description')
             pa(longOpt: 'parameters', 'cli.option.parameters.description')
+            pr(longOpt: 'preview', 'cli.option.preview.description')
             i(longOpt: 'indy', 'cli.option.indy.description')
             D(longOpt: 'define', args: 2, argName: 'name=value', valueSeparator: '=', 'cli.option.define.description')
             _(longOpt: 'configscript', args: 1, 'cli.option.configscript.description')
@@ -964,6 +974,10 @@ class CliBuilderTest extends GroovyTestCase {
         assert cli.parse(['-parameters']).pa
         assert cli.parse(['-pa']).parameters
 
+        assert cli.parse(['--enable-preview']).pr
+        assert cli.parse(['-preview']).pr
+        assert cli.parse(['-pr']).preview
+
         assert cli.parse(['--indy']).i
         assert cli.parse(['-indy']).i
         assert cli.parse(['-i']).indy
@@ -1012,13 +1026,15 @@ class CliBuilderTest extends GroovyTestCase {
             h(longOpt: 'help', 'cli.option.help.description')
             V(longOpt: 'version', 'cli.option.version.description')
             pa(longOpt: 'parameters', 'cli.option.parameters.description')
+            pr(longOpt: 'preview', 'cli.option.preview.description')
             i(longOpt: 'indy', 'cli.option.indy.description')
             D(longOpt: 'define', args: 2, argName: 'String', valueSeparator: '=', 'cli.option.define.description')
             _(longOpt: 'configscript', args: 1, 'cli.option.configscript.description')
         }
         cli.usage()
         def expectedUsage = """\
-Usage: groovy [-hiV] [-cp] [-pa] [-configscript=PARAM] [-D=<String>=<String>]...
+Usage: groovy [-hiV] [-cp] [-pa] [-pr] [-configscript=PARAM]
+              [-D=<String>=<String>]...
       -configscript, --configscript=PARAM
                             cli.option.configscript.description
       -cp, -classpath, --classpath
@@ -1029,6 +1045,8 @@ Usage: groovy [-hiV] [-cp] [-pa] [-configscript=PARAM] [-D=<String>=<String>]...
   -i, -indy, --indy         cli.option.indy.description
       -pa, -parameters, --parameters
                             cli.option.parameters.description
+      -pr, -preview, --enable-preview
+                            cli.option.preview.description
   -V, -version, --version   cli.option.version.description"""
         assertEquals(expectedUsage, stringWriter.toString().tokenize('\r\n').join('\n'))
 
@@ -1039,13 +1057,14 @@ Usage: groovy [-hiV] [-cp] [-pa] [-configscript=PARAM] [-D=<String>=<String>]...
             h(longOpt: 'help', 'cli.option.help.description')
             V(longOpt: 'version', 'cli.option.version.description')
             pa(longOpt: 'parameters', 'cli.option.parameters.description')
+            pr(longOpt: 'preview', 'cli.option.preview.description')
             i(longOpt: 'indy', 'cli.option.indy.description')
             D(longOpt: 'define', args: 2, argName: 'String', valueSeparator: '=', 'cli.option.define.description')
             _(longOpt: 'configscript', args: 1, 'cli.option.configscript.description')
         }
         cli.usage()
         expectedUsage = """\
-Usage: groovy [-hiV] [-cp] [-pa] [--configscript=PARAM]
+Usage: groovy [-hiV] [-cp] [-pa] [-pr] [--configscript=PARAM]
               [-D=<String>=<String>]...
       --configscript=PARAM   cli.option.configscript.description
       -cp, --classpath       cli.option.cp.description
@@ -1054,6 +1073,7 @@ Usage: groovy [-hiV] [-cp] [-pa] [--configscript=PARAM]
   -h, --help                 cli.option.help.description
   -i, --indy                 cli.option.indy.description
       -pa, --parameters      cli.option.parameters.description
+      -pr, --enable-preview         cli.option.preview.description
   -V, --version              cli.option.version.description"""
         assertEquals(expectedUsage, stringWriter.toString().tokenize('\r\n').join('\n'))
     }
diff --git a/subprojects/groovy-console/src/spec/doc/groovy-console.adoc b/subprojects/groovy-console/src/spec/doc/groovy-console.adoc
index d49639c..a77d7df 100644
--- a/subprojects/groovy-console/src/spec/doc/groovy-console.adoc
+++ b/subprojects/groovy-console/src/spec/doc/groovy-console.adoc
@@ -62,8 +62,9 @@ The Groovy Swing Console allows a user to enter and run Groovy scripts.
   -D, --define=<name=value>  Define a system property
   -h, --help                 Display this help message
   -i, --indy                 Enable InvokeDynamic (Indy) compilation for scripts
-      -pa, --parameters      Generate metadata for reflection on method parameter
+  -pa, --parameters          Generate metadata for reflection on method parameter
                                names (jdk8+ only)
+  -pr, --enable-preview             Enable preview Java features (JEP 12) (jdk12+ only)
   -V, --version              Display the version
 -----------------------------------------------------------------
 
diff --git a/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc b/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
index b3d00f0..bb25a67 100644
--- a/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
+++ b/subprojects/groovy-groovysh/src/spec/doc/groovysh.adoc
@@ -61,8 +61,9 @@ experiments.
                           Define a system property
   -e, --evaluate=<CODE>   Evaluate the code first when starting interactive session
   -h, --help              Display this help message
-      -pa, --parameters   Generate metadata for reflection on method parameter names
+  -pa, --parameters       Generate metadata for reflection on method parameter names
                             (jdk8+ only)
+  -pr, --enable-preview          Enable preview Java features (JEP 12) (jdk12+ only)
   -q, --quiet             Suppress superfluous output
   -T, --terminal=<TYPE>   Specify the terminal TYPE to use
   -v, --verbose           Enable verbose output


[groovy] 03/03: GROOVY-9073: added compiler option to enable preview features - fix typo (closes #906)

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

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

commit 4945a52e04bf57874ab59a6e791dd324062c9b1f
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Apr 25 20:01:01 2019 +1000

    GROOVY-9073: added compiler option to enable preview features - fix typo (closes #906)
---
 src/bin/startGroovy | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/bin/startGroovy b/src/bin/startGroovy
index eb39c68..a232f1f 100644
--- a/src/bin/startGroovy
+++ b/src/bin/startGroovy
@@ -290,7 +290,7 @@ startGroovy ( ) {
             "$STARTER_MAIN_CLASS" \
             --main "$CLASS" \
             --conf "$GROOVY_CONF" \
-            --classpath "$CP" "$REPLACE_PREVIEW" \
+            --classpath "$CP" $REPLACE_PREVIEW \
             "$@"
     fi
 }


[groovy] 02/03: GROOVY-9073: added compiler option to enable preview features (adjustments to startup scripts)

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

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

commit 9bcf4c7a4d662af6a79e9a95128c22f6e08f623e
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Apr 25 12:32:07 2019 +1000

    GROOVY-9073: added compiler option to enable preview features (adjustments to startup scripts)
---
 src/bin/groovysh_completion                        |  2 +-
 src/bin/startGroovy                                | 10 ++++++++-
 src/bin/startGroovy.bat                            | 26 ++++++++++++++++++++--
 .../codehaus/groovy/tools/FileSystemCompiler.java  |  2 +-
 .../groovy/cli/picocli/CliBuilderTest.groovy       | 25 +++++++++------------
 5 files changed, 45 insertions(+), 20 deletions(-)

diff --git a/src/bin/groovysh_completion b/src/bin/groovysh_completion
index d3e4a8a..a175fbe 100644
--- a/src/bin/groovysh_completion
+++ b/src/bin/groovysh_completion
@@ -87,7 +87,7 @@ function _picocli_groovysh() {
   PREV_WORD=${COMP_WORDS[COMP_CWORD-1]}
 
   COMMANDS=""
-  FLAG_OPTS="-cp -classpath --classpath -h --help -V --version -v --verbose -q --quiet -d --debug -pr --enable-preview -pr --parameters"
+  FLAG_OPTS="-cp -classpath --classpath -h --help -V --version -v --verbose -q --quiet -d --debug -pr --enable-preview -pa --parameters"
   ARG_OPTS="-e --evaluate -C --color -D --define -T --terminal"
 
   COMPREPLY=( $(compgen -W "${FLAG_OPTS} ${ARG_OPTS} ${COMMANDS}" -- ${CURR_WORD}) )
diff --git a/src/bin/startGroovy b/src/bin/startGroovy
index 175690b..eb39c68 100644
--- a/src/bin/startGroovy
+++ b/src/bin/startGroovy
@@ -81,6 +81,14 @@ if [ "$1" = "-cp" ] || [ "$1" = "-classpath" ] || [ "$1" = "--classpath" ] ; the
     shift 2
 fi
 
+REPLACE_PREVIEW=
+if [ "$1" = "-pr" ] || [ "$1" = "--enable-preview" ] ; then
+    JAVA_OPTS="$JAVA_OPTS --enable-preview -Dgroovy.preview.features=true"
+    # for now, also remember arg to pass through
+    REPLACE_PREVIEW="--enable-preview"
+    shift 1
+fi
+
 # Attempt to set JAVA_HOME if it's not already set.
 if [ -z "$JAVA_HOME" ] ; then
     if $darwin ; then 
@@ -282,7 +290,7 @@ startGroovy ( ) {
             "$STARTER_MAIN_CLASS" \
             --main "$CLASS" \
             --conf "$GROOVY_CONF" \
-            --classpath "$CP" \
+            --classpath "$CP" "$REPLACE_PREVIEW" \
             "$@"
     fi
 }
diff --git a/src/bin/startGroovy.bat b/src/bin/startGroovy.bat
index d1864e2..c07012b 100644
--- a/src/bin/startGroovy.bat
+++ b/src/bin/startGroovy.bat
@@ -119,11 +119,27 @@ set CP=
 if "x%~1" == "x-cp" set CP=%~2
 if "x%~1" == "x-classpath" set CP=%~2
 if "x%~1" == "x--classpath" set CP=%~2
-if "x" == "x%CP%" goto init
+if "x" == "x%CP%" goto preview_check
 set _SKIP=4
 shift
 shift
 
+:preview_check
+@rem classpath handling
+set PREV=
+set REPLACE_PREVIEW=
+if "x%~1" == "x-pr" goto preview_enable
+if "x%~1" == "x--enable-preview" goto preview_enable
+goto init
+
+:preview_enable
+set JAVA_OPTS=%JAVA_OPTS% --enable-preview -Dgroovy.preview.features=true
+@rem for now, also remember arg to pass through
+set REPLACE_PREVIEW=--enable-preview
+if "%_SKIP%" == "4" set _SKIP=5
+if "%_SKIP%" == "2" set _SKIP=3
+shift
+
 :init
 @rem get name of script to launch with full path
 set GROOVY_SCRIPT_NAME=%~f1
@@ -193,6 +209,7 @@ rem  add the next part to _ARG until the matching quote is found
 goto :win9xME_args_loop
 
 :argIsComplete
+if "x5" == "x%_SKIP%" goto skip_5
 if "x4" == "x%_SKIP%" goto skip_4
 if "x3" == "x%_SKIP%" goto skip_3
 if "x2" == "x%_SKIP%" goto skip_2
@@ -209,6 +226,11 @@ set CMD_LINE_ARGS=%CMD_LINE_ARGS% %_ARG%
 set _ARG=
 goto win9xME_args_loop
 
+:skip_5
+set _ARG=
+set _SKIP=4
+goto win9xME_args_loop
+
 :skip_4
 set _ARG=
 set _SKIP=3
@@ -273,7 +295,7 @@ if "%JAVA_VERSION%" gtr "1.8.0" if "%GROOVY_TURN_OFF_JAVA_WARNINGS%" == "true"
 if exist "%USERPROFILE%/.groovy/postinit.bat" call "%USERPROFILE%/.groovy/postinit.bat"
 
 @rem Execute Groovy
-"%JAVA_EXE%" %GROOVY_OPTS% %JAVA_OPTS% -classpath "%STARTER_CLASSPATH%" %STARTER_MAIN_CLASS% --main %CLASS% --conf "%STARTER_CONF%" --classpath "%CP%" %CMD_LINE_ARGS%
+"%JAVA_EXE%" %GROOVY_OPTS% %JAVA_OPTS% -classpath "%STARTER_CLASSPATH%" %STARTER_MAIN_CLASS% --main %CLASS% --conf "%STARTER_CONF%" --classpath "%CP%" %REPLACE_PREVIEW% %CMD_LINE_ARGS%
 
 :end
 @rem End local scope for the variables with windows NT shell
diff --git a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
index d8be2f5..9a0d042 100644
--- a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
+++ b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
@@ -334,7 +334,7 @@ public class FileSystemCompiler {
         @Option(names = {"-pa", "--parameters"}, description = "Generate metadata for reflection on method parameter names (jdk8+ only)")
         private boolean parameterMetadata;
 
-        @Option(names = {"-pr", "--enable-preview"}, description = "Enable preview Java features (JEP 12) (jdk12+ only)")
+        @Option(names = {"-pr", "--enable-preview"}, description = "Enable preview Java features (JEP 12) (jdk12+ only) - must be after classpath but before other arguments")
         private boolean previewFeatures;
 
         @Option(names = {"-j", "--jointCompilation"}, description = "Attach javac compiler to compile .java files")
diff --git a/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy b/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy
index be164c4..526f6cf 100644
--- a/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy
+++ b/subprojects/groovy-cli-picocli/src/test/groovy/groovy/cli/picocli/CliBuilderTest.groovy
@@ -896,7 +896,7 @@ class CliBuilderTest extends GroovyTestCase {
             h(longOpt: 'help', 'cli.option.help.description')
             V(longOpt: 'version', 'cli.option.version.description')
             pa(longOpt: 'parameters', 'cli.option.parameters.description')
-            pr(longOpt: 'preview', 'cli.option.preview.description')
+            pr(longOpt: 'enable-preview', 'cli.option.preview.description')
             i(longOpt: 'indy', 'cli.option.indy.description')
             D(longOpt: 'define', args: 2, argName: 'name=value', valueSeparator: '=', 'cli.option.define.description')
             _(longOpt: 'configscript', args: 1, 'cli.option.configscript.description')
@@ -914,14 +914,9 @@ class CliBuilderTest extends GroovyTestCase {
         assert !options.pa
         assert options.arguments() == ['-parameters']
 
-        assert cli.parse(['--enable-preview']).preview
+        assert cli.parse(['--enable-preview']).'enable-preview'
         assert cli.parse(['--enable-preview']).pr
 
-        options = cli.parse(['-preview'])
-        assert !options.preview
-        assert !options.pr
-        assert options.arguments() == ['-preview']
-
         assert cli.parse(['--indy']).indy
         assert cli.parse(['--indy']).i
         resetPrintWriter()
@@ -960,7 +955,7 @@ class CliBuilderTest extends GroovyTestCase {
             h(longOpt: 'help', 'cli.option.help.description')
             V(longOpt: 'version', 'cli.option.version.description')
             pa(longOpt: 'parameters', 'cli.option.parameters.description')
-            pr(longOpt: 'preview', 'cli.option.preview.description')
+            pr(longOpt: 'enable-preview', 'cli.option.preview.description')
             i(longOpt: 'indy', 'cli.option.indy.description')
             D(longOpt: 'define', args: 2, argName: 'name=value', valueSeparator: '=', 'cli.option.define.description')
             _(longOpt: 'configscript', args: 1, 'cli.option.configscript.description')
@@ -974,9 +969,9 @@ class CliBuilderTest extends GroovyTestCase {
         assert cli.parse(['-parameters']).pa
         assert cli.parse(['-pa']).parameters
 
-        assert cli.parse(['--enable-preview']).pr
-        assert cli.parse(['-preview']).pr
-        assert cli.parse(['-pr']).preview
+        assert cli.parse(['--enable-preview']).'enable-preview'
+        assert cli.parse(['-enable-preview']).'enable-preview'
+        assert cli.parse(['-pr']).pr
 
         assert cli.parse(['--indy']).i
         assert cli.parse(['-indy']).i
@@ -1026,7 +1021,7 @@ class CliBuilderTest extends GroovyTestCase {
             h(longOpt: 'help', 'cli.option.help.description')
             V(longOpt: 'version', 'cli.option.version.description')
             pa(longOpt: 'parameters', 'cli.option.parameters.description')
-            pr(longOpt: 'preview', 'cli.option.preview.description')
+            pr(longOpt: 'enable-preview', 'cli.option.preview.description')
             i(longOpt: 'indy', 'cli.option.indy.description')
             D(longOpt: 'define', args: 2, argName: 'String', valueSeparator: '=', 'cli.option.define.description')
             _(longOpt: 'configscript', args: 1, 'cli.option.configscript.description')
@@ -1045,7 +1040,7 @@ Usage: groovy [-hiV] [-cp] [-pa] [-pr] [-configscript=PARAM]
   -i, -indy, --indy         cli.option.indy.description
       -pa, -parameters, --parameters
                             cli.option.parameters.description
-      -pr, -preview, --enable-preview
+      -pr, -enable-preview, --enable-preview
                             cli.option.preview.description
   -V, -version, --version   cli.option.version.description"""
         assertEquals(expectedUsage, stringWriter.toString().tokenize('\r\n').join('\n'))
@@ -1057,7 +1052,7 @@ Usage: groovy [-hiV] [-cp] [-pa] [-pr] [-configscript=PARAM]
             h(longOpt: 'help', 'cli.option.help.description')
             V(longOpt: 'version', 'cli.option.version.description')
             pa(longOpt: 'parameters', 'cli.option.parameters.description')
-            pr(longOpt: 'preview', 'cli.option.preview.description')
+            pr(longOpt: 'enable-preview', 'cli.option.preview.description')
             i(longOpt: 'indy', 'cli.option.indy.description')
             D(longOpt: 'define', args: 2, argName: 'String', valueSeparator: '=', 'cli.option.define.description')
             _(longOpt: 'configscript', args: 1, 'cli.option.configscript.description')
@@ -1073,7 +1068,7 @@ Usage: groovy [-hiV] [-cp] [-pa] [-pr] [--configscript=PARAM]
   -h, --help                 cli.option.help.description
   -i, --indy                 cli.option.indy.description
       -pa, --parameters      cli.option.parameters.description
-      -pr, --enable-preview         cli.option.preview.description
+      -pr, --enable-preview  cli.option.preview.description
   -V, --version              cli.option.version.description"""
         assertEquals(expectedUsage, stringWriter.toString().tokenize('\r\n').join('\n'))
     }