aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-21 08:25:47 (EST)
committerWinston Prakash2011-12-01 20:46:51 (EST)
commit719ac7e19de1f727856eff1f9f68b2b635d93cad (patch)
treeef039dc55406d2123035e681141a5ae1e8a7a282
parent0efa84441abdcdbda74b3675ff0e6ae72ffa394b (diff)
downloadorg.eclipse.hudson.core-719ac7e19de1f727856eff1f9f68b2b635d93cad.zip
org.eclipse.hudson.core-719ac7e19de1f727856eff1f9f68b2b635d93cad.tar.gz
org.eclipse.hudson.core-719ac7e19de1f727856eff1f9f68b2b635d93cad.tar.bz2
Implement getters and setters logic for blockBuildWhenUpstreamBuilding, blockBuildWhenDownstreamBuilding fields. Use Boolean wrapper instead of primitive type
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/AbstractProject.java35
-rw-r--r--hudson-core/src/main/java/hudson/model/IAbstractProject.java4
-rw-r--r--hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java174
3 files changed, 201 insertions, 12 deletions
diff --git a/hudson-core/src/main/java/hudson/model/AbstractProject.java b/hudson-core/src/main/java/hudson/model/AbstractProject.java
index a47c2d6..bb4ff8a 100644
--- a/hudson-core/src/main/java/hudson/model/AbstractProject.java
+++ b/hudson-core/src/main/java/hudson/model/AbstractProject.java
@@ -179,13 +179,13 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
* 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;
+ 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.
*/
- protected volatile boolean blockBuildWhenUpstreamBuilding = false;
+ protected volatile Boolean blockBuildWhenUpstreamBuilding = false;
/**
* Identifies {@link JDK} to be used.
@@ -603,24 +603,39 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
return true;
}
- public boolean blockBuildWhenDownstreamBuilding() {
- return blockBuildWhenDownstreamBuilding;
+ public Boolean blockBuildWhenDownstreamBuilding() {
+ if (null != blockBuildWhenDownstreamBuilding) {
+ return blockBuildWhenDownstreamBuilding;
+ }
+ return hasParentTemplate() && getTemplate().blockBuildWhenDownstreamBuilding();
}
- public void setBlockBuildWhenDownstreamBuilding(boolean b) throws IOException {
- blockBuildWhenDownstreamBuilding = b;
+ public void setBlockBuildWhenDownstreamBuilding(Boolean b) throws IOException {
+ if (!(hasParentTemplate() && ObjectUtils.equals(getTemplate().blockBuildWhenDownstreamBuilding(), b))) {
+ blockBuildWhenDownstreamBuilding = b;
+ } else {
+ blockBuildWhenDownstreamBuilding = null;
+ }
save();
}
- public boolean blockBuildWhenUpstreamBuilding() {
- return blockBuildWhenUpstreamBuilding;
+ public Boolean blockBuildWhenUpstreamBuilding() {
+ if (null != blockBuildWhenUpstreamBuilding) {
+ return blockBuildWhenUpstreamBuilding;
+ }
+ return hasParentTemplate() && getTemplate().blockBuildWhenUpstreamBuilding();
}
- public void setBlockBuildWhenUpstreamBuilding(boolean b) throws IOException {
- blockBuildWhenUpstreamBuilding = b;
+ public void setBlockBuildWhenUpstreamBuilding(Boolean b) throws IOException {
+ if (!(hasParentTemplate() && ObjectUtils.equals(getTemplate().blockBuildWhenUpstreamBuilding(), b))) {
+ blockBuildWhenUpstreamBuilding = b;
+ } else {
+ blockBuildWhenUpstreamBuilding = null;
+ }
save();
}
+
public boolean isDisabled() {
return disabled;
}
diff --git a/hudson-core/src/main/java/hudson/model/IAbstractProject.java b/hudson-core/src/main/java/hudson/model/IAbstractProject.java
index 147c8e2..67b6899 100644
--- a/hudson-core/src/main/java/hudson/model/IAbstractProject.java
+++ b/hudson-core/src/main/java/hudson/model/IAbstractProject.java
@@ -68,14 +68,14 @@ public interface IAbstractProject extends IJob {
*
* @return true if yes, false - otherwise.
*/
- boolean blockBuildWhenDownstreamBuilding();
+ Boolean blockBuildWhenDownstreamBuilding();
/**
* Indicates whether build should be blocked while upstream project is building.
*
* @return true if yes, false - otherwise.
*/
- boolean blockBuildWhenUpstreamBuilding();
+ Boolean blockBuildWhenUpstreamBuilding();
/**
* Checks whether scmRetryCount is configured
diff --git a/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java b/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
index 5599c0a..e7069ce 100644
--- a/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
+++ b/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
@@ -442,6 +442,180 @@ public class FreeStyleProjectTest {
verifyAll();
}
+ @Test
+ public void testSetScmCheckoutRetryCountEqualsWithParent() throws IOException {
+ String scmCheckoutRetryCount = "10";
+ int globalScmCheckoutRetryCount = 4;
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ parentProject.setScmCheckoutRetryCount(scmCheckoutRetryCount);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ Hudson hudson = createMock(Hudson.class);
+ expect(hudson.getScmCheckoutRetryCount()).andReturn(globalScmCheckoutRetryCount);
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ replayAll();
+ assertEquals(childProject.getScmCheckoutRetryCount(), globalScmCheckoutRetryCount);
+ childProject.setTemplate(parentProject);
+ childProject.setScmCheckoutRetryCount(scmCheckoutRetryCount);
+ assertEquals(childProject.getScmCheckoutRetryCount(), Integer.parseInt(scmCheckoutRetryCount));
+ verifyAll();
+ }
+
+ @Test
+ public void testSetScmCheckoutRetryCountNotEqualsWithParent() throws IOException{
+ String parentScmCheckoutRetryCount = "10";
+ String childScmCheckoutRetryCount = "11";
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ parentProject.setScmCheckoutRetryCount(parentScmCheckoutRetryCount);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setTemplate(parentProject);
+ childProject.setScmCheckoutRetryCount(childScmCheckoutRetryCount);
+
+ Hudson hudson = createMock(Hudson.class);
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ replayAll();
+ assertEquals(childProject.getScmCheckoutRetryCount(), Integer.parseInt(childScmCheckoutRetryCount));
+ verifyAll();
+ }
+
+ @Test
+ public void testSetScmCheckoutRetryCountParentNull() throws IOException{
+ String scmCheckoutRetryCount = "10";
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setScmCheckoutRetryCount(scmCheckoutRetryCount);
+ assertEquals(Integer.parseInt(scmCheckoutRetryCount), childProject.getScmCheckoutRetryCount());
+ }
+
+ @Test
+ public void testSetInvalidScmCheckoutRetryCount() throws IOException{
+ String scmCheckoutRetryCount = "asd10asdasd";
+ int globalScmCheckoutRetryCount = 4;
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setScmCheckoutRetryCount(scmCheckoutRetryCount);
+ Hudson hudson = createMock(Hudson.class);
+ expect(hudson.getScmCheckoutRetryCount()).andReturn(globalScmCheckoutRetryCount).anyTimes();
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ replayAll();
+ assertEquals(globalScmCheckoutRetryCount, childProject.getScmCheckoutRetryCount());
+ verifyAll();
+ }
+
+ @Test
+ public void testGetScmCheckoutRetryCount() throws IOException{
+ String scmCheckoutRetryCountString = "10";
+ int globalScmCheckoutRetryCount = 4;
+ int scmCheckoutRetryCount = Integer.parseInt(scmCheckoutRetryCountString);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ Hudson hudson = createMock(Hudson.class);
+ expect(hudson.getScmCheckoutRetryCount()).andReturn(globalScmCheckoutRetryCount).anyTimes();
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ replayAll();
+
+ childProject.allowSave.set(false);
+ childProject.setScmCheckoutRetryCount(scmCheckoutRetryCountString);
+ assertEquals(scmCheckoutRetryCount, childProject.getScmCheckoutRetryCount());
+
+ parentProject.allowSave.set(false);
+ parentProject.setScmCheckoutRetryCount(scmCheckoutRetryCountString);
+ childProject.setScmCheckoutRetryCount(" ");
+ childProject.setTemplate(parentProject);
+ assertEquals(childProject.getScmCheckoutRetryCount(), scmCheckoutRetryCount);
+
+ parentProject.setScmCheckoutRetryCount(" ");
+ assertEquals(globalScmCheckoutRetryCount, childProject.getScmCheckoutRetryCount());
+ verifyAll();
+ }
+
+ @Test
+ public void testSetBlockBuildWhenDownstreamBuildingEqualsWithParent() throws IOException {
+ boolean blockBuildWhenDownstreamBuilding = true;
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ parentProject.setBlockBuildWhenDownstreamBuilding(blockBuildWhenDownstreamBuilding);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setTemplate(parentProject);
+ childProject.setBlockBuildWhenDownstreamBuilding(blockBuildWhenDownstreamBuilding);
+ assertEquals(childProject.blockBuildWhenDownstreamBuilding(), (Boolean) blockBuildWhenDownstreamBuilding);
+ childProject.setBlockBuildWhenDownstreamBuilding(null);
+ assertNull(childProject.blockBuildWhenDownstreamBuilding);
+ assertEquals(childProject.blockBuildWhenDownstreamBuilding(), (Boolean) blockBuildWhenDownstreamBuilding);
+ }
+
+ @Test
+ public void testSetBlockBuildWhenDownstreamBuildingNotEqualsWithParent() throws IOException {
+ boolean childBlockBuildWhenDownstreamBuilding = false;
+ boolean parentBlockBuildWhenDownstreamBuilding = true;
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ parentProject.setBlockBuildWhenDownstreamBuilding(parentBlockBuildWhenDownstreamBuilding);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setTemplate(parentProject);
+ childProject.setBlockBuildWhenDownstreamBuilding(childBlockBuildWhenDownstreamBuilding);
+ assertNotNull(childProject.blockBuildWhenDownstreamBuilding);
+ assertEquals(childProject.blockBuildWhenDownstreamBuilding(), (Boolean) childBlockBuildWhenDownstreamBuilding);
+ }
+
+ @Test
+ public void testSetBlockBuildWhenDownstreamBuildingParentNull() throws IOException {
+ boolean blockBuildWhenDownstreamBuilding = true;
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setBlockBuildWhenDownstreamBuilding(blockBuildWhenDownstreamBuilding);
+ assertEquals(childProject.blockBuildWhenDownstreamBuilding(), (Boolean) blockBuildWhenDownstreamBuilding);
+ }
+
+ @Test
+ public void testSetBlockBuildWhenUpstreamBuildingEqualsWithParent() throws IOException {
+ boolean blockBuildWhenUpstreamBuilding = true;
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ parentProject.setBlockBuildWhenUpstreamBuilding(blockBuildWhenUpstreamBuilding);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setTemplate(parentProject);
+ childProject.setBlockBuildWhenUpstreamBuilding(blockBuildWhenUpstreamBuilding);
+ assertEquals(childProject.blockBuildWhenUpstreamBuilding(), (Boolean) blockBuildWhenUpstreamBuilding);
+ childProject.setBlockBuildWhenUpstreamBuilding(null);
+ assertNull(childProject.blockBuildWhenUpstreamBuilding);
+ assertEquals(childProject.blockBuildWhenUpstreamBuilding(), (Boolean) blockBuildWhenUpstreamBuilding);
+ }
+
+ @Test
+ public void testSetBlockBuildWhenUpstreamBuildingNotEqualsWithParent() throws IOException {
+ boolean childBlockBuildWhenUpstreamBuilding = false;
+ boolean parentBlockBuildWhenUpstreamBuilding = true;
+ FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ parentProject.allowSave.set(false);
+ parentProject.setBlockBuildWhenUpstreamBuilding(parentBlockBuildWhenUpstreamBuilding);
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setTemplate(parentProject);
+ childProject.setBlockBuildWhenUpstreamBuilding(childBlockBuildWhenUpstreamBuilding);
+ assertNotNull(childProject.blockBuildWhenUpstreamBuilding);
+ assertEquals(childProject.blockBuildWhenUpstreamBuilding(), (Boolean) childBlockBuildWhenUpstreamBuilding);
+ }
+
+ @Test
+ public void testSetBlockBuildWhenUpstreamBuildingParentNull() throws IOException {
+ boolean blockBuildWhenUpstreamBuilding = true;
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ childProject.allowSave.set(false);
+ childProject.setBlockBuildWhenUpstreamBuilding(blockBuildWhenUpstreamBuilding);
+ assertEquals(childProject.blockBuildWhenUpstreamBuilding(), (Boolean) blockBuildWhenUpstreamBuilding);
+ }
+
private class FreeStyleProjectMock extends FreeStyleProject {
private FreeStyleProjectMock(String name) {