Class Descriptor<T extends Describable<T>>
- Direct Known Subclasses:
AbstractNodeMonitorDescriptor
,ArtifactManagerFactoryDescriptor
,AuthorizationStrategy.Unsecured.DescriptorImpl
,BuildDiscarderDescriptor
,BuildStepDescriptor
,BuildWrapperDescriptor
,CaptchaSupportDescriptor
,CloudSet.DescriptorImpl
,ComputerConnectorDescriptor
,ComputerSet.DescriptorImpl
,ConsoleAnnotationDescriptor
,Correlator
,CrumbIssuerDescriptor
,DefaultConsoleUrlProvider.DescriptorImpl
,DelegatingComputerLauncher.DescriptorImpl
,EnvVarsFilterLocalRuleDescriptor
,FingerprintStorageDescriptor
,FullControlOnceLoggedInAuthorizationStrategy.DescriptorImpl
,GlobalBuildDiscarderStrategyDescriptor
,GlobalConfiguration
,GlobalSecurityConfiguration.DescriptorImpl
,GlobalSettingsProviderDescriptor
,HudsonPrivateSecurityRealm.DescriptorImpl
,IdStrategyDescriptor
,JNLPLauncher.DescriptorImpl
,JobPropertyDescriptor
,LabelAtomPropertyDescriptor
,LegacyAuthorizationStrategy.DescriptorImpl
,LegacySecurityRealm.DescriptorImpl
,ListViewColumnDescriptor
,MarkupFormatterDescriptor
,MyViewsTabBarDescriptor
,NodeDescriptor
,PageDecorator
,ParameterDefinition.ParameterDescriptor
,ProjectNamingStrategy.ProjectNamingStrategyDescriptor
,PropertyDescriptor
,ProxyConfiguration.DescriptorImpl
,QueueItemAuthenticatorDescriptor
,RemotingWorkDirSettings.DescriptorImpl
,RetentionStrategy.Always.DescriptorImpl
,RetentionStrategy.Demand.DescriptorImpl
,SCMCheckoutStrategyDescriptor
,SCMDescriptor
,SettingsProviderDescriptor
,SimplePageDecorator
,SimpleScheduledRetentionStrategy.DescriptorImpl
,StatusFilter.StatusFilterDescriptor
,ToolDescriptor
,ToolInstallerDescriptor
,TopLevelItemDescriptor
,TriggerDescriptor
,UserPropertyDescriptor
,ViewDescriptor
,ViewPropertyDescriptor
,ViewsTabBarDescriptor
Descriptor
is an object that has metadata about a Describable
object, and also serves as a factory (in a way this relationship is similar
to Object
/Class
relationship.
A Descriptor
/Describable
combination is used throughout in Jenkins to implement a
configuration/extensibility mechanism.
Take the list view support as an example, which is implemented
in ListView
class. Whenever a new view is created, a new
ListView
instance is created with the configuration
information. This instance gets serialized to XML, and this instance
will be called to render the view page. This is the job
of Describable
— each instance represents a specific
configuration of a view (what projects are in it, regular expression, etc.)
For Jenkins to create such configured ListView
instance, Jenkins
needs another object that captures the metadata of ListView
,
and that is what a Descriptor
is for. ListView
class
has a singleton descriptor, and this descriptor helps render
the configuration form, remember system-wide configuration, and works as a factory.
Descriptor
also usually have its associated views.
Persistence
Descriptor
can persist data just by storing them in fields.
However, it is the responsibility of the derived type to properly
invoke save()
and load()
.
load()
is automatically invoked as a JSR-250 lifecycle method if derived class
do implement PersistentDescriptor
.
Reflection Enhancement
Descriptor
defines addition to the standard Java reflection
and provides reflective information about its corresponding Describable
.
These are primarily used by tag libraries to
keep the Jelly scripts concise.- Author:
- Kohsuke Kawaguchi
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
static final class
Represents a readable property onDescribable
.static final class
Special type indicating thatDescriptor
describes itself. -
Field Summary
Modifier and TypeFieldDescriptionThe class being described by this descriptor. -
Constructor Summary
ModifierConstructorDescriptionprotected
Infers the type of the correspondingDescribable
from the outer class.protected
Descriptor
(Class<? extends T> clazz) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addHelpFileRedirect
(String fieldName, Class<? extends Describable> owner, String fieldNameToRedirectTo) Tells Jenkins that the help file for the field 'fieldName' is defined in the help file for the 'fieldNameToRedirectTo' in the 'owner' class.static <T> T
Replacement forStaplerRequest2.bindJSON(Class, JSONObject)
which honorsnewInstance(StaplerRequest2, JSONObject)
.static <T> T
Deprecated.void
calcAutoCompleteSettings
(String field, Map<String, Object> attributes) Computes the auto-completion settingvoid
calcFillSettings
(String field, Map<String, Object> attributes) Computes the list of other form fields that the given field depends on, via the doFillXyzItems method, and sets that as the 'fillDependsOn' attribute.boolean
configure
(org.kohsuke.stapler.StaplerRequest req) Deprecated.As of 1.239, useconfigure(StaplerRequest2, JSONObject)
.boolean
configure
(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject json) Invoked when the global configuration page is submitted.boolean
configure
(org.kohsuke.stapler.StaplerRequest req, net.sf.json.JSONObject json) Deprecated.void
doHelp
(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) Serveshelp.html
from the resource ofclazz
.void
doHelp
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) Deprecated.static Descriptor
static <T extends Descriptor>
Tfind
(Collection<? extends T> list, String string) static <T extends Descriptor>
TfindByDescribableClassName
(Collection<? extends T> list, String className) Finds a descriptor from a collection by the class name of theDescribable
it describes.static <T extends Descriptor>
TfindById
(Collection<? extends T> list, String id) Finds a descriptor from a collection by its ID.Define the global configuration category the global config of this Descriptor is in.getCheckMethod
(String fieldName) If the field "xyz" of aDescribable
has the corresponding "doCheckXyz" method, return the model of the check method.getCheckUrl
(String fieldName) Deprecated.since 1.528 UsegetCheckMethod(String)
protected XmlFile
static String
final String
Gets the URL that this Descriptor is bound to, relative to the context path.Gets the URL that this Descriptor is bound to, relative to the nearestDescriptorByNameOwner
.Human readable name of this kind of configurable object.getGlobalPropertyType
(String field) Obtains the property type of the given field of this descriptor.Returns the resource path to the help screen HTML, if any.getHelpFile
(String fieldName) Returns the path to the help screen HTML for the given field.getHelpFile
(org.kohsuke.stapler.lang.Klass<?> clazz, String fieldName) getId()
Uniquely identifies thisDescriptor
among all the otherDescriptor
s.final String
Gets the class name nicely escaped to be usable as a key in the structured form submission.org.kohsuke.stapler.lang.Klass<?>
getKlass()
Returns theKlass
object used for the purpose of loading resources from this descriptor.protected PluginWrapper
Returns the plugin in which this descriptor is defined.getPossibleViewNames
(String baseName) getPropertyType
(Object instance, String field) Used by Jelly to abstract away the handling of global.jelly vs config.jelly databinding difference.getPropertyType
(String field) Obtains the property type of the given field ofclazz
getPropertyTypeOrDie
(Object instance, String field) Akin togetPropertyType(Object,String)
but never returns null.Returns the permission type needed in order to access thegetGlobalConfigPage()
for this descriptor.static URL
getStaticHelpUrl
(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.lang.Klass<?> c, String suffix) static URL
getStaticHelpUrl
(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.lang.Klass<?> c, String suffix) Deprecated.getT()
Unlikeclazz
, return the parameter type 'T', which determines theDescriptorExtensionList
that this goes to.protected final String
getViewPage
(Class<?> clazz, String pageName) final boolean
isInstance
(T instance) Checks if the given object is created from thisDescriptor
.final boolean
isSubTypeOf
(Class type) Checks if the type represented by this descriptor is a subtype of the given type.void
load()
Loads the data from the disk into this object.newInstance
(org.kohsuke.stapler.StaplerRequest req) Deprecated.ImplementnewInstance(StaplerRequest, JSONObject)
method instead.newInstance
(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject formData) Creates a configured instance from the submitted form.newInstance
(org.kohsuke.stapler.StaplerRequest req, net.sf.json.JSONObject formData) Deprecated.static <T extends Describable<T>>
List<T>newInstancesFromHeteroList
(org.kohsuke.stapler.StaplerRequest2 req, Object formData, Collection<? extends Descriptor<T>> descriptors) static <T extends Describable<T>>
List<T>newInstancesFromHeteroList
(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject formData, String key, Collection<? extends Descriptor<T>> descriptors) Used to buildDescribable
instance list from<f:hetero-list>
tag.static <T extends Describable<T>>
List<T>newInstancesFromHeteroList
(org.kohsuke.stapler.StaplerRequest req, Object formData, Collection<? extends Descriptor<T>> descriptors) static <T extends Describable<T>>
List<T>newInstancesFromHeteroList
(org.kohsuke.stapler.StaplerRequest req, net.sf.json.JSONObject formData, String key, Collection<? extends Descriptor<T>> descriptors) void
save()
Saves the configuration info to the disk.protected static Class
self()
static <T> T[]
toArray
(T... values) static <T> List<T>
toList
(T... values) static <T extends Describable<T>>
Map<Descriptor<T>,T>
-
Field Details
-
clazz
The class being described by this descriptor.
-
-
Constructor Details
-
Descriptor
- Parameters:
clazz
- Pass inself()
to have the descriptor describe itself, (this hack is needed since derived types can't call "getClass()" to refer to itself.
-
Descriptor
protected Descriptor()Infers the type of the correspondingDescribable
from the outer class. This version works when you follow the common convention, where a descriptor is written as the static nested class of the describable class.- Since:
- 1.278
-
-
Method Details
-
getDisplayName
Human readable name of this kind of configurable object. Should be overridden for most descriptors, if the display name is visible somehow. As a fallback it usesClass.getSimpleName()
onclazz
, so for exampleMyThing
fromsome.pkg.MyThing.DescriptorImpl
. Historically some implementations returned null as a way of hiding the descriptor from the UI, but this is generally managed by an explicit method such asisEnabled
orisApplicable
. -
getId
Uniquely identifies thisDescriptor
among all the otherDescriptor
s.Historically
clazz
is assumed to be unique, so this method uses that as the default, but if you are addingDescriptor
s programmatically for the same type, you can change this to disambiguate them.To look up
Descriptor
from ID, useJenkins.getDescriptor(String)
.- Returns:
- Stick to valid Java identifier character, plus '.', which had to be allowed for historical reasons.
- Since:
- 1.391
-
getT
Unlikeclazz
, return the parameter type 'T', which determines theDescriptorExtensionList
that this goes to.In those situations where subtypes cannot provide the type parameter, this method can be overridden to provide it.
-
getDescriptorUrl
Gets the URL that this Descriptor is bound to, relative to the nearestDescriptorByNameOwner
. SinceJenkins
is aDescriptorByNameOwner
, there's always one such ancestor to any request. -
getDescriptorFullUrl
Gets the URL that this Descriptor is bound to, relative to the context path.- Since:
- 1.406
-
getCurrentDescriptorByNameUrl
- Since:
- 1.402
-
getCheckUrl
Deprecated.since 1.528 UsegetCheckMethod(String)
-
getCheckMethod
If the field "xyz" of aDescribable
has the corresponding "doCheckXyz" method, return the model of the check method.This method is used to hook up the form validation method to the corresponding HTML input element.
-
calcFillSettings
Computes the list of other form fields that the given field depends on, via the doFillXyzItems method, and sets that as the 'fillDependsOn' attribute. Also computes the URL of the doFillXyzItems and sets that as the 'fillUrl' attribute. -
calcAutoCompleteSettings
Computes the auto-completion setting -
getPropertyType
@CheckForNull public Descriptor.PropertyType getPropertyType(@NonNull Object instance, @NonNull String field) Used by Jelly to abstract away the handling of global.jelly vs config.jelly databinding difference. -
getPropertyTypeOrDie
@NonNull public Descriptor.PropertyType getPropertyTypeOrDie(@NonNull Object instance, @NonNull String field) Akin togetPropertyType(Object,String)
but never returns null.- Throws:
AssertionError
- in case the field cannot be found- Since:
- 1.492
-
getPropertyType
Obtains the property type of the given field ofclazz
-
getGlobalPropertyType
Obtains the property type of the given field of this descriptor. -
getJsonSafeClassName
Gets the class name nicely escaped to be usable as a key in the structured form submission. -
newInstance
@Deprecated public T newInstance(org.kohsuke.stapler.StaplerRequest req) throws Descriptor.FormException Deprecated.ImplementnewInstance(StaplerRequest, JSONObject)
method instead. Deprecated as of 1.145.- Throws:
Descriptor.FormException
-
newInstance
public T newInstance(@Nullable org.kohsuke.stapler.StaplerRequest2 req, @NonNull net.sf.json.JSONObject formData) throws Descriptor.FormException Creates a configured instance from the submitted form.Hudson only invokes this method when the user wants an instance of
T
. So there's no need to check that in the implementation.The default implementation of this method uses
bindJSON(org.kohsuke.stapler.StaplerRequest2, java.lang.Class<T>, net.sf.json.JSONObject)
which performs the databinding on the constructor ofclazz
.For some types of
Describable
, such asListViewColumn
, this method can be invoked with null request object for historical reason. Such design is considered broken, but due to the compatibility reasons we cannot fix it. Because of this, the default implementation gracefully handles null request, but the contract of the method still is "request is always non-null." Extension points that need to define the "default instance" semantics should define a descriptor subtype and add the no-arg newInstance method.- Parameters:
req
- Always non-null (see note above.) This object includes represents the entire submission.formData
- The JSON object that captures the configuration data for thisDescriptor
. See the developer documentation. Always non-null.- Throws:
Descriptor.FormException
- Signals a problem in the submitted form.- Since:
- 2.475
-
newInstance
@Deprecated public T newInstance(@Nullable org.kohsuke.stapler.StaplerRequest req, @NonNull net.sf.json.JSONObject formData) throws Descriptor.FormException Deprecated.- Throws:
Descriptor.FormException
- Since:
- 1.145
-
bindJSON
public static <T> T bindJSON(org.kohsuke.stapler.StaplerRequest2 req, Class<T> type, net.sf.json.JSONObject src) Replacement forStaplerRequest2.bindJSON(Class, JSONObject)
which honorsnewInstance(StaplerRequest2, JSONObject)
. This is automatically used insidenewInstance(StaplerRequest2, JSONObject)
so a direct call would only be necessary in case the top level binding might use aDescriptor
which overridesnewInstance(StaplerRequest2, JSONObject)
.- Since:
- 2.475
-
bindJSON
@Deprecated public static <T> T bindJSON(org.kohsuke.stapler.StaplerRequest req, Class<T> type, net.sf.json.JSONObject src) Deprecated.- Since:
- 2.342
-
getKlass
public org.kohsuke.stapler.lang.Klass<?> getKlass()Returns theKlass
object used for the purpose of loading resources from this descriptor. This hook enables other JVM languages to provide more integrated lookup. -
getHelpFile
Returns the resource path to the help screen HTML, if any.Starting 1.282, this method uses "convention over configuration" — you should just put the "help.html" (and its localized versions, if any) in the same directory you put your Jelly view files, and this method will automatically does the right thing.
This value is relative to the context root of Hudson, so normally the values are something like
"/plugin/emma/help.html"
to refer to static resource files in a plugin, or"/publisher/EmmaPublisher/abc"
to refer to Jelly scriptabc.jelly
or a methodEmmaPublisher.doAbc()
.- Returns:
- null to indicate that there's no help.
-
getHelpFile
Returns the path to the help screen HTML for the given field.The help files are assumed to be at "help/FIELDNAME.html" with possible locale variations.
-
getHelpFile
-
addHelpFileRedirect
protected void addHelpFileRedirect(String fieldName, Class<? extends Describable> owner, String fieldNameToRedirectTo) Tells Jenkins that the help file for the field 'fieldName' is defined in the help file for the 'fieldNameToRedirectTo' in the 'owner' class.- Since:
- 1.425
-
isInstance
Checks if the given object is created from thisDescriptor
. -
isSubTypeOf
Checks if the type represented by this descriptor is a subtype of the given type. -
configure
@Deprecated public boolean configure(org.kohsuke.stapler.StaplerRequest req) throws Descriptor.FormException Deprecated.As of 1.239, useconfigure(StaplerRequest2, JSONObject)
.- Throws:
Descriptor.FormException
-
configure
public boolean configure(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject json) throws Descriptor.FormException Invoked when the global configuration page is submitted. Can be overridden to store descriptor-specific information.- Parameters:
json
- The JSON object that captures the configuration data for thisDescriptor
. See the developer documentation.- Returns:
- false to keep the client in the same config page.
- Throws:
Descriptor.FormException
- Since:
- 2.475
-
configure
@Deprecated public boolean configure(org.kohsuke.stapler.StaplerRequest req, net.sf.json.JSONObject json) throws Descriptor.FormException Deprecated.- Throws:
Descriptor.FormException
-
getConfigPage
-
getGlobalConfigPage
-
getCategory
Define the global configuration category the global config of this Descriptor is in.- Returns:
- never null, always the same value for a given instance of
Descriptor
. - Since:
- 2.0, used to be in
GlobalConfiguration
before that.
-
getRequiredGlobalConfigPagePermission
Returns the permission type needed in order to access thegetGlobalConfigPage()
for this descriptor. By default, requiresJenkins.ADMINISTER
permission. For now this only applies to descriptors configured through the global (GlobalConfigurationCategory.Unclassified
) configuration. Override to return something different if appropriate. The only currently supported alternative return value isJenkins.MANAGE
.- Returns:
- Permission required to globally configure this descriptor.
- Since:
- 2.222
-
getViewPage
-
getPossibleViewNames
-
save
public void save()Saves the configuration info to the disk. -
load
public void load()Loads the data from the disk into this object.The constructor of the derived class must call this method. (If we do that in the base class, the derived class won't get a chance to set default values.)
-
getConfigFile
-
getPlugin
Returns the plugin in which this descriptor is defined.- Returns:
- null to indicate that this descriptor came from the core.
-
doHelp
public void doHelp(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.StaplerResponse2 rsp) throws IOException, jakarta.servlet.ServletException Serveshelp.html
from the resource ofclazz
.- Throws:
IOException
jakarta.servlet.ServletException
-
doHelp
@Deprecated @StaplerNotDispatchable public void doHelp(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.StaplerResponse rsp) throws IOException, javax.servlet.ServletException Deprecated.- Throws:
IOException
javax.servlet.ServletException
-
getStaticHelpUrl
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static URL getStaticHelpUrl(org.kohsuke.stapler.StaplerRequest2 req, org.kohsuke.stapler.lang.Klass<?> c, String suffix) - Since:
- 2.475
-
getStaticHelpUrl
@Deprecated @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static URL getStaticHelpUrl(org.kohsuke.stapler.StaplerRequest req, org.kohsuke.stapler.lang.Klass<?> c, String suffix) Deprecated. -
toArray
public static <T> T[] toArray(T... values) -
toList
-
toMap
-
newInstancesFromHeteroList
public static <T extends Describable<T>> List<T> newInstancesFromHeteroList(org.kohsuke.stapler.StaplerRequest2 req, net.sf.json.JSONObject formData, String key, Collection<? extends Descriptor<T>> descriptors) throws Descriptor.FormException Used to buildDescribable
instance list from<f:hetero-list>
tag.- Parameters:
req
- Request that represents the form submission.formData
- Structured form data that represents the contains data for the list of describables.key
- The JSON property name for 'formData' that represents the data for the list of describables.descriptors
- List of descriptors to create instances from.- Returns:
- Can be empty but never null.
- Throws:
Descriptor.FormException
- Since:
- 2.475
-
newInstancesFromHeteroList
@Deprecated public static <T extends Describable<T>> List<T> newInstancesFromHeteroList(org.kohsuke.stapler.StaplerRequest req, net.sf.json.JSONObject formData, String key, Collection<? extends Descriptor<T>> descriptors) throws Descriptor.FormException - Throws:
Descriptor.FormException
-
newInstancesFromHeteroList
public static <T extends Describable<T>> List<T> newInstancesFromHeteroList(org.kohsuke.stapler.StaplerRequest2 req, Object formData, Collection<? extends Descriptor<T>> descriptors) throws Descriptor.FormException - Throws:
Descriptor.FormException
- Since:
- 2.475
-
newInstancesFromHeteroList
@Deprecated public static <T extends Describable<T>> List<T> newInstancesFromHeteroList(org.kohsuke.stapler.StaplerRequest req, Object formData, Collection<? extends Descriptor<T>> descriptors) throws Descriptor.FormException - Throws:
Descriptor.FormException
-
findById
@CheckForNull public static <T extends Descriptor> T findById(Collection<? extends T> list, String id) Finds a descriptor from a collection by its ID.- Parameters:
id
- should matchgetId()
- Since:
- 1.610
-
findByDescribableClassName
@CheckForNull public static <T extends Descriptor> T findByDescribableClassName(Collection<? extends T> list, String className) Finds a descriptor from a collection by the class name of theDescribable
it describes.- Parameters:
className
- should matchClass.getName()
of aclazz
- Since:
- 1.610
-
find
@Deprecated @CheckForNull public static <T extends Descriptor> T find(Collection<? extends T> list, String string) Deprecated.Finds a descriptor from a collection by its class name or ID. -
find
-
self
-
bindJSON(StaplerRequest2, Class, JSONObject)