Search in sources :

Example 6 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.

the class ExopackageInstaller method filterLibrariesForAbi.

@VisibleForTesting
static ImmutableMap<String, Path> filterLibrariesForAbi(Path nativeLibsDir, ImmutableMultimap<String, Path> allLibraries, String abi, ImmutableSet<String> ignoreLibraries) {
    ImmutableMap.Builder<String, Path> filteredLibraries = ImmutableMap.builder();
    for (Map.Entry<String, Path> entry : allLibraries.entries()) {
        Path relativePath = nativeLibsDir.relativize(entry.getValue());
        // relativePath is of the form libs/x86/foo.so, or assetLibs/x86/foo.so etc.
        Preconditions.checkState(relativePath.getNameCount() == 3);
        Preconditions.checkState(relativePath.getName(0).toString().equals("libs") || relativePath.getName(0).toString().equals("assetLibs"));
        String libAbi = relativePath.getParent().getFileName().toString();
        String libName = relativePath.getFileName().toString();
        if (libAbi.equals(abi) && !ignoreLibraries.contains(libName)) {
            filteredLibraries.put(entry);
        }
    }
    return filteredLibraries.build();
}
Also used : Path(java.nio.file.Path) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.

the class CompileStringsStep method groupFilesByLocale.

/**
   * Groups a list of strings.xml files by locale.
   * String files with no resource qualifier (eg. values/strings.xml) are mapped to the "en" locale
   *
   * eg. given the following list:
   *
   * ImmutableList.of(
   *   Paths.get("one/res/values-es/strings.xml"),
   *   Paths.get("two/res/values-es/strings.xml"),
   *   Paths.get("three/res/values-pt-rBR/strings.xml"),
   *   Paths.get("four/res/values-pt-rPT/strings.xml"),
   *   Paths.get("five/res/values/strings.xml"));
   *
   * returns:
   *
   * ImmutableMap.of(
   *   "es", ImmutableList.of(Paths.get("one/res/values-es/strings.xml"),
   *        Paths.get("two/res/values-es/strings.xml")),
   *   "pt_BR", ImmutableList.of(Paths.get("three/res/values-pt-rBR/strings.xml'),
   *   "pt_PT", ImmutableList.of(Paths.get("four/res/values-pt-rPT/strings.xml"),
   *   "en", ImmutableList.of(Paths.get("five/res/values/strings.xml")));
   */
@VisibleForTesting
ImmutableMultimap<String, Path> groupFilesByLocale(ImmutableList<Path> files) {
    ImmutableMultimap.Builder<String, Path> localeToFiles = ImmutableMultimap.builder();
    for (Path filepath : files) {
        String path = MorePaths.pathWithUnixSeparators(filepath);
        Matcher matcher = NON_ENGLISH_STRING_FILE_PATTERN.matcher(path);
        if (matcher.matches()) {
            String baseLocale = matcher.group(1);
            String country = matcher.group(2);
            String locale = country == null ? baseLocale : baseLocale + "_" + country;
            if (country != null && !regionSpecificToBaseLocaleMap.containsKey(locale)) {
                regionSpecificToBaseLocaleMap.put(locale, baseLocale);
            }
            localeToFiles.put(locale, filepath);
        } else {
            Preconditions.checkState(path.endsWith(ENGLISH_STRING_PATH_SUFFIX), "Invalid path passed to compile strings: " + path);
            localeToFiles.put(ENGLISH_LOCALE, filepath);
        }
    }
    return localeToFiles.build();
}
Also used : Path(java.nio.file.Path) Matcher(java.util.regex.Matcher) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 8 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.

the class RuleUtils method createGroupsFromEntryMaps.

@VisibleForTesting
static ImmutableList<GroupedSource> createGroupsFromEntryMaps(Multimap<Path, String> subgroups, Multimap<Path, GroupedSource> entries, Comparator<GroupedSource> comparator, Path rootGroupPath, Path groupPath) {
    ImmutableList.Builder<GroupedSource> groupBuilder = ImmutableList.builder();
    for (String subgroupName : ImmutableSortedSet.copyOf(subgroups.get(groupPath))) {
        Path subgroupPath = groupPath.resolve(subgroupName);
        groupBuilder.add(GroupedSource.ofSourceGroup(subgroupName, subgroupPath.subpath(rootGroupPath.getNameCount(), subgroupPath.getNameCount()), createGroupsFromEntryMaps(subgroups, entries, comparator, rootGroupPath, subgroupPath)));
    }
    SortedSet<GroupedSource> sortedEntries = ImmutableSortedSet.copyOf(comparator, entries.get(groupPath));
    for (GroupedSource groupedSource : sortedEntries) {
        groupBuilder.add(groupedSource);
    }
    return groupBuilder.build().asList();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 9 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.

the class CxxDescriptionEnhancer method getNonDefaultSharedLibrarySoname.

@VisibleForTesting
static String getNonDefaultSharedLibrarySoname(String declared, String sharedLibraryExtension, String sharedLibraryVersionedExtensionFormat) {
    Matcher match = SONAME_EXT_MACRO_PATTERN.matcher(declared);
    if (!match.find()) {
        return declared;
    }
    String version = match.group(1);
    if (version == null) {
        return match.replaceFirst(sharedLibraryExtension);
    }
    return match.replaceFirst(String.format(sharedLibraryVersionedExtensionFormat, version));
}
Also used : Matcher(java.util.regex.Matcher) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 10 with VisibleForTesting

use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.annotations.VisibleForTesting in project buck by facebook.

the class TestCommand method filterTestRules.

@VisibleForTesting
Iterable<TestRule> filterTestRules(BuckConfig buckConfig, ImmutableSet<BuildTarget> explicitBuildTargets, Iterable<TestRule> testRules) {
    ImmutableSortedSet.Builder<TestRule> builder = ImmutableSortedSet.orderedBy(Comparator.comparing(TestRule::getFullyQualifiedName));
    for (TestRule rule : testRules) {
        boolean explicitArgument = explicitBuildTargets.contains(rule.getBuildTarget());
        boolean matchesLabel = isMatchedByLabelOptions(buckConfig, rule.getLabels());
        // want to.
        if (shouldExcludeWin() && !matchesLabel) {
            continue;
        }
        // filter those out if such is the user's will.
        if (shouldExcludeTransitiveTests() && !explicitArgument) {
            continue;
        }
        // were explicitly specified by the user.
        if (explicitArgument || matchesLabel) {
            builder.add(rule);
        }
    }
    return builder.build();
}
Also used : TestRule(com.facebook.buck.rules.TestRule) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1954 IOException (java.io.IOException)284 ArrayList (java.util.ArrayList)214 Map (java.util.Map)156 HashMap (java.util.HashMap)147 List (java.util.List)113 File (java.io.File)94 ImmutableMap (com.google.common.collect.ImmutableMap)72 HashSet (java.util.HashSet)67 Path (org.apache.hadoop.fs.Path)63 ImmutableList (com.google.common.collect.ImmutableList)60 Path (java.nio.file.Path)60 Set (java.util.Set)52 Matcher (java.util.regex.Matcher)46 Collectors (java.util.stream.Collectors)46 Collection (java.util.Collection)39 Optional (java.util.Optional)38 NotNull (org.jetbrains.annotations.NotNull)37 ImmutableSet (com.google.common.collect.ImmutableSet)34 TreeMap (java.util.TreeMap)34