コード例 #1
0
 public ImmutableMap<String, String> getEntriesForSection(String section) {
   ImmutableMap<String, String> entries = config.get(section);
   if (entries != null) {
     return entries;
   } else {
     return ImmutableMap.of();
   }
 }
コード例 #2
0
ファイル: ProjectFilesystem.java プロジェクト: disigma/buck
  private static ImmutableSet<PathOrGlobMatcher> extractIgnorePaths(
      final Path root, Config config) {
    ImmutableSet.Builder<PathOrGlobMatcher> builder = ImmutableSet.builder();

    builder.add(new PathOrGlobMatcher(root, ".idea"));

    final String projectKey = "project";
    final String ignoreKey = "ignore";

    String buckdDirProperty = System.getProperty(BUCK_BUCKD_DIR_KEY, ".buckd");
    if (!Strings.isNullOrEmpty(buckdDirProperty)) {
      builder.add(new PathOrGlobMatcher(root, buckdDirProperty));
    }

    Path cacheDir = getCacheDir(root, config.getValue("cache", "dir"));
    builder.add(new PathOrGlobMatcher(cacheDir));

    builder.addAll(
        FluentIterable.from(config.getListWithoutComments(projectKey, ignoreKey))
            .transform(
                new Function<String, PathOrGlobMatcher>() {
                  @Nullable
                  @Override
                  public PathOrGlobMatcher apply(String input) {
                    // We don't really want to ignore the output directory when doing things like
                    // filesystem
                    // walks, so return null
                    if (BuckConstant.BUCK_OUTPUT_DIRECTORY.equals(input)) {
                      return null; // root.getFileSystem().getPathMatcher("glob:**");
                    }

                    if (GLOB_CHARS.matcher(input).find()) {
                      return new PathOrGlobMatcher(
                          root.getFileSystem().getPathMatcher("glob:" + input), input);
                    }
                    return new PathOrGlobMatcher(root, input);
                  }
                })
            // And now remove any null patterns
            .filter(Predicates.<PathOrGlobMatcher>notNull())
            .toList());

    return builder.build();
  }
コード例 #3
0
 public Optional<Float> getRemoteLogSampleRate() {
   Optional<Float> sampleRate = config.getFloat("log", "remote_log_sample_rate");
   if (sampleRate.isPresent()) {
     if (sampleRate.get() > 1.0f) {
       throw new HumanReadableException(
           ".buckconfig: remote_log_sample_rate should be less than or equal to 1.0.");
     }
     if (sampleRate.get() < 0.0f) {
       throw new HumanReadableException(
           ".buckconfig: remote_log_sample_rate should be greater than or equal to 0.");
     }
   }
   return sampleRate;
 }
コード例 #4
0
  @Test
  public void shouldFindNeededDependenciesFromSymbols() throws IOException, InterruptedException {
    ProjectWorkspace workspace =
        TestDataHelper.createProjectWorkspaceForScenario(this, "symbol_finder", temporaryFolder);
    workspace.setUp();

    ProjectFilesystem projectFilesystem = new ProjectFilesystem(temporaryFolder.getRootPath());
    ImmutableMap<String, String> environment = ImmutableMap.copyOf(System.getenv());

    Config rawConfig =
        Config.createDefaultConfig(
            projectFilesystem.getRootPath(),
            ImmutableMap.<String, ImmutableMap<String, String>>of());
    BuckConfig config =
        new BuckConfig(
            rawConfig, projectFilesystem, Architecture.detect(), Platform.detect(), environment);
    ImmutableSet<Description<?>> allDescriptions =
        DefaultKnownBuildRuleTypes.getDefaultKnownBuildRuleTypes(projectFilesystem)
            .getAllDescriptions();
    BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();

    MissingSymbolsHandler missingSymbolsHandler =
        MissingSymbolsHandler.create(
            projectFilesystem,
            allDescriptions,
            config,
            buckEventBus,
            new TestConsole(),
            DEFAULT_JAVAC_OPTIONS,
            environment);

    MissingSymbolEvent missingSymbolEvent =
        MissingSymbolEvent.create(
            BuildTargetFactory.newInstance(workspace.getDestPath(), "//java/com/example/b:b"),
            "com.example.a.A",
            MissingSymbolEvent.SymbolType.Java);

    ImmutableSetMultimap<BuildTarget, BuildTarget> neededDeps =
        missingSymbolsHandler.getNeededDependencies(ImmutableList.of(missingSymbolEvent));

    assertEquals(
        "MissingSymbolsHandler failed to find the needed dependency.",
        neededDeps,
        ImmutableSetMultimap.of(
            BuildTargetFactory.newInstance(workspace.getDestPath(), "//java/com/example/b:b"),
            BuildTargetFactory.newInstance(workspace.getDestPath(), "//java/com/example/a:a")));
  }
コード例 #5
0
  /**
   * Create a map of {@link BuildTarget} base paths to aliases. Note that there may be more than one
   * alias to a base path, so the first one listed in the .buckconfig will be chosen.
   */
  public ImmutableMap<Path, String> getBasePathToAliasMap() {
    ImmutableMap<String, String> aliases = config.get(ALIAS_SECTION_HEADER);
    if (aliases == null) {
      return ImmutableMap.of();
    }

    // Build up the Map with an ordinary HashMap because we need to be able to check whether the Map
    // already contains the key before inserting.
    Map<Path, String> basePathToAlias = Maps.newHashMap();
    for (Map.Entry<String, BuildTarget> entry : aliasToBuildTargetMap.entrySet()) {
      String alias = entry.getKey();
      BuildTarget buildTarget = entry.getValue();

      Path basePath = buildTarget.getBasePath();
      if (!basePathToAlias.containsKey(basePath)) {
        basePathToAlias.put(basePath, alias);
      }
    }
    return ImmutableMap.copyOf(basePathToAlias);
  }
コード例 #6
0
 public ImmutableSet<String> getSections() {
   return config.getSectionToEntries().keySet();
 }
コード例 #7
0
 /** @return the maximum load limit that Buck should stay under on the system. */
 public float getLoadLimit() {
   return config.getFloat("build", "load_limit").or(Float.POSITIVE_INFINITY);
 }
コード例 #8
0
 /**
  * @return the number of threads Buck should use or the specified defaultValue if it is not set.
  */
 public int getNumThreads(int defaultValue) {
   return config.getLong("build", "threads").or((long) defaultValue).intValue();
 }
コード例 #9
0
 public boolean getBooleanValue(String sectionName, String propertyName, boolean defaultValue) {
   return config.getBooleanValue(sectionName, propertyName, defaultValue);
 }
コード例 #10
0
 public Optional<Long> getLong(String sectionName, String propertyName) {
   return config.getLong(sectionName, propertyName);
 }
コード例 #11
0
 public Optional<String> getValue(String sectionName, String propertyName) {
   return config.getValue(sectionName, propertyName);
 }
コード例 #12
0
 public <T extends Enum<T>> Optional<T> getEnum(String section, String field, Class<T> clazz) {
   return config.getEnum(section, field, clazz);
 }
コード例 #13
0
 public ImmutableList<String> getListWithoutComments(String section, String field) {
   return config.getListWithoutComments(section, field);
 }