Search in sources :

Example 1 with DescriptorConfigurator

use of io.jenkins.plugins.casc.impl.configurators.DescriptorConfigurator in project configuration-as-code-plugin by jenkinsci.

the class RootElementConfigurator method all.

static List<RootElementConfigurator> all() {
    final Jenkins jenkins = Jenkins.get();
    List<RootElementConfigurator> configurators = new ArrayList<>(jenkins.getExtensionList(RootElementConfigurator.class));
    for (GlobalConfigurationCategory category : GlobalConfigurationCategory.all()) {
        configurators.add(new GlobalConfigurationCategoryConfigurator(category));
    }
    for (ManagementLink link : ManagementLink.all()) {
        final String name = link.getUrlName();
        final Descriptor descriptor = Jenkins.get().getDescriptor(name);
        if (descriptor != null)
            configurators.add(new DescriptorConfigurator(descriptor));
    }
    configurators.sort(Configurator.extensionOrdinalSort());
    return configurators;
}
Also used : Jenkins(jenkins.model.Jenkins) GlobalConfigurationCategoryConfigurator(io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator) ArrayList(java.util.ArrayList) ManagementLink(hudson.model.ManagementLink) DescriptorConfigurator(io.jenkins.plugins.casc.impl.configurators.DescriptorConfigurator) Descriptor(hudson.model.Descriptor) GlobalConfigurationCategory(jenkins.model.GlobalConfigurationCategory)

Example 2 with DescriptorConfigurator

use of io.jenkins.plugins.casc.impl.configurators.DescriptorConfigurator in project configuration-as-code-plugin by jenkinsci.

the class DefaultConfiguratorRegistry method internalLookup.

