/** As {@link #chain(Collection)}, but explicitly using ( ) grouping characters * to ensure exits are caught. */ public static String chainSubshell(Collection<String> commands) { // the spaces are not required, but it might be possible that a (( expr )) is interpreted differently // (won't hurt to have the spaces in any case!) return "( " + Strings.join(commands, " && ") + " )"; }
/** As {@link #alternatives(Collection)} */ public static String alternatives(String ...commands) { return "( " + Strings.join(commands, " || ") + " )"; }
/** * Returns a sequence of chained commands that runs until one of them fails (i.e. joined by '&&') * This currently runs as a subshell (so exits are swallowed) but behaviour may be changed imminently. * (Use {@link #chainGroup(Collection)} or {@link #chainSubshell(Collection)} to be clear.) */ public static String chain(Collection<String> commands) { return "( " + Strings.join(commands, " && ") + " )"; }
/** * Returns a sequence of chained commands that runs until one of them succeeds (i.e. joined by '||'). * This currently runs as a subshell (so exits are swallowed) but behaviour may be changed imminently. * (Use {@link #alternativesGroup(Collection)} or {@link #alternativesSubshell(Collection)} to be clear.) */ public static String alternatives(Collection<String> commands) { return "( " + Strings.join(commands, " || ") + " )"; }
/** As {@link #alternatives(Collection)}, but explicitly using ( ) grouping characters * to ensure exits are caught. */ public static String alternativesSubshell(Collection<String> commands) { // the spaces are not required, but it might be possible that a (( expr )) is interpreted differently // (won't hurt to have the spaces in any case!) return "( " + Strings.join(commands, " || ") + " )"; }
@Override public String apply(@Nullable Iterable<?> input) { return Strings.join(input, separator); } };
@Override public String apply(@Nullable Object[] input) { if (input == null) return Strings.EMPTY; return Strings.join(input, separator); } };
private String makeAsIndentedList(String yaml) { String[] lines = yaml.split("\n"); lines[0] = "- "+lines[0]; for (int i=1; i<lines.length; i++) lines[i] = " " + lines[i]; return Strings.join(lines, "\n"); }
private String makeAsIndentedObject(String yaml) { String[] lines = yaml.split("\n"); for (int i=0; i<lines.length; i++) lines[i] = " " + lines[i]; return Strings.join(lines, "\n"); }
/** @return true iff there are arguments; it also sys.errs a warning in that case */ protected boolean warnIfArguments() { if (arguments.isEmpty()) return false; stderr.println("Invalid subcommand arguments: "+Strings.join(arguments, " ")); return true; }
@Override public int run() { String scriptContents = toScript(props, commands, env); if (LOG.isTraceEnabled()) LOG.trace("Running shell command at {} as script: {}", host, scriptContents); copyTempFileToServer(ImmutableMap.of("permissions", "0700"), writeTempFile(scriptContents), scriptPath); String cmd = Strings.join(buildRunScriptCommand(), separator); return asInt(sshExec(props, cmd), -1); } }.run();
@Override public String apply(@Nullable ProcessTaskWrapper<?> input) { if (logger!=null) logger.info(input+" COMMANDS:\n"+Strings.join(input.getCommands(),"\n")); if (logger!=null) logger.info(input+" STDOUT:\n"+input.getStdout()); if (logger!=null) logger.info(input+" STDERR:\n"+input.getStderr()); if (requireZero && input.getExitCode()!=0) throw new IllegalStateException("non-zero exit code in "+input.getSummary()+": see log for more details!"); return input.getStdout(); } };
protected Builder xsltTransformerRecursiveCopyWithExtraRules(String ...rules) { String xsltTemplate = ResourceUtils.create(this).getResourceAsString("classpath://org/apache/brooklyn/core/mgmt/rebind/transformer/recursiveCopyWithExtraRules.xslt"); String xslt = TemplateProcessor.processTemplateContents(xsltTemplate, ImmutableMap.of("extra_rules", Strings.join(rules, "\n"))); return xsltTransformer(xslt); }
public void upload(Path zip) throws ParsingException, CSARVersionAlreadyExistsException { LOG.debug("Uploading type: " + zip); ParsingResult<Csar> types = archiveUploadService.upload(zip); if (ArchiveUploadService.hasError(types, ParsingErrorLevel.ERROR)) { throw new UserFacingException("Errors parsing types:\n" + Strings.join(types.getContext().getParsingErrors(), "\n ")); } }
/** returns a "groupId:artifactId:version:(classifier:)packaging" string * which maven refers to as the co-ordinate */ public String getCoordinate() { return Strings.join(MutableList.<String>of().append(groupId, artifactId, packaging). appendIfNotNull(classifier).append(version), ":"); }
protected RuntimeException logWithDetailsAndThrow(String message, Throwable optionalCause) { log.warn(message+" (throwing)"); Streams.logStreamTail(log, "STDERR of problem in "+Tasks.current(), stderr, 1024); Streams.logStreamTail(log, "STDOUT of problem in "+Tasks.current(), stdout, 1024); Streams.logStreamTail(log, "STDIN of problem in "+Tasks.current(), Streams.byteArrayOfString(Strings.join(getLines(),"\n")), 4096); if (optionalCause!=null) throw new IllegalStateException(message, optionalCause); throw new IllegalStateException(message); }
@Test public void testListCurrentCatalogItems() { LocalManagementContext mgmt = newManagementContext(BrooklynProperties.Factory.newDefault()); log.info("ITEMS\n"+Strings.join(mgmt.getCatalog().getCatalogItems(), "\n")); }
/** creates the TaskBuilder which can be further customized; typically invoked by the initial {@link #newTask()} */ public TaskBuilder<Object> constructCustomizedTaskBuilder() { TaskBuilder<Object> tb = TaskBuilder.builder().dynamic(false).displayName("ssh: "+getSummary()); tb.tag(BrooklynTaskTags.tagForStream(BrooklynTaskTags.STREAM_STDIN, Streams.byteArrayOfString(Strings.join(commands, "\n")))); tb.tag(BrooklynTaskTags.tagForEnvStream(BrooklynTaskTags.STREAM_ENV, shellEnvironment)); return tb; }
/** creates the command for running knife. * in some cases knife may be added multiple times, * and in that case the parameter here tells which time it is being added, * on a single run. */ protected String buildKnifeCommand(int knifeCommandIndex) { MutableList<String> words = new MutableList<String>(); words.add(knifeExecutable()); words.addAll(initialKnifeParameters()); words.addAll(knifeParameters()); String x = knifeConfigFileOption(); if (Strings.isNonBlank(x)) words.add(knifeConfigFileOption()); return Strings.join(words, " "); }
/** creates the command for running knife. * in some cases knife may be added multiple times, * and in that case the parameter here tells which time it is being added, * on a single run. */ protected String buildKnifeCommand(int knifeCommandIndex) { MutableList<String> words = new MutableList<String>(); words.add(knifeExecutable()); words.addAll(initialKnifeParameters()); words.addAll(knifeParameters()); String x = knifeConfigFileOption(); if (Strings.isNonBlank(x)) words.add(knifeConfigFileOption()); return Strings.join(words, " "); }