本文整理汇总了Java中hudson.Launcher.ProcStarter类的典型用法代码示例。如果您正苦于以下问题:Java ProcStarter类的具体用法?Java ProcStarter怎么用?Java ProcStarter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProcStarter类属于hudson.Launcher包,在下文中一共展示了ProcStarter类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readFromProcess
import hudson.Launcher.ProcStarter; //导入依赖的package包/类
/**
* Executes a command and reads the result to a string. It uses the launcher to run the command to make sure the
* launcher decorator is used ie. docker.image step
*
* @param args command arguments
* @return output from the command
* @throws InterruptedException if interrupted
*/
@Nullable
private String readFromProcess(String... args) throws InterruptedException {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ProcStarter ps = launcher.launch();
Proc p = launcher.launch(ps.cmds(args).stdout(baos));
int exitCode = p.join();
if (exitCode == 0) {
return baos.toString(getComputer().getDefaultCharset().name()).replaceAll("[\t\r\n]+", " ").trim();
} else {
return null;
}
} catch (IOException e) {
e.printStackTrace(console.format("Error executing command '%s' : %s%n", Arrays.toString(args), e.getMessage()));
}
return null;
}
示例2: executeTest
import hudson.Launcher.ProcStarter; //导入依赖的package包/类
/**
* Used to execute/start a remote process that initializes the testing
* process.
*
* @param build
* the current build
* @param listener
* the build's listener
* @param entry
* containing the {@link Node} and its {@link EnvVars}
* @return the started process
* @throws InterruptedException
* @throws IOException
* @since 1.0
*/
private Proc executeTest(AbstractBuild<?, ?> build, BuildListener listener,
Entry<Node, EnvVars> entry) throws InterruptedException,
IOException {
final EnvVars vars = NodeUtils.getEnvironment(entry.getKey(),
entry.getValue());
final Node node = entry.getKey();
// Get testing environment on the specific node
FilePath testEnv = FilePathUtils.getPathToTestEnvOnNode(node, build);
// Create a remote launcher
RemoteLauncher remoteLaucher = new RemoteLauncher(listener,
node.getChannel(), true);
// Create process starter
ProcStarter starter = remoteLaucher.launch()
.cmds(buildShellCmds(vars, node, build)).stdout(listener)
.stderr(listener.getLogger()).pwd(testEnv.getParent());
// Launch the process
Proc proc = remoteLaucher.launch(starter);
return proc;
}
示例3: execute
import hudson.Launcher.ProcStarter; //导入依赖的package包/类
/**
* Execute a Drush command.
*/
protected boolean execute(ArgumentListBuilder args, TaskListener out) throws IOException, InterruptedException {
ProcStarter starter = launcher.launch().pwd(workspace).cmds(args);
if (out == null) {
// Output stdout/stderr into listener.
starter.stdout(listener);
} else {
// Output stdout into out.
// Do not output stderr since this breaks the XML formatting on stdout.
starter.stdout(out).stderr(NullOutputStream.NULL_OUTPUT_STREAM);
}
starter.join();
return true;
}
示例4: commandsEscaping
import hudson.Launcher.ProcStarter; //导入依赖的package包/类
@Test
public void commandsEscaping() {
ProcStarter procStarter = new DummyLauncher(null).launch();
procStarter = procStarter.cmds("$$$$", "$$?");
String[] commands = ContainerExecDecorator.getCommands(procStarter);
assertArrayEquals(new String[] { "\\$\\$", "\\$?" }, commands);
}
示例5: execCommand
import hudson.Launcher.ProcStarter; //导入依赖的package包/类
private ProcReturn execCommand(boolean quiet, String... cmd) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Launcher launcher = decorator
.decorate(new DummyLauncher(new StreamTaskListener(new TeeOutputStream(out, System.out))), null);
ContainerExecProc proc = (ContainerExecProc) launcher
.launch(launcher.new ProcStarter().pwd("/tmp").cmds(cmd).quiet(quiet));
// wait for proc to finish (shouldn't take long)
while (proc.isAlive()) {
Thread.sleep(100);
}
assertFalse("proc is alive", proc.isAlive());
int exitCode = proc.joinWithTimeout(10, TimeUnit.SECONDS, StreamTaskListener.fromStderr());
return new ProcReturn(proc, exitCode, out.toString());
}