Search in sources :

Example 16 with DefaultProcessExecutor

use of com.facebook.buck.util.DefaultProcessExecutor in project buck by facebook.

the class RageCommandIntegrationTest method testExtraInfo.

@Test
public void testExtraInfo() throws Exception {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "interactive_report", temporaryFolder);
    workspace.setUp();
    RageConfig rageConfig = createRageConfig(0, "python, extra.py", RageProtocolVersion.SIMPLE);
    ProjectFilesystem filesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    Console console = new TestConsole();
    CapturingDefectReporter defectReporter = new CapturingDefectReporter();
    AutomatedReport automatedReport = new AutomatedReport(defectReporter, filesystem, ObjectMappers.newDefaultInstance(), new TestConsole(), TestBuildEnvironmentDescription.INSTANCE, VcsInfoCollector.create(new NoOpCmdLineInterface()), rageConfig, new DefaultExtraInfoCollector(rageConfig, filesystem, new DefaultProcessExecutor(console)));
    automatedReport.collectAndSubmitResult();
    DefectReport defectReport = defectReporter.getDefectReport();
    assertThat(defectReport.getExtraInfo(), Matchers.equalTo(Optional.of("Extra\n")));
    assertThat(FluentIterable.from(defectReport.getIncludedPaths()).transform(Object::toString), Matchers.hasItem(Matchers.endsWith("extra.txt")));
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) NoOpCmdLineInterface(com.facebook.buck.util.versioncontrol.NoOpCmdLineInterface) Console(com.facebook.buck.util.Console) TestConsole(com.facebook.buck.testutil.TestConsole) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) Test(org.junit.Test)

Example 17 with DefaultProcessExecutor

use of com.facebook.buck.util.DefaultProcessExecutor in project buck by facebook.

the class PythonTestIntegrationTest method assumePythonVersionIsAtLeast.

private void assumePythonVersionIsAtLeast(String expectedVersion, String message) throws InterruptedException {
    PythonVersion actualVersion = new PythonBuckConfig(FakeBuckConfig.builder().build(), new ExecutableFinder()).getPythonEnvironment(new DefaultProcessExecutor(new TestConsole())).getPythonVersion();
    assumeTrue(String.format("Needs at least Python-%s, but found Python-%s: %s", expectedVersion, actualVersion, message), new VersionStringComparator().compare(actualVersion.getVersionString(), expectedVersion) >= 0);
}
Also used : ExecutableFinder(com.facebook.buck.io.ExecutableFinder) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) VersionStringComparator(com.facebook.buck.util.VersionStringComparator) TestConsole(com.facebook.buck.testutil.TestConsole)

Example 18 with DefaultProcessExecutor

use of com.facebook.buck.util.DefaultProcessExecutor in project buck by facebook.

the class TestCellBuilder method build.

public Cell build() throws IOException, InterruptedException {
    ProcessExecutor executor = new DefaultProcessExecutor(new TestConsole());
    BuckConfig config = buckConfig == null ? FakeBuckConfig.builder().setFilesystem(filesystem).build() : buckConfig;
    KnownBuildRuleTypesFactory typesFactory = new KnownBuildRuleTypesFactory(executor, androidDirectoryResolver);
    if (parserFactory == null) {
        return CellProvider.createForLocalBuild(filesystem, watchman, config, cellConfig, typesFactory).getCellByPath(filesystem.getRootPath());
    }
    // The constructor for `Cell` is private, and it's in such a central location I don't really
    // want to make it public. Brace yourselves.
    Enhancer enhancer = new Enhancer();
    enhancer.setSuperclass(Cell.class);
    enhancer.setCallback((MethodInterceptor) (obj, method, args, proxy) -> {
        if ("createBuildFileParserFactory".equals(method.getName())) {
            return parserFactory;
        }
        return proxy.invokeSuper(obj, args);
    });
    return (Cell) enhancer.create();
}
Also used : MethodInterceptor(net.sf.cglib.proxy.MethodInterceptor) FakeAndroidDirectoryResolver(com.facebook.buck.android.FakeAndroidDirectoryResolver) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) IOException(java.io.IOException) ProjectBuildFileParserFactory(com.facebook.buck.json.ProjectBuildFileParserFactory) Watchman(com.facebook.buck.io.Watchman) NULL_WATCHMAN(com.facebook.buck.io.Watchman.NULL_WATCHMAN) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) BuckConfig(com.facebook.buck.cli.BuckConfig) CellConfig(com.facebook.buck.config.CellConfig) TestConsole(com.facebook.buck.testutil.TestConsole) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) AndroidDirectoryResolver(com.facebook.buck.android.AndroidDirectoryResolver) Enhancer(net.sf.cglib.proxy.Enhancer) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) Nullable(javax.annotation.Nullable) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) Enhancer(net.sf.cglib.proxy.Enhancer) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) TestConsole(com.facebook.buck.testutil.TestConsole)

