Search in sources :

Example 1 with FluentIterable

use of com.google.common.collect.FluentIterable in project buck by facebook.

the class ParsePipelineTest method speculativeDepsTraversalWhenGettingAllNodes.

@Test
public void speculativeDepsTraversalWhenGettingAllNodes() throws Exception {
    final Fixture fixture = createMultiThreadedFixture("pipeline_test");
    final Cell cell = fixture.getCell();
    ImmutableSet<TargetNode<?, ?>> libTargetNodes = fixture.getTargetNodeParsePipeline().getAllNodes(cell, fixture.getCell().getFilesystem().resolve("BUCK"));
    FluentIterable<BuildTarget> allDeps = FluentIterable.from(libTargetNodes).transformAndConcat(new Function<TargetNode<?, ?>, Iterable<BuildTarget>>() {

        @Override
        public Iterable<BuildTarget> apply(TargetNode<?, ?> input) {
            return input.getDeps();
        }
    });
    waitForAll(allDeps, dep -> fixture.getTargetNodeParsePipelineCache().lookupComputedNode(cell, dep) != null);
    fixture.close();
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) FluentIterable(com.google.common.collect.FluentIterable) BuildTarget(com.facebook.buck.model.BuildTarget) Cell(com.facebook.buck.rules.Cell) Test(org.junit.Test)

Example 2 with FluentIterable

use of com.google.common.collect.FluentIterable 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 3 with FluentIterable

use of com.google.common.collect.FluentIterable in project gerrit by GerritCodeReview.

the class AccountIT method assertKeys.

