use of com.facebook.buck.util.FakeProcessExecutor in project buck by facebook.
the class CleanCommandTest method createCommandRunnerParams.
private CommandRunnerParams createCommandRunnerParams() throws InterruptedException, IOException {
projectFilesystem = new FakeProjectFilesystem();
Cell cell = new TestCellBuilder().setFilesystem(projectFilesystem).build();
Supplier<AndroidPlatformTarget> androidPlatformTargetSupplier = AndroidPlatformTarget.EXPLODING_ANDROID_PLATFORM_TARGET_SUPPLIER;
return CommandRunnerParams.builder().setConsole(new TestConsole()).setStdIn(new ByteArrayInputStream("".getBytes("UTF-8"))).setCell(cell).setAndroidPlatformTargetSupplier(androidPlatformTargetSupplier).setArtifactCacheFactory(new SingletonArtifactCacheFactory(new NoopArtifactCache())).setBuckEventBus(BuckEventBusFactory.newInstance()).setParser(createMock(Parser.class)).setPlatform(Platform.detect()).setEnvironment(ImmutableMap.copyOf(System.getenv())).setJavaPackageFinder(new FakeJavaPackageFinder()).setObjectMapper(ObjectMappers.newDefaultInstance()).setClock(new DefaultClock()).setProcessManager(Optional.empty()).setWebServer(Optional.empty()).setBuckConfig(FakeBuckConfig.builder().build()).setFileHashCache(new StackedFileHashCache(ImmutableList.of())).setExecutors(ImmutableMap.of()).setBuildEnvironmentDescription(CommandRunnerParamsForTesting.BUILD_ENVIRONMENT_DESCRIPTION).setVersionedTargetGraphCache(new VersionedTargetGraphCache()).setActionGraphCache(new ActionGraphCache(new BroadcastEventListener())).setKnownBuildRuleTypesFactory(new KnownBuildRuleTypesFactory(new FakeProcessExecutor(), new FakeAndroidDirectoryResolver())).build();
}
use of com.facebook.buck.util.FakeProcessExecutor in project buck by facebook.
the class ExternalJavacTest method externalJavacWillHashTheExternalIfNoVersionInformationIsReturned.
@Test
public void externalJavacWillHashTheExternalIfNoVersionInformationIsReturned() throws IOException {
Path javac = Files.createTempFile("fake", "javac");
javac.toFile().deleteOnExit();
ProcessExecutorParams javacExe = ProcessExecutorParams.builder().addCommand(javac.toAbsolutePath().toString(), "-version").build();
FakeProcess javacProc = new FakeProcess(0, "", "");
final FakeProcessExecutor executor = new FakeProcessExecutor(ImmutableMap.of(javacExe, javacProc));
ExternalJavac compiler = new ExternalJavac(Either.ofLeft(javac)) {
@Override
ProcessExecutor createProcessExecutor() {
return executor;
}
};
RuleKeyObjectSink sink = createMock(RuleKeyObjectSink.class);
expect(sink.setReflectively("javac", javac.toString())).andReturn(sink);
replay(sink);
compiler.appendToRuleKey(sink);
}
use of com.facebook.buck.util.FakeProcessExecutor in project buck by facebook.
the class ExternalJavacTest method externalJavacWillHashTheJavacVersionIfPresent.
@Test
public void externalJavacWillHashTheJavacVersionIfPresent() throws IOException {
Path javac = Files.createTempFile("fake", "javac");
javac.toFile().deleteOnExit();
String reportedJavacVersion = "mozzarella";
JavacVersion javacVersion = JavacVersion.of(reportedJavacVersion);
ProcessExecutorParams javacExe = ProcessExecutorParams.builder().addCommand(javac.toAbsolutePath().toString(), "-version").build();
FakeProcess javacProc = new FakeProcess(0, "", reportedJavacVersion);
final FakeProcessExecutor executor = new FakeProcessExecutor(ImmutableMap.of(javacExe, javacProc));
ExternalJavac compiler = new ExternalJavac(Either.ofLeft(javac)) {
@Override
ProcessExecutor createProcessExecutor() {
return executor;
}
};
RuleKeyObjectSink sink = createMock(RuleKeyObjectSink.class);
expect(sink.setReflectively("javac.version", javacVersion.toString())).andReturn(sink);
replay(sink);
compiler.appendToRuleKey(sink);
}
use of com.facebook.buck.util.FakeProcessExecutor in project buck by facebook.
the class JavacStepTest method successfulCompileDoesNotSendStdoutAndStderrToConsole.
@Test
public void successfulCompileDoesNotSendStdoutAndStderrToConsole() throws Exception {
FakeJavac fakeJavac = new FakeJavac();
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").build();
ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> false, file -> false, (path, glob) -> ImmutableSet.of());
JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
FakeProcess fakeJavacProcess = new FakeProcess(0, "javac stdout\n", "javac stderr\n");
ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
executionContext.getBuckEventBus().register(listener);
StepExecutionResult result = step.execute(executionContext);
// Note that we don't include stderr in the step result on success.
assertThat(result, equalTo(StepExecutionResult.SUCCESS));
assertThat(listener.getLogMessages(), empty());
}
use of com.facebook.buck.util.FakeProcessExecutor in project buck by facebook.
the class JavacStepTest method missingBootclasspathDirFailsWithError.
@Test
public void missingBootclasspathDirFailsWithError() throws Exception {
FakeJavac fakeJavac = new FakeJavac();
BuildRuleResolver buildRuleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
ProjectFilesystem fakeFilesystem = FakeProjectFilesystem.createJavaOnlyFilesystem();
JavacOptions javacOptions = JavacOptions.builder().setSourceLevel("8.0").setTargetLevel("8.0").setBootclasspath("/no-such-dir").build();
ClasspathChecker classpathChecker = new ClasspathChecker("/", ":", Paths::get, dir -> false, file -> false, (path, glob) -> ImmutableSet.of());
JavacStep step = new JavacStep(Paths.get("output"), NoOpClassUsageFileWriter.instance(), Optional.empty(), ImmutableSortedSet.of(), Paths.get("pathToSrcsList"), ImmutableSortedSet.of(), fakeJavac, javacOptions, BuildTargetFactory.newInstance("//foo:bar"), Optional.empty(), sourcePathResolver, ruleFinder, fakeFilesystem, classpathChecker, Optional.empty());
FakeProcess fakeJavacProcess = new FakeProcess(1, "javac stdout\n", "javac stderr\n");
ExecutionContext executionContext = TestExecutionContext.newBuilder().setProcessExecutor(new FakeProcessExecutor(Functions.constant(fakeJavacProcess), new TestConsole())).build();
BuckEventBusFactory.CapturingConsoleEventListener listener = new BuckEventBusFactory.CapturingConsoleEventListener();
executionContext.getBuckEventBus().register(listener);
StepExecutionResult result = step.execute(executionContext);
assertThat(result, equalTo(StepExecutionResult.ERROR));
assertThat(listener.getLogMessages(), equalTo(ImmutableList.of("Invalid Java compiler options: Bootstrap classpath /no-such-dir " + "contains no valid entries")));
}
Aggregations