aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakozak2011-11-23 03:52:44 (EST)
committerWinston Prakash2011-12-01 20:47:07 (EST)
commit8e6a0564dae6e140fb8ebf6221080ae0948b2704 (patch)
tree4665a0123a5cd72f6332c6ebc6d170fe0651351a
parentc85fcabbfee5b9fd2501b9999fbc8f24f5d35097 (diff)
downloadorg.eclipse.hudson.core-8e6a0564dae6e140fb8ebf6221080ae0948b2704.zip
org.eclipse.hudson.core-8e6a0564dae6e140fb8ebf6221080ae0948b2704.tar.gz
org.eclipse.hudson.core-8e6a0564dae6e140fb8ebf6221080ae0948b2704.tar.bz2
Apply ProjectProperties for builders, publishers, buildWrappers. Implement test case for checking Project properties conversion to IProjectProperties
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
-rw-r--r--hudson-core/src/main/java/hudson/model/Items.java11
-rw-r--r--hudson-core/src/main/java/hudson/model/Project.java54
-rw-r--r--hudson-core/src/test/java/hudson/model/LegacyProjectTest.java38
-rw-r--r--hudson-core/src/test/resources/hudson/model/freestyle/config.xml12
4 files changed, 94 insertions, 21 deletions
diff --git a/hudson-core/src/main/java/hudson/model/Items.java b/hudson-core/src/main/java/hudson/model/Items.java
index 130e35b..d559a2b 100644
--- a/hudson-core/src/main/java/hudson/model/Items.java
+++ b/hudson-core/src/main/java/hudson/model/Items.java
@@ -19,8 +19,13 @@ package hudson.model;
import com.thoughtworks.xstream.XStream;
import hudson.DescriptorExtensionList;
import hudson.Extension;
+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.IntegerProjectProperty;
+import org.eclipse.hudson.api.model.project.property.LogRotatorProjectProperty;
+import org.eclipse.hudson.api.model.project.property.ResultProjectProperty;
import org.eclipse.hudson.api.model.project.property.StringProjectProperty;
import hudson.matrix.MatrixProject;
import hudson.matrix.MatrixConfiguration;
@@ -132,9 +137,15 @@ public class Items {
XSTREAM.alias("matrix-config",MatrixConfiguration.class);
//aliases for project properties.
+ XSTREAM.alias("base-property", BaseProjectProperty.class);
XSTREAM.alias("integer-property", IntegerProjectProperty.class);
XSTREAM.alias("boolean-property", BooleanProjectProperty.class);
XSTREAM.alias("string-property", StringProjectProperty.class);
+ XSTREAM.alias("log-rotator-property", LogRotatorProjectProperty.class);
+ XSTREAM.alias("result-property", ResultProjectProperty.class);
+
+ XSTREAM.alias("axis-list-property", AxisListProjectProperty.class);
+ XSTREAM.alias("describable-list-property", DescribableListProjectProperty.class);
XSTREAM.aliasField("project-properties", Job.class, "jobProperties");
}
}
diff --git a/hudson-core/src/main/java/hudson/model/Project.java b/hudson-core/src/main/java/hudson/model/Project.java
index abc87a5..0906d5d 100644
--- a/hudson-core/src/main/java/hudson/model/Project.java
+++ b/hudson-core/src/main/java/hudson/model/Project.java
@@ -50,35 +50,42 @@ import java.util.Set;
* @author Kohsuke Kawaguchi
*/
public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
- extends AbstractProject<P,B> implements SCMedItem, Saveable, ProjectWithMaven, BuildableItemWithBuildWrappers,
- IProject {
+ extends AbstractProject<P, B>
+ implements SCMedItem, Saveable, ProjectWithMaven, BuildableItemWithBuildWrappers, IProject {
public static final String BUILDERS_PROPERTY_NAME = "builders";
public static final String BUILD_WRAPPERS_PROPERTY_NAME = "buildWrappers";
+ public static final String PUBLISHERS_PROPERTY_NAME = "publishers";
/**
* List of active {@link Builder}s configured for this project.
+ *
* @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 DescribableList<Builder,Descriptor<Builder>> builders =
- new DescribableList<Builder,Descriptor<Builder>>(this);
+ private DescribableList<Builder, Descriptor<Builder>> builders =
+ new DescribableList<Builder, Descriptor<Builder>>(this);
/**
* List of active {@link Publisher}s configured for this project.
+ *
+ * @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 DescribableList<Publisher,Descriptor<Publisher>> publishers =
- new DescribableList<Publisher,Descriptor<Publisher>>(this);
+ private DescribableList<Publisher, Descriptor<Publisher>> publishers =
+ new DescribableList<Publisher, Descriptor<Publisher>>(this);
/**
* List of active {@link BuildWrapper}s configured for this project.
+ *
* @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 DescribableList<BuildWrapper,Descriptor<BuildWrapper>> buildWrappers =
- new DescribableList<BuildWrapper,Descriptor<BuildWrapper>>(this);
+ private DescribableList<BuildWrapper, Descriptor<BuildWrapper>> buildWrappers =
+ new DescribableList<BuildWrapper, Descriptor<BuildWrapper>>(this);
/**
* Creates a new project.
@@ -92,7 +99,7 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
super.onLoad(parent, name);
getBuildersList().setOwner(this);
- publishers.setOwner(this);
+ getPublishersList().setOwner(this);
getBuildWrappersList().setOwner(this);
}
@@ -107,6 +114,10 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
setBuildWrappers(buildWrappers);
buildWrappers = null;
}
+ if (null == getProperty(PUBLISHERS_PROPERTY_NAME)) {
+ setPublishers(publishers);
+ publishers = null;
+ }
}
public AbstractProject<?, ?> asProject() {
@@ -118,7 +129,7 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
}
public Map<Descriptor<Publisher>,Publisher> getPublishers() {
- return publishers.toMap();
+ return getPublishersList().toMap();
}
public void setBuilders(DescribableList<Builder,Descriptor<Builder>> builders) {
@@ -128,9 +139,13 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
public DescribableList<Builder,Descriptor<Builder>> getBuildersList() {
return getDescribableListProjectProperty(BUILDERS_PROPERTY_NAME).getValue();
}
-
- public DescribableList<Publisher,Descriptor<Publisher>> getPublishersList() {
- return publishers;
+
+ public DescribableList<Publisher, Descriptor<Publisher>> getPublishersList() {
+ return getDescribableListProjectProperty(PUBLISHERS_PROPERTY_NAME).getValue();
+ }
+
+ public void setPublishers(DescribableList<Publisher, Descriptor<Publisher>> publishers) {
+ getDescribableListProjectProperty(PUBLISHERS_PROPERTY_NAME).setValue(publishers);
}
public Map<Descriptor<BuildWrapper>,BuildWrapper> getBuildWrappers() {
@@ -151,7 +166,7 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
activities.addAll(super.getResourceActivities());
activities.addAll(Util.filter(getBuildersList(), ResourceActivity.class));
- activities.addAll(Util.filter(publishers,ResourceActivity.class));
+ activities.addAll(Util.filter(getPublishersList(),ResourceActivity.class));
activities.addAll(Util.filter(getBuildWrappersList(), ResourceActivity.class));
return activities;
@@ -164,7 +179,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 {
- publishers.add(buildStep);
+ getPublishersList().add(buildStep);
}
/**
@@ -174,11 +189,11 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
* Use {@code getPublishersList().remove(x)}
*/
public void removePublisher(Descriptor<Publisher> descriptor) throws IOException {
- publishers.remove(descriptor);
+ getPublishersList().remove(descriptor);
}
public Publisher getPublisher(Descriptor<Publisher> descriptor) {
- for (Publisher p : publishers) {
+ for (Publisher p : getPublishersList()) {
if(p.getDescriptor()==descriptor)
return p;
}
@@ -186,7 +201,7 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
}
protected void buildDependencyGraph(DependencyGraph graph) {
- publishers.buildDependencyGraph(this,graph);
+ getPublishersList().buildDependencyGraph(this, graph);
getBuildersList().buildDependencyGraph(this, graph);
getBuildWrappersList().buildDependencyGraph(this, graph);
}
@@ -213,7 +228,8 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>>
JSONObject json = req.getSubmittedForm();
setBuildWrappers(DescribableListUtil.buildFromJson(this, req, json, BuildWrappers.getFor(this)));
setBuilders(DescribableListUtil.buildFromHetero(this, req, json, "builder", Builder.all()));
- publishers.rebuild(req, json, BuildStepDescriptor.filter(Publisher.all(), this.getClass()));
+ setPublishers(DescribableListUtil.buildFromJson(this, req, json,
+ BuildStepDescriptor.filter(Publisher.all(), this.getClass())));
}
@Override
diff --git a/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java b/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
index 2a51588..f048163 100644
--- a/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
+++ b/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
@@ -14,6 +14,7 @@
*******************************************************************************/
package hudson.model;
+import hudson.tasks.Maven;
import java.io.File;
import java.net.URISyntaxException;
import org.junit.Before;
@@ -22,8 +23,8 @@ 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;
+import static junit.framework.Assert.*;
+import static org.junit.Assert.assertFalse;
/**
* Test for legacy
@@ -37,6 +38,7 @@ import static junit.framework.Assert.assertNull;
public class LegacyProjectTest {
private File config;
+
@Before
public void setUp() throws URISyntaxException {
config = new File(FreeStyleProject.class.getResource("/hudson/model/freestyle").toURI());
@@ -61,6 +63,38 @@ public class LegacyProjectTest {
/**
* Tests unmarshalls FreeStyleProject configuration and checks whether properties
+ * from Project are configured
+ *
+ * @throws Exception if any.
+ */
+ @Test
+ public void testLoadLegacyProject() throws Exception {
+ Project project = (Project) Items.getConfigFile(config).read();
+ project.setAllowSave(false);
+ project.initProjectProperties();
+ //All properties should be null, because of legacy implementation. Version < 2.2.1
+ assertNull(project.getProperty(Project.BUILDERS_PROPERTY_NAME));
+ assertNull(project.getProperty(Project.BUILD_WRAPPERS_PROPERTY_NAME));
+ assertNull(project.getProperty(Project.PUBLISHERS_PROPERTY_NAME));
+ project.buildProjectProperties();
+ //Verify builders
+ assertNotNull(project.getProperty(Project.BUILDERS_PROPERTY_NAME));
+ assertFalse(project.getBuildersList().isEmpty());
+ assertEquals(1, project.getBuildersList().size());
+ assertTrue(project.getBuildersList().get(0) instanceof Maven);
+
+ //Verify buildWrappers
+ assertNotNull(project.getProperty(Project.BUILD_WRAPPERS_PROPERTY_NAME));
+ assertTrue(project.getBuildWrappersList().isEmpty());
+
+ //Verify publishers
+ assertNotNull(project.getProperty(Project.PUBLISHERS_PROPERTY_NAME));
+ assertFalse(project.getPublishersList().isEmpty());
+ assertEquals(2, project.getPublishersList().size());
+ }
+
+ /**
+ * Tests unmarshalls FreeStyleProject configuration and checks whether properties
* from AbstractProject are configured
*
* @throws Exception if any.
diff --git a/hudson-core/src/test/resources/hudson/model/freestyle/config.xml b/hudson-core/src/test/resources/hudson/model/freestyle/config.xml
index 8490d89..473a0ff 100644
--- a/hudson-core/src/test/resources/hudson/model/freestyle/config.xml
+++ b/hudson-core/src/test/resources/hudson/model/freestyle/config.xml
@@ -30,8 +30,20 @@
<dontNotifyEveryUnstableBuild>false</dontNotifyEveryUnstableBuild>
<sendToIndividuals>true</sendToIndividuals>
</hudson.tasks.Mailer>
+ <hudson.tasks.junit.JUnitResultArchiver>
+ <testResults>hudson-core/target/surefire-reports/*.xml, hudson-remoting/target/surefire-reports/*.xml</testResults>
+ <keepLongStdio>false</keepLongStdio>
+ <testDataPublishers/>
+ </hudson.tasks.junit.JUnitResultArchiver>
</publishers>
<jdk>jdk1.5</jdk>
<buildWrappers/>
+ <builders>
+ <hudson.tasks.Maven>
+ <targets>clean install -P debug,hudson</targets>
+ <mavenName>maven-3.0.3</mavenName>
+ <usePrivateRepository>false</usePrivateRepository>
+ </hudson.tasks.Maven>
+ </builders>
<customWorkspace>/tmp</customWorkspace>
</project> \ No newline at end of file