aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-23 10:46:14 (EST)
committerWinston Prakash2011-12-01 20:47:16 (EST)
commit93629f02db4566800aaa3e8a617520aefeea53c8 (patch)
tree10ebb8b7ccc88144644590219ba0c5de7cff4c78
parent2154d3f70ef72670d54ea85226f57c692fe4ca8c (diff)
downloadorg.eclipse.hudson.core-93629f02db4566800aaa3e8a617520aefeea53c8.zip
org.eclipse.hudson.core-93629f02db4566800aaa3e8a617520aefeea53c8.tar.gz
org.eclipse.hudson.core-93629f02db4566800aaa3e8a617520aefeea53c8.tar.bz2
Refine isModified logic. Use this field only for special ProjectProperty that will be the wrapper for Publishers, BuilWrappers and other classes without correctly implemented equals methods.
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/matrix/MatrixProject.java54
-rw-r--r--hudson-core/src/main/java/hudson/model/AbstractProject.java91
-rw-r--r--hudson-core/src/main/java/hudson/model/BaseBuildableProject.java7
-rw-r--r--hudson-core/src/main/java/hudson/model/FreeStyleProject.java9
-rw-r--r--hudson-core/src/main/java/hudson/model/Items.java2
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java45
-rw-r--r--hudson-core/src/main/java/hudson/model/Project.java2
-rw-r--r--hudson-core/src/main/java/hudson/util/DescribableListUtil.java8
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/IProjectProperty.java19
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java52
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectProperty.java6
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/ExternalProjectProperty.java66
-rw-r--r--hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java5
-rw-r--r--hudson-core/src/test/java/hudson/model/LegacyProjectTest.java19
-rw-r--r--hudson-core/src/test/java/hudson/util/DescribableListUtilTest.java7
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java1
16 files changed, 171 insertions, 222 deletions
diff --git a/hudson-core/src/main/java/hudson/matrix/MatrixProject.java b/hudson-core/src/main/java/hudson/matrix/MatrixProject.java
index 32271f5..883a66b 100644
--- a/hudson-core/src/main/java/hudson/matrix/MatrixProject.java
+++ b/hudson-core/src/main/java/hudson/matrix/MatrixProject.java
@@ -176,11 +176,7 @@ public class MatrixProject extends BaseBuildableProject<MatrixProject, MatrixBui
* @inheritDoc
*/
public void setAxes(AxisList axes) throws IOException {
- setAxes(axes, true);
- }
-
- protected void setAxes(AxisList axes, boolean forceModify) throws IOException {
- setProjectPropertyValue(AXES_PROPERTY_NAME, AxisListProjectProperty.class, axes, forceModify);
+ getAxesListProjectProperty(AXES_PROPERTY_NAME).setValue(axes);
rebuildConfigurations();
save();
}
@@ -196,12 +192,7 @@ public class MatrixProject extends BaseBuildableProject<MatrixProject, MatrixBui
* @inheritDoc
*/
public void setRunSequentially(boolean runSequentially) throws IOException {
- setRunSequentially(runSequentially, true);
- }
-
- protected void setRunSequentially(boolean runSequentially, boolean forceModify) throws IOException {
- setProjectPropertyValue(RUN_SEQUENTIALLY_PROPERTY_NAME, BooleanProjectProperty.class, runSequentially,
- forceModify);
+ getBooleanProperty(RUN_SEQUENTIALLY_PROPERTY_NAME).setValue(runSequentially);
save();
}
@@ -216,12 +207,7 @@ public class MatrixProject extends BaseBuildableProject<MatrixProject, MatrixBui
* @inheritDoc
*/
public void setCombinationFilter(String combinationFilter) throws IOException {
- setCombinationFilter(combinationFilter, true);
- }
-
- protected void setCombinationFilter(String combinationFilter, boolean forceModify) throws IOException {
- setProjectPropertyValue(COMBINATION_FILTER_PROPERTY_NAME, StringProjectProperty.class, combinationFilter,
- forceModify);
+ getStringProperty(COMBINATION_FILTER_PROPERTY_NAME).setValue(combinationFilter);
rebuildConfigurations();
save();
}
@@ -237,12 +223,7 @@ public class MatrixProject extends BaseBuildableProject<MatrixProject, MatrixBui
* @inheritDoc
*/
public void setTouchStoneCombinationFilter(String touchStoneCombinationFilter) {
- setTouchStoneCombinationFilter(touchStoneCombinationFilter, true);
- }
-
- protected void setTouchStoneCombinationFilter(String touchStoneCombinationFilter, boolean forceModify) {
- setProjectPropertyValue(TOUCH_STONE_COMBINATION_FILTER_PROPERTY_NAME, StringProjectProperty.class,
- touchStoneCombinationFilter, forceModify);
+ getStringProperty(TOUCH_STONE_COMBINATION_FILTER_PROPERTY_NAME).setValue(touchStoneCombinationFilter);
}
/**
@@ -256,12 +237,7 @@ public class MatrixProject extends BaseBuildableProject<MatrixProject, MatrixBui
* @inheritDoc
*/
public void setTouchStoneResultCondition(Result touchStoneResultCondition) {
- setTouchStoneResultCondition(touchStoneResultCondition, true);
- }
-
- protected void setTouchStoneResultCondition(Result touchStoneResultCondition, boolean forceModify) {
- setProjectPropertyValue(TOUCH_STONE_RESULT_CONDITION_PROPERTY_NAME, ResultProjectProperty.class,
- touchStoneResultCondition, forceModify);
+ getResultProperty(TOUCH_STONE_RESULT_CONDITION_PROPERTY_NAME).setValue(touchStoneResultCondition);
}
/**
@@ -275,12 +251,7 @@ public class MatrixProject extends BaseBuildableProject<MatrixProject, MatrixBui
* @inheritDoc
*/
public void setCustomWorkspace(String customWorkspace) throws IOException {
- setCustomWorkspace(customWorkspace, true);
- }
-
- protected void setCustomWorkspace(String customWorkspace, boolean forceModify) throws IOException {
- setProjectPropertyValue(CUSTOM_WORKSPACE_PROPERTY_NAME, StringProjectProperty.class, customWorkspace,
- forceModify);
+ getStringProperty(CUSTOM_WORKSPACE_PROPERTY_NAME).setValue(customWorkspace);
}
@Override
@@ -606,23 +577,20 @@ public class MatrixProject extends BaseBuildableProject<MatrixProject, MatrixBui
COMBINATION_FILTER_PROPERTY_NAME)) : null);
if (req.getParameter(HAS_TOUCH_STONE_COMBINATION_FILTER_PARAM)!=null) {
- setTouchStoneCombinationFilter(
- StringUtils.trimToNull(req.getParameter(TOUCH_STONE_COMBINATION_FILTER_PARAM)), false);
- setTouchStoneResultCondition(
- Result.fromString(req.getParameter(TOUCH_STONE_RESULT_CONDITION_PARAM)), false);
+ setTouchStoneCombinationFilter(Util.nullify(req.getParameter(TOUCH_STONE_COMBINATION_FILTER_PARAM)));
+ setTouchStoneResultCondition(Result.fromString(req.getParameter(TOUCH_STONE_RESULT_CONDITION_PARAM)));
} else {
- setTouchStoneCombinationFilter(null, false);
+ setTouchStoneCombinationFilter(null);
}
setCustomWorkspace(
- req.hasParameter(CUSTOM_WORKSPACE_PARAM) ? req.getParameter(CUSTOM_WORKSPACE_DIRECTORY_PARAM) : null,
- false);
+ req.hasParameter(CUSTOM_WORKSPACE_PARAM) ? req.getParameter(CUSTOM_WORKSPACE_DIRECTORY_PARAM) : null);
// parse system axes
DescribableList<Axis, AxisDescriptor> newAxes = DescribableListUtil.buildFromHetero(this, req, json, "axis",
Axis.all());
checkAxisNames(newAxes);
- setAxes(new AxisList(newAxes.toList()), false);
+ setAxes(new AxisList(newAxes.toList()));
setRunSequentially(json.has(RUN_SEQUENTIALLY_PROPERTY_NAME));
diff --git a/hudson-core/src/main/java/hudson/model/AbstractProject.java b/hudson-core/src/main/java/hudson/model/AbstractProject.java
index 75a08d9..5d995bd 100644
--- a/hudson-core/src/main/java/hudson/model/AbstractProject.java
+++ b/hudson-core/src/main/java/hudson/model/AbstractProject.java
@@ -347,29 +347,28 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
void convertBlockBuildWhenUpstreamBuildingProperty() throws IOException {
- if (blockBuildWhenUpstreamBuilding && null == getProperty(BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME)) {
+ if (null == getProperty(BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME)) {
setBlockBuildWhenUpstreamBuilding(blockBuildWhenUpstreamBuilding);
blockBuildWhenUpstreamBuilding = false;
}
}
void convertBlockBuildWhenDownstreamBuildingProperty() throws IOException {
- if (blockBuildWhenDownstreamBuilding
- && null == getProperty(BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME)) {
+ if (null == getProperty(BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME)) {
setBlockBuildWhenDownstreamBuilding(blockBuildWhenDownstreamBuilding);
blockBuildWhenDownstreamBuilding = false;
}
}
void convertConcurrentBuildProperty() throws IOException {
- if (concurrentBuild && null == getProperty(CONCURRENT_BUILD_PROPERTY_NAME)) {
+ if (null == getProperty(CONCURRENT_BUILD_PROPERTY_NAME)) {
setConcurrentBuild(concurrentBuild);
concurrentBuild = false;
}
}
void convertCleanWorkspaceRequiredProperty() throws IOException {
- if (cleanWorkspaceRequired && null == getProperty(CLEAN_WORKSPACE_REQUIRED_PROPERTY_NAME)) {
+ if (null == getProperty(CLEAN_WORKSPACE_REQUIRED_PROPERTY_NAME)) {
setCleanWorkspaceRequired(cleanWorkspaceRequired);
cleanWorkspaceRequired = false;
}
@@ -426,11 +425,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
return Hudson.CONCURRENT_BUILD && getBooleanProperty(CONCURRENT_BUILD_PROPERTY_NAME).getValue();
}
public void setConcurrentBuild(boolean b) throws IOException {
- setConcurrentBuild(b, true);
- }
-
- public void setConcurrentBuild(boolean b, boolean forceModify) throws IOException {
- setProjectPropertyValue(CONCURRENT_BUILD_PROPERTY_NAME, BooleanProjectProperty.class, b, forceModify);
+ getBooleanProperty(CONCURRENT_BUILD_PROPERTY_NAME).setValue(b);
save();
}
@@ -439,13 +434,9 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
public void setCleanWorkspaceRequired(boolean cleanWorkspaceRequired) {
- setCleanWorkspaceRequired(cleanWorkspaceRequired, true);
+ getBooleanProperty(CLEAN_WORKSPACE_REQUIRED_PROPERTY_NAME).setValue(cleanWorkspaceRequired);
}
- public void setCleanWorkspaceRequired(boolean cleanWorkspaceRequired, boolean forceModify) {
- setProjectPropertyValue(CLEAN_WORKSPACE_REQUIRED_PROPERTY_NAME, BooleanProjectProperty.class,
- cleanWorkspaceRequired, forceModify);
- }
/**
* If this project is configured to be always built on this node,
* return that {@link Node}. Otherwise null.
@@ -656,11 +647,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
* @throws IOException if any.
*/
public void setQuietPeriod(Integer seconds) throws IOException {
- setQuietPeriod(seconds, true);
- }
-
- protected void setQuietPeriod(Integer seconds, boolean forceModify) throws IOException {
- setProjectPropertyValue(QUIET_PERIOD_PROPERTY_NAME, IntegerProjectProperty.class, seconds, forceModify);
+ getIntegerProperty(QUIET_PERIOD_PROPERTY_NAME).setValue(seconds);
save();
}
@@ -671,12 +658,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
public void setScmCheckoutRetryCount(Integer retryCount) {
- setScmCheckoutRetryCount(retryCount, true);
- }
-
- public void setScmCheckoutRetryCount(Integer retryCount, boolean forceModify) {
- setProjectPropertyValue(SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME, IntegerProjectProperty.class, retryCount,
- forceModify);
+ getIntegerProperty(SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME).setValue(retryCount);
}
/**
@@ -687,15 +669,11 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
* @throws IOException if any.
*/
protected void setScmCheckoutRetryCount(String scmCheckoutRetryCount) throws IOException {
- setScmCheckoutRetryCount(scmCheckoutRetryCount, true);
- }
-
- protected void setScmCheckoutRetryCount(String scmCheckoutRetryCount, boolean forceModify) throws IOException {
Integer retryCount = null;
if (NumberUtils.isNumber(scmCheckoutRetryCount)) {
retryCount = NumberUtils.createInteger(scmCheckoutRetryCount);
}
- setScmCheckoutRetryCount(retryCount, forceModify);
+ setScmCheckoutRetryCount(retryCount);
}
/**
@@ -716,16 +694,13 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
* @throws IOException if any.
*/
protected void setQuietPeriod(String seconds) throws IOException {
- setQuietPeriod(seconds, true);
- }
-
- protected void setQuietPeriod(String seconds, boolean forceModify) throws IOException {
Integer period = null;
if (NumberUtils.isNumber(seconds)) {
period = NumberUtils.createInteger(seconds);
}
- setQuietPeriod(period, forceModify);
+ setQuietPeriod(period);
}
+
/**
* Checks whether scmRetryCount is configured
*
@@ -754,12 +729,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
public void setBlockBuildWhenDownstreamBuilding(boolean b) throws IOException {
- setBlockBuildWhenDownstreamBuilding(b, true);
- }
-
- public void setBlockBuildWhenDownstreamBuilding(boolean b, boolean forceModify) throws IOException {
- setProjectPropertyValue(BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME,
- BooleanProjectProperty.class, b, forceModify);
+ getBooleanProperty(BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME).setValue(b);
save();
}
@@ -768,12 +738,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
public void setBlockBuildWhenUpstreamBuilding(boolean b) throws IOException {
- setBlockBuildWhenUpstreamBuilding(b, true);
- }
-
- public void setBlockBuildWhenUpstreamBuilding(boolean b, boolean forceModify) throws IOException {
- setProjectPropertyValue(BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME,
- BooleanProjectProperty.class, b, forceModify);
+ getBooleanProperty(BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME).setValue(b);
save();
}
@@ -1118,11 +1083,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
public void setJDK(String jdk) {
- setJDK(jdk, true);
- }
-
- public void setJDK(String jdk, boolean forceModify) {
- setProjectPropertyValue(JDK_PROPERTY_NAME, StringProjectProperty.class, jdk, forceModify);
+ getStringProperty(JDK_PROPERTY_NAME).setValue(jdk);
}
public BuildAuthorizationToken getAuthToken() {
@@ -1614,11 +1575,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
@SuppressWarnings("unchecked")
public void setScm(SCM scm) throws IOException {
- setScm(scm, true);
- }
-
- public void setScm(SCM scm, boolean forceModify) throws IOException {
- setProjectPropertyValue(SCM_PROPERTY_NAME, SCMProjectProperty.class, scm, forceModify);
+ getProperty(SCM_PROPERTY_NAME, SCMProjectProperty.class).setValue(scm);
//save();
}
@@ -1902,13 +1859,13 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
makeDisabled(null != req.getParameter("disable"));
setCascadingProjectName(StringUtils.trimToNull(req.getParameter("cascadingProjectName")));
- setJDK(req.getParameter("jdk"), false);
- setQuietPeriod(null != req.getParameter(HAS_QUIET_PERIOD_PROPERTY_NAME) ? req.getParameter("quiet_period") : null,
- false);
+ setJDK(req.getParameter("jdk"));
+ setQuietPeriod(null != req.getParameter(HAS_QUIET_PERIOD_PROPERTY_NAME)
+ ? req.getParameter("quiet_period") : null);
setScmCheckoutRetryCount(null != req.getParameter(HAS_SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME)
- ? req.getParameter("scmCheckoutRetryCount") : null, false);
- setBlockBuildWhenDownstreamBuilding(null != req.getParameter("blockBuildWhenDownstreamBuilding"), false);
- setBlockBuildWhenUpstreamBuilding(null != req.getParameter("blockBuildWhenUpstreamBuilding"), false);
+ ? req.getParameter("scmCheckoutRetryCount") : null);
+ 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.
@@ -1925,15 +1882,15 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
- setCleanWorkspaceRequired(null != req.getParameter("cleanWorkspaceRequired"), false);
+ setCleanWorkspaceRequired(null != req.getParameter("cleanWorkspaceRequired"));
canRoam = assignedNode==null;
- setConcurrentBuild(req.getSubmittedForm().has("concurrentBuild"), false);
+ setConcurrentBuild(req.getSubmittedForm().has("concurrentBuild"));
authToken = BuildAuthorizationToken.create(req);
- setScm(SCMS.parseSCM(req,this), false);
+ setScm(SCMS.parseSCM(req,this));
for (Trigger t : triggers)
t.stop();
diff --git a/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java b/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java
index d6e3f58..34bb2e6 100644
--- a/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java
+++ b/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java
@@ -32,6 +32,7 @@ import java.util.logging.Logger;
import net.sf.json.JSONObject;
import org.eclipse.hudson.api.model.IProject;
import org.eclipse.hudson.api.model.project.property.BaseProjectProperty;
+import org.eclipse.hudson.api.model.project.property.ExternalProjectProperty;
import org.kohsuke.stapler.StaplerRequest;
/**
@@ -158,7 +159,7 @@ public abstract class BaseBuildableProject<P extends BaseBuildableProject<P,B>,B
}
public Publisher getPublisher(Descriptor<Publisher> descriptor) {
- return (Publisher) getBaseProjectProperty(descriptor.getJsonSafeClassName()).getValue();
+ return (Publisher) getExternalProjectProperty(descriptor.getJsonSafeClassName()).getValue();
}
/**
* Returns the list of the publishers available in the hudson.
@@ -172,7 +173,7 @@ public abstract class BaseBuildableProject<P extends BaseBuildableProject<P,B>,B
DescribableList<Publisher, Descriptor<Publisher>> result
= new DescribableList<Publisher, Descriptor<Publisher>>(this);
for (Descriptor<Publisher> descriptor : descriptors) {
- BaseProjectProperty<Publisher> property = getBaseProjectProperty(descriptor.getJsonSafeClassName());
+ ExternalProjectProperty<Publisher> property = getExternalProjectProperty(descriptor.getJsonSafeClassName());
if (null != property.getValue()) {
publisherList.add(property.getValue());
}
@@ -220,7 +221,7 @@ public abstract class BaseBuildableProject<P extends BaseBuildableProject<P,B>,B
protected void buildPublishers( StaplerRequest req, JSONObject json, List<Descriptor<Publisher>> descriptors) throws FormException{
for (Descriptor<Publisher> d : descriptors) {
String name = d.getJsonSafeClassName();
- BaseProjectProperty<Publisher> baseProperty = getBaseProjectProperty(name);
+ ExternalProjectProperty<Publisher> baseProperty = getExternalProjectProperty(name);
Publisher publisher = null;
if (json.has(name)) {
publisher = d.newInstance(req, json.getJSONObject(name));
diff --git a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
index ee6084f..f996f7a 100644
--- a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
+++ b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
@@ -88,12 +88,7 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
* @throws IOException if any.
*/
public void setCustomWorkspace(String customWorkspace) throws IOException {
- setCustomWorkspace(customWorkspace, true);
- }
-
- protected void setCustomWorkspace(String customWorkspace, boolean forceModify) throws IOException {
- setProjectPropertyValue(CUSTOM_WORKSPACE_PROPERTY_NAME, StringProjectProperty.class, customWorkspace,
- forceModify);
+ getStringProperty(CUSTOM_WORKSPACE_PROPERTY_NAME).setValue(customWorkspace);
save();
}
@@ -102,7 +97,7 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
throws IOException, ServletException, Descriptor.FormException {
super.submit(req, rsp);
setCustomWorkspace(
- req.hasParameter("customWorkspace") ? req.getParameter("customWorkspace.directory") : null, false);
+ req.hasParameter("customWorkspace") ? req.getParameter("customWorkspace.directory") : null);
}
@Override
diff --git a/hudson-core/src/main/java/hudson/model/Items.java b/hudson-core/src/main/java/hudson/model/Items.java
index d559a2b..2f725db 100644
--- a/hudson-core/src/main/java/hudson/model/Items.java
+++ b/hudson-core/src/main/java/hudson/model/Items.java
@@ -23,6 +23,7 @@ import org.eclipse.hudson.api.model.project.property.AxisListProjectProperty;
import org.eclipse.hudson.api.model.project.property.BaseProjectProperty;
import org.eclipse.hudson.api.model.project.property.BooleanProjectProperty;
import org.eclipse.hudson.api.model.project.property.DescribableListProjectProperty;
+import org.eclipse.hudson.api.model.project.property.ExternalProjectProperty;
import org.eclipse.hudson.api.model.project.property.IntegerProjectProperty;
import org.eclipse.hudson.api.model.project.property.LogRotatorProjectProperty;
import org.eclipse.hudson.api.model.project.property.ResultProjectProperty;
@@ -138,6 +139,7 @@ public class Items {
//aliases for project properties.
XSTREAM.alias("base-property", BaseProjectProperty.class);
+ XSTREAM.alias("external-property", ExternalProjectProperty.class);
XSTREAM.alias("integer-property", IntegerProjectProperty.class);
XSTREAM.alias("boolean-property", BooleanProjectProperty.class);
XSTREAM.alias("string-property", StringProjectProperty.class);
diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java
index f82072c..fa0a51a 100644
--- a/hudson-core/src/main/java/hudson/model/Job.java
+++ b/hudson-core/src/main/java/hudson/model/Job.java
@@ -22,6 +22,7 @@ import org.eclipse.hudson.api.model.project.property.AxisListProjectProperty;
import org.eclipse.hudson.api.model.project.property.BaseProjectProperty;
import org.eclipse.hudson.api.model.project.property.BooleanProjectProperty;
import org.eclipse.hudson.api.model.project.property.DescribableListProjectProperty;
+import org.eclipse.hudson.api.model.project.property.ExternalProjectProperty;
import org.eclipse.hudson.api.model.project.property.IntegerProjectProperty;
import org.eclipse.hudson.api.model.project.property.LogRotatorProjectProperty;
import org.eclipse.hudson.api.model.project.property.ResultProjectProperty;
@@ -283,6 +284,10 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
return (BaseProjectProperty) getProperty(key, BaseProjectProperty.class);
}
+ public ExternalProjectProperty getExternalProjectProperty(String key) {
+ return (ExternalProjectProperty) getProperty(key, ExternalProjectProperty.class);
+ }
+
public ResultProjectProperty getResultProperty(String key) {
return (ResultProjectProperty) getProperty(key, ResultProjectProperty.class);
}
@@ -552,33 +557,9 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
*
* @param logRotator log rotator.
*/
- public void setLogRotator(LogRotator logRotator) {
- setLogRotator(logRotator, true);
- }
-
- public void setLogRotator(LogRotator logRotator, boolean forceModify) {
- setProjectPropertyValue(LOG_ROTATOR_PROPERTY_NAME, LogRotatorProjectProperty.class, logRotator, forceModify);
- }
-
- /**
- * Update project property with new value. ForceModify flag is taken into account.
- * If property is null - it will be initialized and added to current job.
- *
- * @param key property key.
- * @param clazz property class.
- * @param value new value.
- * @param forceModify true - to set property value even if it was not modified from UI. Basically this parameter is
- * used for cascading functionality.
- */
@SuppressWarnings("unchecked")
- protected void setProjectPropertyValue(String key, Class clazz, Object value, boolean forceModify) {
- IProjectProperty property = getProperty(key, clazz);
- if (null != property) {
- if (forceModify) {
- property.setModified(forceModify);
- }
- property.setValue(value);
- }
+ public void setLogRotator(LogRotator logRotator) {
+ getProperty(LOG_ROTATOR_PROPERTY_NAME, LogRotatorProjectProperty.class).setValue(logRotator);
}
@@ -1248,7 +1229,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
JSONObject json = req.getSubmittedForm();
setLogRotator(req.getParameter("logrotate") != null ? LogRotator.DESCRIPTOR
- .newInstance(req, json.getJSONObject("logrotate")) : null, false);
+ .newInstance(req, json.getJSONObject("logrotate")) : null);
int i = 0;
for (JobPropertyDescriptor d : JobPropertyDescriptor.getPropertyDescriptors(Job.this.getClass())) {
@@ -1453,8 +1434,8 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
.toString();
}
IProjectProperty property = getProperty(propertyName);
- if (null != property) {
- property.setModified(true);
+ if (null != property && property instanceof ExternalProjectProperty) {
+ ((ExternalProjectProperty) property).setModified(true);
}
}
}
@@ -1473,7 +1454,11 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
this.cascadingProject = (JobT) Functions.getItemByName(Hudson.getInstance().getAllItems(this.getClass()),
cascadingProjectName);
for (IProjectProperty property : jobProperties.values()) {
- property.setOverridden(property.isModified());
+ if (property instanceof ExternalProjectProperty) {
+ property.setOverridden(((ExternalProjectProperty) property).isModified());
+ } else {
+ property.setOverridden(property.getValue() != property.getCascadingValue());
+ }
}
}
}
diff --git a/hudson-core/src/main/java/hudson/model/Project.java b/hudson-core/src/main/java/hudson/model/Project.java
index a87d16b..ae2721d 100644
--- a/hudson-core/src/main/java/hudson/model/Project.java
+++ b/hudson-core/src/main/java/hudson/model/Project.java
@@ -78,7 +78,7 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
* Use {@code getPublishersList().add(x)}
*/
public void addPublisher(Publisher buildStep) throws IOException {
- getBaseProjectProperty(buildStep.getDescriptor().getJsonSafeClassName()).setValue(buildStep);
+ getExternalProjectProperty(buildStep.getDescriptor().getJsonSafeClassName()).setValue(buildStep);
}
/**
diff --git a/hudson-core/src/main/java/hudson/util/DescribableListUtil.java b/hudson-core/src/main/java/hudson/util/DescribableListUtil.java
index a91f377..2ea8e10 100644
--- a/hudson-core/src/main/java/hudson/util/DescribableListUtil.java
+++ b/hudson-core/src/main/java/hudson/util/DescribableListUtil.java
@@ -27,6 +27,7 @@ import java.util.Map;
import net.sf.json.JSONObject;
import org.eclipse.hudson.api.model.IJob;
import org.eclipse.hudson.api.model.project.property.BaseProjectProperty;
+import org.eclipse.hudson.api.model.project.property.ExternalProjectProperty;
import org.kohsuke.stapler.StaplerRequest;
/**
@@ -109,11 +110,11 @@ public final class DescribableListUtil {
* @return map of converted properties.
*/
public static <T extends Describable<T>, D extends Descriptor<T>>
- Map<String, BaseProjectProperty<T>> convertToProjectProperties(DescribableList<T, D> describableList, IJob owner) {
- Map<String, BaseProjectProperty<T>> result = Maps.newConcurrentMap();
+ Map<String, ExternalProjectProperty<T>> convertToProjectProperties(DescribableList<T, D> describableList, IJob owner) {
+ Map<String, ExternalProjectProperty<T>> result = Maps.newConcurrentMap();
if (null != describableList) {
for (Map.Entry<D, T> entry : describableList.toMap().entrySet()) {
- BaseProjectProperty<T> property = new BaseProjectProperty<T>(owner);
+ ExternalProjectProperty<T> property = new ExternalProjectProperty<T>(owner);
String key = entry.getKey().getJsonSafeClassName();
property.setKey(key);
property.setValue(entry.getValue());
@@ -124,4 +125,3 @@ public final class DescribableListUtil {
}
}
-
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/IProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/IProjectProperty.java
index 64bda37..4d62292 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/api/model/IProjectProperty.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/IProjectProperty.java
@@ -42,13 +42,10 @@ public interface IProjectProperty<T> extends Serializable {
/**
* Sets property value.
- * If property has cascading value, than modified flag will be checked.
- * If property was modified and {@link #allowOverrideValue(Object, Object)} method returns true, that value will be
- * set to current property.<br/>
+ * If property has cascading value and properties' {@link #allowOverrideValue(Object, Object)} method returns true,
+ * than value will be set to current property.<br/>
* If property doesn't have cascading value, than value will be set directly.
*
- * NOTE: use should call {@link #setModified(boolean)} method before setting cascading value.
- *
* @param value value to set.
*/
void setValue(T value);
@@ -107,16 +104,4 @@ public interface IProjectProperty<T> extends Serializable {
* @param overridden true - mark property as overridden, false - otherwise.
*/
void setOverridden(boolean overridden);
-
- /**
- * Method set modified state for current property.
- *
- * @param modified true if property was modified by user.
- */
- void setModified(boolean modified);
-
- /**
- * @return true if property was modified, false - otherwise.
- */
- boolean isModified();
}
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java
index 3397c3d..e5de78d 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java
@@ -35,7 +35,6 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
private transient IJob job;
private T originalValue;
private boolean propertyOverridden;
- private boolean modified;
/**
* Instantiate new property.
@@ -54,6 +53,13 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
}
/**
+ * @return key for current property
+ */
+ final String getPropertyKey() {
+ return propertyKey;
+ }
+
+ /**
* {@inheritDoc}
*/
public void setJob(IJob job) {
@@ -80,20 +86,6 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
/**
* {@inheritDoc}
*/
- public void setModified(boolean modified) {
- this.modified = modified;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean isModified() {
- return modified;
- }
-
- /**
- * {@inheritDoc}
- */
@SuppressWarnings("unchecked")
public T getCascadingValue() {
if (null == propertyKey) {
@@ -148,15 +140,24 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
if (!getJob().hasCascadingProject()) {
setOriginalValue(value, false);
} else {
- T cascadingValue = getCascadingValue();
- T candidateValue = null == value ? getDefaultValue() : value;
- if (isModified()) {
- if (allowOverrideValue(cascadingValue, candidateValue)) {
- setOriginalValue(value, true);
- } else {
- resetValue();
- }
- }
+ updateOriginalValue(value, getCascadingValue());
+ }
+ }
+
+ /**
+ * Update value for cascading property. Before setting new value it will be checked for equality with cascading
+ * value. If two values are equals - current value will be reset and will retrieved from parent. If not - value will
+ * be set directly.
+ *
+ * @param value new value to be set.
+ * @param cascadingValue current cascading value.
+ */
+ protected void updateOriginalValue(T value, T cascadingValue) {
+ T candidateValue = null == value ? getDefaultValue() : value;
+ if (allowOverrideValue(cascadingValue, candidateValue)) {
+ setOriginalValue(value, true);
+ } else {
+ resetValue();
}
}
@@ -176,8 +177,7 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
* {@inheritDoc}
*/
public void resetValue() {
- this.originalValue = null;
- setOverridden(false);
+ setOriginalValue(null, false);
}
/**
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectProperty.java
index 90b9ad6..7b400c0 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectProperty.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/DescribableListProjectProperty.java
@@ -46,6 +46,12 @@ public class DescribableListProjectProperty extends BaseProjectProperty<Describa
protected boolean returnOriginalValue() {
return isOverridden() || (null != getOriginalValue() && !getOriginalValue().isEmpty());
}
+
+ @Override
+ public DescribableList getOriginalValue() {
+ DescribableList result = super.getOriginalValue();
+ return null != result ? result : getDefaultValue();
+ }
}
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/ExternalProjectProperty.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/ExternalProjectProperty.java
new file mode 100644
index 0000000..45c19e3
--- /dev/null
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/ExternalProjectProperty.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ *
+ * Copyright (c) 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
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *
+ * Nikita Levyankov
+ *
+ *******************************************************************************/
+package org.eclipse.hudson.api.model.project.property;
+
+import org.eclipse.hudson.api.model.IJob;
+
+/**
+ * //TODO class description
+ * <p/>
+ * Date: 10/20/11
+ *
+ * @author Nikita Levyankov
+ */
+public class ExternalProjectProperty<T> extends BaseProjectProperty<T> {
+
+ private boolean modified;
+
+ public ExternalProjectProperty(IJob job) {
+ super(job);
+ }
+
+ /**
+ * Method set modified state for current property.
+ *
+ * @param modified true if property was modified by user.
+ */
+ public void setModified(boolean modified) {
+ this.modified = modified;
+ }
+
+ /**
+ * @return true if property was modified, false - otherwise.
+ */
+ public boolean isModified() {
+ return modified;
+ }
+
+ /**
+ * If property was not marked as {@link #isModified()} by calling {@link #setModified(boolean)} method with
+ * true parameter value, than property will not be updated. This was implemented as the workaround for absent
+ * equals methods for Publishers, BuildWrappers, etc.
+ * <p/>
+ * Such properties could be normally compared and use in cascading functionality.
+ *
+ * @param value new value to be set.
+ * @param cascadingValue current cascading value.
+ */
+ @Override
+ protected void updateOriginalValue(T value, T cascadingValue) {
+ if (isModified()) {
+ super.updateOriginalValue(value, cascadingValue);
+ }
+ }
+}
diff --git a/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java b/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
index 9cf4538..14b1688 100644
--- a/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
+++ b/hudson-core/src/test/java/hudson/model/FreeStyleProjectTest.java
@@ -258,7 +258,6 @@ public class FreeStyleProjectTest {
parentProject.setCustomWorkspace(parentCustomWorkspace);
FreeStyleProjectMock childProject = new FreeStyleProjectMock("child");
childProject.setCascadingProject(parentProject);
- childProject.getStringProperty(FreeStyleProject.CUSTOM_WORKSPACE_PROPERTY_NAME).setModified(true);
childProject.setCustomWorkspace(childCustomWorkspace);
assertEquals(childCustomWorkspace, childProject.getCustomWorkspace());
}
@@ -307,7 +306,6 @@ public class FreeStyleProjectTest {
parentProject.setJDK(parentJdkName);
FreeStyleProjectMock childProject = new FreeStyleProjectMock("child");
childProject.setCascadingProject(parentProject);
- childProject.getStringProperty(AbstractProject.JDK_PROPERTY_NAME).setModified(true);
childProject.setJDK(childJdkName);
assertEquals(childJdkName, childProject.getJDKName());
}
@@ -381,7 +379,6 @@ public class FreeStyleProjectTest {
parentProject.setQuietPeriod(parentQuietPeriod);
FreeStyleProjectMock childProject = new FreeStyleProjectMock("child");
childProject.setCascadingProject(parentProject);
- childProject.getIntegerProperty(AbstractProject.QUIET_PERIOD_PROPERTY_NAME).setModified(true);
childProject.setQuietPeriod(childQuietPeriod);
Hudson hudson = createMock(Hudson.class);
@@ -455,7 +452,6 @@ public class FreeStyleProjectTest {
replayAll();
assertEquals(childProject.getScmCheckoutRetryCount(), globalScmCheckoutRetryCount);
childProject.setCascadingProject(parentProject);
- childProject.getIntegerProperty(AbstractProject.SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME).setModified(true);
childProject.setScmCheckoutRetryCount(scmCheckoutRetryCount);
assertEquals(childProject.getScmCheckoutRetryCount(), Integer.parseInt(scmCheckoutRetryCount));
verifyAll();
@@ -469,7 +465,6 @@ public class FreeStyleProjectTest {
parentProject.setScmCheckoutRetryCount(parentScmCheckoutRetryCount);
FreeStyleProjectMock childProject = new FreeStyleProjectMock("child");
childProject.setCascadingProject(parentProject);
- childProject.getIntegerProperty(AbstractProject.SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME).setModified(true);
childProject.setScmCheckoutRetryCount(childScmCheckoutRetryCount);
Hudson hudson = createMock(Hudson.class);
diff --git a/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java b/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
index d22732e..7e83e55 100644
--- a/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
+++ b/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
@@ -64,9 +64,7 @@ public class LegacyProjectTest {
project.initProjectProperties();
assertNull(project.getProperty(FreeStyleProject.CUSTOM_WORKSPACE_PROPERTY_NAME));
project.convertCustomWorkspaceProperty();
- IProjectProperty property = project.getProperty(FreeStyleProject.CUSTOM_WORKSPACE_PROPERTY_NAME);
- assertNotNull(property);
- assertEquals("/tmp", property.getValue());
+ assertNotNull(project.getProperty(FreeStyleProject.CUSTOM_WORKSPACE_PROPERTY_NAME));
}
/**
@@ -153,10 +151,7 @@ public class LegacyProjectTest {
project.initProjectProperties();
assertNull(project.getProperty(AbstractProject.BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME));
project.convertBlockBuildWhenDownstreamBuildingProperty();
- BooleanProjectProperty property = (BooleanProjectProperty)project.getProperty(
- AbstractProject.BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME);
- assertNotNull(property);
- assertTrue(property.getValue());
+ assertNotNull(project.getProperty(AbstractProject.BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME));
}
/**
@@ -172,10 +167,7 @@ public class LegacyProjectTest {
project.initProjectProperties();
assertNull(project.getProperty(AbstractProject.BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME));
project.convertBlockBuildWhenUpstreamBuildingProperty();
- BooleanProjectProperty property = (BooleanProjectProperty)project.getProperty(
- AbstractProject.BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME);
- assertNotNull(property);
- assertTrue(property.getValue());
+ assertNotNull(project.getProperty(AbstractProject.BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME));
}
/**
@@ -191,10 +183,7 @@ public class LegacyProjectTest {
project.initProjectProperties();
assertNull(project.getProperty(AbstractProject.CONCURRENT_BUILD_PROPERTY_NAME));
project.convertConcurrentBuildProperty();
- BooleanProjectProperty property = (BooleanProjectProperty)project.getProperty(
- AbstractProject.CONCURRENT_BUILD_PROPERTY_NAME);
- assertNotNull(property);
- assertTrue(property.getValue());
+ assertNotNull(project.getProperty(AbstractProject.CONCURRENT_BUILD_PROPERTY_NAME));
}
/**
diff --git a/hudson-core/src/test/java/hudson/util/DescribableListUtilTest.java b/hudson-core/src/test/java/hudson/util/DescribableListUtilTest.java
index 8d819ff..0dabc19 100644
--- a/hudson-core/src/test/java/hudson/util/DescribableListUtilTest.java
+++ b/hudson-core/src/test/java/hudson/util/DescribableListUtilTest.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.util.Map;
import org.eclipse.hudson.api.model.IJob;
import org.eclipse.hudson.api.model.project.property.BaseProjectProperty;
+import org.eclipse.hudson.api.model.project.property.ExternalProjectProperty;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -51,7 +52,7 @@ public class DescribableListUtilTest {
public void testConvertToProjectProperties1() {
prepareJob();
DescribableList<Publisher, Descriptor<Publisher>> list = null;
- Map<String, BaseProjectProperty<Publisher>> map = DescribableListUtil.convertToProjectProperties(list, job);
+ Map<String, ExternalProjectProperty<Publisher>> map = DescribableListUtil.convertToProjectProperties(list, job);
assertNotNull(map);
assertTrue(map.isEmpty());
}
@@ -61,7 +62,7 @@ public class DescribableListUtilTest {
prepareJob();
DescribableList<Publisher, Descriptor<Publisher>> list
= new DescribableList<Publisher, Descriptor<Publisher>>();
- Map<String, BaseProjectProperty<Publisher>> map = DescribableListUtil.convertToProjectProperties(list, job);
+ Map<String, ExternalProjectProperty<Publisher>> map = DescribableListUtil.convertToProjectProperties(list, job);
assertNotNull(map);
assertTrue(map.isEmpty());
}
@@ -82,7 +83,7 @@ public class DescribableListUtilTest {
list.add(new Mailer());
- Map<String, BaseProjectProperty<Publisher>> map = DescribableListUtil.convertToProjectProperties(list, job);
+ Map<String, ExternalProjectProperty<Publisher>> map = DescribableListUtil.convertToProjectProperties(list, job);
assertNotNull(map);
assertEquals(map.size(), 1);
assertNotNull(map.get(mailerName));
diff --git a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java
index e3b958a..1d77dee 100644
--- a/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java
+++ b/hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java
@@ -487,7 +487,6 @@ public class ProjectPropertyTest {
project.setCascadingProject(parent);
//If value set to null, need to check whether default value is equals to cascading
- property.setModified(true);
property.setValue(null);
assertTrue(property.isOverridden());
String overriddenValue = "newValue";