private void assertKeys(Iterable<TestKey> expectedKeys) throws Exception {
    // Check via API.
    FluentIterable<TestKey> expected = FluentIterable.from(expectedKeys);
    Map<String, GpgKeyInfo> keyMap = gApi.accounts().self().listGpgKeys();
    assertThat(keyMap.keySet()).named("keys returned by listGpgKeys()").containsExactlyElementsIn(expected.transform(TestKey::getKeyIdString));
    for (TestKey key : expected) {
        assertKeyEquals(key, gApi.accounts().self().gpgKey(key.getKeyIdString()).get());
        assertKeyEquals(key, gApi.accounts().self().gpgKey(Fingerprint.toString(key.getPublicKey().getFingerprint())).get());
        assertKeyMapContains(key, keyMap);
    }
    // Check raw external IDs.
    Account.Id currAccountId = atrScope.get().getUser().getAccountId();
    Iterable<String> expectedFps = expected.transform(k -> BaseEncoding.base16().encode(k.getPublicKey().getFingerprint()));
    Iterable<String> actualFps = externalIds.byAccount(currAccountId, SCHEME_GPGKEY).stream().map(e -> e.key().id()).collect(toSet());
    assertThat(actualFps).named("external IDs in database").containsExactlyElementsIn(expectedFps);
    // Check raw stored keys.
    for (TestKey key : expected) {
        getOnlyKeyFromStore(key);
    }
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) AllUsersName(com.google.gerrit.server.config.AllUsersName) IGNORE_LABEL(com.google.gerrit.server.StarredChangesUtil.IGNORE_LABEL) Arrays(java.util.Arrays) SshMode(com.google.gerrit.testutil.SshMode) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) TestAccount(com.google.gerrit.acceptance.TestAccount) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Config(org.eclipse.jgit.lib.Config) FluentIterable(com.google.common.collect.FluentIterable) GpgKeyInfo(com.google.gerrit.extensions.common.GpgKeyInfo) Map(java.util.Map) WatchConfig(com.google.gerrit.server.account.WatchConfig) EnumSet(java.util.EnumSet) TestKeys.allValidKeys(com.google.gerrit.gpg.testutil.TestKeys.allValidKeys) GitUtil.deleteRef(com.google.gerrit.acceptance.GitUtil.deleteRef) Set(java.util.Set) RefUpdate(org.eclipse.jgit.lib.RefUpdate) PGPPublicKey(org.bouncycastle.openpgp.PGPPublicKey) ExternalIds(com.google.gerrit.server.account.externalids.ExternalIds) RefNames(com.google.gerrit.reviewdb.client.RefNames) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) ExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate) GitUtil.fetch(com.google.gerrit.acceptance.GitUtil.fetch) Iterables(com.google.common.collect.Iterables) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Fingerprint(com.google.gerrit.gpg.Fingerprint) ArrayList(java.util.ArrayList) AccountByEmailCache(com.google.gerrit.server.account.AccountByEmailCache) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Before(org.junit.Before) MagicBranch(com.google.gerrit.server.util.MagicBranch) TestRepository(org.eclipse.jgit.junit.TestRepository) BaseEncoding(com.google.common.io.BaseEncoding) Test(org.junit.Test) ANONYMOUS_USERS(com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS) TestKeys.validKeyWithoutExpiration(com.google.gerrit.gpg.testutil.TestKeys.validKeyWithoutExpiration) AccountIndexedListener(com.google.gerrit.extensions.events.AccountIndexedListener) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) DynamicSet(com.google.gerrit.extensions.registration.DynamicSet) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Assert(org.junit.Assert) Repository(org.eclipse.jgit.lib.Repository) TestKey(com.google.gerrit.gpg.testutil.TestKey) Inject(com.google.inject.Inject) REFS_GPG_KEYS(com.google.gerrit.gpg.PublicKeyStore.REFS_GPG_KEYS) ChangeRebuilderImpl(com.google.gerrit.server.notedb.rebuild.ChangeRebuilderImpl) AccountCreator(com.google.gerrit.acceptance.AccountCreator) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) DEFAULT_LABEL(com.google.gerrit.server.StarredChangesUtil.DEFAULT_LABEL) TestKeys.validKeyWithExpiration(com.google.gerrit.gpg.testutil.TestKeys.validKeyWithExpiration) Locale(java.util.Locale) After(org.junit.After) AuthException(com.google.gerrit.extensions.restapi.AuthException) Assert.fail(org.junit.Assert.fail) PGPPublicKeyRing(org.bouncycastle.openpgp.PGPPublicKeyRing) AtomicLongMap(com.google.common.util.concurrent.AtomicLongMap) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet(com.google.common.collect.ImmutableSet) Collection(java.util.Collection) Permission(com.google.gerrit.common.data.Permission) SCHEME_GPGKEY(com.google.gerrit.server.account.externalids.ExternalId.SCHEME_GPGKEY) NotifyType(com.google.gerrit.server.account.WatchConfig.NotifyType) TestKeys.validKeyWithSecondUserId(com.google.gerrit.gpg.testutil.TestKeys.validKeyWithSecondUserId) List(java.util.List) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Ref(org.eclipse.jgit.lib.Ref) ConfigSuite(com.google.gerrit.testutil.ConfigSuite) RegistrationHandle(com.google.gerrit.extensions.registration.RegistrationHandle) RefPattern(com.google.gerrit.server.project.RefPattern) Message(com.google.gerrit.testutil.FakeEmailSender.Message) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) PublicKeyStore(com.google.gerrit.gpg.PublicKeyStore) SshKeyInfo(com.google.gerrit.extensions.common.SshKeyInfo) ImmutableList(com.google.common.collect.ImmutableList) UseSsh(com.google.gerrit.acceptance.UseSsh) Account(com.google.gerrit.reviewdb.client.Account) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Truth.assert_(com.google.common.truth.Truth.assert_) Iterator(java.util.Iterator) Sandboxed(com.google.gerrit.acceptance.Sandboxed) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Truth.assertThat(com.google.common.truth.Truth.assertThat) TransportException(org.eclipse.jgit.api.errors.TransportException) ArmoredOutputStream(org.bouncycastle.bcpg.ArmoredOutputStream) Provider(com.google.inject.Provider) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) StarsInput(com.google.gerrit.extensions.api.changes.StarsInput) PushCertificateIdent(org.eclipse.jgit.transport.PushCertificateIdent) TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.reviewdb.client.Account) TestKey(com.google.gerrit.gpg.testutil.TestKey) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) GpgKeyInfo(com.google.gerrit.extensions.common.GpgKeyInfo)

Example 4 with FluentIterable

use of com.google.common.collect.FluentIterable in project crate by crate.

the class ExecutionPhasesTask method executeBulk.

