summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-22 06:57:13 (EST)
committer Winston Prakash2011-12-01 20:46:56 (EST)
commitef80f39fd4e01b6745349ccc580f9ec8753d21ba (patch)
tree57bba368bc72852e1215fcc145020cc0f7f2df80
parenta31dc2572df68e1d6ce4177c509e77a0c246bf35 (diff)
downloadorg.eclipse.hudson.core-ef80f39fd4e01b6745349ccc580f9ec8753d21ba.zip
org.eclipse.hudson.core-ef80f39fd4e01b6745349ccc580f9ec8753d21ba.tar.gz
org.eclipse.hudson.core-ef80f39fd4e01b6745349ccc580f9ec8753d21ba.tar.bz2
Draft implementation which supports legacy properties. Implement unit-test for Legacy configuration testing
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/FreeStyleProject.java12
-rw-r--r--hudson-core/src/main/java/hudson/model/Job.java48
-rw-r--r--hudson-core/src/test/java/hudson/model/LegacyProjectTest.java52
-rw-r--r--hudson-core/src/test/resources/hudson/model/freestyle/config.xml36
4 files changed, 136 insertions, 12 deletions
diff --git a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
index 76f1e6b..2e9e578 100644
--- a/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
+++ b/hudson-core/src/main/java/hudson/model/FreeStyleProject.java
@@ -42,6 +42,8 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
* See {@link #setCustomWorkspace(String)}.
*
* @since 1.216
+ * @deprecated left for backward compatibility
+ * @since 2.1.2
*/
private String customWorkspace;
@@ -97,6 +99,16 @@ public class FreeStyleProject extends Project<FreeStyleProject,FreeStyleBuild> i
super.submit(req, rsp);
}
+ @Override
+ protected void buildProjectProperties() throws IOException {
+ super.buildProjectProperties();
+ //Convert legacy cust omWorkspace property to IProjectProperty logic
+ if (null != customWorkspace && null == getProperty(CUSTOM_WORKSPACE_PROPERTY_NAME)) {
+ setCustomWorkspace(customWorkspace);
+ customWorkspace = null;//Reset to null. No longer needed.
+ }
+ }
+
public DescriptorImpl getDescriptor() {
return DESCRIPTOR;
}
diff --git a/hudson-core/src/main/java/hudson/model/Job.java b/hudson-core/src/main/java/hudson/model/Job.java
index 36f04be..6fa678f 100644
--- a/hudson-core/src/main/java/hudson/model/Job.java
+++ b/hudson-core/src/main/java/hudson/model/Job.java
@@ -178,6 +178,9 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
* @param allowSave allow save.
*/
protected void setAllowSave(Boolean allowSave) {
+ if (null == this.allowSave) {
+ initAllowSave();
+ }
this.allowSave.set(allowSave);
}
@@ -209,7 +212,6 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
/**
* {@inheritDoc}
*/
- //TODO improve error handling for this method
public IProjectProperty getProperty(String key, Class clazz) {
IProjectProperty t = jobProperties.get(key);
if (null == t && null != clazz) {
@@ -240,6 +242,9 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
@Override
public synchronized void save() throws IOException {
+ if (null == allowSave) {
+ initAllowSave();
+ }
if (allowSave.get()) {
super.save();
holdOffBuildUntilSave = false;
@@ -253,14 +258,7 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
super.onLoad(parent, name);
cascadingProject = (JobT) Functions.getItemByName(Hudson.getInstance().getAllItems(this.getClass()),
cascadingProjectName);
- if (null == allowSave) {// Initialize property if null for legacy config.
- allowSave = new ThreadLocal<Boolean>() {
- @Override
- protected Boolean initialValue() {
- return true;
- }
- };
- }
+ initAllowSave();
TextFile f = getNextBuildNumberFile();
if (f.exists()) {
// starting 1.28, we store nextBuildNumber in a separate file.
@@ -285,9 +283,26 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
for (JobProperty p : properties)
p.setOwner(this);
- if (null == jobProperties) {
- jobProperties = new ConcurrentHashMap<String, IProjectProperty>();
- }
+ buildProjectProperties();
+ }
+
+ protected void initAllowSave() {
+ allowSave = new ThreadLocal<Boolean>() {
+ @Override
+ protected Boolean initialValue() {
+ return true;
+ }
+ };
+ }
+
+ /**
+ * Initializes and builds project properties. Also converts legacy properties to IProjectProperties.
+ * Subclasses should inherit and override this behavior.
+ *
+ * @throws IOException if any.
+ */
+ protected void buildProjectProperties() throws IOException {
+ initProjectProperties();
for (Map.Entry<String, IProjectProperty> entry : jobProperties.entrySet()) {
IProjectProperty property = entry.getValue();
property.setKey(entry.getKey());
@@ -295,6 +310,15 @@ public abstract class Job<JobT extends Job<JobT, RunT>, RunT extends Run<JobT, R
}
}
+ /**
+ * Initialize project properties if null.
+ */
+ protected final void initProjectProperties() {
+ if (null == jobProperties) {
+ jobProperties = new ConcurrentHashMap<String, IProjectProperty>();
+ }
+ }
+
@Override
public void onCopiedFrom(Item src) {
super.onCopiedFrom(src);
diff --git a/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java b/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
new file mode 100644
index 0000000..1ddccb2
--- /dev/null
+++ b/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
@@ -0,0 +1,52 @@
+/*******************************************************************************
+ *
+ * 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 hudson.model;
+
+import java.io.File;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertNull;
+
+/**
+ * Test for legacy
+ * <p/>
+ * Date: 9/23/11
+ *
+ * @author Nikita Levyankov
+ */
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({Hudson.class})
+public class LegacyProjectTest {
+
+ /**
+ * Tests unmarshalls FreeStyleProject configuration and checks whether CustomWorkspace property is set,
+ *
+ * @throws Exception if any.
+ */
+ @Test
+ public void testLoadFreeStyleProject() throws Exception {
+ File freeStyleProjectConfig = new File(FreeStyleProject.class.getResource("/hudson/model/freestyle").toURI());
+ FreeStyleProject freeStyleProject = (FreeStyleProject) Items.getConfigFile(freeStyleProjectConfig).read();
+ freeStyleProject.setAllowSave(false);
+ freeStyleProject.initProjectProperties();
+ assertNull(freeStyleProject.getProperty(FreeStyleProject.CUSTOM_WORKSPACE_PROPERTY_NAME));
+ freeStyleProject.buildProjectProperties();
+ assertNotNull(freeStyleProject.getCustomWorkspace());
+ }
+}
diff --git a/hudson-core/src/test/resources/hudson/model/freestyle/config.xml b/hudson-core/src/test/resources/hudson/model/freestyle/config.xml
new file mode 100644
index 0000000..ff6dedb
--- /dev/null
+++ b/hudson-core/src/test/resources/hudson/model/freestyle/config.xml
@@ -0,0 +1,36 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<project>
+ <actions/>
+ <description>test application</description>
+ <logRotator>
+ <daysToKeep>5</daysToKeep>
+ <numToKeep>10</numToKeep>
+ <artifactDaysToKeep>-1</artifactDaysToKeep>
+ <artifactNumToKeep>-1</artifactNumToKeep>
+ </logRotator>
+ <keepDependencies>false</keepDependencies>
+ <creationTime>1316762043103</creationTime>
+ <quietPeriod>5</quietPeriod>
+ <scmCheckoutRetryCount>5</scmCheckoutRetryCount>
+ <advancedAffinityChooser>false</advancedAffinityChooser>
+ <canRoam>true</canRoam>
+ <disabled>false</disabled>
+ <blockBuildWhenDownstreamBuilding>true</blockBuildWhenDownstreamBuilding>
+ <blockBuildWhenUpstreamBuilding>true</blockBuildWhenUpstreamBuilding>
+ <triggers class="vector">
+ <hudson.triggers.SCMTrigger>
+ <spec>5 * * * *</spec>
+ </hudson.triggers.SCMTrigger>
+ </triggers>
+ <concurrentBuild>true</concurrentBuild>
+ <cleanWorkspaceRequired>true</cleanWorkspaceRequired>
+ <publishers>
+ <hudson.tasks.Mailer>
+ <recipients>admin@gmail.com</recipients>
+ <dontNotifyEveryUnstableBuild>false</dontNotifyEveryUnstableBuild>
+ <sendToIndividuals>true</sendToIndividuals>
+ </hudson.tasks.Mailer>
+ </publishers>
+ <buildWrappers/>
+ <customWorkspace>/tmp</customWorkspace>
+</project> \ No newline at end of file