Search in sources :

Example 71 with ImmutableSet

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);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Flavor(com.facebook.buck.model.Flavor) PatternAndMessage(com.facebook.buck.util.PatternAndMessage)

Example 72 with ImmutableSet

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();
}
Also used : Pattern(java.util.regex.Pattern) ImmutableSet(com.google.common.collect.ImmutableSet)

Example 73 with ImmutableSet

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);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList(com.google.common.collect.ImmutableList) BuildTarget(com.facebook.buck.model.BuildTarget) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 74 with ImmutableSet

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"));
}
Also used : Introspector(java.beans.Introspector) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableList(com.google.common.collect.ImmutableList) Checkers.check(org.immutables.check.Checkers.check) FluentIterable(com.google.common.collect.FluentIterable) ImmutableMap(com.google.common.collect.ImmutableMap) PropertyDescriptor(java.beans.PropertyDescriptor) Test(org.junit.Test) PropertyDescriptor(java.beans.PropertyDescriptor) Test(org.junit.Test)

Example 75 with ImmutableSet

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;
}
Also used : FakeBuildContext(com.facebook.buck.rules.FakeBuildContext) StepRunner(com.facebook.buck.step.StepRunner) ActionGraph(com.facebook.buck.rules.ActionGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RichStream(com.facebook.buck.util.RichStream) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) Ansi(com.facebook.buck.util.Ansi) Assert.assertThat(org.junit.Assert.assertThat) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) ByteArrayInputStream(java.io.ByteArrayInputStream) RuleKey(com.facebook.buck.rules.RuleKey) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Assert.fail(org.junit.Assert.fail) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Splitter(com.google.common.base.Splitter) Path(java.nio.file.Path) JavaPackageFinder(com.facebook.buck.jvm.core.JavaPackageFinder) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget) Verbosity(com.facebook.buck.util.Verbosity) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AndroidLibraryBuilder(com.facebook.buck.android.AndroidLibraryBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) DEFAULT_JAVAC_OPTIONS(com.facebook.buck.jvm.java.JavaCompilationConstants.DEFAULT_JAVAC_OPTIONS) BuildTarget(com.facebook.buck.model.BuildTarget) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) EasyMock.createNiceMock(org.easymock.EasyMock.createNiceMock) Matchers.equalTo(org.hamcrest.Matchers.equalTo) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) Matchers.is(org.hamcrest.Matchers.is) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ZipOutputStream(java.util.zip.ZipOutputStream) Iterables(com.google.common.collect.Iterables) Step(com.facebook.buck.step.Step) SourcePath(com.facebook.buck.rules.SourcePath) Hashing(com.google.common.hash.Hashing) FakeBuildableContext(com.facebook.buck.rules.FakeBuildableContext) BuckEventBusFactory(com.facebook.buck.event.BuckEventBusFactory) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) LinkOption(java.nio.file.LinkOption) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) MoreAsserts(com.facebook.buck.testutil.MoreAsserts) ImmutableList(com.google.common.collect.ImmutableList) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) BuildTargetFactory(com.facebook.buck.model.BuildTargetFactory) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) Suppliers(com.google.common.base.Suppliers) EasyMock.replay(org.easymock.EasyMock.replay) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) Before(org.junit.Before) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) Charsets(com.google.common.base.Charsets) Assert.assertNotNull(org.junit.Assert.assertNotNull) TargetNode(com.facebook.buck.rules.TargetNode) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) IOException(java.io.IOException) EasyMock.expect(org.easymock.EasyMock.expect) HashingDeterministicJarWriter(com.facebook.buck.io.HashingDeterministicJarWriter) Console(com.facebook.buck.util.Console) EasyMock(org.easymock.EasyMock) HumanReadableException(com.facebook.buck.util.HumanReadableException) File(java.io.File) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) Rule(org.junit.Rule) Ordering(com.google.common.collect.Ordering) Paths(java.nio.file.Paths) TargetGraphFactory(com.facebook.buck.testutil.TargetGraphFactory) FileHashCache(com.facebook.buck.util.cache.FileHashCache) BuildContext(com.facebook.buck.rules.BuildContext) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) Paths(java.nio.file.Paths)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)212 Path (java.nio.file.Path)66 BuildTarget (com.facebook.buck.model.BuildTarget)58 ImmutableList (com.google.common.collect.ImmutableList)48 ImmutableMap (com.google.common.collect.ImmutableMap)48 IOException (java.io.IOException)43 Optional (java.util.Optional)39 Test (org.junit.Test)35 SourcePath (com.facebook.buck.rules.SourcePath)31 Set (java.util.Set)31 Map (java.util.Map)30 TargetNode (com.facebook.buck.rules.TargetNode)28 List (java.util.List)28 BuildRule (com.facebook.buck.rules.BuildRule)26 HumanReadableException (com.facebook.buck.util.HumanReadableException)23 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)22 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)21 HashMap (java.util.HashMap)21 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)20 VisibleForTesting (com.google.common.annotations.VisibleForTesting)20