@Override
public List<CompletableFuture<Long>> executeBulk() {
    FluentIterable<NodeOperation> nodeOperations = FluentIterable.from(nodeOperationTrees).transformAndConcat(new Function<NodeOperationTree, Iterable<? extends NodeOperation>>() {

        @Nullable
        @Override
        public Iterable<? extends NodeOperation> apply(NodeOperationTree input) {
            return input.nodeOperations();
        }
    });
    Map<String, Collection<NodeOperation>> operationByServer = NodeOperationGrouper.groupByServer(nodeOperations);
    List<ExecutionPhase> handlerPhases = new ArrayList<>(nodeOperationTrees.size());
    List<BatchConsumer> handlerConsumers = new ArrayList<>(nodeOperationTrees.size());
    List<CompletableFuture<Long>> results = new ArrayList<>(nodeOperationTrees.size());
    for (NodeOperationTree nodeOperationTree : nodeOperationTrees) {
        CollectingBatchConsumer<?, Long> consumer = new CollectingBatchConsumer<>(Collectors.collectingAndThen(Collectors.summingLong(r -> ((long) r.get(0))), sum -> sum));
        handlerConsumers.add(consumer);
        results.add(consumer.resultFuture());
        handlerPhases.add(nodeOperationTree.leaf());
    }
    try {
        setupContext(operationByServer, handlerPhases, handlerConsumers);
    } catch (Throwable throwable) {
        return Collections.singletonList(CompletableFutures.failedFuture(throwable));
    }
    return results;
}
Also used : java.util(java.util) SharedShardContexts(io.crate.action.job.SharedShardContexts) ExecutionPhase(io.crate.planner.node.ExecutionPhase) CompletableFuture(java.util.concurrent.CompletableFuture) TransportKillJobsNodeAction(io.crate.executor.transport.kill.TransportKillJobsNodeAction) ContextPreparer(io.crate.action.job.ContextPreparer) FluentIterable(com.google.common.collect.FluentIterable) BatchConsumer(io.crate.data.BatchConsumer) ClusterService(org.elasticsearch.cluster.ClusterService) IndicesService(org.elasticsearch.indices.IndicesService) io.crate.jobs(io.crate.jobs) ESLogger(org.elasticsearch.common.logging.ESLogger) Nullable(javax.annotation.Nullable) NodeOperation(io.crate.operation.NodeOperation) Loggers(org.elasticsearch.common.logging.Loggers) TransportJobAction(io.crate.action.job.TransportJobAction) Bucket(io.crate.data.Bucket) Function(com.google.common.base.Function) CompletableFutures(io.crate.concurrent.CompletableFutures) Collectors(java.util.stream.Collectors) JobRequest(io.crate.action.job.JobRequest) NodeOperationGrouper(io.crate.planner.node.NodeOperationGrouper) Row(io.crate.data.Row) CollectingBatchConsumer(io.crate.data.CollectingBatchConsumer) ExecutionPhases(io.crate.planner.node.ExecutionPhases) NodeOperationTree(io.crate.operation.NodeOperationTree) Tuple(org.elasticsearch.common.collect.Tuple) JobTask(io.crate.executor.JobTask) FluentIterable(com.google.common.collect.FluentIterable) NodeOperation(io.crate.operation.NodeOperation) ExecutionPhase(io.crate.planner.node.ExecutionPhase) NodeOperationTree(io.crate.operation.NodeOperationTree) CompletableFuture(java.util.concurrent.CompletableFuture) Nullable(javax.annotation.Nullable) BatchConsumer(io.crate.data.BatchConsumer) CollectingBatchConsumer(io.crate.data.CollectingBatchConsumer) CollectingBatchConsumer(io.crate.data.CollectingBatchConsumer)

Example 5 with FluentIterable

use of com.google.common.collect.FluentIterable in project buck by facebook.

the class AppleBundleDescription method findDepsForTargetFromConstructorArgs.

/**
   * Propagate the bundle's platform, debug symbol and strip flavors to its dependents
   * which are other bundles (e.g. extensions)
   */
