Skip to content
Permalink
Browse files

[JENKINS-46064] Groovy is groovy again

Use collection.any instead of boring traditional iterations
  • Loading branch information
rsandell committed Aug 18, 2017
1 parent 2b14f51 commit ebc4787807c272f4c87f9cb0a2d72ba541088c7e
@@ -81,14 +81,9 @@ abstract class AbstractChangelogConditionalScript<S extends DeclarativeStageCond
}
return false
}
for (int i = 0; i < changeSets.size(); i++) { //TODO switch to .any when #174 lands.
def set = changeSets.get(i)
def iterator = set.iterator()
while (iterator.hasNext()) {
def change = iterator.next()
if (matches(change)) {
return true
}
return changeSets.any {def set ->
return set.any { def change ->
return matches(change)
}
}
}
@@ -27,6 +27,7 @@ package org.jenkinsci.plugins.pipeline.modeldefinition.when.impl

import hudson.scm.ChangeLogSet
import org.apache.tools.ant.DirectoryScanner
import org.apache.tools.ant.types.selectors.SelectorUtils
import org.jenkinsci.plugins.workflow.cps.CpsScript

class ChangeSetConditionalScript extends AbstractChangelogConditionalScript<ChangeSetConditional> {
@@ -43,14 +44,9 @@ class ChangeSetConditionalScript extends AbstractChangelogConditionalScript<Chan

@Override
boolean matches(ChangeLogSet.Entry change) {
def iterator = change.affectedPaths.iterator()
while (iterator.hasNext()) { //TODO switch to .any when #174 lands
String path = iterator.next();
return change.affectedPaths.any { String path ->
path = path.replace('\\', '/')
if (DirectoryScanner.match(glob, path, describable.isCaseSensitive())) {
return true
}
return SelectorUtils.matchPath(glob, path, describable.isCaseSensitive())
}
return false
}
}
@@ -153,7 +153,10 @@ public void whenChangeset() throws Exception {
sampleRepo.git("commit", "--message=files");

builder.logContains("Hello", "JS World")
.logNotContains("Stage 'Two' skipped due to when conditional", "Warning, empty changelog.")
.logNotContains(
"Stage 'Two' skipped due to when conditional",
"Warning, empty changelog.",
"Examining changelog from all builds of this change request.")
.go();
}

0 comments on commit ebc4787

Please sign in to comment.
You can’t perform that action at this time.