summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-24 02:22:26 (EST)
committer Winston Prakash2011-12-01 20:47:22 (EST)
commit41d738392261b88dd77df0b3ae15367766e569f7 (patch)
tree73c7f46587dfe9e859046f6e0826404cf8e6dc35
parent04926599e92a0278c6c9019ae92918c7886bb780 (diff)
downloadorg.eclipse.hudson.core-41d738392261b88dd77df0b3ae15367766e569f7.zip
org.eclipse.hudson.core-41d738392261b88dd77df0b3ae15367766e569f7.tar.gz
org.eclipse.hudson.core-41d738392261b88dd77df0b3ae15367766e569f7.tar.bz2
Implement recursive filtering for List of cascading candidates
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/Functions.java28
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java6
-rw-r--r--hudson-core/src/main/resources/hudson/model/Job/configure.jelly2
3 files changed, 34 insertions, 2 deletions
diff --git a/hudson-core/src/main/java/hudson/Functions.java b/hudson-core/src/main/java/hudson/Functions.java
index 2a35b57..b8381a6 100644
--- a/hudson-core/src/main/java/hudson/Functions.java
+++ b/hudson-core/src/main/java/hudson/Functions.java
@@ -66,6 +66,7 @@ import hudson.security.captcha.CaptchaSupport;
import hudson.util.Secret;
import hudson.views.MyViewsTabBar;
import hudson.views.ViewsTabBar;
+import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.security.providers.anonymous.AnonymousAuthenticationToken;
import org.apache.commons.jelly.JellyContext;
@@ -1371,6 +1372,33 @@ public class Functions {
return templates.iterator().hasNext() ? templates.iterator().next() : null;
}
+ public static <T extends Item> List<Job> getAllItems(Class<T> type, Job currentJob) {
+ List<T> allItems = Hudson.getInstance().getAllItems(type);
+ List<Job> result = new ArrayList<Job>(allItems.size());
+ for (T item : allItems) {
+ Job job = (Job) item;
+ if (!hasCyclicCascadingLink(job, currentJob.getCascadingChildrenNames())) {
+ result.add(job);
+ }
+ }
+ return result;
+ }
+
+ protected static boolean hasCyclicCascadingLink(Job cascadingCandidate, Set<String> cascadingChildren) {
+ if (null != cascadingCandidate && CollectionUtils.isNotEmpty(cascadingChildren)) {
+ if (cascadingChildren.contains(cascadingCandidate.getName())) {
+ return true;
+ }
+ for (String childName : cascadingChildren) {
+ Job job = getItemByName(Hudson.getInstance().getAllItems(Job.class), childName);
+ if (hasCyclicCascadingLink(cascadingCandidate, job.getCascadingChildrenNames())) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
/**
* Recursively unlink specified project from cascading hierarchy.
*
diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java
index 7099993..752fa93 100644
--- a/hudson-core/src/main/java/hudson/model/Job.java
+++ b/hudson-core/src/main/java/hudson/model/Job.java
@@ -351,6 +351,10 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
cascadingChildrenNames.remove(cascadingChildName);
}
+ public boolean hasCascadingChild(String cascadingChildName) {
+ return null != cascadingChildName && cascadingChildrenNames.contains(cascadingChildName);
+ }
+
/**
* Remove cascading child project name.
*
@@ -800,7 +804,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
*/
@Override
protected void performBeforeItemRenaming(String oldName, String newName){
- Functions.renameCascadingChildLinks(this, oldName, newName);
+ Functions.renameCascadingChildLinks(cascadingProject, oldName, newName);
Functions.renameCascadingParentLinks(oldName, newName);
}
diff --git a/hudson-core/src/main/resources/hudson/model/Job/configure.jelly b/hudson-core/src/main/resources/hudson/model/Job/configure.jelly
index 445a8be..8127b0e 100644
--- a/hudson-core/src/main/resources/hudson/model/Job/configure.jelly
+++ b/hudson-core/src/main/resources/hudson/model/Job/configure.jelly
@@ -33,7 +33,7 @@
<f:textbox name="name" value="${it.name}" />
</f:entry>
</j:if>
- <j:set var="cascadingCandidates" value="${app.getAllItems(it.class)}"/>
+ <j:set var="cascadingCandidates" value="${h.getAllItems(it.class, it)}"/>
<j:if test="${cascadingCandidates.size() gt 1}">
<f:entry title="${%cascadingProjectName}">
<select class="setting-input" name="cascadingProjectName">