Skip to content

Commit 67a01b4

Browse files
authored
Merge pull request jenkinsci#89 from krulls/master
JENKINS-43574: fix construction of RequiredResourcesProperty
2 parents 3b9717e + 90bee03 commit 67a01b4

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

src/main/java/org/jenkins/plugins/lockableresources/RequiredResourcesProperty.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,33 @@ public RequiredResourcesProperty(String resourceNames,
4343
String resourceNamesVar, String resourceNumber,
4444
String labelName, @CheckForNull SecureGroovyScript resourceMatchScript) {
4545
super();
46-
if (resourceNames != null) {
46+
47+
if (resourceNames == null || resourceNames.trim().isEmpty()) {
48+
this.resourceNames = null;
49+
} else {
4750
this.resourceNames = resourceNames.trim();
51+
}
52+
if (resourceNamesVar == null || resourceNamesVar.trim().isEmpty()) {
53+
this.resourceNamesVar = null;
4854
} else {
49-
this.resourceNames = null;
55+
this.resourceNamesVar = resourceNamesVar.trim();
56+
}
57+
if (resourceNumber == null || resourceNumber.trim().isEmpty()) {
58+
this.resourceNumber = null;
59+
} else {
60+
this.resourceNumber = resourceNumber.trim();
5061
}
51-
this.resourceNamesVar = resourceNamesVar;
52-
this.resourceNumber = resourceNumber;
62+
String labelNamePreparation = (labelName == null || labelName.trim().isEmpty()) ? null : labelName.trim();
5363
if (resourceMatchScript != null) {
5464
this.resourceMatchScript = resourceMatchScript.configuringWithKeyItem();
55-
this.labelName = labelName;
65+
this.labelName = labelNamePreparation;
5666
} else if (labelName != null && labelName.startsWith(LockableResource.GROOVY_LABEL_MARKER)) {
5767
this.resourceMatchScript = new SecureGroovyScript(labelName.substring(LockableResource.GROOVY_LABEL_MARKER.length()),
5868
false, null).configuring(ApprovalContext.create());
5969
this.labelName = null;
6070
} else {
6171
this.resourceMatchScript = null;
62-
this.labelName = labelName;
72+
this.labelName = labelNamePreparation;
6373
}
6474
}
6575

src/test/java/org/jenkins/plugins/lockableresources/BasicIntegrationTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ public void configRoundTrip() throws Exception {
109109
assertNotNull(withResourceProp);
110110
assertEquals("resource1", withResourceProp.getResourceNames());
111111
assertEquals("resourceNameVar", withResourceProp.getResourceNamesVar());
112-
assertEquals("", withResourceProp.getResourceNumber());
113-
assertEquals("", withResourceProp.getLabelName());
112+
assertNull(withResourceProp.getResourceNumber());
113+
assertNull(withResourceProp.getLabelName());
114114
assertNull(withResourceProp.getResourceMatchScript());
115115

116116
FreeStyleProject withLabel = j.createFreeStyleProject("withLabel");
@@ -119,9 +119,9 @@ public void configRoundTrip() throws Exception {
119119

120120
RequiredResourcesProperty withLabelProp = withLabelRoundTrip.getProperty(RequiredResourcesProperty.class);
121121
assertNotNull(withLabelProp);
122-
assertEquals("", withLabelProp.getResourceNames());
123-
assertEquals("", withLabelProp.getResourceNamesVar());
124-
assertEquals("", withLabelProp.getResourceNumber());
122+
assertNull(withLabelProp.getResourceNames());
123+
assertNull(withLabelProp.getResourceNamesVar());
124+
assertNull(withLabelProp.getResourceNumber());
125125
assertEquals("some-label", withLabelProp.getLabelName());
126126
assertNull(withLabelProp.getResourceMatchScript());
127127

@@ -132,10 +132,10 @@ public void configRoundTrip() throws Exception {
132132

133133
RequiredResourcesProperty withScriptProp = withScriptRoundTrip.getProperty(RequiredResourcesProperty.class);
134134
assertNotNull(withScriptProp);
135-
assertEquals("", withScriptProp.getResourceNames());
136-
assertEquals("", withScriptProp.getResourceNamesVar());
137-
assertEquals("", withScriptProp.getResourceNumber());
138-
assertEquals("", withScriptProp.getLabelName());
135+
assertNull(withScriptProp.getResourceNames());
136+
assertNull(withScriptProp.getResourceNamesVar());
137+
assertNull(withScriptProp.getResourceNumber());
138+
assertNull(withScriptProp.getLabelName());
139139
assertNotNull(withScriptProp.getResourceMatchScript());
140140
assertEquals("return true", withScriptProp.getResourceMatchScript().getScript());
141141
assertEquals(false, withScriptProp.getResourceMatchScript().isSandbox());

0 commit comments

Comments
 (0)