use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class DotnetFramework method findProgramFiles.
private static Path findProgramFiles(FileSystem osFilesystem, ImmutableMap<String, String> env) {
for (String envName : PROGRAM_FILES_ENV_NAMES) {
for (String key : env.keySet()) {
if (envName.equals(key.toLowerCase(US))) {
String value = env.get(key);
Path path = osFilesystem.getPath(value);
if (Files.exists(path)) {
return path;
} else {
LOG.info("Found a program files path with %s that did not exist: %s", key, value);
}
}
}
}
throw new HumanReadableException("Unable to find ProgramFiles or ProgramFiles(x86) env var");
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class PublicAnnouncementManager method getAndPostAnnouncements.
public void getAndPostAnnouncements() {
final ListenableFuture<ImmutableList<Announcement>> message = service.submit(() -> {
Optional<ClientSideSlb> slb = logConfig.getFrontendConfig().tryCreatingClientSideSlb(clock, eventBus, new CommandThreadFactory("PublicAnnouncement"));
if (slb.isPresent()) {
try (FrontendService frontendService = new FrontendService(ThriftOverHttpServiceConfig.of(new LoadBalancedService(slb.get(), logConfig.createOkHttpClient(), eventBus)))) {
AnnouncementRequest announcementRequest = new AnnouncementRequest();
announcementRequest.setBuckVersion(getBuckVersion());
announcementRequest.setRepository(repository);
FrontendRequest request = new FrontendRequest();
request.setType(FrontendRequestType.ANNOUNCEMENT);
request.setAnnouncementRequest(announcementRequest);
FrontendResponse response = frontendService.makeRequest(request);
return ImmutableList.copyOf(response.announcementResponse.announcements);
} catch (IOException e) {
throw new HumanReadableException("Failed to perform request", e);
}
} else {
throw new HumanReadableException("Failed to establish connection to server.");
}
});
Futures.addCallback(message, new FutureCallback<ImmutableList<Announcement>>() {
@Override
public void onSuccess(ImmutableList<Announcement> announcements) {
LOG.info("Public announcements fetched successfully.");
if (!announcements.isEmpty()) {
String announcement = HEADER_MSG;
for (Announcement entry : announcements) {
announcement = announcement.concat(String.format(ANNOUNCEMENT_TEMPLATE, entry.getErrorMessage(), entry.getSolutionMessage()));
}
consoleEventBusListener.setPublicAnnouncements(eventBus, Optional.of(announcement));
}
}
@Override
public void onFailure(Throwable t) {
LOG.warn("Failed to get public announcements. Reason: %s", t.getMessage());
}
});
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class ChromeTraceBuildListener method createPathAndStream.
private TracePathAndStream createPathAndStream(InvocationInfo invocationInfo) {
String filenameTime = dateFormat.get().format(new Date(clock.currentTimeMillis()));
String traceName = String.format("build.%s.%s.trace", filenameTime, invocationInfo.getBuildId());
if (compressTraces) {
traceName = traceName + ".gz";
}
Path tracePath = invocationInfo.getLogDirectoryPath().resolve(traceName);
try {
projectFilesystem.createParentDirs(tracePath);
OutputStream stream = projectFilesystem.newFileOutputStream(tracePath);
if (compressTraces) {
stream = new BestCompressionGZIPOutputStream(stream, true);
}
return new TracePathAndStream(tracePath, stream);
} catch (IOException e) {
throw new HumanReadableException(e, "Unable to write trace file: " + e);
}
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class GroovyBuckConfig method getGroovyCompiler.
Supplier<Tool> getGroovyCompiler() {
Optional<Path> path = delegate.getPath("groovy", "groovy_home");
final Path groovyHomePath;
if (path.isPresent()) {
groovyHomePath = path.get();
} else {
String defaultGroovyHome = delegate.getEnvironment().get("GROOVY_HOME");
if (defaultGroovyHome == null) {
throw new HumanReadableException("Unable to locate groovy compiler:" + " GROOVY_HOME is not set, and groovy.groovy_home was not provided");
} else {
groovyHomePath = Paths.get(defaultGroovyHome);
}
}
Path compiler = new ExecutableFinder().getExecutable(groovyHomePath.resolve("bin/groovyc"), delegate.getEnvironment());
return Suppliers.ofInstance(new HashedFileTool(compiler));
}
use of com.facebook.buck.util.HumanReadableException in project buck by facebook.
the class Watchman method build.
@VisibleForTesting
@SuppressWarnings("PMD.PrematureDeclaration")
static Watchman build(ListeningProcessExecutor executor, Function<Path, Optional<WatchmanClient>> watchmanConnector, ImmutableSet<Path> projectWatchList, ImmutableMap<String, String> env, ExecutableFinder exeFinder, Console console, Clock clock, Optional<Long> commandTimeoutMillis) throws InterruptedException {
LOG.info("Creating for: " + projectWatchList);
Optional<WatchmanClient> watchmanClient = Optional.empty();
try {
Path watchmanPath = exeFinder.getExecutable(WATCHMAN, env).toAbsolutePath();
Optional<? extends Map<String, ?>> result;
long timeoutMillis = commandTimeoutMillis.orElse(DEFAULT_COMMAND_TIMEOUT_MILLIS);
long endTimeNanos = clock.nanoTime() + TimeUnit.MILLISECONDS.toNanos(timeoutMillis);
result = execute(executor, console, clock, timeoutMillis, TimeUnit.MILLISECONDS.toNanos(timeoutMillis), watchmanPath, "get-sockname");
if (!result.isPresent()) {
return NULL_WATCHMAN;
}
String rawSockname = (String) result.get().get("sockname");
if (rawSockname == null) {
return NULL_WATCHMAN;
}
Path socketPath = Paths.get(rawSockname);
LOG.info("Connecting to Watchman version %s at %s", result.get().get("version"), socketPath);
watchmanClient = watchmanConnector.apply(socketPath);
if (!watchmanClient.isPresent()) {
LOG.warn("Could not connect to Watchman, disabling.");
return NULL_WATCHMAN;
}
LOG.debug("Connected to Watchman");
long versionQueryStartTimeNanos = clock.nanoTime();
result = watchmanClient.get().queryWithTimeout(endTimeNanos - versionQueryStartTimeNanos, "version", ImmutableMap.of("required", REQUIRED_CAPABILITIES, "optional", ALL_CAPABILITIES.keySet()));
LOG.info("Took %d ms to query capabilities %s", TimeUnit.NANOSECONDS.toMillis(clock.nanoTime() - versionQueryStartTimeNanos), ALL_CAPABILITIES);
if (!result.isPresent()) {
LOG.warn("Could not get version response from Watchman, disabling Watchman");
watchmanClient.get().close();
return NULL_WATCHMAN;
}
ImmutableSet.Builder<Capability> capabilitiesBuilder = ImmutableSet.builder();
if (!extractCapabilities(result.get(), capabilitiesBuilder)) {
LOG.warn("Could not extract capabilities, disabling Watchman");
watchmanClient.get().close();
return NULL_WATCHMAN;
}
ImmutableSet<Capability> capabilities = capabilitiesBuilder.build();
LOG.debug("Got Watchman capabilities: %s", capabilities);
ImmutableMap.Builder<Path, ProjectWatch> projectWatchesBuilder = ImmutableMap.builder();
ImmutableMap.Builder<Path, String> clockIdsBuilder = ImmutableMap.builder();
for (Path rootPath : projectWatchList) {
Optional<ProjectWatch> projectWatch = queryWatchProject(watchmanClient.get(), rootPath, clock, endTimeNanos - clock.nanoTime());
if (!projectWatch.isPresent()) {
watchmanClient.get().close();
return NULL_WATCHMAN;
}
projectWatchesBuilder.put(rootPath, projectWatch.get());
Optional<String> clockId = queryClock(watchmanClient.get(), projectWatch.get().getWatchRoot(), capabilities, clock, endTimeNanos - clock.nanoTime());
if (clockId.isPresent()) {
clockIdsBuilder.put(rootPath, clockId.get());
}
}
return new Watchman(projectWatchesBuilder.build(), capabilities, clockIdsBuilder.build(), Optional.of(socketPath), watchmanClient);
} catch (ClassCastException | HumanReadableException | IOException e) {
LOG.warn(e, "Unable to determine the version of watchman. Going without.");
if (watchmanClient.isPresent()) {
try {
watchmanClient.get().close();
} catch (IOException ioe) {
LOG.warn(ioe, "Could not close watchman query client");
}
}
return NULL_WATCHMAN;
}
}
Aggregations