Search in sources :

Example 1 with DescribableAttribute

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

the class BaseConfigurator method createAttribute.

protected Attribute createAttribute(String name, final TypePair type) {
    boolean multiple = type.rawType.isArray() || Collection.class.isAssignableFrom(type.rawType);
    // If attribute is a Collection|Array of T, we need to introspect further to determine T
    Class c = multiple ? getComponentType(type) : type.rawType;
    if (c == null) {
        throw new IllegalStateException("Unable to detect type of attribute " + getTarget() + '#' + name);
    }
    // special collection types with dedicated handlers to manage data replacement / possible values
    if (DescribableList.class.isAssignableFrom(type.rawType)) {
        return new DescribableListAttribute(name, c);
    } else if (PersistedList.class.isAssignableFrom(type.rawType)) {
        return new PersistedListAttribute(name, c);
    }
    Attribute attribute;
    if (!c.isPrimitive() && !c.isEnum() && Modifier.isAbstract(c.getModifiers())) {
        if (!Describable.class.isAssignableFrom(c)) {
            // Not a Describable, so we don't know how to detect concrete implementation type
            LOGGER.warning("Can't handle " + getTarget() + "#" + name + ": type is abstract but not Describable.");
            return null;
        }
        attribute = new DescribableAttribute(name, c);
    } else {
        attribute = new Attribute(name, c);
    }
    attribute.multiple(multiple);
    return attribute;
}
Also used : PersistedListAttribute(io.jenkins.plugins.casc.impl.attributes.PersistedListAttribute) DescribableAttribute(io.jenkins.plugins.casc.impl.attributes.DescribableAttribute) PersistedListAttribute(io.jenkins.plugins.casc.impl.attributes.PersistedListAttribute) DescribableListAttribute(io.jenkins.plugins.casc.impl.attributes.DescribableListAttribute) Describable(hudson.model.Describable) DescribableAttribute(io.jenkins.plugins.casc.impl.attributes.DescribableAttribute) Collection(java.util.Collection) PersistedList(hudson.util.PersistedList) DescribableListAttribute(io.jenkins.plugins.casc.impl.attributes.DescribableListAttribute)

Aggregations

Describable (hudson.model.Describable)1 PersistedList (hudson.util.PersistedList)1 DescribableAttribute (io.jenkins.plugins.casc.impl.attributes.DescribableAttribute)1 DescribableListAttribute (io.jenkins.plugins.casc.impl.attributes.DescribableListAttribute)1 PersistedListAttribute (io.jenkins.plugins.casc.impl.attributes.PersistedListAttribute)1 Collection (java.util.Collection)1