Пример #1
0
  @BeforeClass
  public static void createParser() {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    FakeBuckConfig buckConfig = new FakeBuckConfig();
    ParserConfig parserConfig = new ParserConfig(buckConfig);
    PythonBuckConfig pythonBuckConfig = new PythonBuckConfig(buckConfig, new ExecutableFinder());

    ImmutableSet<Description<?>> descriptions =
        ImmutableSet.of(
            new RemoteFileDescription(new ExplodingDownloader()), new PrebuiltJarDescription());

    DefaultProjectBuildFileParserFactory parserFactory =
        new DefaultProjectBuildFileParserFactory(
            filesystem.getRootPath(),
            pythonBuckConfig.getPythonInterpreter(),
            parserConfig.getAllowEmptyGlobs(),
            parserConfig.getBuildFileName(),
            parserConfig.getDefaultIncludes(),
            descriptions);
    buildFileParser =
        parserFactory.createParser(
            new TestConsole(),
            ImmutableMap.<String, String>of(),
            BuckEventBusFactory.newInstance());
  }
Пример #2
0
 public BuckQueryEnvironment(CommandRunnerParams params, boolean enableProfiling) {
   this.params = params;
   this.enableProfiling = enableProfiling;
   this.parserConfig = new ParserConfig(params.getBuckConfig());
   this.buildFileTree =
       new FilesystemBackedBuildFileTree(
           params.getCell().getFilesystem(), parserConfig.getBuildFileName());
   this.targetPatternEvaluator = new TargetPatternEvaluator(params, enableProfiling);
 }
Пример #3
0
 @Override
 public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
   ParserConfig parserConfig = new ParserConfig(params.getBuckConfig());
   BuildFileTree buildFileTree =
       new FilesystemBackedBuildFileTree(
           params.getCell().getFilesystem(), parserConfig.getBuildFileName());
   try {
     OwnersReport report =
         buildOwnersReport(
             params, parserConfig, buildFileTree, getArguments(), isGuessForDeletedEnabled());
     printReport(params, report);
   } catch (BuildFileParseException | BuildTargetException e) {
     return BUILD_TARGET_ERROR;
   }
   return 0;
 }
Пример #4
0
  static OwnersReport buildOwnersReport(
      CommandRunnerParams params,
      ParserConfig parserConfig,
      BuildFileTree buildFileTree,
      Iterable<String> arguments,
      boolean guessForDeletedEnabled)
      throws IOException, InterruptedException, BuildFileParseException, BuildTargetException {
    final Path rootPath = params.getCell().getFilesystem().getRootPath();
    Preconditions.checkState(rootPath.isAbsolute());
    Map<Path, List<TargetNode<?>>> targetNodes = Maps.newHashMap();
    OwnersReport report = OwnersReport.emptyReport();

    for (Path filePath : getArgumentsAsPaths(rootPath, arguments)) {
      Optional<Path> basePath = buildFileTree.getBasePathOfAncestorTarget(filePath);
      if (!basePath.isPresent()) {
        report =
            report.updatedWith(
                new OwnersReport(
                    ImmutableSetMultimap.<TargetNode<?>, Path>of(),
                    /* inputWithNoOwners */ ImmutableSet.of(filePath),
                    Sets.<String>newHashSet(),
                    Sets.<String>newHashSet()));
        continue;
      }

      Path buckFile = basePath.get().resolve(parserConfig.getBuildFileName());
      Preconditions.checkState(params.getCell().getFilesystem().exists(buckFile));

      // Parse buck files and load target nodes.
      if (!targetNodes.containsKey(buckFile)) {
        try {
          targetNodes.put(
              buckFile,
              params
                  .getParser()
                  .getOrLoadTargetNodes(
                      buckFile,
                      parserConfig,
                      params.getBuckEventBus(),
                      params.getConsole(),
                      params.getEnvironment()));
        } catch (BuildFileParseException | BuildTargetException e) {
          Path targetBasePath = MorePaths.relativize(rootPath, rootPath.resolve(basePath.get()));
          String targetBaseName = "//" + MorePaths.pathWithUnixSeparators(targetBasePath);

          params
              .getConsole()
              .getStdErr()
              .format("Could not parse build targets for %s", targetBaseName);
          throw e;
        }
      }

      for (TargetNode<?> targetNode : targetNodes.get(buckFile)) {
        report =
            report.updatedWith(
                generateOwnersReport(
                    params,
                    targetNode,
                    ImmutableList.of(filePath.toString()),
                    guessForDeletedEnabled));
      }
    }
    return report;
  }