use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class ProjectBuildFileParserTest method whenSubprocessReturnsWarningThenConsoleEventPublished.
@Test
public void whenSubprocessReturnsWarningThenConsoleEventPublished() throws IOException, BuildFileParseException, InterruptedException {
// This test depends on unix utilities that don't exist on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
TestProjectBuildFileParserFactory buildFileParserFactory = new TestProjectBuildFileParserFactory(cell.getRoot(), cell.getKnownBuildRuleTypes());
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
final List<ConsoleEvent> consoleEvents = new ArrayList<>();
final List<WatchmanDiagnosticEvent> watchmanDiagnosticEvents = new ArrayList<>();
class EventListener {
@Subscribe
public void on(ConsoleEvent consoleEvent) {
consoleEvents.add(consoleEvent);
}
@Subscribe
public void on(WatchmanDiagnosticEvent event) {
watchmanDiagnosticEvents.add(event);
}
}
EventListener eventListener = new EventListener();
buckEventBus.register(eventListener);
try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsSuccessWithWarning(buckEventBus, "This is a warning", "parser")) {
buildFileParser.initIfNeeded();
buildFileParser.getAllRulesAndMetaRules(Paths.get("foo"));
}
assertThat(consoleEvents, Matchers.contains(Matchers.hasToString("Warning raised by BUCK file parser: This is a warning")));
assertThat("Should not receive any watchman diagnostic events", watchmanDiagnosticEvents, Matchers.empty());
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class ProjectBuildFileParserTest method whenSubprocessPrintsWarningToStderrThenConsoleEventPublished.
@Test
public void whenSubprocessPrintsWarningToStderrThenConsoleEventPublished() throws IOException, BuildFileParseException, InterruptedException {
// This test depends on unix utilities that don't exist on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
TestProjectBuildFileParserFactory buildFileParserFactory = new TestProjectBuildFileParserFactory(cell.getRoot(), cell.getKnownBuildRuleTypes());
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
final List<ConsoleEvent> consoleEvents = new ArrayList<>();
class EventListener {
@Subscribe
public void onConsoleEvent(ConsoleEvent consoleEvent) {
consoleEvents.add(consoleEvent);
}
}
EventListener eventListener = new EventListener();
buckEventBus.register(eventListener);
try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsSuccessAndPrintsToStderr(buckEventBus)) {
buildFileParser.initIfNeeded();
buildFileParser.getAllRulesAndMetaRules(Paths.get("foo"));
}
assertThat(consoleEvents, Matchers.contains(Matchers.hasToString("Warning raised by BUCK file parser: Don't Panic!")));
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class ProjectBuildFileParserTest method whenSubprocessReturnsErrorThenConsoleEventPublished.
@Test
public void whenSubprocessReturnsErrorThenConsoleEventPublished() throws IOException, BuildFileParseException, InterruptedException {
// This test depends on unix utilities that don't exist on Windows.
assumeTrue(Platform.detect() != Platform.WINDOWS);
TestProjectBuildFileParserFactory buildFileParserFactory = new TestProjectBuildFileParserFactory(cell.getRoot(), cell.getKnownBuildRuleTypes());
BuckEventBus buckEventBus = BuckEventBusFactory.newInstance(new FakeClock(0));
final List<ConsoleEvent> consoleEvents = new ArrayList<>();
class EventListener {
@Subscribe
public void onConsoleEvent(ConsoleEvent consoleEvent) {
consoleEvents.add(consoleEvent);
}
}
EventListener eventListener = new EventListener();
buckEventBus.register(eventListener);
try (ProjectBuildFileParser buildFileParser = buildFileParserFactory.createNoopParserThatAlwaysReturnsSuccessWithError(buckEventBus, "This is an error", "parser")) {
buildFileParser.initIfNeeded();
buildFileParser.getAllRulesAndMetaRules(Paths.get("foo"));
}
assertThat(consoleEvents, Matchers.contains(Matchers.hasToString("Error raised by BUCK file parser: This is an error")));
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class BuildInfoRecorderTest method testPerformUploadToArtifactCache.
@Test
public void testPerformUploadToArtifactCache() throws IOException, InterruptedException {
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildInfoRecorder buildInfoRecorder = createBuildInfoRecorder(filesystem);
BuckEventBus bus = new BuckEventBus(new FakeClock(0), new BuildId("BUILD"));
final byte[] contents = "contents".getBytes();
Path file = Paths.get("file");
filesystem.writeBytesToPath(contents, file);
buildInfoRecorder.recordArtifact(file);
Path dir = Paths.get("dir");
filesystem.mkdirs(dir);
filesystem.writeBytesToPath(contents, dir.resolve("file"));
buildInfoRecorder.recordArtifact(dir);
// Record some metadata.
buildInfoRecorder.addMetadata("metadata", "metadata");
// Record some build metadata.
buildInfoRecorder.addBuildMetadata("build-metadata", "build-metadata");
buildInfoRecorder.writeMetadataToDisk(true);
final AtomicBoolean stored = new AtomicBoolean(false);
final ArtifactCache cache = new NoopArtifactCache() {
@Override
public boolean isStoreSupported() {
return true;
}
@Override
public ListenableFuture<Void> store(ArtifactInfo info, BorrowablePath output) {
stored.set(true);
// Verify the build metadata.
assertThat(info.getMetadata().get("build-metadata"), Matchers.equalTo("build-metadata"));
// Verify zip contents
try (Zip zip = new Zip(output.getPath(), /* forWriting */
false)) {
assertEquals(ImmutableSet.of("", "dir/", "buck-out/", "buck-out/bin/", "buck-out/bin/foo/", "buck-out/bin/foo/.bar/", "buck-out/bin/foo/.bar/metadata/"), zip.getDirNames());
assertEquals(ImmutableSet.of("dir/file", "file", "buck-out/bin/foo/.bar/metadata/metadata"), zip.getFileNames());
assertArrayEquals(contents, zip.readFully("file"));
assertArrayEquals(contents, zip.readFully("dir/file"));
} catch (IOException e) {
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
return Futures.immediateFuture(null);
}
};
buildInfoRecorder.performUploadToArtifactCache(ImmutableSet.of(new RuleKey("aa")), cache, bus);
assertTrue(stored.get());
}
use of com.facebook.buck.event.BuckEventBus in project buck by facebook.
the class TargetGraphHashingTest method hashChangesWhenSrcContentChanges.
@Test
public void hashChangesWhenSrcContentChanges() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
TargetNode<?, ?> node = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//foo:lib"), HashCode.fromLong(64738), ImmutableSet.of(Paths.get("foo/FooLib.java")));
TargetGraph targetGraph = TargetGraphFactory.newInstance(node);
FileHashCache baseCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef")));
FileHashCache modifiedCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abc1ef")));
Map<BuildTarget, HashCode> baseResult = new TargetGraphHashing(eventBus, targetGraph, baseCache, ImmutableList.of(node)).hashTargetGraph();
Map<BuildTarget, HashCode> modifiedResult = new TargetGraphHashing(eventBus, targetGraph, modifiedCache, ImmutableList.of(node)).hashTargetGraph();
assertThat(baseResult, aMapWithSize(1));
assertThat(baseResult, hasKey(node.getBuildTarget()));
assertThat(modifiedResult, aMapWithSize(1));
assertThat(modifiedResult, hasKey(node.getBuildTarget()));
assertThat(modifiedResult.get(node.getBuildTarget()), not(equalTo(baseResult.get(node.getBuildTarget()))));
}
Aggregations