| author | akozak | 2011-11-21 03:18:54 (EST) |
|---|---|---|
| committer | Winston Prakash | 2011-12-01 20:46:47 (EST) |
| commit | 459ecfa2a1d587863375680b941cfe1c9c030be4 (patch) (side-by-side diff) | |
| tree | ef6d8079d32ab974ef63a90a22c60f9baa78f4fb | |
| parent | ad50cebe6bb0b88438a5438390378e51d118bd1d (diff) | |
| download | org.eclipse.hudson.core-459ecfa2a1d587863375680b941cfe1c9c030be4.zip org.eclipse.hudson.core-459ecfa2a1d587863375680b941cfe1c9c030be4.tar.gz org.eclipse.hudson.core-459ecfa2a1d587863375680b941cfe1c9c030be4.tar.bz2 | |
Add template field and getTemplate methods for project configuration page
Signed-off-by: Winston Prakash <winston.prakash@gmail.com>
4 files changed, 68 insertions, 2 deletions
diff --git a/hudson-core/src/main/java/hudson/model/AbstractProject.java b/hudson-core/src/main/java/hudson/model/AbstractProject.java index e8acc2c..0e43d43 100644 --- a/hudson-core/src/main/java/hudson/model/AbstractProject.java +++ b/hudson-core/src/main/java/hudson/model/AbstractProject.java @@ -85,7 +85,6 @@ import java.util.Vector; import java.util.concurrent.Future; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.regex.Pattern; import javax.servlet.ServletException; import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; @@ -218,6 +217,16 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A @CopyOnWrite protected transient volatile List<Action> transientActions = new Vector<Action>(); + /** + * The name of the template. + */ + private String templateName; + + /** + * Selected template for this project. + */ + private transient AbstractProject template; + private boolean concurrentBuild; /** @@ -1658,6 +1667,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A super.submit(req,rsp); makeDisabled(req.getParameter("disable")!=null); + setTemplateName(Util.fixEmptyAndTrim(req.getParameter("templateName"))); jdk = req.getParameter("jdk"); if(req.getParameter("hasCustomQuietPeriod")!=null) { @@ -1942,4 +1952,35 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A throw new CmdLineException(null,Messages.AbstractItem_NoSuchJobExists(name,AbstractProject.findNearest(name).getFullName())); return item; } + + /** + * Returns template name. + * + * @return template name. + */ + public String getTemplateName() { + return templateName; + } + + /** + * Sets template name. + * + * @param templateName template name. + */ + public void setTemplateName(String templateName) { + this.templateName = templateName; + this.template = Hudson.getInstance().getTemplate(this.getClass(), templateName); + } + + /** + * Returns selected template. + * + * @return template. + */ + public AbstractProject getTemplate() { + if (null == template) { + template = Hudson.getInstance().getTemplate(this.getClass(), templateName); + } + return template; + } } diff --git a/hudson-core/src/main/java/hudson/model/Hudson.java b/hudson-core/src/main/java/hudson/model/Hudson.java index 975b288..86298b9 100644 --- a/hudson-core/src/main/java/hudson/model/Hudson.java +++ b/hudson-core/src/main/java/hudson/model/Hudson.java @@ -17,6 +17,8 @@ package hudson.model; import antlr.ANTLRException; +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; import com.thoughtworks.xstream.XStream; import hudson.BulkChange; import hudson.DNSMultiCast; @@ -1624,6 +1626,25 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl } /** + * Returns template by project type and template name. + * + * @param type type of the project. + * @param templateName name of the template + * @return template. + */ + public <T extends AbstractProject> T getTemplate(Class<T> type, final String templateName) { + if (StringUtils.isBlank(templateName)) { + return null; + } + Iterable<T> templates = Iterables.filter(getAllItems(type), new Predicate<T>() { + public boolean apply(T project) { + return templateName.equalsIgnoreCase(project.getName()); + } + }); + return templates.iterator().hasNext() ? templates.iterator().next() : null; + } + + /** * Updates the slave list. * * @deprecated @@ -3592,7 +3613,7 @@ public final class Hudson extends Node implements ItemGroup<TopLevelItem>, Stapl } return this; } - + /** * @since 2.1.0 */ diff --git a/hudson-core/src/main/java/hudson/util/IOUtils.java b/hudson-core/src/main/java/hudson/util/IOUtils.java index 2109adc..a5ce6f4 100644 --- a/hudson-core/src/main/java/hudson/util/IOUtils.java +++ b/hudson-core/src/main/java/hudson/util/IOUtils.java @@ -86,6 +86,7 @@ public class IOUtils extends org.apache.commons.io.IOUtils { * * @since 1.349 * @deprecated use {@link org.apache.commons.io.IOUtils#skip(java.io.InputStream, long)} instead + * @since 2.1.2 */ public static long skip(InputStream in, long size) throws IOException { return org.apache.commons.io.IOUtils.skip(in, size); diff --git a/hudson-core/src/main/resources/hudson/model/Job/configure.jelly b/hudson-core/src/main/resources/hudson/model/Job/configure.jelly index cde9ffd..80691cd 100644 --- a/hudson-core/src/main/resources/hudson/model/Job/configure.jelly +++ b/hudson-core/src/main/resources/hudson/model/Job/configure.jelly @@ -32,6 +32,9 @@ <f:textbox name="name" value="${it.name}" /> </f:entry> </j:if> + <f:entry title="${%templateName}"> + <f:textbox name="templateName" value="${it.templateName}" /> + </f:entry> <f:entry title="${%Description}" help="/help/project-config/description.html"> <f:textarea name="description" value="${it.description}"/> </f:entry> |

