Search in sources :

Example 36 with HumanReadableException

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");
}
Also used : Path(java.nio.file.Path) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 37 with HumanReadableException

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());
        }
    });
}
Also used : Announcement(com.facebook.buck.distributed.thrift.Announcement) ImmutableList(com.google.common.collect.ImmutableList) CommandThreadFactory(com.facebook.buck.log.CommandThreadFactory) IOException(java.io.IOException) ClientSideSlb(com.facebook.buck.slb.ClientSideSlb) HumanReadableException(com.facebook.buck.util.HumanReadableException) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) FrontendService(com.facebook.buck.distributed.FrontendService) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) LoadBalancedService(com.facebook.buck.slb.LoadBalancedService) AnnouncementRequest(com.facebook.buck.distributed.thrift.AnnouncementRequest)

Example 38 with HumanReadableException

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);
    }
}
Also used : Path(java.nio.file.Path) HumanReadableException(com.facebook.buck.util.HumanReadableException) BestCompressionGZIPOutputStream(com.facebook.buck.util.BestCompressionGZIPOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) BestCompressionGZIPOutputStream(com.facebook.buck.util.BestCompressionGZIPOutputStream) Date(java.util.Date)

Example 39 with HumanReadableException

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));
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) HashedFileTool(com.facebook.buck.rules.HashedFileTool) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 40 with HumanReadableException

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;
    }
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSet(com.google.common.collect.ImmutableSet) HumanReadableException(com.facebook.buck.util.HumanReadableException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

HumanReadableException (com.facebook.buck.util.HumanReadableException)195 Path (java.nio.file.Path)79 SourcePath (com.facebook.buck.rules.SourcePath)50 BuildTarget (com.facebook.buck.model.BuildTarget)49 Test (org.junit.Test)46 IOException (java.io.IOException)45 ImmutableList (com.google.common.collect.ImmutableList)39 BuildRule (com.facebook.buck.rules.BuildRule)31 ImmutableSet (com.google.common.collect.ImmutableSet)30 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)29 ImmutableMap (com.google.common.collect.ImmutableMap)26 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 Optional (java.util.Optional)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)20 VisibleForTesting (com.google.common.annotations.VisibleForTesting)18 Map (java.util.Map)18 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)17 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)16 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)15 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)15