Skip to content

Commit

Permalink
[JENKINS-46064] Groovy is groovy again
Browse files Browse the repository at this point in the history
Use collection.any instead of boring traditional iterations
  • Loading branch information
rsandell committed Aug 18, 2017
1 parent 2b14f51 commit ebc4787
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
Expand Up @@ -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)
}
}
}
Expand Down
Expand Up @@ -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> {
Expand All @@ -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
}
}
Expand Up @@ -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();
}

Expand Down

0 comments on commit ebc4787

Please sign in to comment.