Skip to content

Commit fffc024

Browse files
authored
Merge pull request #3 from rundeck-plugins/issue/2
fixing issue with multiples matchers
2 parents 5f001aa + 333f4d6 commit fffc024

File tree

5 files changed

+118
-9
lines changed

5 files changed

+118
-9
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
*.iws
44
*.iml
55
/build
6+
.idea
7+
out

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: java
22
jdk:
3-
- oraclejdk8
3+
- openjdk8
44
before_cache:
55
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
66
cache:

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ scmVersion {
1717
prefix = 'v'
1818
versionSeparator = ''
1919
}
20-
ignoreUncommittedChanges = false
20+
ignoreUncommittedChanges = true
2121
}
2222

2323
allprojects {

src/main/java/org/rundeck/plugins/nodes/attributes/AttributeNodeEnhancer.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package org.rundeck.plugins.nodes.attributes;
22

3-
4-
import com.dtolabs.rundeck.core.common.INodeEntry;
53
import com.dtolabs.rundeck.core.plugins.Plugin;
6-
import com.dtolabs.rundeck.core.plugins.configuration.DynamicProperties;
7-
import com.dtolabs.rundeck.core.plugins.configuration.StringRenderingConstants;
84
import com.dtolabs.rundeck.plugins.descriptions.*;
95
import com.dtolabs.rundeck.plugins.nodes.IModifiableNodeEntry;
106
import com.dtolabs.rundeck.plugins.nodes.NodeEnhancerPlugin;
11-
import org.rundeck.app.spi.Services;
127

138
import java.io.IOException;
149
import java.io.StringReader;
@@ -109,8 +104,9 @@ private void addAll(final Map<String, String> attributes) {
109104
}
110105

111106
private boolean matchesAll(final Map<String, String> attributes) {
107+
boolean regexMatch = true;
112108
Map<String, Predicate<String>> comparisons = new HashMap<>();
113-
for (final String s : match.split("\r\n")) {
109+
for (final String s : match.split("\r?\n")) {
114110
Matcher matcher = ComparisonPattern.matcher(s);
115111
if (matcher.matches()) {
116112
String key = matcher.group("key");
@@ -120,9 +116,13 @@ private boolean matchesAll(final Map<String, String> attributes) {
120116
comparisons.compute(key, (s1, stringPredicate) ->
121117
stringPredicate != null ? stringPredicate.and(newOp) : newOp
122118
);
123-
119+
}else{
120+
regexMatch = false;
124121
}
125122
}
123+
if(!regexMatch){
124+
return false;
125+
}
126126
for (String s : comparisons.keySet()) {
127127
if (!comparisons.get(s).test(attributes.get(s))) {
128128
return false;
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package org.rundeck.plugins.nodes.attributes
2+
3+
import com.dtolabs.rundeck.core.common.NodeEntryImpl
4+
import com.dtolabs.rundeck.plugins.nodes.IModifiableNodeEntry
5+
import spock.lang.Specification
6+
7+
class AttributeNodeEnhancerSpec extends Specification{
8+
9+
def "test bad regex match"(){
10+
11+
given:
12+
def plugin = new AttributeNodeEnhancer()
13+
plugin.match = "attb1=value1"
14+
plugin.add = "attb2=value2"
15+
16+
17+
def node = new ModifiableNodeEntry("test1")
18+
node.attributes = [attb1:"value1"]
19+
20+
def project = "TestProject"
21+
when:
22+
23+
plugin.updateNode(project, node)
24+
25+
then:
26+
node.attributes.attb2 == null
27+
28+
}
29+
30+
def "test regex match"(){
31+
32+
given:
33+
def plugin = new AttributeNodeEnhancer()
34+
plugin.match = "attb1==value1"
35+
plugin.add = "attb2=value2"
36+
37+
38+
def node = new ModifiableNodeEntry("test1")
39+
node.attributes = [attb1:"value1"]
40+
41+
def project = "TestProject"
42+
when:
43+
44+
plugin.updateNode(project, node)
45+
46+
then:
47+
node.attributes.attb2 == "value2"
48+
49+
}
50+
51+
def "test multiples regex match"(){
52+
53+
given:
54+
def plugin = new AttributeNodeEnhancer()
55+
plugin.match = match
56+
plugin.add = "result=valueResult"
57+
58+
59+
def node = new ModifiableNodeEntry("test1")
60+
node.attributes = [attb1:"value1",attb2:"value2"]
61+
62+
def project = "TestProject"
63+
when:
64+
65+
plugin.updateNode(project, node)
66+
67+
then:
68+
node.attributes.result == result
69+
70+
where:
71+
match | result
72+
"attb1==value1\nattb2==value2" | "valueResult"
73+
"attb1==value1\r\nattb2==value2" | "valueResult"
74+
"attb1=value1\r\nattb2==value2" | null
75+
"attb1==value1\nattb2=value2" | null
76+
}
77+
78+
79+
class ModifiableNodeEntry extends NodeEntryImpl implements IModifiableNodeEntry{
80+
81+
ModifiableNodeEntry(final String nodename) {
82+
super(nodename)
83+
}
84+
85+
86+
@Override
87+
void addAttribute(final String name, final String value) {
88+
attributes.put(name, value)
89+
}
90+
91+
@Override
92+
void removeAttribute(final String name) {
93+
attributes.remove(name)
94+
}
95+
96+
@Override
97+
void addTag(final String tag) {
98+
tags.add(tag)
99+
}
100+
101+
@Override
102+
void removeTag(String tag) {
103+
tags.remove(tag)
104+
}
105+
}
106+
107+
}

0 commit comments

Comments
 (0)