Search in sources :

Example 26 with CommandLine

use of com.thoughtworks.go.util.command.CommandLine in project gocd by gocd.

the class P4CommandTestBase method shouldBombForNonZeroReturnCode.

@Test
public void shouldBombForNonZeroReturnCode() throws Exception {
    ProcessOutputStreamConsumer outputStreamConsumer = Mockito.mock(ProcessOutputStreamConsumer.class);
    CommandLine line = Mockito.mock(CommandLine.class);
    when(line.run(outputStreamConsumer, null, "foo")).thenReturn(1);
    try {
        p4.execute(line, "foo", outputStreamConsumer, true);
        fail("did't bomb for non zero return code");
    } catch (Exception ignored) {
    }
    verify(line).run(outputStreamConsumer, null, "foo");
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine) ProcessOutputStreamConsumer(com.thoughtworks.go.util.command.ProcessOutputStreamConsumer) Test(org.junit.Test)

Example 27 with CommandLine

use of com.thoughtworks.go.util.command.CommandLine in project gocd by gocd.

the class CommandBuilderTest method commandWithArgsList_shouldAddCmdBeforeAWindowsCommand.

@Test
@RunIf(value = EnhancedOSChecker.class, arguments = { EnhancedOSChecker.WINDOWS })
public void commandWithArgsList_shouldAddCmdBeforeAWindowsCommand() {
    String[] args = { "some thing" };
    CommandBuilderWithArgList commandBuilderWithArgList = new CommandBuilderWithArgList("echo", args, tempWorkDir, null, null, "some desc");
    CommandLine commandLine = commandBuilderWithArgList.buildCommandLine();
    assertThat(commandLine.toStringForDisplay(), is("cmd /c echo some thing"));
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine) RunIf(com.googlecode.junit.ext.RunIf) Test(org.junit.Test)

Example 28 with CommandLine

use of com.thoughtworks.go.util.command.CommandLine in project gocd by gocd.

the class HgTestRepo method hgAt.

private CommandLine hgAt(File workingFolder, String... arguments) {
    CommandLine hg = CommandLine.createCommandLine("hg").withArgs(arguments).withEncoding("utf-8");
    hg.setWorkingDir(workingFolder);
    return hg;
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine)

Example 29 with CommandLine

use of com.thoughtworks.go.util.command.CommandLine in project gocd by gocd.

the class SvnRemoteRepository method start.

public void start() throws Exception {
    if (processWrapper != null) {
        throw new RuntimeException("Cannot start repository twice!");
    }
    port = RandomPort.find(toString());
    CommandLine svnserve = CommandLine.createCommandLine("svnserve").withArgs("-d", "--foreground", "--listen-port", Integer.toString(port), "-r", repo.projectRepositoryRoot().getCanonicalPath()).withEncoding("utf-8");
    consumer = inMemoryConsumer();
    processWrapper = svnserve.execute(consumer, new EnvironmentVariableContext(), null);
    RandomPort.waitForPort(port);
    if (!processWrapper.isRunning()) {
        throw new RuntimeException("Could not run command " + svnserve);
    }
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext)

Example 30 with CommandLine

use of com.thoughtworks.go.util.command.CommandLine in project gocd by gocd.

the class ExecCommandExecutor method createCommandLine.

private CommandLine createCommandLine(String cmd, String consoleLogCharset) {
    CommandLine commandLine;
    if (SystemUtils.IS_OS_WINDOWS) {
        commandLine = CommandLine.createCommandLine("cmd");
        commandLine.withArg("/c");
        commandLine.withArg(StringUtils.replace(cmd, "/", "\\"));
    } else {
        commandLine = CommandLine.createCommandLine(cmd);
    }
    commandLine.withEncoding(consoleLogCharset);
    return commandLine;
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine)

Aggregations

CommandLine (com.thoughtworks.go.util.command.CommandLine)31 Test (org.junit.Test)16 InMemoryStreamConsumer (com.thoughtworks.go.util.command.InMemoryStreamConsumer)6 ConsoleResult (com.thoughtworks.go.util.command.ConsoleResult)5 File (java.io.File)5 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)3 CommandLineException (com.thoughtworks.go.util.command.CommandLineException)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 RunIf (com.googlecode.junit.ext.RunIf)2 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)2 ProcessOutputStreamConsumer (com.thoughtworks.go.util.command.ProcessOutputStreamConsumer)2 LinkedList (java.util.LinkedList)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 CheckedCommandLineException (com.thoughtworks.go.util.command.CheckedCommandLineException)1 CompositeConsumer (com.thoughtworks.go.util.command.CompositeConsumer)1 CruiseControlException (com.thoughtworks.go.util.command.CruiseControlException)1 ExecScript (com.thoughtworks.go.util.command.ExecScript)1 UrlArgument (com.thoughtworks.go.util.command.UrlArgument)1 IOException (java.io.IOException)1