From ffb9bdf64edfb41022e4c0f975014f2d7f6bd211 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Fri, 20 Mar 2009 23:56:54 +0000 Subject: [PATCH] generalized it so that we can have other Descriptors call this. Since implementing this method involves in some kind of downcasting anyway, there's not much point in defining subtype-specific isApplicable methods git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@16417 71c3de6d-444a-0410-be80-ed276b4c234a --- .../main/java/hudson/model/AbstractProject.java | 15 ++++++++++----- .../java/hudson/tasks/BuildStepDescriptor.java | 5 ++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/hudson/model/AbstractProject.java b/core/src/main/java/hudson/model/AbstractProject.java index bca296e2c6..ebb87005d2 100644 --- a/core/src/main/java/hudson/model/AbstractProject.java +++ b/core/src/main/java/hudson/model/AbstractProject.java @@ -1308,19 +1308,24 @@ public abstract class AbstractProject

,R extends A */ public static abstract class AbstractProjectDescriptor extends TopLevelItemDescriptor { /** - * {@link AbstractProject} subtypes can override this method to veto some {@link BuildStepDescriptor}s + * {@link AbstractProject} subtypes can override this method to veto some {@link Descriptor}s * from showing up on their configuration screen. This is often useful when you are building - * a workflow specific project type, where generic builders and publishers don't make sense. + * a workflow/company specific project type, where you want to limit the number of choices + * given to the users. * *

- * This method works like AND in conjunction with {@link BuildStepDescriptor#isApplicable(Class)}. - * Both this method and that method need to return true in order for a given {@link BuildStepDescriptor} + * Some {@link Descriptor}s define their own schemes for controlling applicability + * (such as {@link BuildStepDescriptor#isApplicable(Class)}), + * This method works like AND in conjunction with them; + * Both this method and that method need to return true in order for a given {@link Descriptor} * to show up for the given {@link Project}. * *

* The default implementation returns true for everything. + * + * @see BuildStepDescriptor#isApplicable(Class) */ - public boolean isApplicable(BuildStepDescriptor descriptor) { + public boolean isApplicable(Descriptor descriptor) { return true; } } diff --git a/core/src/main/java/hudson/tasks/BuildStepDescriptor.java b/core/src/main/java/hudson/tasks/BuildStepDescriptor.java index 89bda5ae6c..d27da3b7f7 100644 --- a/core/src/main/java/hudson/tasks/BuildStepDescriptor.java +++ b/core/src/main/java/hudson/tasks/BuildStepDescriptor.java @@ -61,6 +61,7 @@ public abstract class BuildStepDescriptor> * * @return * true to allow user to configure this post-promotion task for the given project. + * @see AbstractProjectDescriptor#isApplicable(Descriptor) */ public abstract boolean isApplicable(Class jobType); @@ -75,10 +76,12 @@ public abstract class BuildStepDescriptor> List> r = new ArrayList>(base.size()); for (Descriptor d : base) { + if (pd instanceof AbstractProjectDescriptor && !((AbstractProjectDescriptor)pd).isApplicable(d)) + continue; + if (d instanceof BuildStepDescriptor) { BuildStepDescriptor bd = (BuildStepDescriptor) d; if(!bd.isApplicable(type)) continue; - if(pd instanceof AbstractProjectDescriptor && !((AbstractProjectDescriptor)pd).isApplicable(bd)) continue; r.add(bd); } else { // old plugins built before 1.150 may not implement BuildStepDescriptor