Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active Nov 18, 2022
Embed
What would you like to do?
// live template expression
// groovyScript("/absolute/path/to/inline.groovy", clipboard());
def cb = _1
def ls = System.lineSeparator()
return cb.split(ls).collect { l ->
def w = l.split("\"", -1)
if (w.size() == 3) { // single quoted string per a line
def s = w[1].split(":")
switch(s.size()) {
case 2: // plugins
"${w[0]}{ id = \"${s[0]}\", version = \"${s[1]}\" }${w[2]}"
break
case 3: // libraries
"${w[0]}{ module = \"${s[0]}:${s[1]}\", version = \"${s[2]}\" }${w[2]}"
break
default: // NG?
"${l} ###"
}
} else {
l
}
}.join(ls)
@benigumocom
Copy link
Author

benigumocom commented Nov 17, 2022

groovyScript("def ls = System.lineSeparator();return _1.split(ls).collect() { l -> l.replaceAll(/^([a-z0-9\\-]+) = \"([^\\:\"]+):([^\\:\"]+)\"/) { _, k, i, v -> \"$k = { id = \\\"$i\\\", version = \\\"$v\\\" }\"}.replaceAll(/^([a-z0-9\\-]+) = \"([^\\:\"]+):([^\\:\"]+):([^\\:\"]+)\"/) { _, k, g, a, v -> \"$k = { module = \\\"$g:$a\\\", version = \\\"$v\\\" }\"}}.join(ls)", clipboard());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment