Search in sources :

Example 66 with VisibleForTesting

use of 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 67 with VisibleForTesting

use of 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 68 with VisibleForTesting

use of 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 69 with VisibleForTesting

use of 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 70 with VisibleForTesting

use of 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)808 IOException (java.io.IOException)135 ArrayList (java.util.ArrayList)67 Map (java.util.Map)52 Path (java.nio.file.Path)47 File (java.io.File)41 HashMap (java.util.HashMap)37 Path (org.apache.hadoop.fs.Path)33 List (java.util.List)29 ImmutableList (com.google.common.collect.ImmutableList)28 Matcher (java.util.regex.Matcher)26 HashSet (java.util.HashSet)23 ImmutableMap (com.google.common.collect.ImmutableMap)21 FileStatus (org.apache.hadoop.fs.FileStatus)21 SourcePath (com.facebook.buck.rules.SourcePath)20 FileHandle (org.apache.hadoop.nfs.nfs3.FileHandle)19 DFSClient (org.apache.hadoop.hdfs.DFSClient)18 Nfs3FileAttributes (org.apache.hadoop.nfs.nfs3.Nfs3FileAttributes)18 ImmutableSet (com.google.common.collect.ImmutableSet)17 LinkedHashMap (java.util.LinkedHashMap)17