/** * Short-hand for the top-level invocation. */ static String step2Groovy(Step s) throws UnsupportedOperationException { return object2Groovy(new StringBuilder(), s, false).toString(); }
/** * Publicly accessible version of {@link #object2Groovy(StringBuilder, Object, boolean)} that translates an object into * the equivalent Pipeline Groovy string. * * @param o The object to translate. * @return A string translation of the object. */ public static String object2Groovy(Object o) throws UnsupportedOperationException { return object2Groovy(new StringBuilder(), o, false).toString(); }
private static StringBuilder list2groovy(StringBuilder b, List<?> o) { b.append('['); boolean first = true; for (Object elt : o) { if (first) { first = false; } else { b.append(", "); } object2Groovy(b, elt, true); } return b.append(']'); }
@Override @Nonnull public String toGroovy(@Nonnull TriggersDirective directive) { StringBuilder result = new StringBuilder("triggers {\n"); for (Trigger trigger : directive.triggers) { result.append(Snippetizer.object2Groovy(UninstantiatedDescribable.from(trigger))); result.append("\n"); } result.append("}\n"); return result.toString(); } }
@Override @Nonnull public String toGroovy(@Nonnull ParametersDirective directive) { StringBuilder result = new StringBuilder("parameters {\n"); for (ParameterDefinition param : directive.parameters) { result.append(Snippetizer.object2Groovy(UninstantiatedDescribable.from(param))); result.append("\n"); } result.append("}\n"); return result.toString(); } }
private static void mapWithoutBracket2groovy(StringBuilder b, Map<?, ?> map) { boolean first = true; for (Entry<?, ?> entry : map.entrySet()) { if (first) { first = false; } else { b.append(", "); } Object key = entry.getKey(); if (key instanceof String && SourceVersion.isName((String) key)) { b.append(key); } else { object2Groovy(b, key, true); } b.append(": "); object2Groovy(b, entry.getValue(), true); } }
@Override @Nonnull public String toGroovy(@Nonnull OptionsDirective directive) { StringBuilder result = new StringBuilder("options {\n"); for (Describable d : directive.options) { if (d instanceof Step) { String origGroovy = Snippetizer.object2Groovy(d); // Need to remove the block bit since we're cheating. result.append(origGroovy.substring(0, origGroovy.length() - " {\n // some block\n}".length())); result.append("\n"); } else { result.append(Snippetizer.object2Groovy(UninstantiatedDescribable.from(d))); result.append("\n"); } } result.append("}\n"); return result.toString(); } }
@Override @Nonnull public String toGroovy(@Nonnull LibrariesDirective directive) { StringBuilder result = new StringBuilder("libraries {\n"); if (!directive.getLibs().isEmpty()) { for (NameAndVersion l : directive.getLibs()) { result.append("lib(").append(Snippetizer.object2Groovy(l.getLibString())).append(")\n"); } } else { result.append("// No libraries specified\n"); } result.append("}\n"); return result.toString(); }
@Override @Nonnull public String toGroovy(@Nonnull ToolsDirective directive) { StringBuilder result = new StringBuilder("tools {\n"); if (!directive.getTools().isEmpty()) { for (ToolInstallation tool : directive.getToolInstallations()) { result.append(DirectiveGenerator.getSymbolForDescriptor(tool.getDescriptor())).append(" "); result.append(Snippetizer.object2Groovy(tool.getName())).append("\n"); } } else { result.append("// No valid tools specified\n"); } result.append("}\n"); return result.toString(); } }
@Restricted(NoExternalUse.class) public static String mapToClosure(Map<String,?> args) { StringBuilder result = new StringBuilder("{\n"); for (Map.Entry<String,?> arg : args.entrySet()) { if (!(arg.getValue() instanceof String && arg.getValue().equals(""))) { result.append(arg.getKey()).append(" "); if (arg.getValue() instanceof Map) { result.append(mapToClosure((Map<String, ?>) arg.getValue())); } else if (arg.getValue() instanceof UninstantiatedDescribable) { result.append(mapToClosure(((UninstantiatedDescribable) arg.getValue()).getArguments())); } else if (arg.getValue() != null) { result.append(Snippetizer.object2Groovy(arg.getValue())).append("\n"); } } } result.append("}\n"); return result.toString(); }
@Nonnull private String conditionalToGroovy(@Nonnull DeclarativeStageConditional<?> conditional) { DeclarativeStageConditionalDescriptor descriptor = conditional.getDescriptor(); if (descriptor.getAllowedChildrenCount() == 0) { return Snippetizer.object2Groovy(UninstantiatedDescribable.from(conditional)) + "\n"; } else { StringBuilder result = new StringBuilder(); result.append(descriptor.getName()).append(" {\n"); for (DeclarativeStageConditional c : conditional.getChildren()) { result.append(conditionalToGroovy(c)); } result.append("}\n"); return result.toString(); } } }
if (directive.getMessage() != null) { StringBuilder result = new StringBuilder("input {\n"); result.append("message ").append(Snippetizer.object2Groovy(directive.getMessage())).append("\n"); if (!StringUtils.isEmpty(directive.getId())) { result.append("id ").append(Snippetizer.object2Groovy(directive.getId())).append("\n"); result.append("ok ").append(Snippetizer.object2Groovy(directive.getOk())).append("\n"); result.append("submitter ").append(Snippetizer.object2Groovy(directive.getSubmitter())).append("\n"); result.append("submitterParameter ").append(Snippetizer.object2Groovy(directive.getSubmitterParameter())).append("\n"); result.append(Snippetizer.object2Groovy(UninstantiatedDescribable.from(p))).append("\n");
object2Groovy(b, args.values().iterator().next(), true); } else {
} else if (model.hasSingleRequiredParameter() && ud.getArguments().size() == 1) { result.append(Snippetizer.object2Groovy(ud)).append("\n"); } else {