use of 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 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 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 com.google.common.collect.ImmutableSet in project immutables by immutables.
the class BeanFriendlyTest method modifiableAsJavaBean.
@Test
public void modifiableAsJavaBean() throws Exception {
ImmutableSet<String> rwProperties = ImmutableSet.of("primary", "id", "description", "names", "options");
FluentIterable<PropertyDescriptor> propertyDescriptors = FluentIterable.of(Introspector.getBeanInfo(ModifiableBeanFriendly.class).getPropertyDescriptors());
check(propertyDescriptors.transform(p -> p.getName()).toSet().containsAll(rwProperties));
for (PropertyDescriptor pd : propertyDescriptors) {
check(pd.getReadMethod()).notNull();
if (rwProperties.contains(pd.getName())) {
check(pd.getWriteMethod()).notNull();
}
}
ModifiableBeanFriendly bean = new ModifiableBeanFriendly();
bean.setPrimary(true);
bean.setDescription("description");
bean.setId(1000);
bean.setNames(ImmutableList.of("name"));
bean.addNames("name2");
bean.putOptions("foo", "bar");
// This bean can become immutable.
BeanFriendly immutableBean = bean.toImmutable();
check(immutableBean.isPrimary());
check(immutableBean.getDescription()).is("description");
check(immutableBean.getId()).is(1000);
check(immutableBean.getNames()).isOf("name", "name2");
check(immutableBean.getOptions()).is(ImmutableMap.of("foo", "bar"));
}
use of 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;
}
Aggregations