summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-22 03:07:03 (EST)
committer Winston Prakash2011-12-01 20:46:54 (EST)
commit6e4a006a90c46c98516597f1c527783e6d564ba9 (patch)
tree72d60df32777ae985166ff4d36a420002c313335
parente319a8290db2d6d67661880b53889e6066a7e959 (diff)
downloadorg.eclipse.hudson.core-6e4a006a90c46c98516597f1c527783e6d564ba9.zip
org.eclipse.hudson.core-6e4a006a90c46c98516597f1c527783e6d564ba9.tar.gz
org.eclipse.hudson.core-6e4a006a90c46c98516597f1c527783e6d564ba9.tar.bz2
Improve cascading methods for FreeStyle and AbstractProject classes. Integrate isPropertyOverriden method. Fix unit tests
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/matrix/MatrixBuild.java4
-rw-r--r--hudson-core/src/main/java/hudson/model/AbstractProject.java159
-rw-r--r--hudson-core/src/main/java/hudson/model/FreeStyleProject.java27
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java38
-rw-r--r--hudson-core/src/main/java/hudson/model/Project.java2
-rw-r--r--hudson-core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly2
-rw-r--r--hudson-core/src/main/resources/lib/hudson/project/config-blockWhenUpstreamBuilding.jelly2
-rw-r--r--hudson-core/src/main/resources/lib/hudson/project/config-cleanWorkspace.jelly2
-rw-r--r--hudson-core/src/main/resources/lib/hudson/project/config-customWorkspace.jelly2
-rw-r--r--hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java112
10 files changed, 166 insertions, 184 deletions
diff --git a/hudson-core/src/main/java/hudson/matrix/MatrixBuild.java b/hudson-core/src/main/java/hudson/matrix/MatrixBuild.java
index fad2d96..abe14d5 100644
--- a/hudson-core/src/main/java/hudson/matrix/MatrixBuild.java
+++ b/hudson-core/src/main/java/hudson/matrix/MatrixBuild.java
@@ -1,6 +1,6 @@
/*******************************************************************************
*
- * Copyright (c) 2004-2009 Oracle Corporation.
+ * Copyright (c) 2004-2011 Oracle Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,7 +9,7 @@
*
* Contributors:
*
-* Kohsuke Kawaguchi, Red Hat, Inc., Tom Huybrechts
+* Kohsuke Kawaguchi, Red Hat, Inc., Tom Huybrechts, Anton Kozak, Nikita Levyankov
*
*
*******************************************************************************/
diff --git a/hudson-core/src/main/java/hudson/model/AbstractProject.java b/hudson-core/src/main/java/hudson/model/AbstractProject.java
index 1570364..0b2a67b 100644
--- a/hudson-core/src/main/java/hudson/model/AbstractProject.java
+++ b/hudson-core/src/main/java/hudson/model/AbstractProject.java
@@ -1,6 +1,6 @@
/*******************************************************************************
*
- * Copyright (c) 2004-2010 Oracle Corporation.
+ * Copyright (c) 2004-2011 Oracle Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,7 +9,8 @@
*
* Contributors:
*
- * Kohsuke Kawaguchi, Brian Westrich, Erik Ramfelt, Ertan Deniz, Jean-Baptiste Quenot, Luca Domenico Milanesio, R. Tyler Ballance, Stephen Connolly, Tom Huybrechts, id:cactusman, Yahoo! Inc.
+ * Kohsuke Kawaguchi, Brian Westrich, Erik Ramfelt, Ertan Deniz, Jean-Baptiste Quenot, Luca Domenico Milanesio,
+ * R. Tyler Ballance, Stephen Connolly, Tom Huybrechts, id:cactusman, Yahoo! Inc., Anton Kozak, Nikita Levyankov
*
*
*******************************************************************************/
@@ -118,6 +119,11 @@ import static javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends AbstractBuild<P,R>> extends Job<P,R> implements BuildableItem,
IAbstractProject {
+ public static final String CONCURRENT_BUILD_PROPERTY_NAME = "concurrentBuild";
+ public static final String CLEAN_WORKSPACE_REQUIRED_PROPERTY_NAME = "cleanWorkspaceRequired";
+ public static final String BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME = "blockBuildWhenDownstreamBuilding";
+ public static final String BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME = "blockBuildWhenUpstreamBuilding";
+
/**
* {@link SCM} associated with the project.
* To allow derived classes to link {@link SCM} config to elsewhere,
@@ -180,13 +186,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;
+ 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;
+ protected volatile boolean blockBuildWhenUpstreamBuilding;
/**
* Identifies {@link JDK} to be used.
@@ -222,9 +228,9 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
@CopyOnWrite
protected transient volatile List<Action> transientActions = new Vector<Action>();
- private Boolean concurrentBuild;
+ private boolean concurrentBuild;
- private volatile Boolean cleanWorkspaceRequired;
+ private volatile boolean cleanWorkspaceRequired;
protected AbstractProject(ItemGroup parent, String name) {
super(parent, name);
@@ -299,72 +305,51 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
*/
@Exported
public boolean isConcurrentBuild() {
- Boolean result = isConcurrentBuild(true);
- return null != result ? result : false;
+ return isConcurrentBuild(true);
}
- public Boolean isConcurrentBuild(boolean useParentValue) {
- if (!useParentValue) {
- return concurrentBuild;
+ public boolean isConcurrentBuild(boolean useParentValue) {
+ if (!useParentValue || !hasCascadingProject() || isOverriddenProperty(CONCURRENT_BUILD_PROPERTY_NAME)) {
+ return Hudson.CONCURRENT_BUILD && concurrentBuild;
} else {
- if (null != concurrentBuild) {
- return Hudson.CONCURRENT_BUILD && concurrentBuild;
- }
return hasCascadingProject() && getCascadingProject().isConcurrentBuild();
}
}
- /**
- * @param b boolean value.
- * @throws IOException if any.
- * @since 2.1.2
- * @deprecated
- */
public void setConcurrentBuild(boolean b) throws IOException {
- setConcurrentBuild(Boolean.valueOf(b));
- }
-
- public void setConcurrentBuild(Boolean b) throws IOException {
- if (!(hasCascadingProject()
- && ObjectUtils.equals(getCascadingProject().isConcurrentBuild(), b))) {
- concurrentBuild = b;
+ if (!hasCascadingProject()) {
+ this.concurrentBuild = b;
+ } else if (!ObjectUtils.equals(getCascadingProject().isConcurrentBuild(), b)) {
+ this.concurrentBuild = b;
+ registerOverriddenProperty(CONCURRENT_BUILD_PROPERTY_NAME);
} else {
- this.concurrentBuild = null;
+ this.concurrentBuild = false;
+ unRegisterOverriddenProperty(CONCURRENT_BUILD_PROPERTY_NAME);
}
save();
}
public boolean isCleanWorkspaceRequired() {
- Boolean result = isCleanWorkspaceRequired(true);
- return null != result ? result : false;
+ return isCleanWorkspaceRequired(true);
}
- public Boolean isCleanWorkspaceRequired(boolean useParentValue) {
- if (!useParentValue) {
+ public boolean isCleanWorkspaceRequired(boolean useParentValue) {
+ if (!useParentValue || !hasCascadingProject() || isOverriddenProperty(CLEAN_WORKSPACE_REQUIRED_PROPERTY_NAME)) {
return cleanWorkspaceRequired;
} else {
- if (null != cleanWorkspaceRequired) {
- return cleanWorkspaceRequired;
- }
return hasCascadingProject() && getCascadingProject().isCleanWorkspaceRequired();
}
}
- /**
- * @param cleanWorkspaceRequired boolean value.
- * @since 2.1.2
- * @deprecated
- */
public void setCleanWorkspaceRequired(boolean cleanWorkspaceRequired) {
- setCleanWorkspaceRequired(Boolean.valueOf(cleanWorkspaceRequired));
- }
-
- public void setCleanWorkspaceRequired(Boolean cleanWorkspaceRequired) {
- if (!(hasCascadingProject()
- && ObjectUtils.equals(getCascadingProject().isCleanWorkspaceRequired(), cleanWorkspaceRequired))) {
+ if (!hasCascadingProject()) {
+ this.cleanWorkspaceRequired = cleanWorkspaceRequired;
+ } else if (!ObjectUtils.equals(getCascadingProject().isCleanWorkspaceRequired(), cleanWorkspaceRequired)) {
+ registerOverriddenProperty(CLEAN_WORKSPACE_REQUIRED_PROPERTY_NAME);
this.cleanWorkspaceRequired = cleanWorkspaceRequired;
} else {
- this.cleanWorkspaceRequired = null;
+ this.cleanWorkspaceRequired = false;
+ unRegisterOverriddenProperty(CLEAN_WORKSPACE_REQUIRED_PROPERTY_NAME);
}
}
@@ -605,16 +590,19 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
// ugly name because of EL
public boolean getHasCustomQuietPeriod() {
- return quietPeriod!=null;
+ return (hasCascadingProject() && getCascadingProject().getHasCustomQuietPeriod())
+ || (!hasCascadingProject() && quietPeriod!=null);
}
/**
* Sets the custom quiet period of this project, or revert to the global default if null is given.
- * @param seconds quit period
+ * @param seconds quiet period
* @throws IOException if any.
*/
public void setQuietPeriod(Integer seconds) throws IOException {
- if (!(hasCascadingProject() && ObjectUtils.equals(getCascadingProject().getQuietPeriod(), seconds))) {
+ if (!(hasCascadingProject()
+ && (ObjectUtils.equals(getCascadingProject().getQuietPeriod(), seconds))
+ && ObjectUtils.notEqual(seconds, Hudson.getInstance().getQuietPeriod()))) {
this.quietPeriod = seconds;
} else {
this.quietPeriod = null;
@@ -655,76 +643,57 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
public boolean blockBuildWhenDownstreamBuilding() {
- Boolean result = blockBuildWhenDownstreamBuilding(true);
- return null != result ? result : false;
+ return blockBuildWhenDownstreamBuilding(true);
}
- public Boolean blockBuildWhenDownstreamBuilding(boolean useParentValue) {
- if (!useParentValue) {
+ public boolean blockBuildWhenDownstreamBuilding(boolean useParentValue) {
+ if (!useParentValue || !hasCascadingProject()
+ || isOverriddenProperty(BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME)) {
return blockBuildWhenDownstreamBuilding;
} else {
- if (null != blockBuildWhenDownstreamBuilding) {
- return blockBuildWhenDownstreamBuilding;
- }
return hasCascadingProject() && getCascadingProject().blockBuildWhenDownstreamBuilding();
}
}
- /**
- * @param b boolean value.
- * @throws IOException if any.
- * @since 2.1.2
- * @deprecated
- */
public void setBlockBuildWhenDownstreamBuilding(boolean b) throws IOException {
- setBlockBuildWhenDownstreamBuilding(Boolean.valueOf(b));
- }
-
- public void setBlockBuildWhenDownstreamBuilding(Boolean b) throws IOException {
- if (!(hasCascadingProject() && ObjectUtils.equals(getCascadingProject().blockBuildWhenDownstreamBuilding(), b))) {
- blockBuildWhenDownstreamBuilding = b;
+ if (!hasCascadingProject()) {
+ this.blockBuildWhenDownstreamBuilding = b;
+ } else if (!ObjectUtils.equals(getCascadingProject().blockBuildWhenDownstreamBuilding(), b)) {
+ this.blockBuildWhenDownstreamBuilding = b;
+ registerOverriddenProperty(BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME);
} else {
- blockBuildWhenDownstreamBuilding = null;
+ this.blockBuildWhenDownstreamBuilding = false;
+ unRegisterOverriddenProperty(BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME);
}
save();
}
public boolean blockBuildWhenUpstreamBuilding() {
- Boolean result = blockBuildWhenUpstreamBuilding(true);
- return null != result ? result : false;
+ return blockBuildWhenUpstreamBuilding(true);
}
- public Boolean blockBuildWhenUpstreamBuilding(boolean useParentValue) {
- if (!useParentValue) {
+ public boolean blockBuildWhenUpstreamBuilding(boolean useParentValue) {
+ if (!useParentValue || !hasCascadingProject()
+ || isOverriddenProperty(BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME)) {
return blockBuildWhenUpstreamBuilding;
} else {
- if (null != blockBuildWhenUpstreamBuilding) {
- return blockBuildWhenUpstreamBuilding;
- }
return hasCascadingProject() && getCascadingProject().blockBuildWhenUpstreamBuilding();
}
}
- /**
- * @param b boolean value.
- * @throws IOException if any.
- * @since 2.1.2
- * @deprecated
- */
public void setBlockBuildWhenUpstreamBuilding(boolean b) throws IOException {
- setBlockBuildWhenUpstreamBuilding(Boolean.valueOf(b));
- }
-
- public void setBlockBuildWhenUpstreamBuilding(Boolean b) throws IOException {
- if (!(hasCascadingProject() && ObjectUtils.equals(getCascadingProject().blockBuildWhenUpstreamBuilding(), b))) {
- blockBuildWhenUpstreamBuilding = b;
+ if (!hasCascadingProject()) {
+ this.blockBuildWhenUpstreamBuilding = b;
+ } else if (!ObjectUtils.equals(getCascadingProject().blockBuildWhenUpstreamBuilding(), b)) {
+ this.blockBuildWhenUpstreamBuilding = b;
+ registerOverriddenProperty(BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME);
} else {
- blockBuildWhenUpstreamBuilding = null;
+ this.blockBuildWhenUpstreamBuilding = false;
+ unRegisterOverriddenProperty(BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME);
}
save();
}
-
public boolean isDisabled() {
return disabled;
}
@@ -1853,8 +1822,8 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
setQuietPeriod(null != req.getParameter("hasCustomQuietPeriod") ? req.getParameter("quiet_period") : null);
setScmCheckoutRetryCount(null != req.getParameter("hasCustomScmCheckoutRetryCount")
? req.getParameter("scmCheckoutRetryCount") : null);
- setBlockBuildWhenDownstreamBuilding((Boolean) (null != req.getParameter("blockBuildWhenDownstreamBuilding")));
- setBlockBuildWhenUpstreamBuilding((Boolean) (null != req.getParameter("blockBuildWhenUpstreamBuilding")));
+ setBlockBuildWhenDownstreamBuilding(null != req.getParameter("blockBuildWhenDownstreamBuilding"));
+ setBlockBuildWhenUpstreamBuilding(null != req.getParameter("blockBuildWhenUpstreamBuilding"));
if (req.getParameter("hasSlaveAffinity") != null) {
// New logic for handling whether this choice came from the dropdown or textfield.
@@ -1871,11 +1840,11 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
- setCleanWorkspaceRequired((Boolean) (null != req.getParameter("cleanWorkspaceRequired")));
+ setCleanWorkspaceRequired(null != req.getParameter("cleanWorkspaceRequired"));
canRoam = assignedNode==null;
- setConcurrentBuild((Boolean) (req.getSubmittedForm().has("concurrentBuild")));
+ setConcurrentBuild(req.getSubmittedForm().has("concurrentBuild"));
authToken = BuildAuthorizationToken.create(req);
diff --git a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
index 45beb08..ed4a24e 100644
--- a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
+++ b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
@@ -1,6 +1,6 @@
/*******************************************************************************
*
- * Copyright (c) 2004-2009 Oracle Corporation.
+ * Copyright (c) 2004-2011 Oracle Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -9,7 +9,7 @@
*
* Contributors:
*
-* Kohsuke Kawaguchi, id:cactusman
+* Kohsuke Kawaguchi, id:cactusman, Anton Kozak, Nikita Levyankov
*
*
*******************************************************************************/
@@ -36,7 +36,7 @@ import javax.servlet.ServletException;
public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> implements TopLevelItem,
IFreeStyleProject {
- private static final String DEFAULT_CUSTOM_WORKSPACE = "default_workspace";
+ public static final String CUSTOM_WORKSPACE_PROPERTY_NAME = "customWorkspace";
/**
* See {@link #setCustomWorkspace(String)}.
@@ -62,21 +62,12 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
}
public String getCustomWorkspace(boolean useParentValue) {
- if (!useParentValue || !isCustomWorkspaceInherited()) {
- return DEFAULT_CUSTOM_WORKSPACE.equals(customWorkspace) ? null : StringUtils.trimToNull(customWorkspace);
- }
- if (StringUtils.isNotBlank(customWorkspace)) {
+ if (!useParentValue || isOverriddenProperty(CUSTOM_WORKSPACE_PROPERTY_NAME) || null != customWorkspace) {
return customWorkspace;
}
return hasCascadingProject() ? getCascadingProject().getCustomWorkspace() : null;
}
- public boolean isCustomWorkspaceInherited() {
- return hasCascadingProject() && !DEFAULT_CUSTOM_WORKSPACE.equals(customWorkspace)
- && StringUtils.isBlank(customWorkspace);
- }
-
-
public String getCustomWorkspace() {
return getCustomWorkspace(true);
}
@@ -103,11 +94,15 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
* @throws IOException if any.
*/
public void setCustomWorkspace(String customWorkspace) throws IOException {
- if (!(hasCascadingProject()
- && StringUtils.equalsIgnoreCase(getCascadingProject().getCustomWorkspace(), customWorkspace))) {
- this.customWorkspace = null == customWorkspace ? DEFAULT_CUSTOM_WORKSPACE : customWorkspace;
+ String workspace = StringUtils.trimToNull(customWorkspace);
+ if (!hasCascadingProject()) {
+ this.customWorkspace = workspace;
+ } else if (!StringUtils.equalsIgnoreCase(getCascadingProject().getCustomWorkspace(), workspace)) {
+ this.customWorkspace = workspace;
+ registerOverriddenProperty(CUSTOM_WORKSPACE_PROPERTY_NAME);
} else {
this.customWorkspace = null;
+ unRegisterOverriddenProperty(CUSTOM_WORKSPACE_PROPERTY_NAME);
}
save();
}
diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java
index 9dd2b73..df33360 100644
--- a/hudson-core/src/main/java/hudson/model/Job.java
+++ b/hudson-core/src/main/java/hudson/model/Job.java
@@ -9,7 +9,8 @@
*
* Contributors:
*
- * Kohsuke Kawaguchi, Martin Eigenbrodt, Matthew R. Harrah, Red Hat, Inc., Stephen Connolly, Tom Huybrechts, Winston Prakash
+ * Kohsuke Kawaguchi, Martin Eigenbrodt, Matthew R. Harrah, Red Hat, Inc., Stephen Connolly, Tom Huybrechts,
+ * Winston Prakash, Anton Kozak, Nikita Levyankov
*
*
*******************************************************************************/
@@ -19,6 +20,7 @@ package hudson.model;
import hudson.Functions;
import hudson.util.graph.GraphSeries;
import hudson.widgets.Widget;
+import java.util.concurrent.CopyOnWriteArraySet;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Sets;
@@ -107,6 +109,9 @@ import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, RunT>>
extends AbstractItem implements ExtensionPoint, StaplerOverridable, IJob {
private static transient final String HUDSON_BUILDS_PROPERTY_KEY = "HUDSON_BUILDS";
+
+ private Set<String> overriddenValues = new CopyOnWriteArraySet<String>();
+
/**
* Next build number. Kept in a separate file because this is the only
* information that gets updated often. This allows the rest of the
@@ -166,6 +171,34 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
super(parent, name);
}
+ /**
+ * Checks whether property is overridden by this job and doesn't equal to cascading parent
+ *
+ * @param propertyName property name.
+ * @return true - if overridden, false - otherwise.
+ */
+ public boolean isOverriddenProperty(String propertyName) {
+ return null != propertyName && overriddenValues.contains(propertyName);
+ }
+
+ /**
+ * Marks property name as overridden. Is used to show, that given property will have overridden property value.
+ *
+ * @param propertyName name of property.
+ */
+ protected void registerOverriddenProperty(String propertyName) {
+ overriddenValues.add(propertyName);
+ }
+
+ /**
+ * Un-mark property name as overridden. Property will inherit value from cascading parent.
+ *
+ * @param propertyName name of property.
+ */
+ protected void unRegisterOverriddenProperty(String propertyName) {
+ overriddenValues.remove(propertyName);
+ }
+
@Override
public synchronized void save() throws IOException {
if (allowSave.get()) {
@@ -190,6 +223,9 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
}
};
}
+ if (null == overriddenValues) {
+ overriddenValues = new CopyOnWriteArraySet<String>();
+ }
TextFile f = getNextBuildNumberFile();
if (f.exists()) {
// starting 1.28, we store nextBuildNumber in a separate file.
diff --git a/hudson-core/src/main/java/hudson/model/Project.java b/hudson-core/src/main/java/hudson/model/Project.java
index 270571f..171ff2b 100644
--- a/hudson-core/src/main/java/hudson/model/Project.java
+++ b/hudson-core/src/main/java/hudson/model/Project.java
@@ -9,7 +9,7 @@
*
* Contributors:
*
- * Kohsuke Kawaguchi, Jorg Heymans, Stephen Connolly, Tom Huybrechts
+ * Kohsuke Kawaguchi, Jorg Heymans, Stephen Connolly, Tom Huybrechts, Anton Kozak, Nikita Levyankov
*
*
*******************************************************************************/
diff --git a/hudson-core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly b/hudson-core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly
index d825d28..63a278d 100644
--- a/hudson-core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly
+++ b/hudson-core/src/main/resources/lib/hudson/project/config-blockWhenDownstreamBuilding.jelly
@@ -21,5 +21,5 @@
title="${%Block build when downstream project is building}"
help="/help/project-config/block-downstream-building.html"
checked="${it.blockBuildWhenDownstreamBuilding()}"
- isCascadingValue="${it.hasCascadingProject() and null != it.blockBuildWhenDownstreamBuilding(false)}"/>
+ isCascadingValue="${it.isOverriddenProperty(it.BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME)}"/>
</j:jelly>
diff --git a/hudson-core/src/main/resources/lib/hudson/project/config-blockWhenUpstreamBuilding.jelly b/hudson-core/src/main/resources/lib/hudson/project/config-blockWhenUpstreamBuilding.jelly
index d210083..05ccee6 100644
--- a/hudson-core/src/main/resources/lib/hudson/project/config-blockWhenUpstreamBuilding.jelly
+++ b/hudson-core/src/main/resources/lib/hudson/project/config-blockWhenUpstreamBuilding.jelly
@@ -21,5 +21,5 @@
title="${%Block build when upstream project is building}"
help="/help/project-config/block-upstream-building.html"
checked="${it.blockBuildWhenUpstreamBuilding()}"
- isCascadingValue="${it.hasCascadingProject() and null != it.blockBuildWhenUpstreamBuilding(false)}"/>
+ isCascadingValue="${it.isOverriddenProperty(it.BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME)}"/>
</j:jelly>
diff --git a/hudson-core/src/main/resources/lib/hudson/project/config-cleanWorkspace.jelly b/hudson-core/src/main/resources/lib/hudson/project/config-cleanWorkspace.jelly
index c36d563..2f385dd 100644
--- a/hudson-core/src/main/resources/lib/hudson/project/config-cleanWorkspace.jelly
+++ b/hudson-core/src/main/resources/lib/hudson/project/config-cleanWorkspace.jelly
@@ -19,6 +19,6 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:optionalBlock name="cleanWorkspaceRequired" title="${%Clean workspace before build}"
checked="${it.cleanWorkspaceRequired}"
- isCascadingValue="${it.hasCascadingProject() and null != it.isCleanWorkspaceRequired(false)}"
+ isCascadingValue="${it.isOverriddenProperty(it.CLEAN_WORKSPACE_REQUIRED_PROPERTY_NAME)}"
help="/help/project-config/cleanWorkspace.html" />
</j:jelly>
diff --git a/hudson-core/src/main/resources/lib/hudson/project/config-customWorkspace.jelly b/hudson-core/src/main/resources/lib/hudson/project/config-customWorkspace.jelly
index 2d72cef..f4fa3b7 100644
--- a/hudson-core/src/main/resources/lib/hudson/project/config-customWorkspace.jelly
+++ b/hudson-core/src/main/resources/lib/hudson/project/config-customWorkspace.jelly
@@ -18,7 +18,7 @@
<!-- custom workspace -->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:optionalBlock name="customWorkspace" title="${%Use custom workspace}" checked="${it.customWorkspace!=null}"
- isCascadingValue="${it.hasCascadingProject() and !it.isCustomWorkspaceInherited()}"
+ isCascadingValue="${it.isOverriddenProperty(it.CUSTOM_WORKSPACE_PROPERTY_NAME)}"
help="/help/project-config/custom-workspace.html">
<f:entry title="${%Directory}">
<f:textbox name="customWorkspace.directory" value="${it.customWorkspace}" />
diff --git a/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java b/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
index 2fcf241..9bd1531 100644
--- a/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
+++ b/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
@@ -353,40 +353,39 @@ public class FreeStyleProjectTest {
String quietPeriod = "10";
int globalQuietPeriod = 4;
FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
+ FreeStyleProject childProject = new FreeStyleProjectMock("child");
+ Hudson hudson = createMock(Hudson.class);
+ expect(hudson.getQuietPeriod()).andReturn(globalQuietPeriod).anyTimes();
+ mockStatic(Hudson.class);
+ expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
+ replayAll();
parentProject.allowSave.set(false);
parentProject.setQuietPeriod(quietPeriod);
- FreeStyleProject childProject = new FreeStyleProjectMock("child");
childProject.allowSave.set(false);
childProject.setCascadingProject(parentProject);
childProject.setQuietPeriod(quietPeriod);
childProject.setCascadingProject(null);
-
- Hudson hudson = createMock(Hudson.class);
- expect(hudson.getQuietPeriod()).andReturn(globalQuietPeriod);
- mockStatic(Hudson.class);
- expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
- replayAll();
assertEquals(childProject.getQuietPeriod(), globalQuietPeriod);
verifyAll();
}
-
@Test
- public void testSetQuietPeriodNotEqualsWithParent() throws IOException{
- String parentQuietPeriod = "10";
- String childQuietPeriod = "11";
+ public void testSetQuietPeriodEqualsGlobal() throws IOException {
+ String quietPeriod = "4";
+ int globalQuietPeriod = 4;
FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
- parentProject.allowSave.set(false);
- parentProject.setQuietPeriod(parentQuietPeriod);
FreeStyleProject childProject = new FreeStyleProjectMock("child");
- childProject.allowSave.set(false);
- childProject.setCascadingProject(parentProject);
- childProject.setQuietPeriod(childQuietPeriod);
-
Hudson hudson = createMock(Hudson.class);
+ expect(hudson.getQuietPeriod()).andReturn(globalQuietPeriod).anyTimes();
mockStatic(Hudson.class);
expect(Hudson.getInstance()).andReturn(hudson).anyTimes();
replayAll();
- assertEquals(childProject.getQuietPeriod(), Integer.parseInt(childQuietPeriod));
+ parentProject.allowSave.set(false);
+ parentProject.setQuietPeriod(quietPeriod);
+ childProject.allowSave.set(false);
+ childProject.setCascadingProject(parentProject);
+ childProject.setQuietPeriod(quietPeriod);
+ childProject.setCascadingProject(null);
+ assertEquals(childProject.getQuietPeriod(), globalQuietPeriod);
verifyAll();
}
@@ -547,7 +546,7 @@ public class FreeStyleProjectTest {
childProject.allowSave.set(false);
childProject.setCascadingProject(parentProject);
childProject.setBlockBuildWhenDownstreamBuilding(blockBuildWhenDownstreamBuilding);
- assertNull(childProject.blockBuildWhenDownstreamBuilding);
+ assertFalse(childProject.blockBuildWhenDownstreamBuilding);
}
@Test
@@ -567,35 +566,37 @@ public class FreeStyleProjectTest {
@Test
public void testSetBlockBuildWhenDownstreamBuildingParentNull() throws IOException {
- Boolean blockBuildWhenDownstreamBuilding = true;
+ boolean blockBuildWhenDownstreamBuilding = true;
FreeStyleProject childProject = new FreeStyleProjectMock("child");
childProject.allowSave.set(false);
childProject.setBlockBuildWhenDownstreamBuilding(blockBuildWhenDownstreamBuilding);
//if parent is not set, value should be populated according to existing logic
- assertEquals(blockBuildWhenDownstreamBuilding, childProject.blockBuildWhenDownstreamBuilding);
+ assertEquals(blockBuildWhenDownstreamBuilding, childProject.blockBuildWhenDownstreamBuilding(false));
}
@Test
public void testBlockBuildWhenDownstreamBuilding() throws IOException {
- Boolean childBlockBuildWhenDownstreamBuilding = false;
- Boolean parentBlockBuildWhenDownstreamBuilding = true;
+ boolean childBlockBuildWhenDownstreamBuilding = false;
+ boolean parentBlockBuildWhenDownstreamBuilding = true;
FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
parentProject.allowSave.set(false);
parentProject.setBlockBuildWhenDownstreamBuilding(parentBlockBuildWhenDownstreamBuilding);
+ assertEquals(parentBlockBuildWhenDownstreamBuilding, parentProject.blockBuildWhenDownstreamBuilding());
FreeStyleProject childProject = new FreeStyleProjectMock("child");
childProject.allowSave.set(false);
- childProject.setBlockBuildWhenDownstreamBuilding(null);
+ //Set equal to parent in order to inherit from cascading project
childProject.setCascadingProject(parentProject);
+ childProject.setBlockBuildWhenDownstreamBuilding(parentBlockBuildWhenDownstreamBuilding);
//Value should be taken from cascadingProject
- assertEquals(parentBlockBuildWhenDownstreamBuilding, (Boolean) childProject.blockBuildWhenDownstreamBuilding());
+ assertEquals(parentBlockBuildWhenDownstreamBuilding, childProject.blockBuildWhenDownstreamBuilding());
childProject.setBlockBuildWhenDownstreamBuilding(childBlockBuildWhenDownstreamBuilding);
//Child value is not equals to parent - override value in child.
- assertEquals(childBlockBuildWhenDownstreamBuilding, (Boolean) childProject.blockBuildWhenDownstreamBuilding());
+ assertEquals(childBlockBuildWhenDownstreamBuilding, childProject.blockBuildWhenDownstreamBuilding());
}
@Test
public void testSetBlockBuildWhenUpstreamBuildingEqualsWithParent() throws IOException {
- Boolean blockBuildWhenUpstreamBuilding = true;
+ boolean blockBuildWhenUpstreamBuilding = true;
FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
parentProject.allowSave.set(false);
parentProject.setBlockBuildWhenUpstreamBuilding(blockBuildWhenUpstreamBuilding);
@@ -603,7 +604,7 @@ public class FreeStyleProjectTest {
childProject.allowSave.set(false);
childProject.setCascadingProject(parentProject);
childProject.setBlockBuildWhenUpstreamBuilding(blockBuildWhenUpstreamBuilding);
- assertNull(childProject.blockBuildWhenUpstreamBuilding(false));
+ assertFalse(childProject.blockBuildWhenUpstreamBuilding(false));
}
@Test
@@ -623,7 +624,7 @@ public class FreeStyleProjectTest {
@Test
public void testSetBlockBuildWhenUpstreamBuildingParentNull() throws IOException {
- Boolean blockBuildWhenUpstreamBuilding = true;
+ boolean blockBuildWhenUpstreamBuilding = true;
FreeStyleProject childProject = new FreeStyleProjectMock("child");
childProject.allowSave.set(false);
childProject.setBlockBuildWhenUpstreamBuilding(blockBuildWhenUpstreamBuilding);
@@ -633,26 +634,27 @@ public class FreeStyleProjectTest {
@Test
public void testBlockBuildWhenUpstreamBuilding() throws IOException {
- Boolean childBlockBuildWhenUpstreamBuilding = false;
- Boolean parentBlockBuildWhenUpstreamBuilding = true;
+ 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.setBlockBuildWhenUpstreamBuilding(null);
+ //Set equal to parent in order to inherit from cascading project
+ childProject.setBlockBuildWhenUpstreamBuilding(parentBlockBuildWhenUpstreamBuilding);
childProject.setCascadingProject(parentProject);
//Value should be taken from cascadingProject
- assertEquals(parentBlockBuildWhenUpstreamBuilding, (Boolean) childProject.blockBuildWhenUpstreamBuilding());
+ assertEquals(parentBlockBuildWhenUpstreamBuilding, childProject.blockBuildWhenUpstreamBuilding());
childProject.setBlockBuildWhenUpstreamBuilding(childBlockBuildWhenUpstreamBuilding);
//Child value is not equals to parent - override value in child.
- assertEquals(childBlockBuildWhenUpstreamBuilding, (Boolean) childProject.blockBuildWhenUpstreamBuilding());
+ assertEquals(childBlockBuildWhenUpstreamBuilding, childProject.blockBuildWhenUpstreamBuilding());
}
// ---
@Test
public void testSetCleanWorkspaceRequiredEqualsWithParent() throws IOException {
- Boolean cleanWorkspaceRequired = true;
+ boolean cleanWorkspaceRequired = true;
FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
parentProject.allowSave.set(false);
parentProject.setCleanWorkspaceRequired(cleanWorkspaceRequired);
@@ -660,7 +662,7 @@ public class FreeStyleProjectTest {
childProject.allowSave.set(false);
childProject.setCascadingProject(parentProject);
childProject.setCleanWorkspaceRequired(cleanWorkspaceRequired);
- assertNull(childProject.isCleanWorkspaceRequired(false));
+ assertFalse(childProject.isCleanWorkspaceRequired(false));
}
@Test
@@ -675,12 +677,12 @@ public class FreeStyleProjectTest {
childProject.setCascadingProject(parentProject);
childProject.setCleanWorkspaceRequired(childCleanWorkspaceRequired);
//if child value is not equals to parent one, field should be populated
- assertNotNull(childProject.isCleanWorkspaceRequired(false));
+ assertFalse(childProject.isCleanWorkspaceRequired(false));
}
@Test
public void testSetCleanWorkspaceRequiredParentNull() throws IOException {
- Boolean cleanWorkspaceRequired = true;
+ boolean cleanWorkspaceRequired = true;
FreeStyleProject childProject = new FreeStyleProjectMock("child");
childProject.allowSave.set(false);
childProject.setCleanWorkspaceRequired(cleanWorkspaceRequired);
@@ -690,20 +692,20 @@ public class FreeStyleProjectTest {
@Test
public void testIsCleanWorkspaceRequired() throws IOException {
- Boolean childCleanWorkspaceRequired = false;
- Boolean parentCleanWorkspaceRequired = true;
+ boolean childCleanWorkspaceRequired = false;
+ boolean parentCleanWorkspaceRequired = true;
FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
parentProject.allowSave.set(false);
parentProject.setCleanWorkspaceRequired(parentCleanWorkspaceRequired);
FreeStyleProject childProject = new FreeStyleProjectMock("child");
childProject.allowSave.set(false);
- childProject.setCleanWorkspaceRequired(null);
+ childProject.setCleanWorkspaceRequired(parentCleanWorkspaceRequired);
childProject.setCascadingProject(parentProject);
//Value should be taken from cascadingProject
- assertEquals(parentCleanWorkspaceRequired, (Boolean) childProject.isCleanWorkspaceRequired());
+ assertEquals(parentCleanWorkspaceRequired, childProject.isCleanWorkspaceRequired());
childProject.setCleanWorkspaceRequired(childCleanWorkspaceRequired);
//Child value is not equals to parent - override value in child.
- assertEquals(childCleanWorkspaceRequired, (Boolean) childProject.isCleanWorkspaceRequired());
+ assertEquals(childCleanWorkspaceRequired, childProject.isCleanWorkspaceRequired());
}
@Test
@@ -716,7 +718,7 @@ public class FreeStyleProjectTest {
childProject.allowSave.set(false);
childProject.setCascadingProject(parentProject);
childProject.setConcurrentBuild(concurrentBuild);
- assertNull(childProject.isConcurrentBuild(false));
+ assertFalse(childProject.isConcurrentBuild(false));
}
@Test
@@ -753,8 +755,8 @@ public class FreeStyleProjectTest {
parentProject.setConcurrentBuild(parentConcurrentBuild);
FreeStyleProject childProject = new FreeStyleProjectMock("child");
childProject.allowSave.set(false);
- childProject.setConcurrentBuild(null);
childProject.setCascadingProject(parentProject);
+ childProject.setConcurrentBuild(true);
//Value should be taken from cascadingProject
assertEquals(parentConcurrentBuild, (Boolean) childProject.isConcurrentBuild());
childProject.setConcurrentBuild(childConcurrentBuild);
@@ -762,26 +764,6 @@ public class FreeStyleProjectTest {
assertEquals(childConcurrentBuild, (Boolean) childProject.isConcurrentBuild());
}
- @Test
- public void testIsCustomWorkspaceInherited() throws IOException{
- FreeStyleProject parentProject = new FreeStyleProjectMock("parent");
- parentProject.allowSave.set(false);
- assertFalse(parentProject.isCustomWorkspaceInherited());
- String temp = "/temp";
- parentProject.setCustomWorkspace(temp);
- assertFalse(parentProject.isCustomWorkspaceInherited());
- FreeStyleProject childProject = new FreeStyleProjectMock("child");
- childProject.allowSave.set(false);
- childProject.setCascadingProject(parentProject);
- assertTrue(childProject.isCustomWorkspaceInherited());
- childProject.setCustomWorkspace("/temp1");
- assertFalse(childProject.isCustomWorkspaceInherited());
- childProject.setCustomWorkspace(null);
- assertFalse(childProject.isCustomWorkspaceInherited());
- childProject.setCustomWorkspace(temp);
- assertTrue(childProject.isCustomWorkspaceInherited());
- }
-
private class FreeStyleProjectMock extends FreeStyleProject {
private FreeStyleProjectMock(String name) {