Search in sources :

Example 6 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project buck by facebook.

the class AndroidBinaryDescription method addFallbackLocales.

private ImmutableSet<String> addFallbackLocales(ImmutableSet<String> locales) {
    ImmutableSet.Builder<String> allLocales = ImmutableSet.builder();
    for (String locale : locales) {
        allLocales.add(locale);
        Matcher matcher = COUNTRY_LOCALE_PATTERN.matcher(locale);
        if (matcher.matches()) {
            allLocales.add(matcher.group(1));
        }
    }
    return allLocales.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Matcher(java.util.regex.Matcher)

Example 7 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project buck by facebook.

the class AppleCoreSimulatorServiceController method getMatchingServiceNames.

private ImmutableSet<String> getMatchingServiceNames(Pattern serviceNamePattern) throws IOException, InterruptedException {
    ImmutableList<String> launchctlListCommand = ImmutableList.of("launchctl", "list");
    LOG.debug("Getting list of services with %s", launchctlListCommand);
    ProcessExecutorParams launchctlListParams = ProcessExecutorParams.builder().setCommand(launchctlListCommand).build();
    ProcessExecutor.LaunchedProcess launchctlListProcess = processExecutor.launchProcess(launchctlListParams);
    ImmutableSet.Builder<String> resultBuilder = ImmutableSet.builder();
    try (InputStreamReader stdoutReader = new InputStreamReader(launchctlListProcess.getInputStream(), StandardCharsets.UTF_8);
        BufferedReader bufferedStdoutReader = new BufferedReader(stdoutReader)) {
        String line;
        while ((line = bufferedStdoutReader.readLine()) != null) {
            Matcher launchctlListOutputMatcher = LAUNCHCTL_LIST_OUTPUT_PATTERN.matcher(line);
            if (launchctlListOutputMatcher.matches()) {
                String serviceName = launchctlListOutputMatcher.group(3);
                Matcher serviceNameMatcher = serviceNamePattern.matcher(serviceName);
                if (serviceNameMatcher.find()) {
                    LOG.debug("Found matching service name: %s", serviceName);
                    resultBuilder.add(serviceName);
                }
            }
        }
    } finally {
        processExecutor.destroyLaunchedProcess(launchctlListProcess);
        processExecutor.waitForLaunchedProcess(launchctlListProcess);
    }
    return resultBuilder.build();
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) ImmutableSet(com.google.common.collect.ImmutableSet) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) ProcessExecutor(com.facebook.buck.util.ProcessExecutor)

Example 8 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project buck by facebook.

the class TestRunning method getRulesUnderTest.

/**
   * Generates the set of Java library rules under test.
   */
private static ImmutableSet<JavaLibrary> getRulesUnderTest(Iterable<TestRule> tests) {
    ImmutableSet.Builder<JavaLibrary> rulesUnderTest = ImmutableSet.builder();
    // Gathering all rules whose source will be under test.
    for (TestRule test : tests) {
        if (test instanceof JavaTest) {
            // Look at the transitive dependencies for `tests` attribute that refers to this test.
            JavaTest javaTest = (JavaTest) test;
            ImmutableSet<JavaLibrary> transitiveDeps = javaTest.getCompiledTestsLibrary().getTransitiveClasspathDeps();
            for (JavaLibrary dep : transitiveDeps) {
                if (dep instanceof JavaLibraryWithTests) {
                    ImmutableSortedSet<BuildTarget> depTests = ((JavaLibraryWithTests) dep).getTests();
                    if (depTests.contains(test.getBuildTarget())) {
                        rulesUnderTest.add(dep);
                    }
                }
            }
        }
    }
    return rulesUnderTest.build();
}
Also used : TestRule(com.facebook.buck.rules.TestRule) JavaLibraryWithTests(com.facebook.buck.jvm.java.JavaLibraryWithTests) ImmutableSet(com.google.common.collect.ImmutableSet) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) DefaultJavaLibrary(com.facebook.buck.jvm.java.DefaultJavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) JavaTest(com.facebook.buck.jvm.java.JavaTest)

Example 9 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project buck by facebook.

the class AbstractCellConfig method getOverridesByPath.

/**
   * Translates the 'cell name'->override map into a 'Path'->override map.
   * @param pathMapping a map containing paths to all of the cells we want to query.
   * @return 'Path'->override map
   */
