mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 14:02:22 +00:00
supporting filtering for SCMs
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@16430 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
903782ce65
commit
5ab7f1a6d0
6 files changed
+63
-4
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user