private Configurator internalLookup(Type type) {
    Class clazz = Types.erasure(type);
    final Jenkins jenkins = Jenkins.get();
    final ExtensionList<Configurator> l = jenkins.getExtensionList(Configurator.class);
    for (Configurator c : l) {
        if (c.canConfigure(clazz)) {
            // this type has a dedicated Configurator implementation
            return c;
        }
    }
    // TODO: Only try to cast if we can actually get the parameterized type
    if (Collection.class.isAssignableFrom(clazz) && type instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) type;
        Type actualType = pt.getActualTypeArguments()[0];
        if (actualType instanceof WildcardType) {
            actualType = ((WildcardType) actualType).getUpperBounds()[0];
        }
        if (actualType instanceof ParameterizedType) {
            actualType = ((ParameterizedType) actualType).getRawType();
        }
        if (!(actualType instanceof Class)) {
            throw new IllegalStateException("Can't handle " + type);
        }
        // cache is not reëntrant
        return internalLookup(actualType);
    }
    if (Configurable.class.isAssignableFrom(clazz)) {
        return new ConfigurableConfigurator(clazz);
    }
    if (Descriptor.class.isAssignableFrom(clazz)) {
        ExtensionList extensions = jenkins.getExtensionList(clazz);
        if (!extensions.isEmpty()) {
            return new DescriptorConfigurator((Descriptor) extensions.get(0));
        }
    }
    if (DataBoundConfigurator.getDataBoundConstructor(clazz) != null) {
        return new DataBoundConfigurator(clazz);
    }
    if (Modifier.isAbstract(clazz.getModifiers()) && Describable.class.isAssignableFrom(clazz)) {
        // this is a jenkins Describable component, with various implementations
        return new HeteroDescribableConfigurator(clazz);
    }
    if (Extension.class.isAssignableFrom(clazz)) {
        return new ExtensionConfigurator(clazz);
    }
    if (Stapler.lookupConverter(clazz) != null) {
        return new PrimitiveConfigurator(clazz);
    }
    if (clazz.isEnum()) {
        return new EnumConfigurator(clazz);
    }
    LOGGER.warning("Configuration-as-Code can't handle type " + type);
    return null;
}
Also used : ConfigurableConfigurator(io.jenkins.plugins.casc.impl.configurators.ConfigurableConfigurator) EnumConfigurator(io.jenkins.plugins.casc.impl.configurators.EnumConfigurator) Describable(hudson.model.Describable) DescriptorConfigurator(io.jenkins.plugins.casc.impl.configurators.DescriptorConfigurator) RootElementConfigurator(io.jenkins.plugins.casc.RootElementConfigurator) PrimitiveConfigurator(io.jenkins.plugins.casc.impl.configurators.PrimitiveConfigurator) HeteroDescribableConfigurator(io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator) DataBoundConfigurator(io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator) Configurator(io.jenkins.plugins.casc.Configurator) EnumConfigurator(io.jenkins.plugins.casc.impl.configurators.EnumConfigurator) ConfigurableConfigurator(io.jenkins.plugins.casc.impl.configurators.ConfigurableConfigurator) ExtensionConfigurator(io.jenkins.plugins.casc.impl.configurators.ExtensionConfigurator) DataBoundConfigurator(io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator) DescriptorConfigurator(io.jenkins.plugins.casc.impl.configurators.DescriptorConfigurator) Jenkins(jenkins.model.Jenkins) ParameterizedType(java.lang.reflect.ParameterizedType) WildcardType(java.lang.reflect.WildcardType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WildcardType(java.lang.reflect.WildcardType) ExtensionConfigurator(io.jenkins.plugins.casc.impl.configurators.ExtensionConfigurator) HeteroDescribableConfigurator(io.jenkins.plugins.casc.impl.configurators.HeteroDescribableConfigurator) ExtensionList(hudson.ExtensionList) Collection(java.util.Collection) PrimitiveConfigurator(io.jenkins.plugins.casc.impl.configurators.PrimitiveConfigurator)

Example 3 with DescriptorConfigurator

use of io.jenkins.plugins.casc.impl.configurators.DescriptorConfigurator in project configuration-as-code-plugin by jenkinsci.

the class MavenConfigurator method describe.

@NonNull
@Override
public Set<Attribute<GlobalMavenConfig, ?>> describe() {
    final Set<Attribute<GlobalMavenConfig, ?>> attributes = super.describe();
    final Descriptor descriptor = Jenkins.get().getDescriptorOrDie(Maven.class);
    final Configurator<Descriptor> task = new DescriptorConfigurator(descriptor);
    for (Attribute attribute : task.describe()) {
        attributes.add(new Attribute<GlobalMavenConfig, Object>(attribute.getName(), attribute.getType()).multiple(attribute.isMultiple()).getter(g -> attribute.getValue(descriptor)).setter((g, v) -> attribute.setValue(descriptor, v)));
    }
    return attributes;
}
Also used : Restricted(org.kohsuke.accmod.Restricted) Maven(hudson.tasks.Maven) Descriptor(hudson.model.Descriptor) ConfigurationContext(io.jenkins.plugins.casc.ConfigurationContext) Jenkins(jenkins.model.Jenkins) Configurator(io.jenkins.plugins.casc.Configurator) Set(java.util.Set) GlobalMavenConfig(jenkins.mvn.GlobalMavenConfig) NoExternalUse(org.kohsuke.accmod.restrictions.NoExternalUse) CNode(io.jenkins.plugins.casc.model.CNode) Mapping(io.jenkins.plugins.casc.model.Mapping) BaseConfigurator(io.jenkins.plugins.casc.BaseConfigurator) DescriptorConfigurator(io.jenkins.plugins.casc.impl.configurators.DescriptorConfigurator) NonNull(edu.umd.cs.findbugs.annotations.NonNull) Attribute(io.jenkins.plugins.casc.Attribute) Extension(hudson.Extension) CheckForNull(edu.umd.cs.findbugs.annotations.CheckForNull) GlobalConfiguration(jenkins.model.GlobalConfiguration) Attribute(io.jenkins.plugins.casc.Attribute) DescriptorConfigurator(io.jenkins.plugins.casc.impl.configurators.DescriptorConfigurator) Descriptor(hudson.model.Descriptor) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Aggregations

DescriptorConfigurator (io.jenkins.plugins.casc.impl.configurators.DescriptorConfigurator)3 Jenkins (jenkins.model.Jenkins)3 Descriptor (hudson.model.Descriptor)2 Configurator (io.jenkins.plugins.casc.Configurator)2 CheckForNull (edu.umd.cs.findbugs.annotations.CheckForNull)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 Extension (hudson.Extension)1 ExtensionList (hudson.ExtensionList)1 Describable (hudson.model.Describable)1 ManagementLink (hudson.model.ManagementLink)1 Maven (hudson.tasks.Maven)1 Attribute (io.jenkins.plugins.casc.Attribute)1 BaseConfigurator (io.jenkins.plugins.casc.BaseConfigurator)1 ConfigurationContext (io.jenkins.plugins.casc.ConfigurationContext)1 RootElementConfigurator (io.jenkins.plugins.casc.RootElementConfigurator)1 ConfigurableConfigurator (io.jenkins.plugins.casc.impl.configurators.ConfigurableConfigurator)1 DataBoundConfigurator (io.jenkins.plugins.casc.impl.configurators.DataBoundConfigurator)1 EnumConfigurator (io.jenkins.plugins.casc.impl.configurators.EnumConfigurator)1 ExtensionConfigurator (io.jenkins.plugins.casc.impl.configurators.ExtensionConfigurator)1 GlobalConfigurationCategoryConfigurator (io.jenkins.plugins.casc.impl.configurators.GlobalConfigurationCategoryConfigurator)1