use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project buck by facebook.
the class UnexpectedFlavorException method createWithSuggestions.
public static UnexpectedFlavorException createWithSuggestions(Cell cell, BuildTarget target) {
// Get the specific message
String exceptionMessage = createDefaultMessage(cell, target);
// Get some suggestions on how to solve it.
String suggestions = "";
Optional<ImmutableSet<PatternAndMessage>> configMessagesForFlavors = cell.getBuckConfig().getUnexpectedFlavorsMessages();
for (Flavor flavor : target.getFlavors()) {
boolean foundInConfig = false;
if (configMessagesForFlavors.isPresent()) {
for (PatternAndMessage flavorPattern : configMessagesForFlavors.get()) {
if (flavorPattern.getPattern().matcher(flavor.getName()).find()) {
foundInConfig = true;
suggestions += flavor.getName() + " : " + flavorPattern.getMessage() + "\n";
}
}
}
if (!foundInConfig) {
for (PatternAndMessage flavorPattern : suggestedMessagesForFlavors) {
if (flavorPattern.getPattern().matcher(flavor.getName()).find()) {
suggestions += flavor.getName() + " : " + flavorPattern.getMessage() + "\n";
}
}
}
}
if (!suggestions.isEmpty()) {
exceptionMessage += "\nHere are some things you can try to get the following " + "flavors to work::\n" + suggestions;
}
return new UnexpectedFlavorException(exceptionMessage);
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project buck by facebook.
the class RegexFilterFunction method eval.
@Override
public ImmutableSet<QueryTarget> eval(QueryEnvironment env, ImmutableList<Argument> args, ListeningExecutorService executor) throws QueryException, InterruptedException {
Pattern compiledPattern;
try {
compiledPattern = Pattern.compile(getPattern(args));
} catch (IllegalArgumentException e) {
throw new QueryException(String.format("Illegal pattern regexp '%s': %s", getPattern(args), e.getMessage()));
}
Set<QueryTarget> targets = getExpressionToEval(args).eval(env, executor);
ImmutableSet.Builder<QueryTarget> result = new ImmutableSet.Builder<>();
for (QueryTarget target : targets) {
String attributeValue = getStringToFilter(env, args, target);
if (compiledPattern.matcher(attributeValue).find()) {
result.add(target);
}
}
return result.build();
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project buck by facebook.
the class ConvertingPipeline method getAllNodesJob.
@Override
public ListenableFuture<ImmutableSet<T>> getAllNodesJob(final Cell cell, final Path buildFile) throws BuildTargetException {
// TODO(tophyr): this hits the chained pipeline before hitting the cache
ListenableFuture<List<T>> allNodesListJob = Futures.transformAsync(getItemsToConvert(cell, buildFile), allToConvert -> {
if (shuttingDown()) {
return Futures.immediateCancelledFuture();
}
ImmutableList.Builder<ListenableFuture<T>> allNodeJobs = ImmutableList.builder();
for (final F from : allToConvert) {
if (isValid(from)) {
final BuildTarget target = getBuildTarget(cell.getRoot(), buildFile, from);
allNodeJobs.add(cache.getJobWithCacheLookup(cell, target, () -> {
if (shuttingDown()) {
return Futures.immediateCancelledFuture();
}
return dispatchComputeNode(cell, target, from);
}));
}
}
return Futures.allAsList(allNodeJobs.build());
}, executorService);
return Futures.transform(allNodesListJob, (Function<List<T>, ImmutableSet<T>>) ImmutableSet::copyOf, executorService);
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project buck by facebook.
the class DefaultJavaLibraryTest method createDefaultJavaLibraryRuleWithAbiKey.
private BuildRule createDefaultJavaLibraryRuleWithAbiKey(BuildTarget buildTarget, ImmutableSet<String> srcs, ImmutableSortedSet<BuildRule> deps, ImmutableSortedSet<BuildRule> exportedDeps, Optional<AbstractJavacOptions.SpoolMode> spoolMode, ImmutableList<String> postprocessClassesCommands) {
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
ImmutableSortedSet<? extends SourcePath> srcsAsPaths = FluentIterable.from(srcs).transform(Paths::get).transform(p -> new PathSourcePath(projectFilesystem, p)).toSortedSet(Ordering.natural());
BuildRuleParams buildRuleParams = new FakeBuildRuleParamsBuilder(buildTarget).setDeclaredDeps(ImmutableSortedSet.copyOf(deps)).build();
JavacOptions javacOptions = spoolMode.isPresent() ? JavacOptions.builder(DEFAULT_JAVAC_OPTIONS).setSpoolMode(spoolMode.get()).build() : DEFAULT_JAVAC_OPTIONS;
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
DefaultJavaLibrary defaultJavaLibrary = new DefaultJavaLibrary(buildRuleParams, new SourcePathResolver(ruleFinder), ruleFinder, srcsAsPaths, /* resources */
ImmutableSet.of(), javacOptions.getGeneratedSourceFolderName(), /* proguardConfig */
Optional.empty(), postprocessClassesCommands, exportedDeps, /* providedDeps */
ImmutableSortedSet.of(), ImmutableSortedSet.of(), javacOptions.trackClassUsage(), /* additionalClasspathEntries */
ImmutableSet.of(), new JavacToJarStepFactory(javacOptions, JavacOptionsAmender.IDENTITY), /* resourcesRoot */
Optional.empty(), /* manifest file */
Optional.empty(), /* mavenCoords */
Optional.empty(), /* tests */
ImmutableSortedSet.of(), /* classesToRemoveFromJar */
ImmutableSet.of()) {
};
ruleResolver.addToIndex(defaultJavaLibrary);
return defaultJavaLibrary;
}
use of org.apache.beam.vendor.calcite.v1_28_0.com.google.common.collect.ImmutableSet in project buck by facebook.
the class PrebuiltJarSymbolsFinderTest method contentsOfBinaryJarShouldAffectRuleKey.
@Test
public void contentsOfBinaryJarShouldAffectRuleKey() throws IOException {
// The path to the JAR file to use as the binaryJar of the PrebuiltJarSymbolsFinder.
final Path relativePathToJar = Paths.get("common.jar");
final Path absolutePathToJar = tmp.getRoot().resolve(relativePathToJar);
// Mock out calls to a SourcePathResolver so we can create a legitimate
// DefaultRuleKeyFactory.
final SourcePathRuleFinder ruleFinder = createMock(SourcePathRuleFinder.class);
final SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
createMock(SourcePathResolver.class);
expect(ruleFinder.getRule(anyObject(SourcePath.class))).andReturn(Optional.empty()).anyTimes();
// Calculates the RuleKey for a JavaSymbolsRule with a PrebuiltJarSymbolsFinder whose binaryJar
// is a JAR file with the specified entries.
Function<ImmutableSet<String>, RuleKey> createRuleKey = entries -> {
File jarFile = absolutePathToJar.toFile();
JavaSymbolsRule javaSymbolsRule;
FakeFileHashCache fileHashCache;
try {
PrebuiltJarSymbolsFinder finder = createFinderForFileWithEntries(relativePathToJar.getFileName().toString(), entries);
HashCode hash = Files.hash(jarFile, Hashing.sha1());
Map<Path, HashCode> pathsToHashes = ImmutableMap.of(absolutePathToJar, hash);
fileHashCache = new FakeFileHashCache(pathsToHashes);
javaSymbolsRule = new JavaSymbolsRule(BuildTargetFactory.newInstance("//foo:rule"), finder, ImmutableSortedSet.of(), ObjectMappers.newDefaultInstance(), new ProjectFilesystem(tmp.getRoot()));
} catch (IOException e) {
throw new RuntimeException(e);
}
RuleKey ruleKey = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder).build(javaSymbolsRule);
jarFile.delete();
return ruleKey;
};
RuleKey key1 = createRuleKey.apply(ImmutableSet.of("entry1", "entry2"));
RuleKey key2 = createRuleKey.apply(ImmutableSet.of("entry1", "entry2"));
RuleKey key3 = createRuleKey.apply(ImmutableSet.of("entry1", "entry2", "entry3"));
assertNotNull(key1);
assertNotNull(key2);
assertNotNull(key3);
assertEquals("Two instances of a JavaSymbolsRule with the same inputs should have the same RuleKey.", key1, key2);
assertNotEquals("Changing the contents of the binaryJar for the PrebuiltJarSymbolsFinder should change " + "the RuleKey of the JavaSymbolsRule that contains it.", key1, key3);
}
Aggregations