use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class AuditInputCommand method runWithoutHelp.
@Override
public int runWithoutHelp(final CommandRunnerParams params) throws IOException, InterruptedException {
// Create a TargetGraph that is composed of the transitive closure of all of the dependent
// TargetNodes for the specified BuildTargets.
final ImmutableSet<String> fullyQualifiedBuildTargets = ImmutableSet.copyOf(getArgumentsFormattedAsBuildTargets(params.getBuckConfig()));
if (fullyQualifiedBuildTargets.isEmpty()) {
params.getBuckEventBus().post(ConsoleEvent.severe("Please specify at least one build target."));
return 1;
}
ImmutableSet<BuildTarget> targets = getArgumentsFormattedAsBuildTargets(params.getBuckConfig()).stream().map(input -> BuildTargetParser.INSTANCE.parse(input, BuildTargetPatternParser.fullyQualified(), params.getCell().getCellPathResolver())).collect(MoreCollectors.toImmutableSet());
LOG.debug("Getting input for targets: %s", targets);
TargetGraph graph;
try (CommandThreadManager pool = new CommandThreadManager("Audit", getConcurrencyLimit(params.getBuckConfig()))) {
graph = params.getParser().buildTargetGraph(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), targets);
} catch (BuildFileParseException | BuildTargetException e) {
params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
return 1;
}
if (shouldGenerateJsonOutput()) {
return printJsonInputs(params, graph);
}
return printInputs(params, graph);
}
use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class AuditRulesCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
ProjectFilesystem projectFilesystem = params.getCell().getFilesystem();
try (ProjectBuildFileParser parser = params.getCell().createBuildFileParser(new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(params.getObjectMapper())), params.getConsole(), params.getBuckEventBus(), /* ignoreBuckAutodepsFiles */
false)) {
PrintStream out = params.getConsole().getStdOut();
for (String pathToBuildFile : getArguments()) {
if (!json) {
// Print a comment with the path to the build file.
out.printf("# %s\n\n", pathToBuildFile);
}
// Resolve the path specified by the user.
Path path = Paths.get(pathToBuildFile);
if (!path.isAbsolute()) {
Path root = projectFilesystem.getRootPath();
path = root.resolve(path);
}
// Parse the rules from the build file.
List<Map<String, Object>> rawRules;
try {
rawRules = parser.getAll(path);
} catch (BuildFileParseException e) {
throw new HumanReadableException(e);
}
// Format and print the rules from the raw data, filtered by type.
final ImmutableSet<String> types = getTypes();
Predicate<String> includeType = type -> types.isEmpty() || types.contains(type);
printRulesToStdout(params, rawRules, includeType);
}
} catch (BuildFileParseException e) {
throw new HumanReadableException("Unable to create parser");
}
return 0;
}
use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class BuckQueryEnvironment method getBuildFiles.
@Override
public ImmutableSet<QueryTarget> getBuildFiles(Set<QueryTarget> targets) throws QueryException {
final ProjectFilesystem cellFilesystem = rootCell.getFilesystem();
final Path rootPath = cellFilesystem.getRootPath();
Preconditions.checkState(rootPath.isAbsolute());
ImmutableSet.Builder<QueryTarget> builder = ImmutableSet.builder();
for (QueryTarget target : targets) {
Preconditions.checkState(target instanceof QueryBuildTarget);
BuildTarget buildTarget = ((QueryBuildTarget) target).getBuildTarget();
Cell cell = rootCell.getCell(buildTarget);
if (!buildFileTrees.containsKey(cell)) {
LOG.info("Creating a new filesystem-backed build file tree for %s", cell.getRoot());
buildFileTrees.put(cell, new FilesystemBackedBuildFileTree(cell.getFilesystem(), cell.getBuildFileName()));
}
BuildFileTree buildFileTree = Preconditions.checkNotNull(buildFileTrees.get(cell));
Optional<Path> path = buildFileTree.getBasePathOfAncestorTarget(buildTarget.getBasePath());
Preconditions.checkState(path.isPresent());
Path buildFilePath = MorePaths.relativize(rootPath, cell.getFilesystem().resolve(path.get()).resolve(cell.getBuildFileName()));
Preconditions.checkState(cellFilesystem.exists(buildFilePath));
builder.add(QueryFileTarget.of(buildFilePath));
}
return builder.build();
}
use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class AuditFlavorsCommand method printFlavors.
private void printFlavors(ImmutableList<TargetNode<?, ?>> targetNodes, CommandRunnerParams params) {
DirtyPrintStreamDecorator stdout = params.getConsole().getStdOut();
for (TargetNode<?, ?> node : targetNodes) {
Description<?> description = node.getDescription();
stdout.println(node.getBuildTarget().getFullyQualifiedName());
if (description instanceof Flavored) {
Optional<ImmutableSet<FlavorDomain<?>>> flavorDomains = ((Flavored) description).flavorDomains();
if (flavorDomains.isPresent()) {
for (FlavorDomain<?> domain : flavorDomains.get()) {
ImmutableSet<UserFlavor> userFlavors = RichStream.from(domain.getFlavors().stream()).filter(UserFlavor.class).collect(MoreCollectors.toImmutableSet());
if (userFlavors.isEmpty()) {
continue;
}
stdout.printf(" %s\n", domain.getName());
for (UserFlavor flavor : userFlavors) {
String flavorLine = String.format(" %s", flavor.getName());
String flavorDescription = flavor.getDescription();
if (flavorDescription.length() > 0) {
flavorLine += String.format(" -> %s", flavorDescription);
}
flavorLine += "\n";
stdout.printf(flavorLine);
}
}
} else {
stdout.println(" unknown");
}
} else {
stdout.println(" no flavors");
}
}
}
use of com.google.common.collect.ImmutableSet in project buck by facebook.
the class AuditFlavorsCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
ImmutableSet<BuildTarget> targets = getArgumentsFormattedAsBuildTargets(params.getBuckConfig()).stream().map(input -> BuildTargetParser.INSTANCE.parse(input, BuildTargetPatternParser.fullyQualified(), params.getCell().getCellPathResolver())).collect(MoreCollectors.toImmutableSet());
if (targets.isEmpty()) {
params.getBuckEventBus().post(ConsoleEvent.severe("Please specify at least one build target."));
return 1;
}
ImmutableList.Builder<TargetNode<?, ?>> builder = ImmutableList.builder();
try (CommandThreadManager pool = new CommandThreadManager("Audit", getConcurrencyLimit(params.getBuckConfig()))) {
for (BuildTarget target : targets) {
TargetNode<?, ?> targetNode = params.getParser().getTargetNode(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), target);
builder.add(targetNode);
}
} catch (BuildFileParseException | BuildTargetException e) {
params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
return 1;
}
ImmutableList<TargetNode<?, ?>> targetNodes = builder.build();
if (shouldGenerateJsonOutput()) {
printJsonFlavors(targetNodes, params);
} else {
printFlavors(targetNodes, params);
}
return 0;
}
Aggregations