From 4752e41dd188a1f58a8e8516f66b2b5e8f72d7d3 Mon Sep 17 00:00:00 2001 From: Petkov Date: Mon, 7 Oct 2019 12:02:09 +0100 Subject: [PATCH] Change discovery to recursive as per https://github.com/jenkinsci/global-build-stats-plugin/pull/14#issuecomment-520787043 --- .../business/GlobalBuildStatsBusiness.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/hudson/plugins/global_build_stats/business/GlobalBuildStatsBusiness.java b/src/main/java/hudson/plugins/global_build_stats/business/GlobalBuildStatsBusiness.java index 10dff89..c8833ff 100644 --- a/src/main/java/hudson/plugins/global_build_stats/business/GlobalBuildStatsBusiness.java +++ b/src/main/java/hudson/plugins/global_build_stats/business/GlobalBuildStatsBusiness.java @@ -34,6 +34,7 @@ import org.jfree.ui.RectangleEdge; import org.jfree.ui.RectangleInsets; +import org.jenkinsci.plugins.workflow.multibranch.WorkflowMultiBranchProject; import com.cloudbees.hudson.plugins.folder.Folder; public class GlobalBuildStatsBusiness { @@ -96,15 +97,7 @@ public void changePluginStateBeforeSavingIt(GlobalBuildStatsPlugin plugin) { List jobBuildResultsRead = new ArrayList(); for (TopLevelItem item : Hudson.getInstance().getItems()) { - if (item instanceof Folder){ - Folder f = (Folder)item; - for (TopLevelItem i : f.getItems()){ - handleItem(jobBuildResultsRead,i); - } - } - if (item instanceof Job) { - handleItem(jobBuildResultsRead, item); - } + recursivelyAddBuilds(jobBuildResultsRead, item); } plugin.getJobBuildResultsSharder().queueResultsToAdd( @@ -112,11 +105,24 @@ public void changePluginStateBeforeSavingIt(GlobalBuildStatsPlugin plugin) { } }); } - - public void handleItem(List results, TopLevelItem item){ + + public void recursivelyAddBuilds(List results, TopLevelItem item){ if (item instanceof Job){ - addBuildsFrom(results, (Job)item); + addBuildsFrom(results, (Job) item); } + if (item instanceof Folder){ + Folder f = (Folder) item; + for (TopLevelItem i : f.getItems()){ + recursivelyAddBuilds(results, i); + } + } + + if (item instanceof WorkflowMultiBranchProject) { + WorkflowMultiBranchProject w = (WorkflowMultiBranchProject) item; + for (TopLevelItem i : w.getItems()) { + recursivelyAddBuilds(results, i); + } + } } public JFreeChart createChart(BuildStatConfiguration config){