From e83a0b509c5ceb0a99463bce11b9fa38eb83e865 Mon Sep 17 00:00:00 2001 From: mleinart Date: Thu, 16 Dec 2010 03:09:48 -0600 Subject: [PATCH 1/2] [FIXED HUDSON-7046] - Add "Block build when downstream project is building" option --- .../java/hudson/model/AbstractProject.java | 56 ++++++++++++++++++- .../model/AbstractItem/configure-common.jelly | 1 + .../hudson/model/Messages.properties | 3 +- .../config-blockWhenDownstreamBuilding.jelly | 31 ++++++++++ .../block-downstream-building.html | 3 + 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly create mode 100644 war/src/main/webapp/help/project-config/block-downstream-building.html diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index 21026297a1..2dd84ac1b8 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -174,6 +174,12 @@ public abstract class AbstractProject

,R extends A */ protected volatile boolean disabled; + /** + * True to keep builds of this project in queue when downstream projects are + * building. False by default to keep from breaking existing behavior. + */ + protected volatile boolean blockBuildWhenDownstreamBuilding = false; + /** * True to keep builds of this project in queue when upstream projects are * building. False by default to keep from breaking existing behavior. @@ -500,6 +506,15 @@ public abstract class AbstractProject

,R extends A return true; } + public boolean blockBuildWhenDownstreamBuilding() { + return blockBuildWhenDownstreamBuilding; + } + + public void setBlockBuildWhenDownstreamBuilding(boolean b) throws IOException { + blockBuildWhenDownstreamBuilding = b; + save(); + } + public boolean blockBuildWhenUpstreamBuilding() { return blockBuildWhenUpstreamBuilding; } @@ -998,6 +1013,22 @@ public abstract class AbstractProject

,R extends A return Messages.AbstractProject_BuildInProgress(lbn, eta); } } + + /** + * Because the downstream build is in progress, and we are configured to wait for that. + */ + public static class BecauseOfDownstreamBuildInProgress extends CauseOfBlockage { + public final AbstractProject up; + + public BecauseOfDownstreamBuildInProgress(AbstractProject up) { + this.up = up; + } + + @Override + public String getShortDescription() { + return Messages.AbstractProject_DownstreamBuildInProgress(up.getName()); + } + } /** * Because the upstream build is in progress, and we are configured to wait for that. @@ -1018,7 +1049,11 @@ public abstract class AbstractProject

,R extends A public CauseOfBlockage getCauseOfBlockage() { if (isBuilding() && !isConcurrentBuild()) return new BecauseOfBuildInProgress(getLastBuild()); - if (blockBuildWhenUpstreamBuilding()) { + if (blockBuildWhenDownstreamBuilding()) { + AbstractProject bup = getBuildingDownstream(); + if (bup!=null) + return new BecauseOfDownstreamBuildInProgress(bup); + } else if (blockBuildWhenUpstreamBuilding()) { AbstractProject bup = getBuildingUpstream(); if (bup!=null) return new BecauseOfUpstreamBuildInProgress(bup); @@ -1026,6 +1061,24 @@ public abstract class AbstractProject

,R extends A return null; } + /** + * Returns the project if any of the downstream project (or itself) is either + * building or is in the queue. + *

+ * This means eventually there will be an automatic triggering of + * the given project (provided that all builds went smoothly.) + */ + protected AbstractProject getBuildingDownstream() { + DependencyGraph graph = Hudson.getInstance().getDependencyGraph(); + Set tups = graph.getTransitiveDownstream(this); + tups.add(this); + for (AbstractProject tup : tups) { + if(tup!=this && (tup.isBuilding() || tup.isInQueue())) + return tup; + } + return null; + } + /** * Returns the project if any of the upstream project (or itself) is either * building or is in the queue. @@ -1570,6 +1623,7 @@ public abstract class AbstractProject

,R extends A } else { scmCheckoutRetryCount = null; } + blockBuildWhenDownstreamBuilding = req.getParameter("blockBuildWhenDownstreamBuilding")!=null; blockBuildWhenUpstreamBuilding = req.getParameter("blockBuildWhenUpstreamBuilding")!=null; if(req.getParameter("hasSlaveAffinity")!=null) { diff --git a/core/src/main/resources/hudson/model/AbstractItem/configure-common.jelly b/core/src/main/resources/hudson/model/AbstractItem/configure-common.jelly index fb40c91665..cb33be6aa6 100644 --- a/core/src/main/resources/hudson/model/AbstractItem/configure-common.jelly +++ b/core/src/main/resources/hudson/model/AbstractItem/configure-common.jelly @@ -61,6 +61,7 @@ THE SOFTWARE. + diff --git a/core/src/main/resources/hudson/model/Messages.properties b/core/src/main/resources/hudson/model/Messages.properties index 5291611773..1c987b1d62 100644 --- a/core/src/main/resources/hudson/model/Messages.properties +++ b/core/src/main/resources/hudson/model/Messages.properties @@ -33,6 +33,7 @@ AbstractProject.Pronoun=Project AbstractProject.Aborted=Aborted AbstractProject.BuildInProgress=Build #{0} is already in progress{1} AbstractProject.UpstreamBuildInProgress=Upstream project {0} is already building. +AbstractProject.DownstreamBuildInProgress=Downstream project {0} is already building. AbstractProject.Disabled=Build disabled AbstractProject.ETA=\ (ETA:{0}) AbstractProject.NoBuilds=No existing build. Scheduling a new one. @@ -285,4 +286,4 @@ CLI.quiet-down.shortDescription=Quiet down Hudson, in preparation for a restart. CLI.cancel-quiet-down.shortDescription=Cancel the effect of the "quiet-down" command. CLI.reload-configuration.shortDescription=Discard all the loaded data in memory and reload everything from file system. Useful when you modified config files directly on disk. -BuildAuthorizationToken.InvalidTokenProvided=Invalid token provided. \ No newline at end of file +BuildAuthorizationToken.InvalidTokenProvided=Invalid token provided. diff --git a/core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly b/core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly new file mode 100644 index 0000000000..3f5b547027 --- /dev/null +++ b/core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly @@ -0,0 +1,31 @@ + + + + + + diff --git a/war/src/main/webapp/help/project-config/block-downstream-building.html b/war/src/main/webapp/help/project-config/block-downstream-building.html new file mode 100644 index 0000000000..7d8ddc42f0 --- /dev/null +++ b/war/src/main/webapp/help/project-config/block-downstream-building.html @@ -0,0 +1,3 @@ +

+ When this option is checked, Hudson will prevent the project from building when a parent of this project is in the queue, or building. The parents include the direct as well as the transitive parents. +
From 1f2ba8f7cfc1acb4f1b33b5e780ca23d01fdff07 Mon Sep 17 00:00:00 2001 From: mleinart Date: Mon, 3 Jan 2011 14:49:35 -0600 Subject: [PATCH 2/2] Fix verbiage in comments and help to refer to downstream children rather than upstream parents --- .../lib/hudson/project/config-blockWhenDownstreamBuilding.jelly | 2 +- .../webapp/help/project-config/block-downstream-building.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly b/core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly index 3f5b547027..04400e5cd9 100644 --- a/core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly +++ b/core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> - + - When this option is checked, Hudson will prevent the project from building when a parent of this project is in the queue, or building. The parents include the direct as well as the transitive parents. + When this option is checked, Hudson will prevent the project from building when a child of this project is in the queue, or building. The children include the direct as well as the transitive children.