Search in sources :

Example 1 with ProcessOutputStreamConsumer

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

the class ProcessWrapperTest method shouldThrowExceptionWhenExecutableDoesNotExist.

@Test
public void shouldThrowExceptionWhenExecutableDoesNotExist() throws IOException {
    CommandLine line = CommandLine.createCommandLine("doesnotexist");
    try {
        ProcessOutputStreamConsumer outputStreamConsumer = inMemoryConsumer();
        line.execute(outputStreamConsumer, new EnvironmentVariableContext(), null);
        fail("Expected exception");
    } catch (CommandLineException e) {
        assertThat(e.getMessage(), containsString("Make sure this command can execute manually."));
        assertThat(e.getMessage(), containsString("doesnotexist"));
        assertThat(e.getResult(), notNullValue());
    }
}
Also used : CommandLine(com.thoughtworks.go.util.command.CommandLine) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) ProcessOutputStreamConsumer(com.thoughtworks.go.util.command.ProcessOutputStreamConsumer) CommandLineException(com.thoughtworks.go.util.command.CommandLineException) Test(org.junit.Test)

Example 2 with ProcessOutputStreamConsumer

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

the class BuildSession method newSafeConsole.

private SafeOutputStreamConsumer newSafeConsole() {
    ProcessOutputStreamConsumer processConsumer = new ProcessOutputStreamConsumer<>(console, console);
    SafeOutputStreamConsumer streamConsumer = new SafeOutputStreamConsumer(processConsumer);
    for (String secret : secretSubstitutions.keySet()) {
        streamConsumer.addSecret(new SecretSubstitution(secret, secretSubstitutions.get(secret)));
    }
    return streamConsumer;
}
Also used : SafeOutputStreamConsumer(com.thoughtworks.go.util.command.SafeOutputStreamConsumer) ProcessOutputStreamConsumer(com.thoughtworks.go.util.command.ProcessOutputStreamConsumer)

Example 3 with ProcessOutputStreamConsumer

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

the class MaterialAgentFactoryTest method shouldCreateMaterialAgent_withAgentsUuidAsSubprocessExecutionContextNamespace.

@Test
public void shouldCreateMaterialAgent_withAgentsUuidAsSubprocessExecutionContextNamespace() throws IOException {
    String agentUuid = "uuid-01783738";
    File workingDirectory = temporaryFolder.newFolder();
    MaterialAgentFactory factory = new MaterialAgentFactory(new ProcessOutputStreamConsumer(new DevNull(), new DevNull()), workingDirectory, new AgentIdentifier("host", "1.1.1.1", agentUuid), packageRepositoryExtension, scmExtension);
    GitMaterial gitMaterial = new GitMaterial("http://foo", "master", "dest_folder");
    MaterialAgent agent = factory.createAgent(new MaterialRevision(gitMaterial));
    assertThat(agent, is(instanceOf(AbstractMaterialAgent.class)));
    SubprocessExecutionContext execCtx = (SubprocessExecutionContext) ReflectionUtil.getField(agent, "execCtx");
    assertThat(execCtx.getProcessNamespace("fingerprint"), is(CachedDigestUtils.sha256Hex(String.format("%s%s%s", "fingerprint", agentUuid, gitMaterial.workingdir(workingDirectory)))));
}
Also used : GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) DevNull(com.thoughtworks.go.util.command.DevNull) SubprocessExecutionContext(com.thoughtworks.go.config.materials.SubprocessExecutionContext) AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) PluggableSCMMaterialAgent(com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialAgent) PackageMaterialAgent(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialAgent) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) File(java.io.File) ProcessOutputStreamConsumer(com.thoughtworks.go.util.command.ProcessOutputStreamConsumer) Test(org.junit.Test)

Example 4 with ProcessOutputStreamConsumer

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

the class TfsExecutorTest method createBuildSession.

private void createBuildSession() {
    AgentIdentifier agentIdentifier = mock(AgentIdentifier.class);
    when(workingDir.getAbsolutePath()).thenReturn("working dir");
    ProcessOutputStreamConsumer processOutputStreamConsumer = mock(ProcessOutputStreamConsumer.class);
    buildSession = mock(BuildSession.class);
    when(buildSession.resolveRelativeDir("working dir")).thenReturn(workingDir);
    when(buildSession.getAgentIdentifier()).thenReturn(agentIdentifier);
    when(buildSession.processOutputStreamConsumer()).thenReturn(processOutputStreamConsumer);
}
Also used : AgentIdentifier(com.thoughtworks.go.remote.AgentIdentifier) ProcessOutputStreamConsumer(com.thoughtworks.go.util.command.ProcessOutputStreamConsumer)

Example 5 with ProcessOutputStreamConsumer

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

the class SvnTestRepo method checkInOneFile.

public void checkInOneFile(String fileName, SvnMaterial svnMaterial) throws Exception {
    final File baseDir = temporaryFolder.newFolder();
    tmpFolders.add(baseDir);
    ProcessOutputStreamConsumer consumer = inMemoryConsumer();
    Revision revision = latestRevision(svnMaterial, baseDir, new TestSubprocessExecutionContext());
    svnMaterial.updateTo(consumer, baseDir, new RevisionContext(revision), new TestSubprocessExecutionContext());
    File workingDir = new File(baseDir, svnMaterial.getFolder());
    File newFileToAdd = new File(workingDir, fileName);
    newFileToAdd.getParentFile().mkdirs();
    FileUtils.writeStringToFile(newFileToAdd, "", UTF_8);
    svnMaterial.add(consumer, newFileToAdd);
    svnMaterial.commit(consumer, workingDir, "adding file [" + svnMaterial.getFolder() + "/" + fileName + "]");
}
Also used : File(java.io.File) ProcessOutputStreamConsumer(com.thoughtworks.go.util.command.ProcessOutputStreamConsumer)

Aggregations

ProcessOutputStreamConsumer (com.thoughtworks.go.util.command.ProcessOutputStreamConsumer)7 Test (org.junit.Test)3 AgentIdentifier (com.thoughtworks.go.remote.AgentIdentifier)2 CommandLine (com.thoughtworks.go.util.command.CommandLine)2 File (java.io.File)2 SubprocessExecutionContext (com.thoughtworks.go.config.materials.SubprocessExecutionContext)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)1 PackageMaterialAgent (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialAgent)1 PluggableSCMMaterialAgent (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialAgent)1 CommandLineException (com.thoughtworks.go.util.command.CommandLineException)1 DevNull (com.thoughtworks.go.util.command.DevNull)1 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)1 SafeOutputStreamConsumer (com.thoughtworks.go.util.command.SafeOutputStreamConsumer)1