From 4df2499a7a745ada4429df2d152a9227fdfb2acc Mon Sep 17 00:00:00 2001 From: "CloudBees DEV@Cloud" Date: Tue, 11 Apr 2017 10:34:18 +0100 Subject: [PATCH 1/2] Release candidate v1.12+build.201704111018 --- build-monitor-acceptance/pom.xml | 2 +- build-monitor-plugin/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build-monitor-acceptance/pom.xml b/build-monitor-acceptance/pom.xml index 09a7cab7c..fab7c3619 100644 --- a/build-monitor-acceptance/pom.xml +++ b/build-monitor-acceptance/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins build-monitor - 1.12-SNAPSHOT + 1.12+build.201704111018 ../pom.xml diff --git a/build-monitor-plugin/pom.xml b/build-monitor-plugin/pom.xml index 2f5a7a57a..41c8cd351 100644 --- a/build-monitor-plugin/pom.xml +++ b/build-monitor-plugin/pom.xml @@ -4,7 +4,7 @@ org.jenkins-ci.plugins build-monitor - 1.12-SNAPSHOT + 1.12+build.201704111018 ../pom.xml diff --git a/pom.xml b/pom.xml index fbb986aaa..5c06e3a7a 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ org.jenkins-ci.plugins build-monitor - 1.12-SNAPSHOT + 1.12+build.201704111018 pom Build Monitor From 2d42f2cd22ae503ee73e5a6270845c1267a5f9ec Mon Sep 17 00:00:00 2001 From: Magnus Reftel Date: Fri, 14 Oct 2016 23:17:25 +0200 Subject: [PATCH 2/2] Feature: include/exclude branches of multi-branch pipelines Closes #246 --- build-monitor-plugin/pom.xml | 2 +- .../buildmonitor/BuildMonitorView.java | 25 +++- .../plugins/buildmonitor/Config.java | 22 +++ .../plugins/buildmonitor/JobFilter.java | 66 +++++++++ .../BuildMonitorView/configure-entries.jelly | 8 + .../help-branchesToExclude.html | 10 ++ .../help-branchesToInclude.html | 9 ++ .../plugins/buildmonitor/JobFilterTest.java | 137 ++++++++++++++++++ 8 files changed, 273 insertions(+), 6 deletions(-) create mode 100644 build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/JobFilter.java create mode 100644 build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/help-branchesToExclude.html create mode 100644 build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/help-branchesToInclude.html create mode 100644 build-monitor-plugin/src/test/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/JobFilterTest.java diff --git a/build-monitor-plugin/pom.xml b/build-monitor-plugin/pom.xml index 41c8cd351..bc6ba5fca 100644 --- a/build-monitor-plugin/pom.xml +++ b/build-monitor-plugin/pom.xml @@ -136,7 +136,7 @@ org.jenkins-ci.plugins cloudbees-folder - 5.16 + 5.12 true diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView.java index 0b324db25..7c17b6d59 100644 --- a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView.java +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView.java @@ -86,6 +86,16 @@ public String currentOrder() { return currentConfig().getOrder().getClass().getSimpleName(); } + @SuppressWarnings("unused") // used in the configure-entries.jelly form + public String branchesToInclude() { + return currentConfig().getBranchesToInclude(); + } + + @SuppressWarnings("unused") // used in the configure-entries.jelly form + public String branchesToExclude() { + return currentConfig().getBranchesToExclude(); + } + @SuppressWarnings("unused") // used in the configure-entries.jelly form public boolean isDisplayCommitters() { return currentConfig().shouldDisplayCommitters(); @@ -112,9 +122,13 @@ protected void submit(StaplerRequest req) throws ServletException, IOException, synchronized (this) { String requestedOrdering = req.getParameter("order"); + String branchesToInclude = req.getParameter("branchesToInclude"); + String branchesToExclude = req.getParameter("branchesToExclude"); title = req.getParameter("title"); currentConfig().setDisplayCommitters(json.optBoolean("displayCommitters", true)); + currentConfig().setBranchesToInclude(branchesToInclude); + currentConfig().setBranchesToExclude(branchesToExclude); try { currentConfig().setOrder(orderIn(requestedOrdering)); @@ -144,13 +158,10 @@ private boolean isGiven(String value) { private List jobViews() { JobViews views = new JobViews(new StaticJenkinsAPIs(), currentConfig()); - //A little bit of evil to make the type system happy. - @SuppressWarnings("unchecked") - List> projects = new ArrayList(filter(super.getItems(), Job.class)); - List jobs = new ArrayList(); - + List> projects = currentJobFilter().filterJobs(this.getItems()); Collections.sort(projects, currentConfig().getOrder()); + List jobs = new ArrayList(projects.size()); for (Job project : projects) { jobs.add(views.viewOf(project)); } @@ -179,6 +190,10 @@ else if (deserailisingFromAnOlderFormat()) { return config; } + private JobFilter currentJobFilter() { + return new JobFilter(currentConfig()); + } + private boolean creatingAFreshView() { return config == null && order == null; } diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/Config.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/Config.java index 83ebd2e7b..d5ffb5a0b 100644 --- a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/Config.java +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/Config.java @@ -44,10 +44,32 @@ public void setDisplayCommitters(boolean flag) { public String toString() { return Objects.toStringHelper(this) .add("order", order.getClass().getSimpleName()) + .add("branchesToInclude", branchesToInclude) + .add("branchesToExclude", branchesToExclude) .toString(); } // -- private Comparator> order; + + private String branchesToInclude; + + public String getBranchesToInclude() { + return branchesToInclude; + } + + public void setBranchesToInclude(String branchesToInclude) { + this.branchesToInclude = branchesToInclude; + } + + private String branchesToExclude; + + public String getBranchesToExclude() { + return branchesToExclude; + } + + public void setBranchesToExclude(String branchesToExclude) { + this.branchesToExclude = branchesToExclude; + } } \ No newline at end of file diff --git a/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/JobFilter.java b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/JobFilter.java new file mode 100644 index 000000000..5530973e2 --- /dev/null +++ b/build-monitor-plugin/src/main/java/com/smartcodeltd/jenkinsci/plugins/buildmonitor/JobFilter.java @@ -0,0 +1,66 @@ +package com.smartcodeltd.jenkinsci.plugins.buildmonitor; + +import com.google.common.base.Strings; +import hudson.model.Item; +import hudson.model.ItemGroup; +import hudson.model.Job; +import hudson.model.TopLevelItem; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.regex.Pattern; + +import static hudson.Util.filter; + +public class JobFilter { + private final Pattern includePattern; + private final Pattern excludePattern; + private Class abstractFolderClass; + + public JobFilter(Config config) { + String include = config.getBranchesToInclude(); + String exclude = config.getBranchesToExclude(); + includePattern = Strings.isNullOrEmpty(include) ? null : Pattern.compile(include); + excludePattern = Strings.isNullOrEmpty(exclude) ? null : Pattern.compile(exclude); + try { + abstractFolderClass = Class.forName("com.cloudbees.hudson.plugins.folder.AbstractFolder") + .asSubclass(ItemGroup.class); + } catch (ClassNotFoundException e) { + abstractFolderClass = null; + } + } + + public List> filterJobs(Collection items) { + List> jobs = new ArrayList>(); + + if (items == null) { + return jobs; + } + + if (abstractFolderClass != null) { + for (ItemGroup folder : filter(items, abstractFolderClass)) { + Collection folderItems = folder.getItems(); + if (folderItems == null) { + continue; + } + List groupJobs = filter(folderItems, Job.class); + for (Job job : groupJobs) { + String relativename = job.getRelativeNameFrom(folder); + boolean shouldInclude = includePattern == null || includePattern.matcher(relativename).find(); + boolean shouldExclude = excludePattern != null && excludePattern.matcher(relativename).find(); + if (shouldInclude && !shouldExclude) { + jobs.add(job); + } + } + } + } + + for (Job job : filter(items, Job.class)) { + jobs.add(job); + } + + return jobs; + } + +} diff --git a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/configure-entries.jelly b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/configure-entries.jelly index 59a277a47..d20d8f1b2 100644 --- a/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/configure-entries.jelly +++ b/build-monitor-plugin/src/main/resources/com/smartcodeltd/jenkinsci/plugins/buildmonitor/BuildMonitorView/configure-entries.jelly @@ -56,6 +56,14 @@ + + + + + + + +