groovy git commit: GROOVY-8353: groovyConsole should support -Dname=value setting of system properties

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

groovy git commit: GROOVY-8353: groovyConsole should support -Dname=value setting of system properties

paulk
Repository: groovy
Updated Branches:
  refs/heads/master 2d9c467ad -> 6605eef92


GROOVY-8353: groovyConsole should support -Dname=value setting of system properties


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/6605eef9
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/6605eef9
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/6605eef9

Branch: refs/heads/master
Commit: 6605eef92c40dbfd26e5021145481dde5f3aeb9d
Parents: 2d9c467
Author: paulk <[hidden email]>
Authored: Thu Oct 12 18:18:36 2017 +1000
Committer: paulk <[hidden email]>
Committed: Thu Oct 12 18:18:36 2017 +1000

----------------------------------------------------------------------
 .../src/main/groovy/groovy/ui/Console.groovy    | 21 ++++++++++----------
 .../main/resources/groovy/ui/Console.properties |  2 ++
 2 files changed, 12 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/6605eef9/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy b/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
index 4bfb2d4..7663719 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/ui/Console.groovy
@@ -67,15 +67,6 @@ import javax.swing.event.DocumentListener
  * Groovy Swing console.
  *
  * Allows user to interactively enter and execute Groovy.
- *
- * @author Danno Ferrin
- * @author Dierk Koenig, changed Layout, included Selection sensitivity, included ObjectBrowser
- * @author Alan Green more features: history, System.out capture, bind result to _
- * @author Guillaume Laforge, stacktrace hyperlinking to the current script line
- * @author Hamlet D'Arcy, AST browser
- * @author Roshan Dawrani
- * @author Paul King
- * @author Andre Steingress
  */
 class Console implements CaretListener, HyperlinkListener, ComponentListener, FocusListener {
 
@@ -212,6 +203,7 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
             V(longOpt: 'version', messages['cli.option.version.description'])
             pa(longOpt: 'parameters', messages['cli.option.parameters.description'])
             i(longOpt: 'indy', messages['cli.option.indy.description'])
+            D(longOpt: 'define', args: 2, argName: 'name=value', valueSeparator: '=', messages['cli.option.define.description'])
         }
         OptionAccessor options = cli.parse(args)
 
@@ -230,6 +222,12 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
             System.exit(0)
         }
 
+        if (options.hasOption('D')) {
+            options.getOptionProperties('D')?.each { k, v ->
+                System.setProperty(k, v)
+            }
+        }
+
         // full stack trace should not be logged to the output window - GROOVY-4663
         java.util.logging.Logger.getLogger(StackTraceUtils.STACK_LOG_NAME).useParentHandlers = false
 
@@ -246,8 +244,9 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
         def console = new Console(Console.class.classLoader?.getRootLoader(), new Binding(), baseConfig)
         console.useScriptClassLoaderForScriptExecution = true
         console.run()
-        if (args.length > 0 && !args[-1].toString().startsWith("-")) {
-            console.loadScriptFile(args[-1] as File)
+        def remaining = options.arguments()
+        if (remaining && !remaining[-1].startsWith("-")) {
+            console.loadScriptFile(remaining[-1] as File)
         }
 
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/6605eef9/subprojects/groovy-console/src/main/resources/groovy/ui/Console.properties
----------------------------------------------------------------------
diff --git a/subprojects/groovy-console/src/main/resources/groovy/ui/Console.properties b/subprojects/groovy-console/src/main/resources/groovy/ui/Console.properties
index b04c0ec..3e1436b 100644
--- a/subprojects/groovy-console/src/main/resources/groovy/ui/Console.properties
+++ b/subprojects/groovy-console/src/main/resources/groovy/ui/Console.properties
@@ -28,6 +28,8 @@ cli.option.parameters.description=Generate metadata for reflection on method par
 
 cli.option.indy.description=Enable InvokeDynamic (Indy) compilation for scripts
 
+cli.option.define.description=Define a system property
+
 cli.info.version=GroovyConsole {0}
 
 # Preferences Dialog