Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWinston Prakash2013-09-26 23:48:11 -0400
committerWinston Prakash2013-09-26 23:48:11 -0400
commitfadd0fbc373a4ddcf13166e39131abd2de3685aa (patch)
tree12f208c1c6c1ebff4f6957935abc665ed13ecc46
parenta5ece2219e450e7072892f5cdea57f21fdc6598d (diff)
downloadorg.eclipse.hudson.core-label-parameter.tar.gz
org.eclipse.hudson.core-label-parameter.tar.xz
org.eclipse.hudson.core-label-parameter.zip
Add methods for accessing the Builders, BuildWrappers & Publishers in a Job. Useful for unit testlabel-parameter
-rw-r--r--hudson-core/src/main/java/hudson/model/BaseBuildableProject.java152
-rw-r--r--hudson-core/src/main/java/org/eclipse/hudson/api/model/IBaseBuildableProject.java84
-rw-r--r--hudson-core/src/test/java/hudson/model/LegacyProjectTest.java2
-rw-r--r--hudson-test-framework/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java9
4 files changed, 217 insertions, 30 deletions
diff --git a/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java b/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java
index ab913c3c..0d9a51f5 100644
--- a/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java
+++ b/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java
@@ -45,6 +45,9 @@ public abstract class BaseBuildableProject<P extends BaseBuildableProject<P, B>,
implements Saveable, BuildableItemWithBuildWrappers, IBaseBuildableProject {
public static final String BUILDERS_PROPERTY_NAME = "builders";
+ public static final String BUILDWRAPPERS_PROPERTY_NAME = "buildwrappers";
+ public static final String PUBLISHERS_PROPERTY_NAME = "publishers";
+
/**
* List of active {@link Builder}s configured for this project.
*
@@ -99,7 +102,7 @@ public abstract class BaseBuildableProject<P extends BaseBuildableProject<P, B>,
protected void buildProjectProperties() throws IOException {
super.buildProjectProperties();
convertBuildersProjectProperty();
- convertBuildWrappersProjectProperties();
+ convertBuildWrappersProperties();
convertPublishersProperties();
}
@@ -137,10 +140,42 @@ public abstract class BaseBuildableProject<P extends BaseBuildableProject<P, B>,
}
return r;
}
+
+ /**
+ * Adds a new {@link BuildStep} builder to this {@link Project} and saves the
+ * configuration.
+ *
+ * @param builder builder.
+ * @throws java.io.IOException exception.
+ */
+ @SuppressWarnings("unchecked")
+ public void addBuilder(Builder builder) throws IOException {
+ CascadingUtil.getExternalProjectProperty(this,
+ builder.getDescriptor().getJsonSafeClassName()).setValue(builder);
+ save();
+ }
+
+ /**
+ * Removes a {@link BuildStep} builder from this project, if it's active.
+ *
+ * @param builder builder.
+ * @throws java.io.IOException exception.
+ */
+ @Override
+ public void removeBuilder(Descriptor<Builder> builder) throws IOException {
+ removeProjectProperty(builder.getJsonSafeClassName());
+ save();
+ }
+
+ @Override
+ public Builder getBuilder(Descriptor<Builder> descriptor) {
+ return (Builder) CascadingUtil.getExternalProjectProperty(this, descriptor.getJsonSafeClassName()).getValue();
+ }
/**
* @inheritDoc
*/
+ @Override
public List<Builder> getBuilders() {
return getBuildersList().toList();
}
@@ -148,34 +183,80 @@ public abstract class BaseBuildableProject<P extends BaseBuildableProject<P, B>,
/**
* @inheritDoc
*/
+ @Override
+ public void setBuilders(DescribableList<Builder, Descriptor<Builder>> builders) {
+ CascadingUtil.getDescribableListProjectProperty(this, BUILDERS_PROPERTY_NAME).setValue(builders);
+ }
+
+ /**
+ * @inheritDoc
+ *
+ * @deprecated as of 2.2.0 do not use this field directly. Use other methods such as getBuilders, addBuilder & removeBuilder
+ */
@SuppressWarnings("unchecked")
+ @Deprecated
+ @Override
public DescribableList<Builder, Descriptor<Builder>> getBuildersList() {
return CascadingUtil.getDescribableListProjectProperty(this, BUILDERS_PROPERTY_NAME).getValue();
}
-
+
/**
- * @inheritDoc
+ * Adds a new {@link BuildStep} to this {@link Project} and saves the
+ * configuration.
+ *
+ * @param publisher publisher.
+ * @throws java.io.IOException exception.
*/
- public void setBuilders(DescribableList<Builder, Descriptor<Builder>> builders) {
- CascadingUtil.getDescribableListProjectProperty(this, BUILDERS_PROPERTY_NAME).setValue(builders);
+ @SuppressWarnings("unchecked")
+ @Override
+ public void addPublisher(Publisher publisher) throws IOException {
+ CascadingUtil.getExternalProjectProperty(this,
+ publisher.getDescriptor().getJsonSafeClassName()).setValue(publisher);
+ save();
}
/**
- * @inheritDoc
+ * Removes a publisher from this project, if it's active.
+ *
+ * @param publisher publisher.
+ * @throws java.io.IOException exception.
*/
- public Map<Descriptor<Publisher>, Publisher> getPublishers() {
- return getPublishersList().toMap();
+ @Override
+ public void removePublisher(Descriptor<Publisher> publisher) throws IOException {
+ removeProjectProperty(publisher.getJsonSafeClassName());
+ save();
}
+ @Override
public Publisher getPublisher(Descriptor<Publisher> descriptor) {
return (Publisher) CascadingUtil.getExternalProjectProperty(this, descriptor.getJsonSafeClassName()).getValue();
}
+
+ /**
+ * @inheritDoc
+ */
+ @Override
+ public Map<Descriptor<Publisher>, Publisher> getPublishers() {
+ return getPublishersList().toMap();
+ }
+
+ /**
+ * @inheritDoc
+ *
+ */
+ @Override
+ public void setPublishers(DescribableList<Publisher, Descriptor<Publisher>> publishers) {
+ CascadingUtil.getDescribableListProjectProperty(this, PUBLISHERS_PROPERTY_NAME).setValue(publishers);
+ }
/**
* Returns the list of the publishers available in the hudson.
*
* @return the list of the publishers available in the hudson.
+ * * @deprecated as of 2.2.0 do not use this field directly. Use other methods such as getPublishers, addPublisher & removePublisher
*/
+ @Deprecated
+ @Override
public DescribableList<Publisher, Descriptor<Publisher>> getPublishersList() {
return DescribableListUtil.convertToDescribableList(Functions.getPublisherDescriptors(this), this);
}
@@ -184,37 +265,57 @@ public abstract class BaseBuildableProject<P extends BaseBuildableProject<P, B>,
* Adds a new {@link BuildStep} to this {@link Project} and saves the
* configuration.
*
- * @param publisher publisher.
+ * @param buildWrapper buildWrapper.
* @throws java.io.IOException exception.
*/
@SuppressWarnings("unchecked")
- public void addPublisher(Publisher publisher) throws IOException {
+ @Override
+ public void addBuildWrapper(BuildWrapper buildWrapper) throws IOException {
CascadingUtil.getExternalProjectProperty(this,
- publisher.getDescriptor().getJsonSafeClassName()).setValue(publisher);
+ buildWrapper.getDescriptor().getJsonSafeClassName()).setValue(buildWrapper);
save();
}
-
- /**
- * Removes a publisher from this project, if it's active.
+
+ /**
+ * Removes a buildWrapper from this project, if it's active.
*
- * @param publisher publisher.
+ * @param buildWrapper buildWrapper.
* @throws java.io.IOException exception.
*/
- public void removePublisher(Descriptor<Publisher> publisher) throws IOException {
- removeProjectProperty(publisher.getJsonSafeClassName());
+ @Override
+ public void removeBuildWrapper(Descriptor<BuildWrapper> buildWrapper) throws IOException {
+ removeProjectProperty(buildWrapper.getJsonSafeClassName());
save();
}
+
+ @Override
+ public BuildWrapper getBuildWrapper(Descriptor<BuildWrapper> descriptor) {
+ return (BuildWrapper) CascadingUtil.getExternalProjectProperty(this, descriptor.getJsonSafeClassName()).getValue();
+ }
/**
* @inheritDoc
*/
+ @Override
public Map<Descriptor<BuildWrapper>, BuildWrapper> getBuildWrappers() {
return getBuildWrappersList().toMap();
}
-
+
+ /**
+ * @inheritDoc
+ *
+ */
+ @Override
+ public void setBuildWrappers(DescribableList<BuildWrapper, Descriptor<BuildWrapper>> buildWrappers) {
+ CascadingUtil.getDescribableListProjectProperty(this, BUILDWRAPPERS_PROPERTY_NAME).setValue(buildWrappers);
+ }
/**
* @inheritDoc
+ *
+ * @deprecated as of 2.2.0 don't use this field directly. Use other methods such as getBuildWrappers, addBuildWrapper & removeBuildWrapper
*/
+ @Override
+ @Deprecated
public DescribableList<BuildWrapper, Descriptor<BuildWrapper>> getBuildWrappersList() {
return DescribableListUtil.convertToDescribableList(Functions.getBuildWrapperDescriptors(this), this);
}
@@ -244,6 +345,11 @@ public abstract class BaseBuildableProject<P extends BaseBuildableProject<P, B>,
throws FormException {
CascadingUtil.buildExternalProperties(req, json, descriptors, this);
}
+
+ protected void buildBuilders(StaplerRequest req, JSONObject json, List<Descriptor<Builder>> descriptors)
+ throws FormException {
+ CascadingUtil.buildExternalProperties(req, json, descriptors, this);
+ }
protected void convertPublishersProperties() {
if (null != publishers) {
@@ -252,17 +358,25 @@ public abstract class BaseBuildableProject<P extends BaseBuildableProject<P, B>,
}
}
- protected void convertBuildWrappersProjectProperties() {
+ protected void convertBuildWrappersProperties() {
if (null != buildWrappers) {
putAllProjectProperties(DescribableListUtil.convertToProjectProperties(buildWrappers, this), false);
buildWrappers = null;
}
}
+ protected void convertBuildersProperties() {
+ if (null != builders && null == getProperty(BUILDERS_PROPERTY_NAME)) {
+ putAllProjectProperties(DescribableListUtil.convertToProjectProperties(builders, this), false);
+ builders = null;
+ }
+ }
+
protected void convertBuildersProjectProperty() {
if (null != builders && null == getProperty(BUILDERS_PROPERTY_NAME)) {
setBuilders(builders);
builders = null;
}
}
+
}
diff --git a/hudson-core/src/main/java/org/eclipse/hudson/api/model/IBaseBuildableProject.java b/hudson-core/src/main/java/org/eclipse/hudson/api/model/IBaseBuildableProject.java
index 76384a13..c32b9116 100644
--- a/hudson-core/src/main/java/org/eclipse/hudson/api/model/IBaseBuildableProject.java
+++ b/hudson-core/src/main/java/org/eclipse/hudson/api/model/IBaseBuildableProject.java
@@ -9,13 +9,15 @@
*
* Contributors:
*
- * Nikita Levyankov
+ * Winston Prakash, Nikita Levyankov
*
*******************************************************************************/
package org.eclipse.hudson.api.model;
import hudson.model.Descriptor;
+import hudson.model.Project;
+import hudson.tasks.BuildStep;
import hudson.tasks.BuildWrapper;
import hudson.tasks.Builder;
import hudson.tasks.Publisher;
@@ -34,25 +36,68 @@ import java.util.Map;
public interface IBaseBuildableProject extends IAbstractProject {
/**
+ * Adds a new {@link hudson.tasks.BuildStep}, builder, to this
+ * {@link IBaseBuildableProject} and saves the configuration.
+ *
+ * @param builder builder.
+ * @throws java.io.IOException exception.
+ */
+ public void addBuilder(Builder builder) throws IOException;
+
+ /**
+ * Removes a {@link BuildStep} builder from this project, if it's active.
+ *
+ * @param builder builder.
+ * @throws java.io.IOException exception.
+ */
+ public void removeBuilder(Descriptor<Builder> builder) throws IOException;
+
+ public Builder getBuilder(Descriptor<Builder> descriptor);
+
+ /**
* @return list of project {@link hudson.tasks.Builder}
*/
List<Builder> getBuilders();
+
+ void setBuilders(DescribableList<Builder, Descriptor<Builder>> builders);
DescribableList<Builder, Descriptor<Builder>> getBuildersList();
- void setBuilders(DescribableList<Builder, Descriptor<Builder>> builders);
-
/**
- * @return map of project {@link hudson.tasks.BuildWrapper}
+ * Adds a new {@link BuildStep} to this {@link Project} and saves the
+ * configuration.
+ *
+ * @param buildWrapper buildWrapper.
+ * @throws java.io.IOException exception.
*/
- Map<Descriptor<BuildWrapper>, BuildWrapper> getBuildWrappers();
-
+ public void addBuildWrapper(BuildWrapper buildWrapper) throws IOException;
+
+ /**
+ * Removes a buildWrapper from this project, if it's active.
+ *
+ * @param buildWrapper buildWrapper.
+ * @throws java.io.IOException exception.
+ */
+ public void removeBuildWrapper(Descriptor<BuildWrapper> buildWrapper) throws IOException;
+
+ public BuildWrapper getBuildWrapper(Descriptor<BuildWrapper> descriptor);
/**
- * @return map of project {@link hudson.tasks.Publisher}
+ * @inheritDoc
*/
- Map<Descriptor<Publisher>, Publisher> getPublishers();
-
- Publisher getPublisher(Descriptor<Publisher> descriptor);
+ public Map<Descriptor<BuildWrapper>, BuildWrapper> getBuildWrappers();
+
+ /**
+ * @inheritDoc
+ *
+ */
+ public void setBuildWrappers(DescribableList<BuildWrapper, Descriptor<BuildWrapper>> buildWrappers);
+ /**
+ * @inheritDoc
+ *
+ * @deprecated as of 2.2.0 don't use this field directly. Use other methods such as getBuildWrappers, addBuildWrapper & removeBuildWrapper
+ */
+ @Deprecated
+ public DescribableList<BuildWrapper, Descriptor<BuildWrapper>> getBuildWrappersList();
/**
* Adds a new {@link hudson.tasks.BuildStep} to this
@@ -70,4 +115,23 @@ public interface IBaseBuildableProject extends IAbstractProject {
* @throws java.io.IOException exception.
*/
void removePublisher(Descriptor<Publisher> publisher) throws IOException;
+
+
+ Publisher getPublisher(Descriptor<Publisher> descriptor);
+
+ /**
+ * @return map of project {@link hudson.tasks.Publisher}
+ */
+ Map<Descriptor<Publisher>, Publisher> getPublishers();
+
+ public void setPublishers(DescribableList<Publisher, Descriptor<Publisher>> publishers);
+
+ /**
+ * Returns the list of the publishers available in the hudson.
+ *
+ * @return the list of the publishers available in the hudson.
+ * * @deprecated as of 2.2.0 do not use this field directly. Use other methods such as getPublishers, addPublisher & removePublisher
+ */
+ @Deprecated
+ public DescribableList<Publisher, Descriptor<Publisher>> getPublishersList();
}
diff --git a/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java b/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
index 4c15a795..d1d66c68 100644
--- a/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
+++ b/hudson-core/src/test/java/hudson/model/LegacyProjectTest.java
@@ -110,7 +110,7 @@ public class LegacyProjectTest {
project.setAllowSave(false);
project.initProjectProperties();
//Property should be null, because of legacy implementation. Version < 2.2.0
- project.convertBuildWrappersProjectProperties();
+ project.convertBuildWrappersProperties();
//Verify buildWrappers
assertTrue(project.getBuildWrappersList().isEmpty());
}
diff --git a/hudson-test-framework/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java b/hudson-test-framework/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java
index 7d664df4..30260023 100644
--- a/hudson-test-framework/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java
+++ b/hudson-test-framework/src/main/java/org/jvnet/hudson/test/HudsonTestCase.java
@@ -615,6 +615,15 @@ public abstract class HudsonTestCase extends TestCase implements RootAction {
return slave;
}
}
+
+ public DumbSlave createSlave(String nodeName, String labels, EnvVars env) throws Exception {
+ synchronized (hudson) {
+ DumbSlave slave = new DumbSlave(nodeName, "dummy",
+ createTmpDir().getPath(), "1", Node.Mode.NORMAL, labels==null?"":labels, createComputerLauncher(env), RetentionStrategy.NOOP, Collections.EMPTY_LIST);
+ hudson.addNode(slave);
+ return slave;
+ }
+ }
public PretendSlave createPretendSlave(FakeLauncher faker) throws Exception {
synchronized (hudson) {

Back to the top