提交 5ab7f1a6 编写于 作者: K kohsuke

supporting filtering for SCMs

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@16430 71c3de6d-444a-0410-be80-ed276b4c234a
上级 903782ce
......@@ -59,6 +59,8 @@ import hudson.tasks.Builder;
import hudson.tasks.Publisher;
import hudson.util.Area;
import hudson.util.Iterators;
import hudson.scm.SCM;
import hudson.scm.SCMDescriptor;
import org.acegisecurity.providers.anonymous.AnonymousAuthenticationToken;
import org.apache.commons.jelly.JellyContext;
import org.apache.commons.jelly.JellyTagException;
......@@ -610,6 +612,10 @@ public class Functions {
return BuildStepDescriptor.filter(Publisher.all(), project.getClass());
}
public static List<SCMDescriptor<?>> getSCMDescriptors(AbstractProject<?,?> project) {
return SCM._for(project);
}
public static List<Descriptor<ComputerLauncher>> getComputerLauncherDescriptors() {
return Hudson.getInstance().getDescriptorList(ComputerLauncher.class);
}
......
......@@ -1169,7 +1169,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
authToken = BuildAuthorizationToken.create(req);
setScm(SCMS.parseSCM(req));
setScm(SCMS.parseSCM(req,this));
for (Trigger t : triggers)
t.stop();
......
......@@ -39,11 +39,15 @@ import hudson.model.TaskListener;
import hudson.model.Node;
import hudson.model.WorkspaceCleanupThread;
import hudson.model.Hudson;
import hudson.model.Descriptor;
import hudson.model.AbstractProject.AbstractProjectDescriptor;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;
import java.util.List;
import java.util.ArrayList;
/**
* Captures the configuration information in it.
......@@ -361,4 +365,26 @@ public abstract class SCM implements Describable<SCM>, ExtensionPoint {
public static DescriptorExtensionList<SCM,SCMDescriptor<?>> all() {
return Hudson.getInstance().getDescriptorList(SCM.class);
}
/**
* Returns the list of {@link SCMDescriptor}s that are applicable to the given project.
*/
public static List<SCMDescriptor<?>> _for(final AbstractProject project) {
if(project==null) return all();
final Descriptor pd = Hudson.getInstance().getDescriptor((Class) project.getClass());
List<SCMDescriptor<?>> r = new ArrayList<SCMDescriptor<?>>();
for (SCMDescriptor<?> scmDescriptor : all()) {
if(!scmDescriptor.isApplicable(project)) continue;
if (pd instanceof AbstractProjectDescriptor) {
AbstractProjectDescriptor apd = (AbstractProjectDescriptor) pd;
if(!apd.isApplicable(scmDescriptor)) continue;
}
r.add(scmDescriptor);
}
return r;
}
}
......@@ -25,6 +25,7 @@ package hudson.scm;
import hudson.model.Descriptor;
import hudson.model.Describable;
import hudson.model.AbstractProject;
import java.util.List;
import java.util.Collections;
......@@ -83,6 +84,19 @@ public abstract class SCMDescriptor<T extends SCM> extends Descriptor<SCM> {
return false;
}
/**
* Allows {@link SCMDescriptor}s to choose which projects it wants to be configurable against.
*
* <p>
* When this method returns false, this {@link SCM} will not appear in the configuration screen
* for the given project. The default method always return true.
*
* @since 1.294
*/
public boolean isApplicable(AbstractProject project) {
return true;
}
/**
* Returns the list of {@link RepositoryBrowser} {@link Descriptor}
* that can be used with this SCM.
......
......@@ -25,6 +25,7 @@ package hudson.scm;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.AbstractProject;
import hudson.model.Descriptor.FormException;
import hudson.util.DescriptorList;
import hudson.DescriptorExtensionList;
......@@ -51,14 +52,26 @@ public class SCMS {
/**
* Parses {@link SCM} configuration from the submitted form.
*
* @param target
* The project for which this SCM is configured to.
*/
public static SCM parseSCM(StaplerRequest req) throws FormException, ServletException {
public static SCM parseSCM(StaplerRequest req, AbstractProject target) throws FormException, ServletException {
String scm = req.getParameter("scm");
if(scm==null) return new NullSCM();
int scmidx = Integer.parseInt(scm);
SCMDescriptor<?> d = SCM.all().get(scmidx);
SCMDescriptor<?> d = SCM._for(target).get(scmidx);
d.generation++;
return d.newInstance(req, req.getSubmittedForm().getJSONObject("scm"));
}
/**
* @deprecated as of 1.294
* Use {@link #parseSCM(StaplerRequest, AbstractProject)} and pass in the caller's project type.
*/
public static SCM parseSCM(StaplerRequest req) throws FormException, ServletException {
return parseSCM(req,null);
}
}
......@@ -25,7 +25,7 @@ THE SOFTWARE.
<!-- SCM config pane -->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:section title="${%Source Code Management}">
<j:getStatic var="scms" className="hudson.scm.SCMS" field="SCMS" />
<j:set var="scms" value="${h.getSCMDescriptors(it)}" />
<j:forEach var="idx" begin="0" end="${size(scms)-1}">
<j:set var="descriptor" value="${scms[idx]}" />
<j:set var="scmd" value="${descriptor}" /><!-- backward compatibility with <1.238 -->
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册