@Nonnull public List<DirectiveDescriptor> getDirectives() { return DirectiveDescriptor.all(); }
@Override @Nonnull public List<Descriptor> getDescriptors() { return ExtensionList.lookup(ParameterDefinition.ParameterDescriptor.class).stream() .filter(d -> DirectiveDescriptor.symbolForDescriptor(d) != null) .sorted(Comparator.comparing(d -> DirectiveDescriptor.symbolForDescriptor(d))) .collect(Collectors.toList()); }
public final String toGroovy(boolean indent) { Descriptor d = getDescriptor(); if (d instanceof DirectiveDescriptor) { if (indent) { return ((DirectiveDescriptor) d).toIndentedGroovy(this); } else { return ((DirectiveDescriptor) d).toGroovy(this); } } else { return "// Not a valid descriptor"; } } }
@Restricted(DoNotUse.class) // accessed via REST API public HttpResponse doGenerateDirective(StaplerRequest req, @QueryParameter String json) throws Exception { // TODO is there not an easier way to do this? Maybe Descriptor.newInstancesFromHeteroList on a one-element JSONArray? JSONObject jsonO = JSONObject.fromObject(json); Jenkins j = Jenkins.getActiveInstance(); Class<?> c = j.getPluginManager().uberClassLoader.loadClass(jsonO.getString("stapler-class")); DirectiveDescriptor descriptor = (DirectiveDescriptor)j.getDescriptor(c.asSubclass(AbstractDirective.class)); if (descriptor == null) { return HttpResponses.plainText("<could not find " + c.getName() + ">"); } Object o; try { o = descriptor.newInstance(req, jsonO); } catch (RuntimeException x) { // e.g. IllegalArgumentException return HttpResponses.plainText(Functions.printThrowable(x)); } try { String groovy = descriptor.toIndentedGroovy((AbstractDirective)o); return HttpResponses.plainText(groovy); } catch (UnsupportedOperationException x) { LOGGER.log(Level.WARNING, "failed to render " + json, x); return HttpResponses.plainText(x.getMessage()); } }
@Nonnull public final String toIndentedGroovy(@Nonnull T directive) { return ModelASTPipelineDef.toIndentedGroovy(toGroovy(directive)); }
@Override @Nonnull public List<Descriptor> getDescriptors() { return ExtensionList.lookup(TriggerDescriptor.class).stream() .filter(d -> DirectiveDescriptor.symbolForDescriptor(d) != null) .sorted(Comparator.comparing(d -> DirectiveDescriptor.symbolForDescriptor(d))) .collect(Collectors.toList()); }
.filter(d -> DirectiveDescriptor.symbolForDescriptor(d) != null) .sorted(Comparator.comparing(d -> DirectiveDescriptor.symbolForDescriptor(d))) .collect(Collectors.toList());