public ImmutableMap<Path, RawConfig> getOverridesByPath(ImmutableMap<RelativeCellName, Path> pathMapping) throws MalformedOverridesException {
    ImmutableSet<RelativeCellName> relativeNamesOfCellsWithOverrides = FluentIterable.from(getValues().keySet()).filter(Predicates.not(ALL_CELLS_OVERRIDE::equals)).toSet();
    ImmutableSet.Builder<Path> pathsWithOverrides = ImmutableSet.builder();
    for (RelativeCellName cellWithOverride : relativeNamesOfCellsWithOverrides) {
        if (!pathMapping.containsKey(cellWithOverride)) {
            throw new MalformedOverridesException(String.format("Trying to override settings for unknown cell %s", cellWithOverride));
        }
        pathsWithOverrides.add(pathMapping.get(cellWithOverride));
    }
    ImmutableMultimap<Path, RelativeCellName> pathToRelativeName = Multimaps.index(pathMapping.keySet(), Functions.forMap(pathMapping));
    for (Path pathWithOverrides : pathsWithOverrides.build()) {
        ImmutableCollection<RelativeCellName> namesForPath = pathToRelativeName.get(pathWithOverrides);
        if (namesForPath.size() > 1) {
            throw new MalformedOverridesException(String.format("Configuration override is ambiguous: cell rooted at %s is reachable " + "as [%s]. Please override the config by placing a .buckconfig.local file in the " + "cell's root folder.", pathWithOverrides, Joiner.on(',').join(namesForPath)));
        }
    }
    Map<Path, RawConfig> overridesByPath = new HashMap<>();
    for (Map.Entry<RelativeCellName, Path> entry : pathMapping.entrySet()) {
        RelativeCellName cellRelativeName = entry.getKey();
        Path cellPath = entry.getValue();
        RawConfig configFromOtherRelativeName = overridesByPath.get(cellPath);
        RawConfig config = getForCell(cellRelativeName);
        if (configFromOtherRelativeName != null) {
            Preconditions.checkState(configFromOtherRelativeName.equals(config), "Attempting to create cell %s at %s with conflicting overrides [%s] vs [%s].", cellRelativeName, cellPath, configFromOtherRelativeName, config);
        } else {
            overridesByPath.put(cellPath, config);
        }
    }
    return ImmutableMap.copyOf(overridesByPath);
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) RelativeCellName(com.facebook.buck.rules.RelativeCellName) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) MoreCollectors.toImmutableMap(com.facebook.buck.util.MoreCollectors.toImmutableMap)

Example 10 with ImmutableSet

use of com.google.common.collect.ImmutableSet in project buck by facebook.

the class TargetPatternEvaluator method resolveFilePattern.

ImmutableSet<QueryTarget> resolveFilePattern(String pattern) throws IOException {
    ImmutableSet<Path> filePaths = PathArguments.getCanonicalFilesUnderProjectRoot(projectRoot, ImmutableList.of(pattern)).relativePathsUnderProjectRoot;
    ImmutableSet.Builder<QueryTarget> builder = ImmutableSortedSet.naturalOrder();
    for (Path filePath : filePaths) {
        builder.add(QueryFileTarget.of(filePath));
    }
    return builder.build();
}
Also used : Path(java.nio.file.Path) QueryTarget(com.facebook.buck.query.QueryTarget) ImmutableSet(com.google.common.collect.ImmutableSet)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)196 Path (java.nio.file.Path)65 BuildTarget (com.facebook.buck.model.BuildTarget)58 ImmutableMap (com.google.common.collect.ImmutableMap)44 ImmutableList (com.google.common.collect.ImmutableList)43 IOException (java.io.IOException)42 Optional (java.util.Optional)37 Test (org.junit.Test)32 SourcePath (com.facebook.buck.rules.SourcePath)31 TargetNode (com.facebook.buck.rules.TargetNode)28 BuildRule (com.facebook.buck.rules.BuildRule)26 Map (java.util.Map)26 List (java.util.List)25 Set (java.util.Set)25 HumanReadableException (com.facebook.buck.util.HumanReadableException)23 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)21 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)20 TargetGraph (com.facebook.buck.rules.TargetGraph)19 VisibleForTesting (com.google.common.annotations.VisibleForTesting)19