@Override
public ImmutableSet<BuildTarget> findDepsForTargetFromConstructorArgs(BuildTarget buildTarget, CellPathResolver cellRoots, AppleBundleDescription.Arg constructorArg) {
    if (!cxxPlatformFlavorDomain.containsAnyOf(buildTarget.getFlavors())) {
        buildTarget = BuildTarget.builder(buildTarget).addAllFlavors(ImmutableSet.of(defaultCxxPlatform.getFlavor())).build();
    }
    Optional<MultiarchFileInfo> fatBinaryInfo = MultiarchFileInfos.create(appleCxxPlatformsFlavorDomain, buildTarget);
    CxxPlatform cxxPlatform;
    if (fatBinaryInfo.isPresent()) {
        AppleCxxPlatform appleCxxPlatform = fatBinaryInfo.get().getRepresentativePlatform();
        cxxPlatform = appleCxxPlatform.getCxxPlatform();
    } else {
        cxxPlatform = ApplePlatforms.getCxxPlatformForBuildTarget(cxxPlatformFlavorDomain, defaultCxxPlatform, buildTarget);
    }
    String platformName = cxxPlatform.getFlavor().getName();
    final Flavor actualWatchFlavor;
    if (ApplePlatform.isSimulator(platformName)) {
        actualWatchFlavor = WATCH_SIMULATOR_FLAVOR;
    } else if (platformName.startsWith(ApplePlatform.IPHONEOS.getName()) || platformName.startsWith(ApplePlatform.WATCHOS.getName())) {
        actualWatchFlavor = WATCH_OS_FLAVOR;
    } else {
        actualWatchFlavor = InternalFlavor.of(platformName);
    }
    FluentIterable<BuildTarget> depsExcludingBinary = FluentIterable.from(constructorArg.deps).filter(Predicates.not(constructorArg.binary::equals));
    // Propagate platform flavors.  Need special handling for watch to map the pseudo-flavor
    // watch to the actual watch platform (simulator or device) so can't use
    // BuildTargets.propagateFlavorsInDomainIfNotPresent()
    {
        FluentIterable<BuildTarget> targetsWithPlatformFlavors = depsExcludingBinary.filter(BuildTargets.containsFlavors(cxxPlatformFlavorDomain));
        FluentIterable<BuildTarget> targetsWithoutPlatformFlavors = depsExcludingBinary.filter(Predicates.not(BuildTargets.containsFlavors(cxxPlatformFlavorDomain)));
        FluentIterable<BuildTarget> watchTargets = targetsWithoutPlatformFlavors.filter(BuildTargets.containsFlavor(WATCH)).transform(input -> BuildTarget.builder(input.withoutFlavors(WATCH)).addFlavors(actualWatchFlavor).build());
        targetsWithoutPlatformFlavors = targetsWithoutPlatformFlavors.filter(Predicates.not(BuildTargets.containsFlavor(WATCH)));
        // Gather all the deps now that we've added platform flavors to everything.
        depsExcludingBinary = targetsWithPlatformFlavors.append(watchTargets).append(BuildTargets.propagateFlavorDomains(buildTarget, ImmutableSet.of(cxxPlatformFlavorDomain), targetsWithoutPlatformFlavors));
    }
    // Propagate some flavors
    depsExcludingBinary = BuildTargets.propagateFlavorsInDomainIfNotPresent(StripStyle.FLAVOR_DOMAIN, buildTarget, depsExcludingBinary);
    depsExcludingBinary = BuildTargets.propagateFlavorsInDomainIfNotPresent(AppleDebugFormat.FLAVOR_DOMAIN, buildTarget, depsExcludingBinary);
    depsExcludingBinary = BuildTargets.propagateFlavorsInDomainIfNotPresent(LinkerMapMode.FLAVOR_DOMAIN, buildTarget, depsExcludingBinary);
    if (fatBinaryInfo.isPresent()) {
        depsExcludingBinary = depsExcludingBinary.append(fatBinaryInfo.get().getRepresentativePlatform().getCodesignProvider().getParseTimeDeps());
    } else {
        depsExcludingBinary = depsExcludingBinary.append(appleCxxPlatformsFlavorDomain.getValue(buildTarget).map(platform -> platform.getCodesignProvider().getParseTimeDeps()).orElse(ImmutableSet.of()));
    }
    return ImmutableSet.copyOf(depsExcludingBinary);
}
Also used : FluentIterable(com.google.common.collect.FluentIterable) CellPathResolver(com.facebook.buck.rules.CellPathResolver) SourcePath(com.facebook.buck.rules.SourcePath) Either(com.facebook.buck.model.Either) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavored(com.facebook.buck.model.Flavored) HasTests(com.facebook.buck.model.HasTests) FlavorDomain(com.facebook.buck.model.FlavorDomain) FluentIterable(com.google.common.collect.FluentIterable) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ImplicitDepsInferringDescription(com.facebook.buck.rules.ImplicitDepsInferringDescription) Predicates(com.google.common.base.Predicates) StripStyle(com.facebook.buck.cxx.StripStyle) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) CxxDescriptionEnhancer(com.facebook.buck.cxx.CxxDescriptionEnhancer) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Version(com.facebook.buck.versions.Version) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) MetadataProvidingDescription(com.facebook.buck.rules.MetadataProvidingDescription) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) AbstractDescriptionArg(com.facebook.buck.rules.AbstractDescriptionArg) Hint(com.facebook.buck.rules.Hint) Optional(java.util.Optional) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTargets(com.facebook.buck.model.BuildTargets) Description(com.facebook.buck.rules.Description) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) BuildTarget(com.facebook.buck.model.BuildTarget) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor)

Aggregations

FluentIterable (com.google.common.collect.FluentIterable)6 ImmutableSet (com.google.common.collect.ImmutableSet)3 Test (org.junit.Test)3 BuildTarget (com.facebook.buck.model.BuildTarget)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ConsoleReporter (com.codahale.metrics.ConsoleReporter)1 Meter (com.codahale.metrics.Meter)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 CxxDescriptionEnhancer (com.facebook.buck.cxx.CxxDescriptionEnhancer)1 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)1 LinkerMapMode (com.facebook.buck.cxx.LinkerMapMode)1 StripStyle (com.facebook.buck.cxx.StripStyle)1 BuildTargets (com.facebook.buck.model.BuildTargets)1 Either (com.facebook.buck.model.Either)1 Flavor (com.facebook.buck.model.Flavor)1 FlavorDomain (com.facebook.buck.model.FlavorDomain)1 Flavored (com.facebook.buck.model.Flavored)1 HasTests (com.facebook.buck.model.HasTests)1 InternalFlavor (com.facebook.buck.model.InternalFlavor)1