Skip to content
Permalink
Browse files
Merge pull request #89 from krulls/master
JENKINS-43574: fix construction of RequiredResourcesProperty
  • Loading branch information
amuniz committed Mar 6, 2018
2 parents 3b9717e + 90bee03 commit 67a01b44f4a995955e0888db62f927fcc740697a
@@ -43,23 +43,33 @@ public RequiredResourcesProperty(String resourceNames,
String resourceNamesVar, String resourceNumber,
String labelName, @CheckForNull SecureGroovyScript resourceMatchScript) {
super();
if (resourceNames != null) {

if (resourceNames == null || resourceNames.trim().isEmpty()) {
this.resourceNames = null;
} else {
this.resourceNames = resourceNames.trim();
}
if (resourceNamesVar == null || resourceNamesVar.trim().isEmpty()) {
this.resourceNamesVar = null;
} else {
this.resourceNames = null;
this.resourceNamesVar = resourceNamesVar.trim();
}
if (resourceNumber == null || resourceNumber.trim().isEmpty()) {
this.resourceNumber = null;
} else {
this.resourceNumber = resourceNumber.trim();
}
this.resourceNamesVar = resourceNamesVar;
this.resourceNumber = resourceNumber;
String labelNamePreparation = (labelName == null || labelName.trim().isEmpty()) ? null : labelName.trim();
if (resourceMatchScript != null) {
this.resourceMatchScript = resourceMatchScript.configuringWithKeyItem();
this.labelName = labelName;
this.labelName = labelNamePreparation;
} else if (labelName != null && labelName.startsWith(LockableResource.GROOVY_LABEL_MARKER)) {
this.resourceMatchScript = new SecureGroovyScript(labelName.substring(LockableResource.GROOVY_LABEL_MARKER.length()),
false, null).configuring(ApprovalContext.create());
this.labelName = null;
} else {
this.resourceMatchScript = null;
this.labelName = labelName;
this.labelName = labelNamePreparation;
}
}

@@ -109,8 +109,8 @@ public void configRoundTrip() throws Exception {
assertNotNull(withResourceProp);
assertEquals("resource1", withResourceProp.getResourceNames());
assertEquals("resourceNameVar", withResourceProp.getResourceNamesVar());
assertEquals("", withResourceProp.getResourceNumber());
assertEquals("", withResourceProp.getLabelName());
assertNull(withResourceProp.getResourceNumber());
assertNull(withResourceProp.getLabelName());
assertNull(withResourceProp.getResourceMatchScript());

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

RequiredResourcesProperty withLabelProp = withLabelRoundTrip.getProperty(RequiredResourcesProperty.class);
assertNotNull(withLabelProp);
assertEquals("", withLabelProp.getResourceNames());
assertEquals("", withLabelProp.getResourceNamesVar());
assertEquals("", withLabelProp.getResourceNumber());
assertNull(withLabelProp.getResourceNames());
assertNull(withLabelProp.getResourceNamesVar());
assertNull(withLabelProp.getResourceNumber());
assertEquals("some-label", withLabelProp.getLabelName());
assertNull(withLabelProp.getResourceMatchScript());

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

RequiredResourcesProperty withScriptProp = withScriptRoundTrip.getProperty(RequiredResourcesProperty.class);
assertNotNull(withScriptProp);
assertEquals("", withScriptProp.getResourceNames());
assertEquals("", withScriptProp.getResourceNamesVar());
assertEquals("", withScriptProp.getResourceNumber());
assertEquals("", withScriptProp.getLabelName());
assertNull(withScriptProp.getResourceNames());
assertNull(withScriptProp.getResourceNamesVar());
assertNull(withScriptProp.getResourceNumber());
assertNull(withScriptProp.getLabelName());
assertNotNull(withScriptProp.getResourceMatchScript());
assertEquals("return true", withScriptProp.getResourceMatchScript().getScript());
assertEquals(false, withScriptProp.getResourceMatchScript().isSandbox());

0 comments on commit 67a01b4

Please sign in to comment.