aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-21 09:23:30 (EST)
committerWinston Prakash2011-12-01 20:46:52 (EST)
commit87f77de516798893892ea675511ac902be79e082 (patch)
tree8636214e8ebb212f6a7cb87ecb7fbcccbb60020a
parentba290102a34b08df8b2db27751098307e7c5b6c9 (diff)
downloadorg.eclipse.hudson.core-87f77de516798893892ea675511ac902be79e082.zip
org.eclipse.hudson.core-87f77de516798893892ea675511ac902be79e082.tar.gz
org.eclipse.hudson.core-87f77de516798893892ea675511ac902be79e082.tar.bz2
Improve methods handling for getters/setters. Add ability to retrieve value from child project without taking into account parent template
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/AbstractProject.java87
-rw-r--r--hudson-core/src/main/java/hudson/model/FreeStyleProject.java12
-rw-r--r--hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java18
3 files changed, 66 insertions, 51 deletions
diff --git a/hudson-core/src/main/java/hudson/model/AbstractProject.java b/hudson-core/src/main/java/hudson/model/AbstractProject.java
index 2f1e2b7..8535556 100644
--- a/hudson-core/src/main/java/hudson/model/AbstractProject.java
+++ b/hudson-core/src/main/java/hudson/model/AbstractProject.java
@@ -182,13 +182,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;
/**
* 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;
/**
* Identifies {@link JDK} to be used.
@@ -224,20 +224,9 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
@CopyOnWrite
protected transient volatile List<Action> transientActions = new Vector<Action>();
- /**
- * Note: this field was made protected for testing purpose. Access it via {@link #isConcurrentBuild()} method
- */
- @Restricted(NoExternalUse.class)
- @RestrictedSince("2.1.2")
- protected Boolean concurrentBuild = false;
+ private Boolean concurrentBuild;
- /**
- * True to clean the workspace prior to each build.
- * Note: this field was made protected for testing purpose. Access it via {@link #isCleanWorkspaceRequired()} method
- */
- @Restricted(NoExternalUse.class)
- @RestrictedSince("2.1.2")
- protected volatile Boolean cleanWorkspaceRequired = false;
+ private volatile Boolean cleanWorkspaceRequired;
protected AbstractProject(ItemGroup parent, String name) {
super(parent, name);
@@ -289,20 +278,6 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
if(transientActions==null)
transientActions = new Vector<Action>(); // happens when loaded from disk
- //Initialize boolean values since from 2.1.2 primitive wrappers were used.
- if (null == blockBuildWhenDownstreamBuilding) {
- blockBuildWhenDownstreamBuilding = false;
- }
- if (null == blockBuildWhenUpstreamBuilding) {
- blockBuildWhenUpstreamBuilding = false;
- }
- if (null == cleanWorkspaceRequired) {
- cleanWorkspaceRequired = false;
- }
- if (null == concurrentBuild) {
- concurrentBuild = false;
- }
-
updateTransientActions();
}
@@ -326,10 +301,19 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
*/
@Exported
public boolean isConcurrentBuild() {
- if (null != concurrentBuild) {
- return Hudson.CONCURRENT_BUILD && concurrentBuild;
+ Boolean result = isConcurrentBuild(true);
+ return null != result ? result : false;
+ }
+
+ public Boolean isConcurrentBuild(boolean useParentValue) {
+ if (!useParentValue) {
+ return concurrentBuild;
+ } else {
+ if (null != concurrentBuild) {
+ return Hudson.CONCURRENT_BUILD && concurrentBuild;
+ }
+ return hasParentTemplate() && getTemplate().isConcurrentBuild();
}
- return null != getTemplate() && getTemplate().isConcurrentBuild();
}
/**
@@ -353,10 +337,19 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
public boolean isCleanWorkspaceRequired() {
- if (null != cleanWorkspaceRequired) {
+ Boolean result = isCleanWorkspaceRequired(true);
+ return null != result ? result : false;
+ }
+
+ public Boolean isCleanWorkspaceRequired(boolean useParentValue) {
+ if (!useParentValue) {
return cleanWorkspaceRequired;
+ } else {
+ if (null != cleanWorkspaceRequired) {
+ return cleanWorkspaceRequired;
+ }
+ return hasParentTemplate() && getTemplate().isCleanWorkspaceRequired();
}
- return hasParentTemplate() && getTemplate().isCleanWorkspaceRequired();
}
/**
@@ -664,10 +657,19 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
public boolean blockBuildWhenDownstreamBuilding() {
- if (null != blockBuildWhenDownstreamBuilding) {
+ Boolean result = blockBuildWhenDownstreamBuilding(true);
+ return null != result ? result : false;
+ }
+
+ public Boolean blockBuildWhenDownstreamBuilding(boolean useParentValue) {
+ if (!useParentValue) {
return blockBuildWhenDownstreamBuilding;
+ } else {
+ if (null != blockBuildWhenDownstreamBuilding) {
+ return blockBuildWhenDownstreamBuilding;
+ }
+ return hasParentTemplate() && getTemplate().blockBuildWhenDownstreamBuilding();
}
- return hasParentTemplate() && getTemplate().blockBuildWhenDownstreamBuilding();
}
/**
@@ -690,10 +692,19 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
public boolean blockBuildWhenUpstreamBuilding() {
- if (null != blockBuildWhenUpstreamBuilding) {
+ Boolean result = blockBuildWhenUpstreamBuilding(true);
+ return null != result ? result : false;
+ }
+
+ public Boolean blockBuildWhenUpstreamBuilding(boolean useParentValue) {
+ if (!useParentValue) {
return blockBuildWhenUpstreamBuilding;
+ } else {
+ if (null != blockBuildWhenUpstreamBuilding) {
+ return blockBuildWhenUpstreamBuilding;
+ }
+ return hasParentTemplate() && getTemplate().blockBuildWhenUpstreamBuilding();
}
- return hasParentTemplate() && getTemplate().blockBuildWhenUpstreamBuilding();
}
/**
diff --git a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
index 638ab8f..92ea80e 100644
--- a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
+++ b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
@@ -57,11 +57,15 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
}
+ public String getCustomWorkspace(boolean useParentValue) {
+ if (!useParentValue || StringUtils.isNotBlank(customWorkspace)) {
+ return customWorkspace;
+ }
+ return hasParentTemplate()? getTemplate().getCustomWorkspace() : null;
+ }
+
public String getCustomWorkspace() {
- if (StringUtils.isNotBlank(customWorkspace)) {
- return customWorkspace;
- }
- return hasParentTemplate()? getTemplate().getCustomWorkspace() : null;
+ return getCustomWorkspace(true);
}
diff --git a/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java b/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
index 8947a6e..dba4ce9 100644
--- a/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
+++ b/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
@@ -602,7 +602,7 @@ public class FreeStyleProjectTest {
childProject.allowSave.set(false);
childProject.setTemplate(parentProject);
childProject.setBlockBuildWhenUpstreamBuilding(blockBuildWhenUpstreamBuilding);
- assertNull(childProject.blockBuildWhenUpstreamBuilding);
+ assertNull(childProject.blockBuildWhenUpstreamBuilding(false));
}
@Test
@@ -617,7 +617,7 @@ public class FreeStyleProjectTest {
childProject.setTemplate(parentProject);
childProject.setBlockBuildWhenUpstreamBuilding(childBlockBuildWhenUpstreamBuilding);
//if child value is not equals to parent one, field should be populated
- assertNotNull(childProject.blockBuildWhenUpstreamBuilding);
+ assertNotNull(childProject.blockBuildWhenUpstreamBuilding(false));
}
@Test
@@ -627,7 +627,7 @@ public class FreeStyleProjectTest {
childProject.allowSave.set(false);
childProject.setBlockBuildWhenUpstreamBuilding(blockBuildWhenUpstreamBuilding);
//if parent is not set, value should be populated according to existing logic
- assertEquals(blockBuildWhenUpstreamBuilding, childProject.blockBuildWhenUpstreamBuilding);
+ assertEquals(blockBuildWhenUpstreamBuilding, childProject.blockBuildWhenUpstreamBuilding(false));
}
@Test
@@ -659,7 +659,7 @@ public class FreeStyleProjectTest {
childProject.allowSave.set(false);
childProject.setTemplate(parentProject);
childProject.setCleanWorkspaceRequired(cleanWorkspaceRequired);
- assertNull(childProject.cleanWorkspaceRequired);
+ assertNull(childProject.isCleanWorkspaceRequired(false));
}
@Test
@@ -674,7 +674,7 @@ public class FreeStyleProjectTest {
childProject.setTemplate(parentProject);
childProject.setCleanWorkspaceRequired(childCleanWorkspaceRequired);
//if child value is not equals to parent one, field should be populated
- assertNotNull(childProject.cleanWorkspaceRequired);
+ assertNotNull(childProject.isCleanWorkspaceRequired(false));
}
@Test
@@ -684,7 +684,7 @@ public class FreeStyleProjectTest {
childProject.allowSave.set(false);
childProject.setCleanWorkspaceRequired(cleanWorkspaceRequired);
//if parent is not set, value should be populated according to existing logic
- assertEquals(cleanWorkspaceRequired, childProject.cleanWorkspaceRequired);
+ assertEquals(cleanWorkspaceRequired, childProject.isCleanWorkspaceRequired(false));
}
@Test
@@ -715,7 +715,7 @@ public class FreeStyleProjectTest {
childProject.allowSave.set(false);
childProject.setTemplate(parentProject);
childProject.setConcurrentBuild(concurrentBuild);
- assertNull(childProject.concurrentBuild);
+ assertNull(childProject.isConcurrentBuild(false));
}
@Test
@@ -730,7 +730,7 @@ public class FreeStyleProjectTest {
childProject.setTemplate(parentProject);
childProject.setConcurrentBuild(childConcurrentBuild);
//if child value is not equals to parent one, field should be populated
- assertEquals(childConcurrentBuild, childProject.concurrentBuild);
+ assertEquals(childConcurrentBuild, (Boolean) childProject.isConcurrentBuild(false));
}
@Test
@@ -740,7 +740,7 @@ public class FreeStyleProjectTest {
childProject.allowSave.set(false);
childProject.setConcurrentBuild(concurrentBuild);
//if parent is not set, value should be populated according to existing logic
- assertEquals(concurrentBuild, childProject.concurrentBuild);
+ assertEquals(concurrentBuild, (Boolean) childProject.isConcurrentBuild(false));
}
@Test