summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-23 07:03:38 (EST)
committer Winston Prakash2011-12-01 20:47:08 (EST)
commitf312b997aeeb980736058c55698652a44ab97211 (patch)
tree401a6d6c8b33a362520e08187a17fe9f0f72be56
parente205412de703cfa05a61d7922087da9437bf12d6 (diff)
downloadorg.eclipse.hudson.core-f312b997aeeb980736058c55698652a44ab97211.zip
org.eclipse.hudson.core-f312b997aeeb980736058c55698652a44ab97211.tar.gz
org.eclipse.hudson.core-f312b997aeeb980736058c55698652a44ab97211.tar.bz2
Imrove BaseProjectProperty. Use reflectionEquals for allowOverride
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/project/property/BaseProjectProperty.java25
-rw-r--r--hudson-core/src/test/java/org/eclipse/hudson/api/model/project/property/ProjectPropertyTest.java4
2 files changed, 23 insertions, 6 deletions
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 042db2c..380d2bf 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
@@ -16,6 +16,7 @@
package org.eclipse.hudson.api.model.project.property;
import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.builder.EqualsBuilder;
import org.eclipse.hudson.api.model.IJob;
import org.eclipse.hudson.api.model.IProjectProperty;
@@ -71,7 +72,7 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
/**
* {@inheritDoc}
*/
- public final void setOverridden(boolean overridden) {
+ public void setOverridden(boolean overridden) {
propertyOverridden = overridden;
}
@@ -121,13 +122,12 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
}
value = prepareValue(value);
if (!getJob().hasCascadingProject()) {
- originalValue = value;
+ setOriginalValue(value, false);
} else {
T cascadingValue = (T) getJob().getCascadingProject().getProperty(propertyKey, this.getClass()).getValue();
T candidateValue = null == value ? getDefaultValue() : value;
if (allowOverrideValue(cascadingValue, candidateValue)) {
- originalValue = value;
- setOverridden(true);
+ setOriginalValue(value, true);
} else {
resetValue();
}
@@ -135,6 +135,18 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
}
/**
+ * Method that sets original value and mark it as overridden if needed. It was created to provide better flexibility
+ * in subclasses.
+ *
+ * @param originalValue value to set
+ * @param overridden true - to mark as overridden.
+ */
+ protected void setOriginalValue(T originalValue, boolean overridden) {
+ this.originalValue = originalValue;
+ setOverridden(overridden);
+ }
+
+ /**
* {@inheritDoc}
*/
public void resetValue() {
@@ -150,7 +162,8 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
* @return true if cascading value should be replaced by candidate value.
*/
protected boolean allowOverrideValue(T cascadingValue, T candidateValue) {
- return ObjectUtils.notEqual(cascadingValue, candidateValue);
+ return ObjectUtils.notEqual(cascadingValue, candidateValue)
+ && !EqualsBuilder.reflectionEquals(cascadingValue, candidateValue);
}
/**
@@ -169,4 +182,4 @@ public class BaseProjectProperty<T> implements IProjectProperty<T> {
public T getOriginalValue() {
return originalValue;
}
-} \ No newline at end of file
+}
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 672c088..b57c33c 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
@@ -18,6 +18,7 @@ package org.eclipse.hudson.api.model.project.property;
import hudson.matrix.Axis;
import hudson.matrix.AxisList;
import hudson.model.FreeStyleProjectMock;
+import hudson.tasks.JavadocArchiver;
import hudson.tasks.LogRotator;
import hudson.tasks.Shell;
import hudson.util.DescribableList;
@@ -230,6 +231,9 @@ public class ProjectPropertyTest {
assertFalse(property.allowOverrideValue(null, null));
assertTrue(property.allowOverrideValue(new Object(), null));
assertTrue(property.allowOverrideValue(null, new Object()));
+ //Test properties that don't have correct equals methods
+ assertFalse(property.allowOverrideValue(new JavadocArchiver("", false), new JavadocArchiver("", false)));
+ assertTrue(property.allowOverrideValue(new JavadocArchiver("", true), new JavadocArchiver("", false)));
}
@Test