use of io.jenkins.plugins.casc.impl.configurators.EnumConfigurator 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;
}
Aggregations