Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-24 07:54:56 -0500
committerWinston Prakash2011-12-01 20:47:25 -0500
commit17b19ae6b4a5c188d3961adfe29ad3eac215fd58 (patch)
treeaefe97519e196ab1102eb7d321da58008c9398fb /hudson-core/src/main
parent3d9956dddf694b50d22f0f36ea68a7eff4d4935b (diff)
downloadorg.eclipse.hudson.core-17b19ae6b4a5c188d3961adfe29ad3eac215fd58.tar.gz
org.eclipse.hudson.core-17b19ae6b4a5c188d3961adfe29ad3eac215fd58.tar.xz
org.eclipse.hudson.core-17b19ae6b4a5c188d3961adfe29ad3eac215fd58.zip
Improve upstream/downstream triggers handling for cascading functionality. Add additional validation for triggers recursion
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
Diffstat (limited to 'hudson-core/src/main')
-rw-r--r--hudson-core/src/main/java/hudson/model/AbstractProject.java4
-rw-r--r--hudson-core/src/main/java/hudson/tasks/BuildTrigger.java26
-rw-r--r--hudson-core/src/main/java/hudson/util/CascadingUtil.java26
-rw-r--r--hudson-core/src/main/resources/hudson/tasks/Messages.properties1
4 files changed, 44 insertions, 13 deletions
diff --git a/hudson-core/src/main/java/hudson/model/AbstractProject.java b/hudson-core/src/main/java/hudson/model/AbstractProject.java
index d936f4df..5d132cf7 100644
--- a/hudson-core/src/main/java/hudson/model/AbstractProject.java
+++ b/hudson-core/src/main/java/hudson/model/AbstractProject.java
@@ -137,6 +137,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
public static final String SCM_PROPERTY_NAME = "scm";
public static final String HAS_QUIET_PERIOD_PROPERTY_NAME = "hasQuietPeriod";
public static final String HAS_SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME = "hasScmCheckoutRetryCount";
+ public static final String BUILD_TRIGGER_PROPERTY_NAME = "hudson-tasks-BuildTrigger";
/**
* {@link SCM} associated with the project.
@@ -912,7 +913,8 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
pl.replace(new BuildTrigger(newChildProjects,
existing==null?Result.SUCCESS:existing.getThreshold()));
}
- p.putAllProjectProperties(DescribableListUtil.convertToProjectProperties(pl, p), false);
+ BuildTrigger buildTrigger = pl.get(BuildTrigger.class);
+ CascadingUtil.getExternalProjectProperty(p, BUILD_TRIGGER_PROPERTY_NAME).setValue(buildTrigger);
}
}
diff --git a/hudson-core/src/main/java/hudson/tasks/BuildTrigger.java b/hudson-core/src/main/java/hudson/tasks/BuildTrigger.java
index 50f07f0a..5ea82da4 100644
--- a/hudson-core/src/main/java/hudson/tasks/BuildTrigger.java
+++ b/hudson-core/src/main/java/hudson/tasks/BuildTrigger.java
@@ -40,6 +40,7 @@ import hudson.model.listeners.ItemListener;
import hudson.util.AutoCompleteSeeder;
import hudson.util.FormValidation;
import net.sf.json.JSONObject;
+import org.apache.commons.lang3.StringUtils;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.AncestorInPath;
@@ -192,14 +193,17 @@ public class BuildTrigger extends Recorder implements DependecyDeclarer {
}
public void buildDependencyGraph(AbstractProject owner, DependencyGraph graph) {
- for (AbstractProject p : getChildProjects())
- graph.addDependency(new Dependency(owner, p) {
- @Override
- public boolean shouldTriggerBuild(AbstractBuild build, TaskListener listener,
- List<Action> actions) {
- return build.getResult().isBetterOrEqualTo(threshold);
- }
- });
+ for (AbstractProject p : getChildProjects()) {
+ if (!StringUtils.equals(p.getName(), owner.getName())) {
+ graph.addDependency(new Dependency(owner, p) {
+ @Override
+ public boolean shouldTriggerBuild(AbstractBuild build, TaskListener listener,
+ List<Action> actions) {
+ return build.getResult().isBetterOrEqualTo(threshold);
+ }
+ });
+ }
+ }
}
@Override
@@ -280,7 +284,8 @@ public class BuildTrigger extends Recorder implements DependecyDeclarer {
/**
* Form validation method.
*/
- public FormValidation doCheck(@AncestorInPath AccessControlled subject, @QueryParameter String value ) {
+ public FormValidation doCheck(@AncestorInPath AccessControlled subject, @AncestorInPath AbstractProject current,
+ @QueryParameter String value ) {
// Require CONFIGURE permission on this project
if(!subject.hasPermission(Item.CONFIGURE)) return FormValidation.ok();
@@ -292,6 +297,9 @@ public class BuildTrigger extends Recorder implements DependecyDeclarer {
return FormValidation.error(Messages.BuildTrigger_NoSuchProject(projectName,AbstractProject.findNearest(projectName).getName()));
if(!(item instanceof AbstractProject))
return FormValidation.error(Messages.BuildTrigger_NotBuildable(projectName));
+ if (StringUtils.equals(projectName, current.getName())) {
+ return FormValidation.error(Messages.BuildTrigger_FailedUsingCurrentProject());
+ }
}
return FormValidation.ok();
diff --git a/hudson-core/src/main/java/hudson/util/CascadingUtil.java b/hudson-core/src/main/java/hudson/util/CascadingUtil.java
index ad3734c0..f0c29477 100644
--- a/hudson-core/src/main/java/hudson/util/CascadingUtil.java
+++ b/hudson-core/src/main/java/hudson/util/CascadingUtil.java
@@ -24,6 +24,7 @@ import hudson.triggers.Trigger;
import hudson.triggers.TriggerDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.sf.json.JSONObject;
@@ -201,7 +202,7 @@ public class CascadingUtil {
*
* @param currentJob job that should be analyzed.
* @param key key.
- * @return {@link org.eclipse.hudson.model.project.property.TriggerProjectProperty} instance.
+ * @return {@link org.eclipse.hudson.api.model.project.property.TriggerProjectProperty} instance.
* @throws NullPointerException if currentJob is null.
*/
public static TriggerProjectProperty getTriggerProjectProperty(Job currentJob, String key) {
@@ -271,9 +272,28 @@ public class CascadingUtil {
*/
public static boolean unlinkProjectFromCascadingParents(Job cascadingProject, String projectToUnlink) {
if (null != cascadingProject && null != projectToUnlink) {
- cascadingProject.removeCascadingChild(projectToUnlink);
+ Job job = Functions.getItemByName(Hudson.getInstance().getAllItems(Job.class), projectToUnlink);
+ Set<String> set = new HashSet<String>(job.getCascadingChildrenNames());
+ set.add(projectToUnlink);
+ return unlinkProjectFromCascadingParents(cascadingProject, set);
+ }
+ return false;
+ }
+
+ /**
+ * Recursively unlink set of projects from cascading hierarchy.
+ *
+ * @param cascadingProject cascading project to start from.
+ * @param projectsToUnlink projects that should be unlinked.
+ * @return if project was unlinked
+ */
+ private static boolean unlinkProjectFromCascadingParents(Job cascadingProject, Set<String> projectsToUnlink) {
+ if (null != cascadingProject && null != projectsToUnlink) {
+ for (String toUnlink : projectsToUnlink) {
+ cascadingProject.removeCascadingChild(toUnlink);
+ }
if (cascadingProject.hasCascadingProject()) {
- unlinkProjectFromCascadingParents(cascadingProject.getCascadingProject(), projectToUnlink);
+ unlinkProjectFromCascadingParents(cascadingProject.getCascadingProject(), projectsToUnlink);
}
return true;
}
diff --git a/hudson-core/src/main/resources/hudson/tasks/Messages.properties b/hudson-core/src/main/resources/hudson/tasks/Messages.properties
index d5321cdf..74029b4c 100644
--- a/hudson-core/src/main/resources/hudson/tasks/Messages.properties
+++ b/hudson-core/src/main/resources/hudson/tasks/Messages.properties
@@ -40,6 +40,7 @@ BuildTrigger.InQueue={0} is already in the queue
BuildTrigger.NoSuchProject=No such project ''{0}''. Did you mean ''{1}''?
BuildTrigger.NotBuildable={0} is not buildable
BuildTrigger.Triggering=Triggering a new build of {0}
+BuildTrigger.FailedUsingCurrentProject=Current project is not allowed to trigger.
CommandInterpreter.CommandFailed=command execution failed
CommandInterpreter.UnableToDelete=Unable to delete script file {0}

Back to the top