hudson.model.Describable Java Examples
The following examples show how to use
hudson.model.Describable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JenkinsRule.java From jenkins-test-harness with MIT License | 6 votes |
/** * Asserts that help files exist for the specified properties of the given instance. * * @param type * The describable class type that should have the associated help files. * @param properties * ','-separated list of properties whose help files should exist. */ public void assertHelpExists(final Class<? extends Describable> type, final String properties) throws Exception { executeOnServer(new Callable<Object>() { public Object call() throws Exception { Descriptor d = jenkins.getDescriptor(type); WebClient wc = createWebClient(); for (String property : listProperties(properties)) { String url = d.getHelpFile(property); assertThat("Help file for the property " + property + " is missing on " + type, url, Matchers.notNullValue()); wc.goTo(url); // make sure it successfully loads } return null; } }); }
Example #2
Source File: BaseConfigurator.java From configuration-as-code-plugin with MIT License | 5 votes |
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; }
Example #3
Source File: PipelineMetadataService.java From blueocean-plugin with MIT License | 5 votes |
private <T extends Describable<T>,D extends Descriptor<T>> void populateMetaSteps(List<Descriptor<?>> r, Class<T> c) { Jenkins j = Jenkins.getInstance(); for (Descriptor<?> d : j.getDescriptorList(c)) { if (SimpleBuildStep.class.isAssignableFrom(d.clazz) && symbolForObject(d) != null) { r.add(d); } else if (SimpleBuildWrapper.class.isAssignableFrom(d.clazz) && symbolForObject(d) != null) { r.add(d); } } }
Example #4
Source File: DockerDirectiveGeneratorTest.java From docker-workflow-plugin with MIT License | 5 votes |
private JSONObject staplerJsonForDescr(Describable d) { DescribableModel<?> m = DescribableModel.of(d.getClass()); JSONObject o = new JSONObject(); o.accumulate("stapler-class", d.getClass().getName()); o.accumulate("$class", d.getClass().getName()); if (d instanceof OptionalJobProperty) { o.accumulate("specified", true); } for (DescribableParameter param : m.getParameters()) { Object v = getValue(param, d); if (v != null) { if (v instanceof Describable) { o.accumulate(param.getName(), staplerJsonForDescr((Describable)v)); } else if (v instanceof List && !((List) v).isEmpty()) { JSONArray a = new JSONArray(); for (Object obj : (List) v) { if (obj instanceof Describable) { a.add(staplerJsonForDescr((Describable) obj)); } else if (obj instanceof Number) { a.add(obj.toString()); } else { a.add(obj); } } o.accumulate(param.getName(), a); } else if (v instanceof Number) { o.accumulate(param.getName(), v.toString()); } else { o.accumulate(param.getName(), v); } } } return o; }
Example #5
Source File: DotCiExtensionsHelper.java From DotCi with MIT License | 5 votes |
private <T extends Describable<T>, D extends Descriptor<T>> List<Descriptor<?>> getClassList(Class<T> c) { ArrayList<Descriptor<?>> r = new ArrayList<Descriptor<?>>(); if (jenkins == null) { return new ArrayList<Descriptor<?>>(); } for (Descriptor<?> d : jenkins.getDescriptorList(c)) { if (SimpleBuildStep.class.isAssignableFrom(d.clazz)) { r.add(d); } } return r; }
Example #6
Source File: HeteroDescribableConfigurator.java From configuration-as-code-plugin with MIT License | 4 votes |
@SuppressWarnings("unchecked") private CNode convertToNode(ConfigurationContext context, Configurator configurator, Describable instance) { return unchecked(() -> configurator.describe(instance, context)).apply(); }
Example #7
Source File: DescribableAttribute.java From configuration-as-code-plugin with MIT License | 4 votes |
public DescribableAttribute(String name, Class<? extends Describable> type) { super(name, type); }
Example #8
Source File: DefaultConfiguratorRegistry.java From configuration-as-code-plugin with MIT License | 4 votes |
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); } return lookup(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; }