Search in sources :

Example 1 with HeterogeneousObjectType

use of org.jenkinsci.plugins.structs.describable.HeterogeneousObjectType in project workflow-cps-plugin by jenkinsci.

the class Snippetizer method getQuasiDescriptors.

@Restricted(NoExternalUse.class)
public Collection<QuasiDescriptor> getQuasiDescriptors(boolean advanced) {
    TreeSet<QuasiDescriptor> t = new TreeSet<>();
    for (StepDescriptor d : StepDescriptor.all()) {
        if (d.isAdvanced() == advanced) {
            t.add(new QuasiDescriptor(d));
            if (d.isMetaStep()) {
                DescribableModel<?> m = DescribableModel.of(d.clazz);
                Collection<DescribableParameter> parameters = m.getParameters();
                if (parameters.size() == 1) {
                    DescribableParameter delegate = parameters.iterator().next();
                    if (delegate.isRequired()) {
                        if (delegate.getType() instanceof HeterogeneousObjectType) {
                            // TODO HeterogeneousObjectType does not yet expose symbol information, and DescribableModel.symbolOf is private
                            for (DescribableModel<?> delegateOptionSchema : ((HeterogeneousObjectType) delegate.getType()).getTypes().values()) {
                                Class<?> delegateOptionType = delegateOptionSchema.getType();
                                Descriptor<?> delegateDescriptor = Jenkins.getActiveInstance().getDescriptorOrDie(delegateOptionType.asSubclass(Describable.class));
                                Set<String> symbols = SymbolLookup.getSymbolValue(delegateDescriptor);
                                if (!symbols.isEmpty()) {
                                    t.add(new QuasiDescriptor(delegateDescriptor));
                                }
                            }
                        }
                    }
                }
            // TODO currently not handling metasteps with other parameters, either required or (like GenericSCMStep) not
            }
        }
    }
    return t;
}
Also used : DescribableParameter(org.jenkinsci.plugins.structs.describable.DescribableParameter) UninstantiatedDescribable(org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable) Describable(hudson.model.Describable) TreeSet(java.util.TreeSet) HeterogeneousObjectType(org.jenkinsci.plugins.structs.describable.HeterogeneousObjectType) BuildStepDescriptor(hudson.tasks.BuildStepDescriptor) StepDescriptor(org.jenkinsci.plugins.workflow.steps.StepDescriptor) Restricted(org.kohsuke.accmod.Restricted)

Aggregations

Describable (hudson.model.Describable)1 BuildStepDescriptor (hudson.tasks.BuildStepDescriptor)1 TreeSet (java.util.TreeSet)1 DescribableParameter (org.jenkinsci.plugins.structs.describable.DescribableParameter)1 HeterogeneousObjectType (org.jenkinsci.plugins.structs.describable.HeterogeneousObjectType)1 UninstantiatedDescribable (org.jenkinsci.plugins.structs.describable.UninstantiatedDescribable)1 StepDescriptor (org.jenkinsci.plugins.workflow.steps.StepDescriptor)1 Restricted (org.kohsuke.accmod.Restricted)1