aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-22 08:03:27 (EST)
committerWinston Prakash2011-12-01 20:46:57 (EST)
commita2be96de345f16175c68858e65fe6b989dbfbcfe (patch)
tree4edd4f0c98166a0d857d26639dd4e021ae0a66e1
parent12993b9d8a6518c52a38b187c580aa44d1d21bc1 (diff)
downloadorg.eclipse.hudson.core-a2be96de345f16175c68858e65fe6b989dbfbcfe.zip
org.eclipse.hudson.core-a2be96de345f16175c68858e65fe6b989dbfbcfe.tar.gz
org.eclipse.hudson.core-a2be96de345f16175c68858e65fe6b989dbfbcfe.tar.bz2
Improve LegacyConverter test. Implement legacy properties conversion and IProperty logic for quietPeriod, scmCheckoutRetryCount
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/matrix/MatrixProject.java19
-rw-r--r--hudson-core/src/main/java/hudson/model/AbstractProject.java75
-rw-r--r--hudson-core/src/main/java/hudson/model/FreeStyleProject.java2
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java4
-rw-r--r--hudson-core/src/test/java/hudson/model/LegacyProjectTest.java25
5 files changed, 76 insertions, 49 deletions
diff --git a/hudson-core/src/main/java/hudson/matrix/MatrixProject.java b/hudson-core/src/main/java/hudson/matrix/MatrixProject.java
index 5a2ec56..357f2e9 100644
--- a/hudson-core/src/main/java/hudson/matrix/MatrixProject.java
+++ b/hudson-core/src/main/java/hudson/matrix/MatrixProject.java
@@ -104,7 +104,7 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i
* The filter that is applied to combinations. It is a Groovy if condition.
* This can be null, which means "true".
*
- * @see #getCombinationFilter()
+ * @deprecated as of 2.2.0, use #getCombinationFilter() and #setCombinationFilter() instead
*/
private volatile String combinationFilter;
@@ -137,10 +137,15 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i
@CopyOnWrite
private transient /*final*/ Set<MatrixConfiguration> activeConfigurations = new LinkedHashSet<MatrixConfiguration>();
+ /**
+ * @deprecated as of 2.2.0, use #isRunSequentially() and #setRunSequentially() instead
+ */
private boolean runSequentially;
/**
- * Filter to select a number of combinations to build first.
+ * Filter to select a number of combinations to build first
+ *
+ * @deprecated as of 2.2.0, use #getTouchStoneCombinationFilter() and #setTouchStoneCombinationFilter() instead
*/
private String touchStoneCombinationFilter;
@@ -148,11 +153,13 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i
* Required result on the touchstone combinations, in order to
* continue with the rest.
* Package visible for the tests only.
+ *
+ * @deprecated as of 2.2.0, use #getTouchStoneResultCondition() and #setTouchStoneResultCondition() instead
*/
Result touchStoneResultCondition;
/**
- * See {@link #setCustomWorkspace(String)}.
+ * @deprecated as of 2.2.0, use #getCustomWorkspace() and #setCustomWorkspace() instead
*/
private String customWorkspace;
@@ -268,7 +275,7 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i
//TODO improve it
public DescribableList<Builder,Descriptor<Builder>> getBuildersList() {
- return !(builders == null || builders.isEmpty()) ? builders
+ return !(builders == null /*|| builders.isEmpty()*/) ? builders
: (hasCascadingProject() ? getCascadingProject().getBuildersList() : null);
}
@@ -285,7 +292,7 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i
*/
//TODO improve it
public DescribableList<Publisher,Descriptor<Publisher>> getPublishersList() {
- return !(publishers == null || publishers.isEmpty()) ? publishers
+ return !(publishers == null /*|| publishers.isEmpty()*/) ? publishers
: (hasCascadingProject() ? getCascadingProject().getPublishersList() : null);
}
@@ -294,7 +301,7 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i
*/
//TODO improve it
public DescribableList<BuildWrapper, Descriptor<BuildWrapper>> getBuildWrappersList() {
- return !(buildWrappers == null || buildWrappers.isEmpty()) ? buildWrappers
+ return !(buildWrappers == null /*|| buildWrappers.isEmpty()*/) ? buildWrappers
: (hasCascadingProject() ? getCascadingProject().getBuildWrappersList() : null);
}
diff --git a/hudson-core/src/main/java/hudson/model/AbstractProject.java b/hudson-core/src/main/java/hudson/model/AbstractProject.java
index ce448a9..c35c127 100644
--- a/hudson-core/src/main/java/hudson/model/AbstractProject.java
+++ b/hudson-core/src/main/java/hudson/model/AbstractProject.java
@@ -123,6 +123,8 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
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";
+ public static final String QUIET_PERIOD_PROPERTY_NAME = "quietPeriod";
+ public static final String SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME = "scmCheckoutRetryCount";
/**
* {@link SCM} associated with the project.
@@ -143,11 +145,18 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
/**
* The quiet period. Null to delegate to the system default.
+ * @deprecated as of 2.2.0
+ * don't use this field directly, logic was moved to {@link org.eclipse.hudson.api.model.IProjectProperty}.
+ * Use getter/setter for accessing to this field.
+ *
*/
private volatile Integer quietPeriod = null;
/**
* The retry count. Null to delegate to the system default.
+ * @deprecated as of 2.2.0
+ * don't use this field directly, logic was moved to {@link org.eclipse.hudson.api.model.IProjectProperty}.
+ * Use getter/setter for accessing to this field.
*/
private volatile Integer scmCheckoutRetryCount = null;
@@ -185,8 +194,7 @@ 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.
*
- * @since 2.2.0
- * @deprecated don't use this field directly, logic was moved to {@link org.eclipse.hudson.api.model.IProjectProperty}.
+ * @deprecated as of 2.2.0. Don't use this field directly, logic was moved to {@link org.eclipse.hudson.api.model.IProjectProperty}.
* Use getter/setter for accessing to this field.
*/
protected volatile boolean blockBuildWhenDownstreamBuilding;
@@ -194,8 +202,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
/**
* True to keep builds of this project in queue when upstream projects are building.
*
- * @since 2.2.0
- * @deprecated don't use this field directly, logic was moved to {@link org.eclipse.hudson.api.model.IProjectProperty}.
+ * @deprecated as of 2.2.0. Don't use this field directly, logic was moved to {@link org.eclipse.hudson.api.model.IProjectProperty}.
* Use getter/setter for accessing to this field.
*/
protected volatile boolean blockBuildWhenUpstreamBuilding;
@@ -235,8 +242,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
protected transient volatile List<Action> transientActions = new Vector<Action>();
/**
- * @since 2.2.0
- * @deprecated don't use this field directly, logic was moved to {@link org.eclipse.hudson.api.model.IProjectProperty}.
+ * @deprecated as of 2.2.0 Don't use this field directly, logic was moved to {@link org.eclipse.hudson.api.model.IProjectProperty}.
* Use getter/setter for accessing to this field.
*/
private boolean concurrentBuild;
@@ -244,8 +250,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
/**
* True to clean the workspace prior to each build.
*
- * @since 2.2.0
- * @deprecated don't use this field directly, logic was moved to {@link org.eclipse.hudson.api.model.IProjectProperty}.
+ * @deprecated as of 2.2.0 don't use this field directly, logic was moved to {@link org.eclipse.hudson.api.model.IProjectProperty}.
* Use getter/setter for accessing to this field.
*/
private volatile boolean cleanWorkspaceRequired;
@@ -318,6 +323,12 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
if (null == getProperty(CLEAN_WORKSPACE_REQUIRED_PROPERTY_NAME)) {
setCleanWorkspaceRequired(cleanWorkspaceRequired);
}
+ if (null == getProperty(QUIET_PERIOD_PROPERTY_NAME)) {
+ setQuietPeriod(quietPeriod);
+ }
+ if (null == getProperty(SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME)) {
+ setScmCheckoutRetryCount(scmCheckoutRetryCount);
+ }
}
@Override
@@ -553,28 +564,30 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
public int getQuietPeriod() {
- if (null != quietPeriod) {
- return quietPeriod;
- }
- return hasCascadingProject() ? getCascadingProject().getQuietPeriod() : Hudson.getInstance().getQuietPeriod();
+ IntegerProjectProperty property = getIntegerProperty(QUIET_PERIOD_PROPERTY_NAME);
+ Integer value = property.getValue();
+ return property.getDefaultValue().equals(value) ? Hudson.getInstance().getQuietPeriod() : value;
+ }
+
+ /**
+ * Sets the custom quiet period of this project, or revert to the global default if null is given.
+ * @param seconds quiet period
+ * @throws IOException if any.
+ */
+ public void setQuietPeriod(Integer seconds) throws IOException {
+ getIntegerProperty(QUIET_PERIOD_PROPERTY_NAME).setValue(seconds);
+ save();
}
public int getScmCheckoutRetryCount() {
- if (null != scmCheckoutRetryCount) {
- return scmCheckoutRetryCount;
- }
- return hasCascadingProject() ?
- getCascadingProject().getScmCheckoutRetryCount() : Hudson.getInstance().getScmCheckoutRetryCount();
+ IntegerProjectProperty property = getIntegerProperty(SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME);
+ Integer value = property.getValue();
+ return property.getDefaultValue().equals(value) ? Hudson.getInstance().getScmCheckoutRetryCount() : value;
}
public void setScmCheckoutRetryCount(Integer retryCount) {
- if (!(hasCascadingProject() && ObjectUtils.equals(getCascadingProject().getScmCheckoutRetryCount(), retryCount))) {
- this.scmCheckoutRetryCount = retryCount;
- } else {
- this.scmCheckoutRetryCount = null;
- }
+ getIntegerProperty(SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME).setValue(retryCount);
}
-
/**
* Sets scmCheckoutRetryCount, Uses {@link NumberUtils#isNumber(String)} for checking retryCount param.
* If it is not valid number, null will be set.
@@ -597,22 +610,6 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
}
/**
- * Sets the custom quiet period of this project, or revert to the global default if null is given.
- * @param seconds quiet period
- * @throws IOException if any.
- */
- public void setQuietPeriod(Integer seconds) throws IOException {
- if (!(hasCascadingProject()
- && (ObjectUtils.equals(getCascadingProject().getQuietPeriod(), seconds))
- && ObjectUtils.notEqual(seconds, Hudson.getInstance().getQuietPeriod()))) {
- this.quietPeriod = seconds;
- } else {
- this.quietPeriod = null;
- }
- save();
- }
-
- /**
* Sets quietPeriod, Uses {@link NumberUtils#isNumber(String)} for checking seconds param. If seconds is not valid
* number, null will be set.
*
diff --git a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
index 74b3cec..f35f922 100644
--- a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
+++ b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
@@ -43,7 +43,7 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
*
* @since 1.216
* @deprecated left for backward compatibility
- * @since 2.1.2
+ * @since 2.2.0
*/
private String customWorkspace;
diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java
index e1af1b9..b95480c 100644
--- a/hudson-core/src/main/java/hudson/model/Job.java
+++ b/hudson-core/src/main/java/hudson/model/Job.java
@@ -244,6 +244,10 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
return (BooleanProjectProperty) getProperty(key, BooleanProjectProperty.class);
}
+ public IntegerProjectProperty getIntegerProperty(String key) {
+ return (IntegerProjectProperty) getProperty(key, IntegerProjectProperty.class);
+ }
+
@Override
public synchronized void save() throws IOException {
if (null == allowSave) {
diff --git a/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java b/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
index 8431693..77f9fac 100644
--- a/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
+++ b/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
@@ -41,22 +41,41 @@ public class LegacyProjectTest {
* @throws Exception if any.
*/
@Test
- public void testLoadFreeStyleProject() throws Exception {
+ public void testLoadLegacyFreeStyleProject() throws Exception {
File freeStyleProjectConfig = new File(FreeStyleProject.class.getResource("/hudson/model/freestyle").toURI());
FreeStyleProject project = (FreeStyleProject) Items.getConfigFile(freeStyleProjectConfig).read();
project.setAllowSave(false);
project.initProjectProperties();
//Checks customWorkspace value
assertNull(project.getProperty(FreeStyleProject.CUSTOM_WORKSPACE_PROPERTY_NAME));
+ project.buildProjectProperties();
+ assertNotNull(project.getProperty(FreeStyleProject.CUSTOM_WORKSPACE_PROPERTY_NAME));
+ }
+
+ /**
+ * Tests unmarshalls FreeStyleProject configuration and checks whether properties
+ * from AbstractProject are configured
+ *
+ * @throws Exception if any.
+ */
+ @Test
+ public void testLoadLegacyAbstractProject() throws Exception {
+ File freeStyleProjectConfig = new File(FreeStyleProject.class.getResource("/hudson/model/freestyle").toURI());
+ AbstractProject project = (AbstractProject) Items.getConfigFile(freeStyleProjectConfig).read();
+ project.setAllowSave(false);
+ project.initProjectProperties();
assertNull(project.getProperty(AbstractProject.BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME));
assertNull(project.getProperty(AbstractProject.BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME));
assertNull(project.getProperty(AbstractProject.CONCURRENT_BUILD_PROPERTY_NAME));
assertNull(project.getProperty(AbstractProject.CLEAN_WORKSPACE_REQUIRED_PROPERTY_NAME));
+ assertNull(project.getProperty(AbstractProject.QUIET_PERIOD_PROPERTY_NAME));
+ assertNull(project.getProperty(AbstractProject.SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME));
project.buildProjectProperties();
- assertNotNull(project.getProperty(FreeStyleProject.CUSTOM_WORKSPACE_PROPERTY_NAME));
assertNotNull(project.getProperty(AbstractProject.BLOCK_BUILD_WHEN_UPSTREAM_BUILDING_PROPERTY_NAME));
assertNotNull(project.getProperty(AbstractProject.BLOCK_BUILD_WHEN_DOWNSTREAM_BUILDING_PROPERTY_NAME));
assertNotNull(project.getProperty(AbstractProject.CONCURRENT_BUILD_PROPERTY_NAME));
assertNotNull(project.getProperty(AbstractProject.CLEAN_WORKSPACE_REQUIRED_PROPERTY_NAME));
+ assertNotNull(project.getProperty(AbstractProject.QUIET_PERIOD_PROPERTY_NAME));
+ assertNotNull(project.getProperty(AbstractProject.SCM_CHECKOUT_RETRY_COUNT_PROPERTY_NAME));
}
-} \ No newline at end of file
+}