Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.kuali.common.core.cli.plexus;
 
 import static com.google.common.base.Preconditions.checkState;
 import static com.google.common.base.Stopwatch.createStarted;
 import static java.lang.System.currentTimeMillis;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 import static org.kuali.common.core.cli.plexus.PlexusCLIUtils.executeCommandLine;
 import static org.kuali.common.util.base.Exceptions.illegalState;
 
public final class PlexusCLIService implements CommandLineService {
	private static final String[] EMPTY_STRING_ARRAY = {};
	public ExecResult execute(ExecRequest request) {
		Commandline cl = getCommandLine(request);
		try {
			int exitCode = executeCommandLine(clrequest);
			return validate(buildResult(exitCodesw), request.getSuccessCodes());
catch (CommandLineException e) {
			throw illegalState(e);
		}
	}
	public ExecResult execute(String executable) {
		return execute(executable, ImmutableList.<Stringof());
	}
	public ExecResult execute(String executableList<Stringargs) {
		ExecRequest request = ExecRequest.builder(executable).withArgs(args).build();
		return execute(request);
	}
	private ExecResult validate(ExecResult resultSet<IntegersuccessCodes) {
		boolean valid = successCodes.isEmpty() || successCodes.contains(result.getExitValue());
		checkState(valid"invalid exit value %s"result.getExitValue());
		return result;
	}
	private ExecResult buildResult(int exitValueStopwatch sw) {
		long stop = currentTimeMillis();
		long start = stop - sw.elapsed();
		return ExecResult.builder().withExitValue(exitValue).withStart(start).withStop(stop).build();
	}
	private Commandline getCommandLine(ExecRequest request) {
		Commandline cl = new Commandline();
		if (request.getShell().isPresent()) {
		}
		if (request.getWorkingDirectory().isPresent()) {
		}
		// Explicit environment variables "win" over system environment variables
		for (Map.Entry<StringStringpair : request.getEnvironmentVariables().entrySet()) {
			cl.addEnvironment(pair.getKey(), pair.getValue());
		}
		return cl;
	}
	private void addSystemEnvironmentVariables(Commandline clboolean add) {
		if (add) {
			try {
catch (Exception e) {
				throw illegalState(e);
			}
		}
	}
New to GrepCode? Check out our FAQ X