Package io.jenkins.plugins.casc
Class BaseConfigurator<T>
- java.lang.Object
-
- io.jenkins.plugins.casc.BaseConfigurator<T>
-
- All Implemented Interfaces:
Configurator<T>
- Direct Known Subclasses:
AdminWhitelistRuleConfigurator
,DataBoundConfigurator
,DescriptorConfigurator
,ExtensionConfigurator
,GlobalConfigurationCategoryConfigurator
,JenkinsConfigurator
,LabelAtomConfigurator
,MavenConfigurator
,SelfConfigurator
,UnsecuredAuthorizationStrategyConfigurator
,UpdateCenterConfigurator
,UpdateSiteConfigurator
public abstract class BaseConfigurator<T> extends Object implements Configurator<T>
a General purpose abstractConfigurator
implementation based on introspection. Target component is identified by implementinginstance(Mapping, ConfigurationContext)
then configuration is applied onAttribute
s as defined bydescribe()
. This base implementation uses JavaBean convention to identify configurable attributes.- Author:
- Nicolas De Loof
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
BaseConfigurator.TypePair
-
Constructor Summary
Constructors Constructor Description BaseConfigurator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
check(CNode c, ConfigurationContext context)
Run the same logic asConfigurator.configure(CNode, ConfigurationContext)
in dry-run mode.protected Mapping
compare(T instance, T reference, ConfigurationContext context)
T
configure(CNode c, ConfigurationContext context)
Configures/creates a Jenkins object based on a tree.protected void
configure(Mapping config, T instance, boolean dryrun, ConfigurationContext context)
Run configuration process on the target instanceprotected Attribute
createAttribute(String name, BaseConfigurator.TypePair type)
Set<Attribute<T,?>>
describe()
Determine the list of Attribute available for configuration of the managed component.boolean
equals(Object obj)
protected Set<String>
exclusions()
Attribute names that are detected by introspection but should be excludedprotected void
handleUnknown(Mapping config, ConfigurationContext context)
int
hashCode()
protected abstract T
instance(Mapping mapping, ConfigurationContext context)
Build or identify the target component this configurator has to handle based on the provided configuration node.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.jenkins.plugins.casc.Configurator
canConfigure, describe, describeStructure, getAttributes, getConfigurators, getDisplayName, getImplementedAPI, getName, getNames, getTarget
-
-
-
-
Method Detail
-
describe
@NonNull public Set<Attribute<T,?>> describe()
Description copied from interface:Configurator
Determine the list of Attribute available for configuration of the managed component.- Specified by:
describe
in interfaceConfigurator<T>
- Returns:
- A set of
Attribute
s that describes this object
-
exclusions
protected Set<String> exclusions()
Attribute names that are detected by introspection but should be excluded
-
createAttribute
protected Attribute createAttribute(String name, BaseConfigurator.TypePair type)
-
instance
protected abstract T instance(Mapping mapping, ConfigurationContext context) throws ConfiguratorException
Build or identify the target component this configurator has to handle based on the provided configuration node.- Parameters:
mapping
- configuration for target component. Implementation may consume some entries to create a fresh new instance.context
-- Returns:
- instance to be configured, but not yet fully configured, see
configure(Mapping, Object, boolean, ConfigurationContext)
- Throws:
ConfiguratorException
-
configure
@NonNull public T configure(CNode c, ConfigurationContext context) throws ConfiguratorException
Description copied from interface:Configurator
Configures/creates a Jenkins object based on a tree.- Specified by:
configure
in interfaceConfigurator<T>
- Parameters:
c
- Map/List/primitive objects (think YAML) that represents the configuration from which a Jenkins object is configured.- Returns:
- Fully configured Jenkins object that results from this configuration. if no new objects got created, but some existing objects may have been modified, return updated target object.
- Throws:
ConfiguratorException
- if something went wrong, depends on the concrete implementation
-
check
public T check(CNode c, ConfigurationContext context) throws ConfiguratorException
Description copied from interface:Configurator
Run the same logic asConfigurator.configure(CNode, ConfigurationContext)
in dry-run mode. Used to verify configuration is fine before being actually applied to a live jenkins controller.- Specified by:
check
in interfaceConfigurator<T>
- Throws:
ConfiguratorException
-
configure
protected void configure(Mapping config, T instance, boolean dryrun, ConfigurationContext context) throws ConfiguratorException
Run configuration process on the target instance- Parameters:
config
- configuration to apply. Can be partial ifinstance(Mapping, ConfigurationContext)
did already used some entriesinstance
- target instance to configuredryrun
- only check configuration is valid regarding target component. Don't actually apply changes to jenkins controller instancecontext
-- Throws:
ConfiguratorException
- something went wrong...
-
handleUnknown
protected final void handleUnknown(Mapping config, ConfigurationContext context) throws ConfiguratorException
- Throws:
ConfiguratorException
-
compare
@NonNull protected Mapping compare(T instance, T reference, ConfigurationContext context) throws Exception
- Throws:
Exception
-
-