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 02:32:22 UTC

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

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 b03dc0939a23f58473ee0e4e0e4ea25e6b65999e
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 e197c6f..a1f26c5 100644
--- a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
+++ b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
@@ -331,7 +331,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'))
     }