Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline Regex handling multiple key-value pairs #5

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions src/main/groovy/com/rundeck/plugin/DataKeyFilterMultiLines.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -100,25 +100,34 @@ See the [Java Pattern](https://docs.oracle.com/javase/8/docs/api/java/util/regex
void complete(final PluginLoggingContext context) {

if(buffer.size()>0){
Matcher match = dataPattern.matcher(buffer.toString())

if (match.matches()) {
def key,value

if(match.groupCount()>0){
if(match.groupCount()==1 && name){
key = name
value = match.group(1)
}else {
if(match.groupCount()>1){
key = match.group(1)
value = match.group(2)

for (String line : buffer.toString().split((System.getProperty("line.separator")))) {

Matcher match = dataPattern.matcher(line)

if (match.matches()) {
def key, value

if (match.groupCount() > 0) {
if (match.groupCount() == 1 && name) {
key = name
value = match.group(1)
} else {
if (match.groupCount() > 1) {
key = match.group(1)
value = match.group(2)
}
}
}

if (key && value) {
allData[key] = value
outputContext.addOutput("data", key, value)
if (key && value) {

if(allData[key] == null ) {
allData[key] = value
} else {
allData[key] = allData[key] + System.getProperty("line.separator") + value
}
outputContext.addOutput("data", key, value)
}
}
}
}
Expand All @@ -136,4 +145,4 @@ See the [Java Pattern](https://docs.oracle.com/javase/8/docs/api/java/util/regex
}

}
}
}