| author | akozak | 2011-11-23 08:35:11 (EST) |
|---|---|---|
| committer | Winston Prakash | 2011-12-01 20:47:11 (EST) |
| commit | 1e335142478d5420ca185c15e2e28cf7360a3103 (patch) (side-by-side diff) | |
| tree | 33493d44588f721742dc30a2ff777f95cc5075aa | |
| parent | c9b9f187e39c1d7a2c6e29b6e34c93395ec5f5f2 (diff) | |
| download | org.eclipse.hudson.core-1e335142478d5420ca185c15e2e28cf7360a3103.zip org.eclipse.hudson.core-1e335142478d5420ca185c15e2e28cf7360a3103.tar.gz org.eclipse.hudson.core-1e335142478d5420ca185c15e2e28cf7360a3103.tar.bz2 | |
Dublicate code was removed from Project and Matrix Build. BaseBuildableProject was introduced.
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
6 files changed, 263 insertions, 313 deletions
diff --git a/hudson-core/src/main/java/hudson/matrix/MatrixBuild.java b/hudson-core/src/main/java/hudson/matrix/MatrixBuild.java index a41aa13..67b78b8 100644 --- a/hudson-core/src/main/java/hudson/matrix/MatrixBuild.java +++ b/hudson-core/src/main/java/hudson/matrix/MatrixBuild.java @@ -17,8 +17,8 @@ package hudson.matrix; import hudson.Util; -import hudson.model.AbstractBuild; import hudson.model.AbstractProject; +import hudson.model.Build; import hudson.model.BuildListener; import hudson.model.Executor; import hudson.model.Fingerprint; @@ -50,7 +50,7 @@ import org.kohsuke.stapler.StaplerResponse; * * @author Kohsuke Kawaguchi */ -public class MatrixBuild extends AbstractBuild<MatrixProject,MatrixBuild> { +public class MatrixBuild extends Build<MatrixProject,MatrixBuild> { private AxisList axes; public MatrixBuild(MatrixProject job) throws IOException { diff --git a/hudson-core/src/main/java/hudson/matrix/MatrixProject.java b/hudson-core/src/main/java/hudson/matrix/MatrixProject.java index bbfbd62..2c32527 100644 --- a/hudson-core/src/main/java/hudson/matrix/MatrixProject.java +++ b/hudson-core/src/main/java/hudson/matrix/MatrixProject.java @@ -22,6 +22,7 @@ import hudson.Util; import hudson.XmlFile; import hudson.model.AbstractProject; import hudson.model.Action; +import hudson.model.BaseBuildableProject; import hudson.model.BuildableItemWithBuildWrappers; import hudson.model.DependencyGraph; import hudson.model.Descriptor; @@ -38,13 +39,10 @@ import hudson.model.Result; import hudson.model.SCMedItem; import hudson.model.Saveable; import hudson.model.TopLevelItem; -import hudson.tasks.BuildStep; import hudson.tasks.BuildStepDescriptor; -import hudson.tasks.BuildWrapper; import hudson.tasks.BuildWrappers; import hudson.tasks.Builder; import hudson.tasks.Publisher; -import hudson.triggers.Trigger; import hudson.util.CopyOnWriteMap; import hudson.util.DescribableList; import hudson.util.DescribableListUtil; @@ -52,7 +50,6 @@ import hudson.util.FormValidation; import hudson.util.FormValidation.Kind; import net.sf.json.JSONObject; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.ObjectUtils; import org.eclipse.hudson.api.matrix.IMatrixProject; import org.kohsuke.stapler.HttpResponse; import org.kohsuke.stapler.StaplerRequest; @@ -82,7 +79,7 @@ import java.util.logging.Logger; * * @author Kohsuke Kawaguchi */ -public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> implements IMatrixProject, TopLevelItem, +public class MatrixProject extends BaseBuildableProject<MatrixProject, MatrixBuild> implements IMatrixProject, TopLevelItem, SCMedItem, ItemGroup<MatrixConfiguration>, Saveable, FlyweightTask, BuildableItemWithBuildWrappers { public static final String HAS_COMBINATION_FILTER_PARAM = "hasCombinationFilter"; @@ -100,7 +97,7 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i /** * Configuration axes. - * @deprecated as of 2.2.1, use #getAxes() and #setAxes() instead + * @deprecated as of 2.2.0, use #getAxes() and #setAxes() instead */ @Deprecated private volatile AxisList axes = new AxisList(); @@ -116,39 +113,6 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i private volatile String combinationFilter; /** - * 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. - */ - @Deprecated - 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. - */ - @Deprecated - 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. - */ - @Deprecated - private DescribableList<BuildWrapper,Descriptor<BuildWrapper>> buildWrappers = - new DescribableList<BuildWrapper,Descriptor<BuildWrapper>>(this); - - /** * All {@link MatrixConfiguration}s, keyed by their {@link MatrixConfiguration#getName() names}. */ private transient /*final*/ Map<Combination,MatrixConfiguration> configurations = new CopyOnWriteMap.Tree<Combination,MatrixConfiguration>(); @@ -160,7 +124,7 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i private transient /*final*/ Set<MatrixConfiguration> activeConfigurations = new LinkedHashSet<MatrixConfiguration>(); /** - * @deprecated as of 2.2.1, use #isRunSequentially() and #setRunSequentially() instead + * @deprecated as of 2.2.0, use #isRunSequentially() and #setRunSequentially() instead */ @Deprecated private boolean runSequentially; @@ -168,7 +132,7 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i /** * Filter to select a number of combinations to build first * - * @deprecated as of 2.2.1, use #getTouchStoneCombinationFilter() and #setTouchStoneCombinationFilter() instead + * @deprecated as of 2.2.0, use #getTouchStoneCombinationFilter() and #setTouchStoneCombinationFilter() instead */ @Deprecated private String touchStoneCombinationFilter; @@ -177,13 +141,13 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i * Required result on the touchstone combinations, in order to * continue with the rest * - * @deprecated as of 2.2.1, use #getTouchStoneResultCondition() and #setTouchStoneResultCondition() instead + * @deprecated as of 2.2.0, use #getTouchStoneResultCondition() and #setTouchStoneResultCondition() instead */ @Deprecated private Result touchStoneResultCondition; /** - * @deprecated as of 2.2.1, use #getCustomWorkspace() and #setCustomWorkspace() instead + * @deprecated as of 2.2.0, use #getCustomWorkspace() and #setCustomWorkspace() instead */ @Deprecated private String customWorkspace; @@ -242,6 +206,7 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i rebuildConfigurations(); save(); } + /** * @inheritDoc */ @@ -284,62 +249,6 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i getStringProperty(CUSTOM_WORKSPACE_PROPERTY_NAME).setValue(customWorkspace); } - /** - * @inheritDoc - */ - public List<Builder> getBuilders() { - return getBuildersList().toList(); - } - - @SuppressWarnings("unchecked") - public DescribableList<Builder,Descriptor<Builder>> getBuildersList() { - return getDescribableListProjectProperty(BUILDERS_PROPERTY_NAME).getValue(); - } - - - public void setBuilders(DescribableList<Builder,Descriptor<Builder>> builders) { - getDescribableListProjectProperty(BUILDERS_PROPERTY_NAME).setValue(builders); - } - - /** - * @inheritDoc - */ - public Map<Descriptor<Publisher>,Publisher> getPublishers() { - return getPublishersList().toMap(); - } - - /** - * @inheritDoc - */ - @SuppressWarnings("unchecked") - 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); - } - - /** - * @inheritDoc - */ - @SuppressWarnings("unchecked") - public DescribableList<BuildWrapper, Descriptor<BuildWrapper>> getBuildWrappersList() { - return getDescribableListProjectProperty(BUILD_WRAPPERS_PROPERTY_NAME).getValue(); - } - - /** - * @inheritDoc - */ - public Map<Descriptor<BuildWrapper>,BuildWrapper> getBuildWrappers() { - return getBuildWrappersList().toMap(); - } - - public void setBuildWrappers(DescribableList<BuildWrapper, Descriptor<BuildWrapper>> buildWrappers) { - getDescribableListProjectProperty(BUILD_WRAPPERS_PROPERTY_NAME).setValue(buildWrappers); - } - - @Override protected void buildProjectProperties() throws IOException { super.buildProjectProperties(); @@ -368,38 +277,10 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i setCustomWorkspace(customWorkspace); customWorkspace = null;//Reset to null. No longer needed. } - if (null == getProperty(BUILDERS_PROPERTY_NAME)) { - setBuilders(builders); - builders = null; - } - if (null == getProperty(BUILD_WRAPPERS_PROPERTY_NAME)) { - setBuildWrappers(buildWrappers); - buildWrappers = null; - } - if (null == getProperty(PUBLISHERS_PROPERTY_NAME)) { - setPublishers(publishers); - publishers = null; - } save(); rebuildConfigurations(); } - @Override - protected List<Action> createTransientActions() { - List<Action> r = super.createTransientActions(); - - for (BuildStep step : getBuildersList()) - r.addAll(step.getProjectActions(this)); - for (BuildStep step : getPublishersList()) - r.addAll(step.getProjectActions(this)); - for (BuildWrapper step : getBuildWrappersList()) - r.addAll(step.getProjectActions(this)); - for (Trigger trigger : getTriggersList()) - r.addAll(trigger.getProjectActions()); - - return r; - } - /** * Gets the subset of {@link AxisList} that are not system axes. * @@ -430,9 +311,6 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i // perhaps the file was edited on disk and the sort order might have been broken Collections.sort(getAxes()); } - getBuildersList().setOwner(this); - getPublishersList().setOwner(this); - getBuildWrappersList().setOwner(this); rebuildConfigurations(); } @@ -652,7 +530,7 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i } public Publisher getPublisher(Descriptor<Publisher> descriptor) { - for (Publisher p : publishers) { + for (Publisher p : getPublishersList()) { if(p.getDescriptor()==descriptor) return p; } @@ -667,12 +545,6 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i return false; } - protected void buildDependencyGraph(DependencyGraph graph) { - getPublishersList().buildDependencyGraph(this,graph); - getBuildersList().buildDependencyGraph(this,graph); - getBuildWrappersList().buildDependencyGraph(this,graph); - } - public MatrixProject asProject() { return this; } @@ -710,8 +582,8 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i req.hasParameter(CUSTOM_WORKSPACE_PARAM) ? req.getParameter(CUSTOM_WORKSPACE_DIRECTORY_PARAM) : null); // parse system axes - DescribableList<Axis,AxisDescriptor> newAxes = new DescribableList<Axis,AxisDescriptor>(this); - newAxes.rebuildHetero(req, json, Axis.all(),"axis"); + DescribableList<Axis, AxisDescriptor> newAxes = DescribableListUtil.buildFromHetero(this, req, json, "axis", + Axis.all()); checkAxisNames(newAxes); setAxes(new AxisList(newAxes.toList())); @@ -719,8 +591,7 @@ public class MatrixProject extends AbstractProject<MatrixProject, MatrixBuild> i setBuildWrappers(DescribableListUtil.buildFromJson(this, req, json, BuildWrappers.getFor(this))); setBuilders(DescribableListUtil.buildFromHetero(this, req, json, "builder", Builder.all())); - setPublishers(DescribableListUtil.buildFromJson(this, req, json, - BuildStepDescriptor.filter(Publisher.all(), this.getClass()))); + buildPublishers(req, json, BuildStepDescriptor.filter(Publisher.all(), this.getClass())); rebuildConfigurations(); } diff --git a/hudson-core/src/main/java/hudson/model/AbstractProject.java b/hudson-core/src/main/java/hudson/model/AbstractProject.java index 947c7a8..0cc428c 100644 --- a/hudson-core/src/main/java/hudson/model/AbstractProject.java +++ b/hudson-core/src/main/java/hudson/model/AbstractProject.java @@ -130,9 +130,6 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A public static final String CUSTOM_WORKSPACE_PROPERTY_NAME = "customWorkspace"; public static final String JDK_PROPERTY_NAME = "jdk"; public static final String PROPERTY_NAME_SEPARATOR = ";"; - 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"; public static final String SCM_PROPERTY_NAME = "scm"; diff --git a/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java b/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java new file mode 100644 index 0000000..c24db67 --- a/dev/null +++ b/hudson-core/src/main/java/hudson/model/BaseBuildableProject.java @@ -0,0 +1,246 @@ +/******************************************************************************* + * + * 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: + * + * Anton Kozak + * + *******************************************************************************/ +package hudson.model; + +import hudson.Functions; +import hudson.model.Descriptor.FormException; +import hudson.tasks.BuildStep; +import hudson.tasks.BuildWrapper; +import hudson.tasks.Builder; +import hudson.tasks.Publisher; +import hudson.triggers.Trigger; +import hudson.util.DescribableList; +import hudson.util.DescribableListUtil; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CopyOnWriteArrayList; +import net.sf.json.JSONObject; +import org.eclipse.hudson.api.model.IProject; +import org.eclipse.hudson.api.model.project.property.BaseProjectProperty; +import org.kohsuke.stapler.StaplerRequest; + +/** + * Base buildable project. + * + * @author Anton Kozak. + */ +public abstract class BaseBuildableProject<P extends BaseBuildableProject<P,B>,B extends Build<P,B>> + extends AbstractProject<P, B> + implements Saveable, BuildableItemWithBuildWrappers, IProject { + + public static final String BUILDERS_PROPERTY_NAME = "builders"; + public static final String BUILD_WRAPPERS_PROPERTY_NAME = "buildWrappers"; + + + /** + * 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. + */ + @Deprecated + 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. + */ + @Deprecated + 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. + */ + @Deprecated + private DescribableList<BuildWrapper,Descriptor<BuildWrapper>> buildWrappers = + new DescribableList<BuildWrapper,Descriptor<BuildWrapper>>(this); + + /** + * Creates a new project. + * @param parent parent {@link ItemGroup}. + * @param name the name of the project. + */ + public BaseBuildableProject(ItemGroup parent, String name) { + super(parent, name); + } + + @Override + public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException { + super.onLoad(parent, name); + + getBuildersList().setOwner(this); + getPublishersList().setOwner(this); + getBuildWrappersList().setOwner(this); + } + + @Override + protected void buildProjectProperties() throws IOException { + super.buildProjectProperties(); + convertBuildersProjectProperty(); + convertBuildWrappersProjectProperties(); + convertPublishersProperties(); + } + + protected void buildDependencyGraph(DependencyGraph graph) { + getPublishersList().buildDependencyGraph(this,graph); + getBuildersList().buildDependencyGraph(this,graph); + getBuildWrappersList().buildDependencyGraph(this,graph); + } + + @Override + protected List<Action> createTransientActions() { + List<Action> r = super.createTransientActions(); + + for (BuildStep step : getBuildersList()) + r.addAll(step.getProjectActions(this)); + for (BuildStep step : getPublishersList()) + r.addAll(step.getProjectActions(this)); + for (BuildWrapper step : getBuildWrappersList()) + r.addAll(step.getProjectActions(this)); + for (Trigger trigger : getTriggersList()) + r.addAll(trigger.getProjectActions()); + + return r; + } + + /** + * @inheritDoc + */ + public List<Builder> getBuilders() { + return getBuildersList().toList(); + } + + /** + * @inheritDoc + */ + @SuppressWarnings("unchecked") + public DescribableList<Builder,Descriptor<Builder>> getBuildersList() { + return getDescribableListProjectProperty(BUILDERS_PROPERTY_NAME).getValue(); + } + + /** + * @inheritDoc + */ + public void setBuilders(DescribableList<Builder,Descriptor<Builder>> builders) { + getDescribableListProjectProperty(BUILDERS_PROPERTY_NAME).setValue(builders); + } + + /** + * @inheritDoc + */ + public Map<Descriptor<Publisher>,Publisher> getPublishers() { + return getPublishersList().toMap(); + } + + public Publisher getPublisher(Descriptor<Publisher> descriptor) { + return (Publisher) getBaseProjectProperty(descriptor.getJsonSafeClassName()).getValue(); + } + /** + * Returns the list of the publishers available in the hudson. + * + * @return the list of the publishers available in the hudson. + */ + @SuppressWarnings("unchecked") + public DescribableList<Publisher, Descriptor<Publisher>> getPublishersList() { + List<Descriptor<Publisher>> descriptors = Functions.getPublisherDescriptors(this); + List<Publisher> publisherList = new CopyOnWriteArrayList<Publisher>(); + DescribableList<Publisher, Descriptor<Publisher>> result + = new DescribableList<Publisher, Descriptor<Publisher>>(this); + for (Descriptor<Publisher> descriptor : descriptors) { + BaseProjectProperty<Publisher> property = getBaseProjectProperty(descriptor.getJsonSafeClassName()); + if (null != property.getValue()) { + publisherList.add(property.getValue()); + } + } + result.addAllTo(publisherList); + return result; + } + + /** + * @inheritDoc + */ + public Map<Descriptor<BuildWrapper>,BuildWrapper> getBuildWrappers() { + return getBuildWrappersList().toMap(); + } + + /** + * @inheritDoc + */ + @SuppressWarnings("unchecked") + public DescribableList<BuildWrapper, Descriptor<BuildWrapper>> getBuildWrappersList() { + return getDescribableListProjectProperty(BUILD_WRAPPERS_PROPERTY_NAME).getValue(); + } + + /** + * Sets build wrappers. + * + * @param buildWrappers buildWrappers. + */ + public void setBuildWrappers(DescribableList<BuildWrapper, Descriptor<BuildWrapper>> buildWrappers) { + getDescribableListProjectProperty(BUILD_WRAPPERS_PROPERTY_NAME).setValue(buildWrappers); + } + + /** + * Builds publishers. + * @param req {@link StaplerRequest} + * @param json {@link JSONObject} + * @param descriptors list of descriptors. + * @throws hudson.model.Descriptor.FormException + */ + @SuppressWarnings("unchecked") + protected void buildPublishers( StaplerRequest req, JSONObject json, List<Descriptor<Publisher>> descriptors) throws FormException{ + for (Descriptor<Publisher> d : descriptors) { + String name = d.getJsonSafeClassName(); + BaseProjectProperty<Publisher> baseProperty = getBaseProjectProperty(name); + Publisher publisher = null; + if (json.has(name)) { + publisher = d.newInstance(req, json.getJSONObject(name)); + } + baseProperty.setValue(publisher); + } + } + + protected void convertPublishersProperties() { + if (null != publishers) { + putAllProjectProperties(DescribableListUtil.convertToProjectProperties(publishers, this), false); + publishers = null; + } + } + + protected void convertBuildWrappersProjectProperties() { + if (null == getProperty(BUILD_WRAPPERS_PROPERTY_NAME)) { + setBuildWrappers(buildWrappers); + buildWrappers = null; + } + } + + protected void convertBuildersProjectProperty() { + if (null == getProperty(BUILDERS_PROPERTY_NAME)) { + setBuilders(builders); + builders = null; + } + } +} diff --git a/hudson-core/src/main/java/hudson/model/Build.java b/hudson-core/src/main/java/hudson/model/Build.java index 04c9543..af6acca 100644 --- a/hudson-core/src/main/java/hudson/model/Build.java +++ b/hudson-core/src/main/java/hudson/model/Build.java @@ -70,7 +70,7 @@ import static hudson.model.Result.ABORTED; * * @author Kohsuke Kawaguchi */ -public abstract class Build <P extends Project<P,B>,B extends Build<P,B>> +public abstract class Build <P extends BaseBuildableProject<P,B>,B extends Build<P,B>> extends AbstractBuild<P,B> { /** diff --git a/hudson-core/src/main/java/hudson/model/Project.java b/hudson-core/src/main/java/hudson/model/Project.java index 412d4a4..a87d16b 100644 --- a/hudson-core/src/main/java/hudson/model/Project.java +++ b/hudson-core/src/main/java/hudson/model/Project.java @@ -16,13 +16,11 @@ package hudson.model; -import hudson.Functions; import hudson.Util; import hudson.diagnosis.OldDataMonitor; import hudson.model.Descriptor.FormException; import hudson.tasks.BuildStep; import hudson.tasks.BuildStepDescriptor; -import hudson.tasks.BuildWrapper; import hudson.tasks.BuildWrappers; import hudson.tasks.Builder; import hudson.tasks.Fingerprinter; @@ -30,21 +28,15 @@ import hudson.tasks.Publisher; import hudson.tasks.Maven; import hudson.tasks.Maven.ProjectWithMaven; import hudson.tasks.Maven.MavenInstallation; -import hudson.triggers.Trigger; -import hudson.util.DescribableList; import hudson.util.DescribableListUtil; -import java.util.concurrent.CopyOnWriteArrayList; import net.sf.json.JSONObject; import org.eclipse.hudson.api.model.IProject; -import org.eclipse.hudson.api.model.project.property.BaseProjectProperty; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; import javax.servlet.ServletException; import java.io.IOException; import java.util.HashSet; -import java.util.List; -import java.util.Map; import java.util.Set; /** @@ -53,134 +45,20 @@ 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> + extends BaseBuildableProject<P, B> implements SCMedItem, Saveable, ProjectWithMaven, BuildableItemWithBuildWrappers, IProject { /** - * 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. - */ - @Deprecated - 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. - */ - @Deprecated - 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. - */ - @Deprecated - private DescribableList<BuildWrapper, Descriptor<BuildWrapper>> buildWrappers = - new DescribableList<BuildWrapper, Descriptor<BuildWrapper>>(this); - - /** * Creates a new project. */ public Project(ItemGroup parent,String name) { - super(parent,name); - } - - @Override - public void onLoad(ItemGroup<? extends Item> parent, String name) throws IOException { - super.onLoad(parent, name); - - getBuildersList().setOwner(this); - getPublishersList().setOwner(this); - getBuildWrappersList().setOwner(this); - } - - @Override - protected void buildProjectProperties() throws IOException { - super.buildProjectProperties(); - convertBuildersProjectProperty(); - convertBuildWrappersProjectProperties(); - convertPublishersProperties(); - } - - void convertPublishersProperties() { - if (null != publishers) { - putAllProjectProperties(DescribableListUtil.convertToProjectProperties(publishers, this), false); - publishers = null; - } - } - - void convertBuildWrappersProjectProperties() { - if (null == getProperty(BUILD_WRAPPERS_PROPERTY_NAME)) { - setBuildWrappers(buildWrappers); - buildWrappers = null; - } - } - - void convertBuildersProjectProperty() { - if (null == getProperty(BUILDERS_PROPERTY_NAME)) { - setBuilders(builders); - builders = null; - } + super(parent, name); } public AbstractProject<?, ?> asProject() { return this; } - public List<Builder> getBuilders() { - return getBuildersList().toList(); - } - - public Map<Descriptor<Publisher>,Publisher> getPublishers() { - return getPublishersList().toMap(); - } - - public void setBuilders(DescribableList<Builder,Descriptor<Builder>> builders) { - getDescribableListProjectProperty(BUILDERS_PROPERTY_NAME).setValue(builders); - } - - public DescribableList<Builder,Descriptor<Builder>> getBuildersList() { - return getDescribableListProjectProperty(BUILDERS_PROPERTY_NAME).getValue(); - } - - public DescribableList<Publisher, Descriptor<Publisher>> getPublishersList() { - List<Descriptor<Publisher>> descriptors = Functions.getPublisherDescriptors(this); - List<Publisher> publisherList = new CopyOnWriteArrayList<Publisher>(); - DescribableList<Publisher, Descriptor<Publisher>> result - = new DescribableList<Publisher, Descriptor<Publisher>>(this); - for (Descriptor<Publisher> descriptor : descriptors) { - BaseProjectProperty<Publisher> property = getBaseProjectProperty(descriptor.getJsonSafeClassName()); - if (null != property.getValue()) { - publisherList.add(property.getValue()); - } - } - result.addAllTo(publisherList); - return result; - } - - public Map<Descriptor<BuildWrapper>,BuildWrapper> getBuildWrappers() { - return getBuildWrappersList().toMap(); - } - - public DescribableList<BuildWrapper, Descriptor<BuildWrapper>> getBuildWrappersList() { - return getDescribableListProjectProperty(BUILD_WRAPPERS_PROPERTY_NAME).getValue(); - } - - public void setBuildWrappers(DescribableList<BuildWrapper, Descriptor<BuildWrapper>> buildWrappers) { - getDescribableListProjectProperty(BUILD_WRAPPERS_PROPERTY_NAME).setValue(buildWrappers); - } - @Override protected Set<ResourceActivity> getResourceActivities() { final Set<ResourceActivity> activities = new HashSet<ResourceActivity>(); @@ -213,15 +91,6 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>> getPublishersList().remove(descriptor); } - public Publisher getPublisher(Descriptor<Publisher> descriptor) { - return (Publisher) getBaseProjectProperty(descriptor.getJsonSafeClassName()).getValue(); - } - - protected void buildDependencyGraph(DependencyGraph graph) { - getPublishersList().buildDependencyGraph(this, graph); - getBuildersList().buildDependencyGraph(this, graph); - getBuildWrappersList().buildDependencyGraph(this, graph); - } @Override public boolean isFingerprintConfigured() { @@ -234,11 +103,6 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>> return null; } -// -// -// actions -// -// @Override protected void submit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException { super.submit(req,rsp); @@ -248,34 +112,6 @@ public abstract class Project<P extends Project<P,B>,B extends Build<P,B>> buildPublishers(req, json, BuildStepDescriptor.filter(Publisher.all(), this.getClass())); } - private void buildPublishers( StaplerRequest req, JSONObject json, List<Descriptor<Publisher>> descriptors) throws FormException{ - for (Descriptor<Publisher> d : descriptors) { - String name = d.getJsonSafeClassName(); - BaseProjectProperty<Publisher> baseProperty = getBaseProjectProperty(name); - Publisher publisher = null; - if (json.has(name)) { - publisher = d.newInstance(req, json.getJSONObject(name)); - } - baseProperty.setValue(publisher); - } - } - - @Override - protected List<Action> createTransientActions() { - List<Action> r = super.createTransientActions(); - - for (BuildStep step : getBuildersList()) - r.addAll(step.getProjectActions(this)); - for (BuildStep step : getPublishersList()) - r.addAll(step.getProjectActions(this)); - for (BuildWrapper step : getBuildWrappers().values()) - r.addAll(step.getProjectActions(this)); - for (Trigger trigger : getTriggers().values()) - r.addAll(trigger.getProjectActions()); - - return r; - } - /** * @deprecated since 2006-11-05. * Left for legacy config file compatibility |