Example 19 with DefaultProcessExecutor

use of com.facebook.buck.util.DefaultProcessExecutor in project buck by facebook.

the class WorkerProcessTest method testDoesNotBlockOnLargeStderr.

@Test(timeout = 20 * 1000)
public void testDoesNotBlockOnLargeStderr() throws IOException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "worker_process", temporaryPaths);
    workspace.setUp();
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(workspace.getDestPath());
    Console console = new Console(Verbosity.ALL, System.out, System.err, Ansi.withoutTty());
    String script;
    if (Platform.detect() == Platform.WINDOWS) {
        script = workspace.getDestPath().resolve("script.bat").toString();
    } else {
        script = "./script.py";
    }
    WorkerProcess workerProcess = new WorkerProcess(new DefaultProcessExecutor(console), ProcessExecutorParams.builder().setCommand(ImmutableList.of(script)).setDirectory(workspace.getDestPath()).build(), projectFilesystem, temporaryPaths.newFolder());
    try {
        workerProcess.ensureLaunchAndHandshake();
        fail("Handshake should have failed");
    } catch (HumanReadableException e) {
        // Check that all of the process's stderr was reported.
        assertThat(e.getMessage().length(), is(greaterThan(1024 * 1024)));
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) HumanReadableException(com.facebook.buck.util.HumanReadableException) Console(com.facebook.buck.util.Console) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 20 with DefaultProcessExecutor

use of com.facebook.buck.util.DefaultProcessExecutor in project buck by facebook.

the class SymlinkFileStepTest method testReplaceMalformedSymlink.

@Test
public void testReplaceMalformedSymlink() throws IOException, InterruptedException {
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    // Run `ln -s /path/that/does/not/exist dummy` in /tmp.
    ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(ImmutableList.of("ln", "-s", "/path/that/does/not/exist", "my_symlink")).setDirectory(tmpDir.getRoot().toPath()).build();
    ProcessExecutor executor = new DefaultProcessExecutor(Console.createNullConsole());
    executor.launchAndExecute(params);
    // Verify that the symlink points to a non-existent file.
    Path symlink = Paths.get(tmpDir.getRoot().getAbsolutePath(), "my_symlink");
    assertFalse("exists() should reflect the existence of what the symlink points to", symlink.toFile().exists());
    assertTrue("even though exists() is false, isSymbolicLink should be true", java.nio.file.Files.isSymbolicLink(symlink));
    // Create an ExecutionContext to return the ProjectFilesystem.
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(tmpDir.getRoot().toPath());
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    tmpDir.newFile("dummy");
    SymlinkFileStep symlinkStep = new SymlinkFileStep(projectFilesystem, /* source */
    Paths.get("dummy"), /* target */
    Paths.get("my_symlink"), /* useAbsolutePaths*/
    true);
    int exitCode = symlinkStep.execute(executionContext).getExitCode();
    assertEquals(0, exitCode);
    assertTrue(java.nio.file.Files.isSymbolicLink(symlink));
    assertTrue(symlink.toFile().exists());
}
Also used : Path(java.nio.file.Path) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) Test(org.junit.Test)

Aggregations

DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)37 TestConsole (com.facebook.buck.testutil.TestConsole)27 Test (org.junit.Test)21 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)20 Path (java.nio.file.Path)13 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)8 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)7 ExecutableFinder (com.facebook.buck.io.ExecutableFinder)5 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)5 NSDictionary (com.dd.plist.NSDictionary)3 NSString (com.dd.plist.NSString)3 SymbolGetter (com.facebook.buck.android.AndroidNdkHelper.SymbolGetter)3 BuckConfig (com.facebook.buck.cli.BuckConfig)3 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)3 DefaultCellPathResolver (com.facebook.buck.rules.DefaultCellPathResolver)3 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)3 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)3 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)3 HumanReadableException (com.facebook.buck.util.HumanReadableException)3