Skip to content
Permalink
Browse files

Update registryTool task to better handle command line arguments (#273)

* Update registryTool task to better handle command line arguments

Tokens are delimited by pipes and can be escaped. If we use -args
directly, we will not be able to escape the delimiter, if both the
double and single quotes happen to be present in the arguments.

See:

https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/JavaExec.html#setArgsString-java.lang.String-
  • Loading branch information...
jianglai committed Sep 20, 2019
1 parent 8f5bd5d commit 3764e2b26c5f7761385696d2f3ff52af7a455125
Showing with 31 additions and 2 deletions.
  1. +31 −2 core/build.gradle
@@ -592,11 +592,40 @@ task findGoldenImages(type: JavaExec) {
args arguments
}

// To run the nomulus tool:
// gradle registryTool --args="foo --bar"
// To run the nomulus tool with these command line tokens:
// "--foo", "bar baz", "--qux=quz"
// gradle registryTool --args="--foo 'bar baz' --qux=quz"
// or:
// gradle registryTool --PtoolArgs="--foo|bar baz|--qux=quz"
// Note that the delimiting pipe can be backslash escaped if it is part of a
// parameter.
task registryTool(type: JavaExec) {
classpath = sourceSets.main.runtimeClasspath
main = 'google.registry.tools.RegistryTool'

// If "-PtoolArgs=..." is present in the command line, use it to set the args,
// otherwise use the default flag, which is "--args" to set the args.
doFirst {
def toolArgs = rootProject.findProperty("toolArgs")
if (toolArgs != null) {
def delimiter = '|'
toolArgs += delimiter
def argsList = []
def currArg = ''
for (def i = 0; i < toolArgs.length(); i++) {
def currChar = toolArgs[i]
if (currChar != delimiter) {
currArg += currChar
} else if (i != 0 && toolArgs[i - 1] == '\\') {
currArg = currArg.substring(0, currArg.length() - 1) + currChar
} else {
argsList.add(currArg)
currArg = ''
}
}
args = argsList
}
}
}

task generateGoldenImages(type: Test) {

0 comments on commit 3764e2b

Please sign in to comment.
You can’t perform that action at this time.