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 2018/05/18 02:24:23 UTC
[1/4] groovy git commit: GROOVY-8567: minor tweaks for Groovyc to
picocli conversion (closes #703)
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_6_X 225e2bfd0 -> d182c9794
GROOVY-8567: minor tweaks for Groovyc to picocli conversion (closes #703)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/7e8c734e
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/7e8c734e
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/7e8c734e
Branch: refs/heads/GROOVY_2_6_X
Commit: 7e8c734e52d18a2182c5cbcb5747a6c731689935
Parents: 225e2bf
Author: Paul King <pa...@asert.com.au>
Authored: Thu May 17 23:13:42 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Fri May 18 12:24:12 2018 +1000
----------------------------------------------------------------------
gradle/assemble.gradle | 10 +++-
gradle/pomconfigurer.gradle | 3 +
.../groovy/tools/FileSystemCompiler.java | 62 +++++++++++++++-----
.../java/org/codehaus/groovy/ant/Groovyc.java | 2 +-
.../groovy/groovy/cli/commons/CliBuilder.groovy | 2 +-
.../groovy/groovy/cli/picocli/CliBuilder.groovy | 2 +-
.../org/codehaus/groovy/tools/shell/Main.groovy | 1 +
7 files changed, 60 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/7e8c734e/gradle/assemble.gradle
----------------------------------------------------------------------
diff --git a/gradle/assemble.gradle b/gradle/assemble.gradle
index f76fe99..d4844bd 100644
--- a/gradle/assemble.gradle
+++ b/gradle/assemble.gradle
@@ -199,7 +199,7 @@ allprojects {
return component.module in [
'antlr', 'antlr-runtime', 'antlr4', 'antlr4-runtime', 'antlr4-annotations',
'asm', 'asm-commons', 'asm-tree', 'asm-util',
- 'commons-cli']
+ 'commons-cli', 'picocli']
}
return false
}
@@ -212,13 +212,17 @@ allprojects {
'org/codehaus/groovy/cli/GroovyPosixParser*.class',
'groovy/util/CliBuilder*.class',
'groovy/util/OptionAccessor*.class',
- 'org/codehaus/groovy/tools/shell/util/HelpFormatter*.class'
+ 'org/codehaus/groovy/tools/shell/util/HelpFormatter*.class',
+ 'groovy/cli/commons/CliBuilder*.class',
+ 'groovy/cli/commons/OptionAccessor*.class',
+ 'groovy/cli/picocli/CliBuilder*.class'
]
patterns = [
'antlr.**' : 'groovyjarjarantlr.@1', // antlr2
'org.antlr.**' : 'groovyjarjarantlr4.@1', // antlr4
'org.objectweb.**' : 'groovyjarjarasm.@1',
- 'org.apache.commons.cli.**': 'groovyjarjarcommonscli.@1'
+ 'org.apache.commons.cli.**': 'groovyjarjarcommonscli.@1',
+ 'picocli.**': 'groovyjarjarpicocli.@1'
]
excludesPerLibrary = [
'*': ['META-INF/maven/**', 'META-INF/*', 'META-INF/services/javax.annotation.processing.Processor', 'module-info.class']
http://git-wip-us.apache.org/repos/asf/groovy/blob/7e8c734e/gradle/pomconfigurer.gradle
----------------------------------------------------------------------
diff --git a/gradle/pomconfigurer.gradle b/gradle/pomconfigurer.gradle
index 3ce9ada..31ea58a 100644
--- a/gradle/pomconfigurer.gradle
+++ b/gradle/pomconfigurer.gradle
@@ -627,6 +627,9 @@ project.ext.pomConfigureClosureWithoutTweaks = {
contributor {
name 'Tom Nichols'
}
+ contributor {
+ name 'Remko Popma'
+ }
}
mailingLists {
mailingList {
http://git-wip-us.apache.org/repos/asf/groovy/blob/7e8c734e/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
index 8b54b30..cd00053 100644
--- a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
+++ b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
@@ -18,24 +18,32 @@
*/
package org.codehaus.groovy.tools;
+import groovy.lang.DeprecationException;
import groovy.lang.GroovyResourceLoader;
import groovy.lang.GroovySystem;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Options;
-import picocli.CommandLine;
-import picocli.CommandLine.*;
import org.codehaus.groovy.control.CompilationUnit;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.ConfigurationException;
import org.codehaus.groovy.runtime.DefaultGroovyStaticMethods;
import org.codehaus.groovy.runtime.StringGroovyMethods;
import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit;
-
-import java.io.*;
+import picocli.CommandLine;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.IVersionProvider;
+import picocli.CommandLine.Option;
+import picocli.CommandLine.Parameters;
+import picocli.CommandLine.ParseResult;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -72,13 +80,6 @@ public class FileSystemCompiler {
unit.compile();
}
- /** @deprecated use {@link #displayHelp(PrintWriter)} instead */
- @Deprecated
- public static void displayHelp(final Options options) {
- final HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp(80, "groovyc [options] <source-files>", "options:", options, "");
- }
-
/** Prints the usage help message for {@link CompilationOptions} to stderr.
* @see #displayHelp(PrintWriter)
* @since 2.5 */
@@ -86,19 +87,20 @@ public class FileSystemCompiler {
displayHelp(new PrintWriter(System.err, true));
}
- /** Prints the usage help message for the {@link CompilationOptions} to the specified PrintWriter. */
+ /** Prints the usage help message for the {@link CompilationOptions} to the specified PrintWriter.
+ * @since 2.5 */
public static void displayHelp(final PrintWriter writer) {
configureParser(new CompilationOptions()).usage(writer);
}
/** Prints version information to stderr.
- * @see #displayVersion(PrintWriter)
- * @since 2.5 */
+ * @see #displayVersion(PrintWriter) */
public static void displayVersion() {
displayVersion(new PrintWriter(System.err, true));
}
- /** Prints version information to the specified PrintWriter. */
+ /** Prints version information to the specified PrintWriter.
+ * @since 2.5 */
public static void displayVersion(final PrintWriter writer) {
for (String line : new VersionProvider().getVersion()) {
writer.println(line);
@@ -288,6 +290,8 @@ public class FileSystemCompiler {
}
}
+ /**
+ * @since 2.5 */
static class VersionProvider implements IVersionProvider {
@Override
public String[] getVersion() {
@@ -299,6 +303,8 @@ public class FileSystemCompiler {
}
}
+ /**
+ * @since 2.5 */
@Command(name = "groovyc",
customSynopsis = "groovyc [options] <source-files>",
sortOptions = false,
@@ -422,6 +428,30 @@ public class FileSystemCompiler {
}
}
+ /** @deprecated use {@link #displayHelp(PrintWriter)} instead */
+ @Deprecated
+ public static void displayHelp(final Options options) {
+ final HelpFormatter formatter = new HelpFormatter();
+ formatter.printHelp(80, "groovyc [options] <source-files>", "options:", options, "");
+ }
+
+ // some methods to avoid binary incompatibility - don't gain us a lot but gives the user
+ // something slightly less cryptic than a NoSuchMethodError or an IncompatibleClassChangeError
+ @Deprecated
+ public static CompilerConfiguration generateCompilerConfigurationFromOptions(org.apache.commons.cli.CommandLine cli) throws IOException {
+ throw new DeprecationException("This method is not supported for Groovy 2.5+. Consider instead using the FileSystemCompiler.CompilationOptions class.");
+ }
+
+ @Deprecated
+ public static String[] generateFileNamesFromOptions(org.apache.commons.cli.CommandLine cli) {
+ throw new DeprecationException("This method is not supported for Groovy 2.5+. Consider instead using the FileSystemCompiler.CompilationOptions class.");
+ }
+
+ @Deprecated
+ public static Options createCompilationOptions() {
+ throw new DeprecationException("This method is not supported for Groovy 2.5+. Consider instead using the FileSystemCompiler.CompilationOptions class.");
+ }
+
/**
* Creates a temporary directory in the default temporary directory (as specified by the system
* property <i>java.io.tmpdir</i>.
http://git-wip-us.apache.org/repos/asf/groovy/blob/7e8c734e/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
----------------------------------------------------------------------
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 7a60ac8..8c57bcc 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
@@ -161,7 +161,7 @@ import java.util.StringTokenizer;
* </project>
* </pre>
* <p>
- * Based heavily on the implementation of the Javac task in Apache Ant.
+ * Based on the implementation of the Javac task in Apache Ant.
* <p>
* Can also be used from {@link groovy.util.AntBuilder} to allow the build file to be scripted in Groovy.
*/
http://git-wip-us.apache.org/repos/asf/groovy/blob/7e8c734e/subprojects/groovy-cli-commons/src/main/groovy/groovy/cli/commons/CliBuilder.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-cli-commons/src/main/groovy/groovy/cli/commons/CliBuilder.groovy b/subprojects/groovy-cli-commons/src/main/groovy/groovy/cli/commons/CliBuilder.groovy
index 790cb82..237b631 100644
--- a/subprojects/groovy-cli-commons/src/main/groovy/groovy/cli/commons/CliBuilder.groovy
+++ b/subprojects/groovy-cli-commons/src/main/groovy/groovy/cli/commons/CliBuilder.groovy
@@ -348,7 +348,7 @@ class CliBuilder {
* Make options accessible from command line args with parser.
* Returns null on bad command lines after displaying usage message.
*/
- groovy.cli.commons.OptionAccessor parse(args) {
+ OptionAccessor parse(args) {
if (expandArgumentFiles) args = expandArgumentFiles(args)
if (!parser) {
parser = posix != null && posix == false ? new GnuParser() : new DefaultParser()
http://git-wip-us.apache.org/repos/asf/groovy/blob/7e8c734e/subprojects/groovy-cli-picocli/src/main/groovy/groovy/cli/picocli/CliBuilder.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-cli-picocli/src/main/groovy/groovy/cli/picocli/CliBuilder.groovy b/subprojects/groovy-cli-picocli/src/main/groovy/groovy/cli/picocli/CliBuilder.groovy
index b196a67..aacd832 100644
--- a/subprojects/groovy-cli-picocli/src/main/groovy/groovy/cli/picocli/CliBuilder.groovy
+++ b/subprojects/groovy-cli-picocli/src/main/groovy/groovy/cli/picocli/CliBuilder.groovy
@@ -510,7 +510,7 @@ class CliBuilder {
* Sets the {@link #posix} property on this <code>CliBuilder</code> and the
* <code>posixClusteredShortOptionsAllowed</code> property on the {@link #parser}
* used by the underlying library.
- * @param poxis whether to allow clustered short options
+ * @param posix whether to allow clustered short options
*/
void setPosix(boolean posix) {
this.posix = posix
http://git-wip-us.apache.org/repos/asf/groovy/blob/7e8c734e/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
index 643f81f..acdc258 100644
--- a/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
+++ b/subprojects/groovy-groovysh/src/main/groovy/org/codehaus/groovy/tools/shell/Main.groovy
@@ -19,6 +19,7 @@
package org.codehaus.groovy.tools.shell
import groovy.cli.commons.CliBuilder
+import groovy.cli.commons.OptionAccessor
import jline.TerminalFactory
import jline.UnixTerminal
import jline.UnsupportedTerminal
[4/4] groovy git commit: remove deprecated methods
Posted by pa...@apache.org.
remove deprecated methods
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d182c979
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d182c979
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d182c979
Branch: refs/heads/GROOVY_2_6_X
Commit: d182c97946a23b7af4f94e707bcdbf66a9e25c8d
Parents: 670e901
Author: Paul King <pa...@asert.com.au>
Authored: Fri May 18 12:22:29 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Fri May 18 12:24:14 2018 +1000
----------------------------------------------------------------------
.../groovy/tools/FileSystemCompiler.java | 38 --------------------
1 file changed, 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/d182c979/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
index cd00053..e9fc8b5 100644
--- a/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
+++ b/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
@@ -18,11 +18,8 @@
*/
package org.codehaus.groovy.tools;
-import groovy.lang.DeprecationException;
import groovy.lang.GroovyResourceLoader;
import groovy.lang.GroovySystem;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Options;
import org.codehaus.groovy.control.CompilationUnit;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.ConfigurationException;
@@ -428,41 +425,6 @@ public class FileSystemCompiler {
}
}
- /** @deprecated use {@link #displayHelp(PrintWriter)} instead */
- @Deprecated
- public static void displayHelp(final Options options) {
- final HelpFormatter formatter = new HelpFormatter();
- formatter.printHelp(80, "groovyc [options] <source-files>", "options:", options, "");
- }
-
- // some methods to avoid binary incompatibility - don't gain us a lot but gives the user
- // something slightly less cryptic than a NoSuchMethodError or an IncompatibleClassChangeError
- @Deprecated
- public static CompilerConfiguration generateCompilerConfigurationFromOptions(org.apache.commons.cli.CommandLine cli) throws IOException {
- throw new DeprecationException("This method is not supported for Groovy 2.5+. Consider instead using the FileSystemCompiler.CompilationOptions class.");
- }
-
- @Deprecated
- public static String[] generateFileNamesFromOptions(org.apache.commons.cli.CommandLine cli) {
- throw new DeprecationException("This method is not supported for Groovy 2.5+. Consider instead using the FileSystemCompiler.CompilationOptions class.");
- }
-
- @Deprecated
- public static Options createCompilationOptions() {
- throw new DeprecationException("This method is not supported for Groovy 2.5+. Consider instead using the FileSystemCompiler.CompilationOptions class.");
- }
-
- /**
- * Creates a temporary directory in the default temporary directory (as specified by the system
- * property <i>java.io.tmpdir</i>.
- *
- * @deprecated Use {@link DefaultGroovyStaticMethods#createTempDir(java.io.File, String, String)} instead.
- */
- @Deprecated
- public static File createTempDir() throws IOException {
- return DefaultGroovyStaticMethods.createTempDir(null);
- }
-
public static void deleteRecursive(File file) {
if (!file.exists()) {
return;
[3/4] groovy git commit: GROOVY-8577: GrapeMain to picocli - trivial
tweak (closes #704)
Posted by pa...@apache.org.
GROOVY-8577: GrapeMain to picocli - trivial tweak (closes #704)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/670e901e
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/670e901e
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/670e901e
Branch: refs/heads/GROOVY_2_6_X
Commit: 670e901e033652cd874173cb88f1aa980b546d39
Parents: 5061cb1
Author: Paul King <pa...@asert.com.au>
Authored: Fri May 18 12:19:45 2018 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Fri May 18 12:24:13 2018 +1000
----------------------------------------------------------------------
src/main/groovy/org/codehaus/groovy/tools/GrapeMain.groovy | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/670e901e/src/main/groovy/org/codehaus/groovy/tools/GrapeMain.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/org/codehaus/groovy/tools/GrapeMain.groovy b/src/main/groovy/org/codehaus/groovy/tools/GrapeMain.groovy
index 705cd26..eaa6964 100644
--- a/src/main/groovy/org/codehaus/groovy/tools/GrapeMain.groovy
+++ b/src/main/groovy/org/codehaus/groovy/tools/GrapeMain.groovy
@@ -110,7 +110,7 @@ class GrapeMain implements Runnable {
// The @Command(mixinStandardHelpOptions = true) attribute cannot be used because
// the unix standard short option for version help is uppercase -V, while previous versions
// of this class use lowercase -v. This custom mixin preserves option compatibility.
- @Command(versionProvider = VersionProvider.class, sortOptions = false,
+ @Command(versionProvider = VersionProvider, sortOptions = false,
parameterListHeading = "%nParameters:%n",
optionListHeading = "%nOptions:%n",
descriptionHeading = "%n")
[2/4] groovy git commit: GROOVY-8577 Migrate
org.codehaus.groovy.tools.GrapeMain.groovy to picocli
Posted by pa...@apache.org.
GROOVY-8577 Migrate org.codehaus.groovy.tools.GrapeMain.groovy to picocli
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/5061cb1e
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/5061cb1e
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/5061cb1e
Branch: refs/heads/GROOVY_2_6_X
Commit: 5061cb1e417f5aa577ba11320e6c7c478b106be1
Parents: 7e8c734
Author: Remko Popma <re...@yahoo.com>
Authored: Fri May 11 01:27:36 2018 +0900
Committer: Paul King <pa...@asert.com.au>
Committed: Fri May 18 12:24:13 2018 +1000
----------------------------------------------------------------------
.../org/codehaus/groovy/tools/GrapeMain.groovy | 533 ++++++++++---------
1 file changed, 283 insertions(+), 250 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/5061cb1e/src/main/groovy/org/codehaus/groovy/tools/GrapeMain.groovy
----------------------------------------------------------------------
diff --git a/src/main/groovy/org/codehaus/groovy/tools/GrapeMain.groovy b/src/main/groovy/org/codehaus/groovy/tools/GrapeMain.groovy
index dd330c3..705cd26 100644
--- a/src/main/groovy/org/codehaus/groovy/tools/GrapeMain.groovy
+++ b/src/main/groovy/org/codehaus/groovy/tools/GrapeMain.groovy
@@ -19,290 +19,323 @@
package org.codehaus.groovy.tools
import groovy.grape.Grape
-import groovy.transform.Field
-import org.apache.commons.cli.CommandLine
-import org.apache.commons.cli.DefaultParser
-import org.apache.commons.cli.HelpFormatter
-import org.apache.commons.cli.Option
-import org.apache.commons.cli.OptionGroup
-import org.apache.commons.cli.Options
import org.apache.ivy.util.DefaultMessageLogger
import org.apache.ivy.util.Message
-
-//commands
-
-@Field install = {arg, cmd ->
- if (arg.size() > 5 || arg.size() < 3) {
- println 'install requires two to four arguments: <group> <module> [<version> [<classifier>]]'
- return
- }
- def ver = '*'
- if (arg.size() >= 4) {
- ver = arg[3]
- }
- def classifier = null
- if (arg.size() >= 5) {
- classifier = arg[4]
+import picocli.CommandLine
+import picocli.CommandLine.Command
+import picocli.CommandLine.Option
+import picocli.CommandLine.Parameters
+import picocli.CommandLine.ParentCommand
+import picocli.CommandLine.RunLast
+import picocli.CommandLine.Unmatched
+
+@Command(name = "grape", description = "Allows for the inspection and management of the local grape cache.",
+ subcommands = [
+ Install.class,
+ Uninstall.class,
+ ListCommand.class,
+ Resolve.class,
+ picocli.CommandLine.HelpCommand.class])
+class GrapeMain implements Runnable {
+ @Option(names = ["-D", "--define"], description = "define a system property", paramLabel = "<name=value>")
+ private Map<String, String> properties = new LinkedHashMap<String, String>()
+
+ @Option(names = ["-r", "--resolver"], description = "define a grab resolver (for install)", paramLabel = "<url>")
+ private List<String> resolvers = new ArrayList<String>()
+
+ @Option(names = ["-q", "--quiet"], description = "Log level 0 - only errors")
+ private boolean quiet
+
+ @Option(names = ["-w", "--warn"], description = "Log level 1 - errors and warnings")
+ private boolean warn
+
+ @Option(names = ["-i", "--info"], description = "Log level 2 - info")
+ private boolean info
+
+ @Option(names = ["-V", "--verbose"], description = "Log level 3 - verbose")
+ private boolean verbose
+
+ @Option(names = ["-d", "--debug"], description = "Log level 4 - debug")
+ private boolean debug
+
+ @Unmatched List<String> unmatched = new ArrayList<String>()
+
+ private CommandLine parser
+
+ public static void main(String[] args) {
+ GrapeMain grape = new GrapeMain()
+ def parser = new CommandLine(grape)
+ parser.addMixin("helpOptions", new HelpOptionsMixin())
+ parser.subcommands.findAll { k, v -> k != 'help' }.each { k, v -> v.addMixin("helpOptions", new HelpOptionsMixin()) }
+
+ grape.parser = parser
+ parser.parseWithHandler(new RunLast(), args)
}
- // set the instance so we can re-set the logger
- Grape.getInstance()
- setupLogging()
+ void run() {
+ if (unmatched) {
+ System.err.println "grape: '${unmatched[0]}' is not a grape command. See 'grape --help'"
+ } else {
+ parser.usage(System.out) // if no subcommand was specified
+ }
+ }
- cmd.getOptionValues('r')?.each { String url ->
- Grape.addResolver(name:url, root:url)
+ private void init() {
+ properties.each { k, v ->
+ System.setProperty(k, v)
+ }
}
- try {
- Grape.grab(autoDownload: true, group: arg[1], module: arg[2], version: ver, classifier: classifier, noExceptions: true)
- } catch (Exception e) {
- println "An error occured : $ex"
+ private void setupLogging(int defaultLevel = 2) { // = Message.MSG_INFO -> some parsing error :(
+ if (quiet) {
+ Message.setDefaultLogger(new DefaultMessageLogger(Message.MSG_ERR))
+ } else if (warn) {
+ Message.setDefaultLogger(new DefaultMessageLogger(Message.MSG_WARN))
+ } else if (info) {
+ Message.setDefaultLogger(new DefaultMessageLogger(Message.MSG_INFO))
+ } else if (verbose) {
+ Message.setDefaultLogger(new DefaultMessageLogger(Message.MSG_VERBOSE))
+ } else if (debug) {
+ Message.setDefaultLogger(new DefaultMessageLogger(Message.MSG_DEBUG))
+ } else {
+ Message.setDefaultLogger(new DefaultMessageLogger(defaultLevel))
+ }
}
-}
-@Field uninstall = {arg, cmd ->
- if (arg.size() != 4) {
- println 'uninstall requires three arguments: <group> <module> <version>'
- // TODO make version optional? support classifier?
-// println 'uninstall requires two to four arguments, <group> <module> [<version>] [<classifier>]'
- return
+ /**
+ * Defines help options (--help and --version) and a version provider used by the top-level command and all subcommands.
+ * Intended to be installed as a picocli mixin.
+ */
+ // IMPLEMENTATION NOTE:
+ // The @Command(mixinStandardHelpOptions = true) attribute cannot be used because
+ // the unix standard short option for version help is uppercase -V, while previous versions
+ // of this class use lowercase -v. This custom mixin preserves option compatibility.
+ @Command(versionProvider = VersionProvider.class, sortOptions = false,
+ parameterListHeading = "%nParameters:%n",
+ optionListHeading = "%nOptions:%n",
+ descriptionHeading = "%n")
+ private static class HelpOptionsMixin {
+ @Option(names = ["-h", "--help"], description = "usage information") boolean isHelpRequested
+ @Option(names = ["-v", "--version"], description = "display the Groovy and JVM versions") boolean isVersionRequested
}
- String group = arg[1]
- String module = arg[2]
- String ver = arg[3]
-// def classifier = null
-
- // set the instance so we can re-set the logger
- Grape.getInstance()
- setupLogging()
-
- if (!Grape.enumerateGrapes().find {String groupName, Map g ->
- g.any {String moduleName, List<String> versions ->
- group == groupName && module == moduleName && ver in versions
- }
- }) {
- println "uninstall did not find grape matching: $group $module $ver"
- def fuzzyMatches = Grape.enumerateGrapes().findAll { String groupName, Map g ->
- g.any {String moduleName, List<String> versions ->
- groupName.contains(group) || moduleName.contains(module) ||
- group.contains(groupName) || module.contains(moduleName)
- }
- }
- if (fuzzyMatches) {
- println 'possible matches:'
- fuzzyMatches.each { String groupName, Map g -> println " $groupName: $g" }
+
+ private static class VersionProvider implements CommandLine.IVersionProvider {
+ String[] getVersion() {
+ String version = GroovySystem.getVersion()
+ return "Groovy Version: $version JVM: ${System.getProperty('java.version')}"
}
- return
}
- Grape.instance.uninstallArtifact(group, module, ver)
-}
-@Field list = {arg, cmd ->
- println ""
+ @Command(name = 'install', header = 'Installs a particular grape',
+ synopsisHeading = 'Usage: grape ',
+ description = 'Installs the specified groovy module or maven artifact. If a version is specified that specific version will be installed, otherwise the most recent version will be used (as if `*` was passed in).')
+ private static class Install implements Runnable {
+ @Parameters(index = '0', arity = '1', description = 'Which module group the module comes from. Translates directly to a Maven groupId or an Ivy Organization. Any group matching /groovy[x][\\..*]^/ is reserved and may have special meaning to the groovy endorsed modules.')
+ String group
- int moduleCount = 0
- int versionCount = 0
+ @Parameters(index = '1', arity = '1', description = 'The name of the module to load. Translated directly to a Maven artifactId or an Ivy artifact.')
+ String module
- // set the instance so we can re-set the logger
- Grape.getInstance()
- setupLogging()
+ @Parameters(index = '2', arity = '0..1', description = 'The version of the module to use. Either a literal version `1.1-RC3` or an Ivy Range `[2.2.1,)` meaning 2.2.1 or any greater version).')
+ String version = '*'
- Grape.enumerateGrapes().each {String groupName, Map group ->
- group.each {String moduleName, List<String> versions ->
- println "$groupName $moduleName $versions"
- moduleCount++
- versionCount += versions.size()
- }
- }
- println ""
- println "$moduleCount Grape modules cached"
- println "$versionCount Grape module versions cached"
-}
+ @Parameters(index = '3', arity = '0..1', description = 'The optional classifier to use (for example, jdk15).')
+ String classifier
-@Field resolve = {arg, cmd ->
- Options options = new Options();
- options.addOption(Option.builder("a").hasArg(false).longOpt("ant").build());
- options.addOption(Option.builder("d").hasArg(false).longOpt("dos").build());
- options.addOption(Option.builder("s").hasArg(false).longOpt("shell").build());
- options.addOption(Option.builder("i").hasArg(false).longOpt("ivy").build());
- CommandLine cmd2 = new DefaultParser().parse(options, arg[1..-1] as String[], true);
- arg = cmd2.args
-
- // set the instance so we can re-set the logger
- Grape.getInstance()
- setupLogging(Message.MSG_ERR)
-
- if ((arg.size() % 3) != 0) {
- println 'There needs to be a multiple of three arguments: (group module version)+'
- return
- }
- if (args.size() < 3) {
- println 'At least one Grape reference is required'
- return
- }
- def before, between, after
- def ivyFormatRequested = false
-
- if (cmd2.hasOption('a')) {
- before = '<pathelement location="'
- between = '">\n<pathelement location="'
- after = '">'
- } else if (cmd2.hasOption('d')) {
- before = 'set CLASSPATH='
- between = ';'
- after = ''
- } else if (cmd2.hasOption('s')) {
- before = 'export CLASSPATH='
- between = ':'
- after = ''
- } else if (cmd2.hasOption('i')) {
- ivyFormatRequested = true
- before = '<dependency '
- between = '">\n<dependency '
- after = '">'
- } else {
- before = ''
- between = '\n'
- after = '\n'
- }
+ @ParentCommand GrapeMain parentCommand
- iter = arg.iterator()
- def params = [[:]]
- def depsInfo = [] // this list will contain the module/group/version info of all resolved dependencies
- if(ivyFormatRequested) {
- params << depsInfo
- }
- while (iter.hasNext()) {
- params.add([group: iter.next(), module: iter.next(), version: iter.next()])
- }
- try {
- def results = []
- def uris = Grape.resolve(* params)
- if(!ivyFormatRequested) {
- for (URI uri: uris) {
- if (uri.scheme == 'file') {
- results += new File(uri).path
- } else {
- results += uri.toASCIIString()
- }
+ void run() {
+ parentCommand.init()
+
+ // set the instance so we can re-set the logger
+ Grape.getInstance()
+ parentCommand.setupLogging()
+
+ parentCommand.resolvers.each { String url ->
+ Grape.addResolver(name:url, root:url)
}
- } else {
- depsInfo.each { dep ->
- results += ('org="' + dep.group + '" name="' + dep.module + '" revision="' + dep.revision)
+
+ try {
+ Grape.grab(autoDownload: true, group: group, module: module, version: version, classifier: classifier, noExceptions: true)
+ } catch (Exception ex) {
+ println "An error occured : $ex"
}
}
+ }
- if (results) {
- println "${before}${results.join(between)}${after}"
- } else {
- println 'Nothing was resolved'
+ @Command(name = 'list', header = 'Lists all installed grapes',
+ synopsisHeading = 'Usage: grape ',
+ description = 'Lists locally installed modules (with their full maven name in the case of groovy modules) and versions.')
+ private static class ListCommand implements Runnable {
+
+ @ParentCommand GrapeMain parentCommand
+
+ void run() {
+ parentCommand.init()
+
+ println ""
+
+ int moduleCount = 0
+ int versionCount = 0
+
+ // set the instance so we can re-set the logger
+ Grape.getInstance()
+ parentCommand.setupLogging()
+
+ Grape.enumerateGrapes().each {String groupName, Map group ->
+ group.each {String moduleName, List<String> versions ->
+ println "$groupName $moduleName $versions"
+ moduleCount++
+ versionCount += versions.size()
+ }
+ }
+ println ""
+ println "$moduleCount Grape modules cached"
+ println "$versionCount Grape module versions cached"
}
- } catch (Exception e) {
- println "Error in resolve:\n\t$e.message"
- if (e.message =~ /unresolved dependency/) println "Perhaps the grape is not installed?"
}
-}
-@Field help = { arg, cmd -> grapeHelp() }
-
-@Field commands = [
- 'install': [closure: install,
- shortHelp: 'Installs a particular grape'],
- 'uninstall': [closure: uninstall,
- shortHelp: 'Uninstalls a particular grape (non-transitively removes the respective jar file from the grape cache)'],
- 'list': [closure: list,
- shortHelp: 'Lists all installed grapes'],
- 'resolve': [closure: resolve,
- shortHelp: 'Enumerates the jars used by a grape'],
- 'help': [closure: help,
- shortHelp: 'Usage information']
-]
-
-@Field grapeHelp = {
- int spacesLen = commands.keySet().max {it.length()}.length() + 3
- String spaces = ' ' * spacesLen
-
- PrintWriter pw = new PrintWriter(binding.variables.out ?: System.out)
- new HelpFormatter().printHelp(
- pw,
- 80,
- "grape [options] <command> [args]\n",
- "options:",
- options,
- 2,
- 4,
- null, // footer
- true);
- pw.flush()
-
- println ""
- println "commands:"
- commands.each {String k, v ->
- println " ${(k + spaces).substring(0, spacesLen)} $v.shortHelp"
- }
- println ""
-}
+ @Command(name = 'resolve', header = 'Enumerates the jars used by a grape',
+ synopsisHeading = 'Usage: grape ',
+ description = 'Prints the file locations of the jars representing the artifcats for the specified module(s) and the respective transitive dependencies.')
+ private static class Resolve implements Runnable {
-@Field setupLogging = {int defaultLevel = 2 -> // = Message.MSG_INFO -> some parsing error :(
- if (cmd.hasOption('q')) {
- Message.setDefaultLogger(new DefaultMessageLogger(Message.MSG_ERR))
- } else if (cmd.hasOption('w')) {
- Message.setDefaultLogger(new DefaultMessageLogger(Message.MSG_WARN))
- } else if (cmd.hasOption('i')) {
- Message.setDefaultLogger(new DefaultMessageLogger(Message.MSG_INFO))
- } else if (cmd.hasOption('V')) {
- Message.setDefaultLogger(new DefaultMessageLogger(Message.MSG_VERBOSE))
- } else if (cmd.hasOption('d')) {
- Message.setDefaultLogger(new DefaultMessageLogger(Message.MSG_DEBUG))
- } else {
- Message.setDefaultLogger(new DefaultMessageLogger(defaultLevel))
- }
-}
+ @Option(names = ['-a', '--ant'], description = 'Express dependencies in a format applicable for an ant script')
+ private boolean ant
-// command line parsing
-@Field Options options = new Options();
+ @Option(names = ['-d', '--dos'], description = 'Express dependencies in a format applicable for a windows batch file')
+ private boolean dos
-options.addOption(Option.builder("D").longOpt("define").desc("define a system property").numberOfArgs(2).valueSeparator().argName("name=value").build());
-options.addOption(Option.builder("r").longOpt("resolver").desc("define a grab resolver (for install)").hasArg(true).argName("url").build());
-options.addOption(Option.builder("h").hasArg(false).desc("usage information").longOpt("help").build());
+ @Option(names = ['-s', '--shell'], description = 'Express dependencies in a format applicable for a unix shell script')
+ private boolean shell
-// Logging Level Options
-options.addOptionGroup(
- new OptionGroup()
- .addOption(Option.builder("q").hasArg(false).desc("Log level 0 - only errors").longOpt("quiet").build())
- .addOption(Option.builder("w").hasArg(false).desc("Log level 1 - errors and warnings").longOpt("warn").build())
- .addOption(Option.builder("i").hasArg(false).desc("Log level 2 - info").longOpt("info").build())
- .addOption(Option.builder("V").hasArg(false).desc("Log level 3 - verbose").longOpt("verbose").build())
- .addOption(Option.builder("d").hasArg(false).desc("Log level 4 - debug").longOpt("debug").build())
-)
-options.addOption(Option.builder("v").hasArg(false).desc("display the Groovy and JVM versions").longOpt("version").build());
+ @Option(names = ['-i', '--ivy'], description = 'Express dependencies in an ivy-like format')
+ private boolean ivyFormatRequested
-@Field CommandLine cmd
+ @ParentCommand GrapeMain parentCommand
-cmd = new DefaultParser().parse(options, args, true);
+ void run() {
+ parentCommand.init()
-if (cmd.hasOption('h')) {
- grapeHelp()
- return
-}
+ // set the instance so we can re-set the logger
+ Grape.getInstance()
+ parentCommand.setupLogging(Message.MSG_ERR)
-if (cmd.hasOption('v')) {
- String version = GroovySystem.getVersion();
- println "Groovy Version: $version JVM: ${System.getProperty('java.version')}"
- return
-}
+ if ((arg.size() % 3) != 0) {
+ println 'There needs to be a multiple of three arguments: (group module version)+'
+ return
+ }
+ if (args.size() < 3) {
+ println 'At least one Grape reference is required'
+ return
+ }
+ def before, between, after
+
+ if (ant) {
+ before = '<pathelement location="'
+ between = '">\n<pathelement location="'
+ after = '">'
+ } else if (dos) {
+ before = 'set CLASSPATH='
+ between = ';'
+ after = ''
+ } else if (shell) {
+ before = 'export CLASSPATH='
+ between = ':'
+ after = ''
+ } else if (ivy) {
+ before = '<dependency '
+ between = '">\n<dependency '
+ after = '">'
+ } else {
+ before = ''
+ between = '\n'
+ after = '\n'
+ }
-if (options.hasOption('D')) {
- cmd.getOptionProperties('D')?.each { k, v ->
- System.setProperty(k, v)
+ iter = arg.iterator()
+ def params = [[:]]
+ def depsInfo = [] // this list will contain the module/group/version info of all resolved dependencies
+ if (ivyFormatRequested) {
+ params << depsInfo
+ }
+ while (iter.hasNext()) {
+ params.add([group: iter.next(), module: iter.next(), version: iter.next()])
+ }
+ try {
+ def results = []
+ def uris = Grape.resolve(* params)
+ if(!ivyFormatRequested) {
+ for (URI uri: uris) {
+ if (uri.scheme == 'file') {
+ results += new File(uri).path
+ } else {
+ results += uri.toASCIIString()
+ }
+ }
+ } else {
+ depsInfo.each { dep ->
+ results += ('org="' + dep.group + '" name="' + dep.module + '" revision="' + dep.revision)
+ }
+ }
+
+ if (results) {
+ println "${before}${results.join(between)}${after}"
+ } else {
+ println 'Nothing was resolved'
+ }
+ } catch (Exception e) {
+ println "Error in resolve:\n\t$e.message"
+ if (e.message =~ /unresolved dependency/) println "Perhaps the grape is not installed?"
+ }
+ }
}
-}
-String[] arg = cmd.args
-if (arg?.length == 0) {
- grapeHelp()
-} else if (commands.containsKey(arg[0])) {
- commands[arg[0]].closure(arg, cmd)
-} else {
- println "grape: '${arg[0]}' is not a grape command. See 'grape --help'"
+ @Command(name = 'uninstall',
+ synopsisHeading = 'Usage: grape ',
+ description = 'Uninstalls a particular grape (non-transitively removes the respective jar file from the grape cache).')
+ private static class Uninstall implements Runnable {
+ @Parameters(index = '0', arity = '1', description = 'Which module group the module comes from. Translates directly to a Maven groupId or an Ivy Organization. Any group matching /groovy[x][\\..*]^/ is reserved and may have special meaning to the groovy endorsed modules.')
+ String group
+
+ @Parameters(index = '1', arity = '1', description = 'The name of the module to load. Translated directly to a Maven artifactId or an Ivy artifact.')
+ String module
+
+ @Parameters(index = '2', arity = '1', description = 'The version of the module to use. Either a literal version `1.1-RC3` or an Ivy Range `[2.2.1,)` meaning 2.2.1 or any greater version).')
+ String version
+
+ // TODO make version optional? support classifier?
+ //@Parameters(index = '3', arity = '0..1', description = 'The optional classifier to use (for example, jdk15).')
+ //String classifier;
+
+ @ParentCommand GrapeMain parentCommand
+
+ void run() {
+ parentCommand.init()
+
+ // set the instance so we can re-set the logger
+ Grape.getInstance()
+ parentCommand.setupLogging()
+
+ if (!Grape.enumerateGrapes().find {String groupName, Map g ->
+ g.any {String moduleName, List<String> versions ->
+ group == groupName && module == moduleName && version in versions
+ }
+ }) {
+ println "uninstall did not find grape matching: $group $module $version"
+ def fuzzyMatches = Grape.enumerateGrapes().findAll { String groupName, Map g ->
+ g.any {String moduleName, List<String> versions ->
+ groupName.contains(group) || moduleName.contains(module) ||
+ group.contains(groupName) || module.contains(moduleName)
+ }
+ }
+ if (fuzzyMatches) {
+ println 'possible matches:'
+ fuzzyMatches.each { String groupName, Map g -> println " $groupName: $g" }
+ }
+ return
+ }
+ Grape.instance.uninstallArtifact(group, module, version)
+ }
+ }
}