use of com.facebook.buck.model.FilesystemBackedBuildFileTree in project buck by facebook.
the class ProjectCommand method runDeprecatedIntellijProjectGenerator.
private int runDeprecatedIntellijProjectGenerator(CommandRunnerParams params, TargetGraph projectGraph, TargetGraphAndTargets targetGraphAndTargets, ImmutableSet<BuildTarget> passedInTargetsSet) throws IOException, InterruptedException {
// Create an ActionGraph that only contains targets that can be represented as IDE
// configuration files.
ActionGraphAndResolver result = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraphAndTargets.getTargetGraph()));
try (ExecutionContext executionContext = createExecutionContext(params)) {
Project project = new Project(new SourcePathResolver(new SourcePathRuleFinder(result.getResolver())), FluentIterable.from(result.getActionGraph().getNodes()).filter(ProjectConfig.class).toSortedSet(Ordering.natural()), getBasePathToAliasMap(params.getBuckConfig()), getJavaPackageFinder(params.getBuckConfig()), executionContext, new FilesystemBackedBuildFileTree(params.getCell().getFilesystem(), params.getBuckConfig().getView(ParserConfig.class).getBuildFileName()), params.getCell().getFilesystem(), getPathToDefaultAndroidManifest(params.getBuckConfig()), new IntellijConfig(params.getBuckConfig()), getPathToPostProcessScript(params.getBuckConfig()), new PythonBuckConfig(params.getBuckConfig(), new ExecutableFinder()).getPythonInterpreter(), params.getObjectMapper(), isAndroidAutoGenerateDisabled(params.getBuckConfig()));
File tempDir = Files.createTempDir();
File tempFile = new File(tempDir, "project.json");
int exitCode;
try {
exitCode = project.createIntellijProject(tempFile, executionContext.getProcessExecutor(), !passedInTargetsSet.isEmpty(), params.getConsole().getStdOut(), params.getConsole().getStdErr());
if (exitCode != 0) {
return exitCode;
}
List<String> additionalInitialTargets = ImmutableList.of();
if (shouldProcessAnnotations()) {
additionalInitialTargets = getAnnotationProcessingTargets(projectGraph, passedInTargetsSet);
}
// Build initial targets.
if (hasInitialTargets(params.getBuckConfig()) || !additionalInitialTargets.isEmpty()) {
BuildCommand buildCommand = createBuildCommandOptionsWithInitialTargets(params.getBuckConfig(), additionalInitialTargets);
buildCommand.setArtifactCacheDisabled(true);
exitCode = buildCommand.runWithoutHelp(params);
if (exitCode != 0) {
return exitCode;
}
}
} finally {
// Either leave project.json around for debugging or delete it on exit.
if (params.getConsole().getVerbosity().shouldPrintOutput()) {
params.getConsole().getStdErr().printf("project.json was written to %s", tempFile.getAbsolutePath());
} else {
tempFile.delete();
tempDir.delete();
}
}
if (passedInTargetsSet.isEmpty()) {
String greenStar = params.getConsole().getAnsi().asHighlightedSuccessText(" * ");
params.getConsole().getStdErr().printf(params.getConsole().getAnsi().asHighlightedSuccessText("=== Did you know ===") + "\n" + greenStar + "You can run `buck project <target>` to generate a minimal project " + "just for that target.\n" + greenStar + "This will make your IDE faster when working on large projects.\n" + greenStar + "See buck project --help for more info.\n" + params.getConsole().getAnsi().asHighlightedSuccessText("--=* Knowing is half the battle!") + "\n");
}
return 0;
}
}
use of com.facebook.buck.model.FilesystemBackedBuildFileTree 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();
}
Aggregations