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();
}
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();
}
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();
}
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);
}
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();
}
Aggregations