/** Formats a {@link ConsoleEvent} and adds it to {@code lines}. */ protected void formatConsoleEvent(ConsoleEvent logEvent, ImmutableList.Builder<String> lines) { String formattedLine = ""; if (logEvent.getLevel().equals(Level.INFO)) { formattedLine = logEvent.getMessage(); } else if (logEvent.getLevel().equals(Level.WARNING)) { formattedLine = ansi.asWarningText(logEvent.getMessage()); } else if (logEvent.getLevel().equals(Level.SEVERE)) { formattedLine = ansi.asErrorText(logEvent.getMessage()); } if (!formattedLine.isEmpty()) { // Split log messages at newlines and add each line individually to keep the line count // consistent. lines.addAll(Splitter.on("\n").split(formattedLine)); } }
/** * Create an Ansi object appropriate for the current output. First respect the user's preferences, * if set. Next, respect any default provided by the caller. (This is used by buckd to tell the * daemon about the client's terminal.) Finally, allow the Ansi class to autodetect whether the * current output is a tty. * * @param defaultColor Default value provided by the caller (e.g. the client of buckd) */ public Ansi createAnsi(Optional<String> defaultColor) { String color = getValue("color", "ui").or(defaultColor).or("auto"); switch (color) { case "false": case "never": return Ansi.withoutTty(); case "true": case "always": return Ansi.forceTty(); case "auto": default: return new Ansi( AnsiEnvironmentChecking.environmentSupportsAnsiEscapes(platform, environment)); } }
public ParallelPerBuildState( ParallelDaemonicParserState permState, ConstructorArgMarshaller marshaller, BuckEventBus eventBus, Cell rootCell, boolean enableProfiling) { this.permState = permState; this.marshaller = marshaller; this.eventBus = eventBus; this.enableProfiling = enableProfiling; this.cells = new ConcurrentHashMap<>(); this.cellSymlinkAllowability = new ConcurrentHashMap<>(); this.parsers = new ThreadLocal<Map<Cell, ProjectBuildFileParser>>() { @Override protected Map<Cell, ProjectBuildFileParser> initialValue() { return new HashMap<>(); } }; this.buildInputPathsUnderSymlink = Sets.newHashSet(); this.symlinkExistenceCache = new ConcurrentHashMap<>(); this.stdout = new PrintStream(ByteStreams.nullOutputStream()); this.stderr = new PrintStream(ByteStreams.nullOutputStream()); this.console = new Console(Verbosity.STANDARD_INFORMATION, stdout, stderr, Ansi.withoutTty()); this.symlinkCheckers = new TargetNodeListener() { @Override public void onCreate(Path buildFile, TargetNode<?> node) throws IOException { registerInputsUnderSymlinks(buildFile, node); } }; this.closer = Closer.create(); this.pendingWorkQueueCount = new AtomicInteger(0); this.pendingBuildTargets = new LinkedBlockingQueue<>(); this.pendingBuildFiles = new LinkedBlockingQueue<>(); this.completionNotifier = new CountDownLatch(1); register(rootCell); }
private ExecutionContext newEmptyExecutionContext(Platform platform) { return ExecutionContext.builder() .setConsole(new Console(Verbosity.SILENT, System.out, System.err, Ansi.withoutTty())) .setProjectFilesystem( new ProjectFilesystem(new File(".")) { @Override public Function<String, Path> getPathRelativizer() { return IdentityPathRelativizer.getIdentityRelativizer(); } @Override public Path resolve(Path path) { return path; } }) .setEventBus(BuckEventBusFactory.newInstance()) .setPlatform(platform) .build(); }
private ExitCodeAndOutput processJsonConfig(File jsonTempFile, boolean generateMinimalProject) throws IOException { ImmutableList.Builder<String> argsBuilder = ImmutableList.<String>builder() .add(pythonInterpreter) .add(PATH_TO_INTELLIJ_PY) .add(jsonTempFile.getAbsolutePath()); if (generateMinimalProject) { argsBuilder.add("--generate_minimum_project"); } final ImmutableList<String> args = argsBuilder.build(); ShellStep command = new ShellStep() { @Override public String getShortName() { return "python"; } @Override protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) { return args; } }; Console console = executionContext.getConsole(); Console childConsole = new Console(Verbosity.SILENT, console.getStdOut(), console.getStdErr(), Ansi.withoutTty()); ExecutionContext childContext = ExecutionContext.builder() .setExecutionContext(executionContext) .setConsole(childConsole) .build(); int exitCode = command.execute(childContext); return new ExitCodeAndOutput(exitCode, command.getStdout(), command.getStderr()); }
/** Print detailed report on all owners. */ private void printFullReport(CommandRunnerParams params, OwnersReport report) { PrintStream out = params.getConsole().getStdOut(); Ansi ansi = params.getConsole().getAnsi(); if (report.owners.isEmpty()) { out.println(ansi.asErrorText("No owners found")); } else { out.println(ansi.asSuccessText("Owners:")); for (TargetNode<?> targetNode : report.owners.keySet()) { out.println(targetNode.getBuildTarget().getFullyQualifiedName()); Set<Path> files = report.owners.get(targetNode); for (Path input : files) { out.println(FILE_INDENT + input); } } } if (!report.inputsWithNoOwners.isEmpty()) { out.println(); out.println(ansi.asErrorText("Files without owners:")); for (Path input : report.inputsWithNoOwners) { out.println(FILE_INDENT + input); } } if (!report.nonExistentInputs.isEmpty()) { out.println(); out.println(ansi.asErrorText("Non existent files:")); for (String input : report.nonExistentInputs) { out.println(FILE_INDENT + input); } } if (!report.nonFileInputs.isEmpty()) { out.println(); out.println(ansi.asErrorText("Non-file inputs:")); for (String input : report.nonFileInputs) { out.println(FILE_INDENT + input); } } }
private ProcessExecutor createProcessExecutor(PrintStream stdout, PrintStream stderr) { return new ProcessExecutor(new Console(Verbosity.SILENT, stdout, stderr, Ansi.withoutTty())); }