Last active
November 18, 2022 23:20
-
-
Save benigumocom/e517f0b2a3cc802019a470a0222ad199 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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());