Example usage for com.google.common.collect ImmutableSet stream

List of usage examples for com.google.common.collect ImmutableSet stream

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSet stream.

Prototype

default Stream<E> stream() 

Source Link

Document

Returns a sequential Stream with this collection as its source.

Usage

From source file:com.facebook.buck.jvm.java.DefaultJavaLibrary.java

protected DefaultJavaLibrary(BuildRuleParams params, final SourcePathResolver resolver,
        SourcePathRuleFinder ruleFinder, Set<? extends SourcePath> srcs, Set<? extends SourcePath> resources,
        Optional<Path> generatedSourceFolder, Optional<SourcePath> proguardConfig,
        ImmutableList<String> postprocessClassesCommands, ImmutableSortedSet<BuildRule> exportedDeps,
        ImmutableSortedSet<BuildRule> providedDeps, BuildTarget abiJar, boolean trackClassUsage,
        final JarArchiveDependencySupplier abiClasspath, ImmutableSet<Path> additionalClasspathEntries,
        CompileToJarStepFactory compileStepFactory, Optional<Path> resourcesRoot,
        Optional<SourcePath> manifestFile, Optional<String> mavenCoords, ImmutableSortedSet<BuildTarget> tests,
        ImmutableSet<Pattern> classesToRemoveFromJar) {
    super(params.appendExtraDeps(() -> ruleFinder.filterBuildRuleInputs(abiClasspath.get())), resolver);
    this.ruleFinder = ruleFinder;
    this.compileStepFactory = compileStepFactory;

    // Exported deps are meant to be forwarded onto the CLASSPATH for dependents,
    // and so only make sense for java library types.
    for (BuildRule dep : exportedDeps) {
        if (!(dep instanceof JavaLibrary)) {
            throw new HumanReadableException(params.getBuildTarget() + ": exported dep " + dep.getBuildTarget()
                    + " (" + dep.getType() + ") " + "must be a type of java library.");
        }/*  w  ww  .  j  ava  2s  . co m*/
    }

    this.srcs = ImmutableSortedSet.copyOf(srcs);
    this.resources = ImmutableSortedSet.copyOf(resources);
    this.proguardConfig = proguardConfig;
    this.postprocessClassesCommands = postprocessClassesCommands;
    this.exportedDeps = exportedDeps;
    this.providedDeps = providedDeps;
    this.additionalClasspathEntries = additionalClasspathEntries.stream().map(getProjectFilesystem()::resolve)
            .collect(MoreCollectors.toImmutableSet());
    this.resourcesRoot = resourcesRoot;
    this.manifestFile = manifestFile;
    this.mavenCoords = mavenCoords;
    this.tests = tests;

    this.abiJar = abiJar;
    this.trackClassUsage = trackClassUsage;
    this.abiClasspath = abiClasspath;
    this.deps = params.getDeps();
    if (!srcs.isEmpty() || !resources.isEmpty() || manifestFile.isPresent()) {
        this.outputJar = Optional.of(getOutputJarPath(getBuildTarget(), getProjectFilesystem()));
    } else {
        this.outputJar = Optional.empty();
    }

    this.outputClasspathEntriesSupplier = Suppliers.memoize(() -> JavaLibraryClasspathProvider
            .getOutputClasspathJars(DefaultJavaLibrary.this, getResolver(), sourcePathForOutputJar()));

    this.transitiveClasspathsSupplier = Suppliers.memoize(
            () -> JavaLibraryClasspathProvider.getClasspathsFromLibraries(getTransitiveClasspathDeps()));

    this.transitiveClasspathDepsSupplier = Suppliers
            .memoize(() -> JavaLibraryClasspathProvider.getTransitiveClasspathDeps(DefaultJavaLibrary.this));

    this.buildOutputInitializer = new BuildOutputInitializer<>(params.getBuildTarget(), this);
    this.generatedSourceFolder = generatedSourceFolder;
    this.classesToRemoveFromJar = classesToRemoveFromJar;
}

From source file:com.ikanow.aleph2.analytics.storm.services.MockAnalyticsContext.java

@Override
public String getAnalyticsContextSignature(final Optional<DataBucketBean> bucket,
        final Optional<Set<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>> services) {
    if (_state_name == State.IN_TECHNOLOGY) {
        // Returns a config object containing:
        // - set up for any of the services described
        // - all the rest of the configuration
        // - the bucket bean ID

        final Config full_config = ModuleUtils.getStaticConfig()
                .withoutPath(DistributedServicesPropertyBean.APPLICATION_NAME)
                .withoutPath("MongoDbManagementDbService.v1_enabled") // (special workaround for V1 sync service)
        ;//from  w w  w . ja  v  a  2 s  .  c  o m

        final Optional<Config> service_config = PropertiesUtils.getSubConfig(full_config, "service");

        final ImmutableSet<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>> complete_services_set = ImmutableSet
                .<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>builder()
                .addAll(services.orElse(Collections.emptySet()))
                .add(Tuples._2T(ICoreDistributedServices.class, Optional.empty()))
                .add(Tuples._2T(IManagementDbService.class, Optional.empty()))
                .add(Tuples._2T(ISearchIndexService.class, Optional.empty()))
                .add(Tuples._2T(ISecurityService.class, Optional.empty()))
                .add(Tuples._2T(IStorageService.class, Optional.empty()))
                .add(Tuples._2T(IManagementDbService.class, IManagementDbService.CORE_MANAGEMENT_DB)).build();

        if (_mutable_state.service_manifest_override.isSet()) {
            if (!complete_services_set.equals(_mutable_state.service_manifest_override.get())) {
                throw new RuntimeException(ErrorUtils.SERVICE_RESTRICTIONS);
            }
        } else {
            _mutable_state.service_manifest_override.set(complete_services_set);
        }

        final Config config_no_services = full_config.withoutPath("service");

        // Ugh need to add: core deps, core + underlying management db to this list

        final Config service_subset = complete_services_set.stream() // DON'T MAKE PARALLEL SEE BELOW
                .map(clazz_name -> {
                    final String config_path = clazz_name._2()
                            .orElse(clazz_name._1().getSimpleName().substring(1));
                    return service_config.get().hasPath(config_path)
                            ? Tuples._2T(config_path, service_config.get().getConfig(config_path))
                            : null;
                }).filter(cfg -> null != cfg).reduce(ConfigFactory.empty(),
                        (acc, k_v) -> acc.withValue(k_v._1(), k_v._2().root()), (acc1, acc2) -> acc1 // (This will never be called as long as the above stream is not parallel)
        );

        final Config config_subset_services = config_no_services.withValue("service", service_subset.root());

        final Config last_call = Lambdas
                .get(() -> _mutable_state.library_configs.isSet()
                        ? config_subset_services
                                .withValue(__MY_MODULE_LIBRARY_ID,
                                        ConfigValueFactory
                                                .fromAnyRef(BeanTemplateUtils
                                                        .toJson(new LibraryContainerBean(
                                                                _mutable_state.library_configs.get().entrySet()
                                                                        .stream()
                                                                        .filter(kv -> kv.getValue().path_name()
                                                                                .equals(kv.getKey()))
                                                                        .map(kv -> kv.getValue())
                                                                        .collect(Collectors.toList())))
                                                        .toString()))
                        : config_subset_services)
                .withValue(__MY_BUCKET_ID,
                        ConfigValueFactory.fromAnyRef(BeanTemplateUtils
                                .toJson(bucket.orElseGet(() -> _mutable_state.bucket.get())).toString()))
                .withValue(__MY_TECH_LIBRARY_ID, ConfigValueFactory.fromAnyRef(
                        BeanTemplateUtils.toJson(_mutable_state.technology_config.get()).toString()));

        final String ret1 = last_call.root().render(ConfigRenderOptions.concise());
        _mutable_state.signature_override.set(ret1);
        final String ret = this.getClass().getName() + ":" + ret1;

        this.overrideSavedContext(); // (FOR TESTING ONLY - ie BECAUSE THIS IS MOCK ANALYTIC CONTEXT)

        return ret;
    } else {
        throw new RuntimeException(ErrorUtils.TECHNOLOGY_NOT_MODULE);
    }
}

From source file:com.ikanow.aleph2.analytics.hadoop.services.MockAnalyticsContext.java

@Override
public String getAnalyticsContextSignature(final Optional<DataBucketBean> bucket,
        final Optional<Set<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>> services) {
    if (_state_name == State.IN_TECHNOLOGY) {
        // Returns a config object containing:
        // - set up for any of the services described
        // - all the rest of the configuration
        // - the bucket bean ID

        final Config full_config = ModuleUtils.getStaticConfig()
                .withoutPath(DistributedServicesPropertyBean.APPLICATION_NAME)
                .withoutPath("MongoDbManagementDbService.v1_enabled") // (special workaround for V1 sync service)
        ;//w  w  w.  ja v  a  2s  .  c  o  m

        final Optional<Config> service_config = PropertiesUtils.getSubConfig(full_config, "service");

        final ImmutableSet<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>> complete_services_set = ImmutableSet
                .<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>builder()
                .addAll(services.orElse(Collections.emptySet()))
                .add(Tuples._2T(ICoreDistributedServices.class, Optional.empty()))
                .add(Tuples._2T(IManagementDbService.class, Optional.empty()))
                .add(Tuples._2T(ISearchIndexService.class, Optional.empty()))
                .add(Tuples._2T(ISecurityService.class, Optional.empty()))
                .add(Tuples._2T(IStorageService.class, Optional.empty()))
                .add(Tuples._2T(IManagementDbService.class, IManagementDbService.CORE_MANAGEMENT_DB)).build();

        if (_mutable_state.service_manifest_override.isSet()) {
            if (!complete_services_set.equals(_mutable_state.service_manifest_override.get())) {
                throw new RuntimeException(HadoopErrorUtils.SERVICE_RESTRICTIONS);
            }
        } else {
            _mutable_state.service_manifest_override.set(complete_services_set);
        }

        final Config config_no_services = full_config.withoutPath("service");

        // Ugh need to add: core deps, core + underlying management db to this list

        final Config service_subset = complete_services_set.stream() // DON'T MAKE PARALLEL SEE BELOW
                .map(clazz_name -> {
                    final String config_path = clazz_name._2()
                            .orElse(clazz_name._1().getSimpleName().substring(1));
                    return service_config.get().hasPath(config_path)
                            ? Tuples._2T(config_path, service_config.get().getConfig(config_path))
                            : null;
                }).filter(cfg -> null != cfg).reduce(ConfigFactory.empty(),
                        (acc, k_v) -> acc.withValue(k_v._1(), k_v._2().root()), (acc1, acc2) -> acc1 // (This will never be called as long as the above stream is not parallel)
        );

        final Config config_subset_services = config_no_services.withValue("service", service_subset.root());

        final Config last_call = Lambdas
                .get(() -> _mutable_state.library_configs.isSet()
                        ? config_subset_services
                                .withValue(__MY_MODULE_LIBRARY_ID,
                                        ConfigValueFactory
                                                .fromAnyRef(BeanTemplateUtils
                                                        .toJson(new LibraryContainerBean(
                                                                _mutable_state.library_configs.get().entrySet()
                                                                        .stream()
                                                                        .filter(kv -> kv.getValue().path_name()
                                                                                .equals(kv.getKey()))
                                                                        .map(kv -> kv.getValue())
                                                                        .collect(Collectors.toList())))
                                                        .toString()))
                        : config_subset_services)
                .withValue(__MY_BUCKET_ID,
                        ConfigValueFactory.fromAnyRef(BeanTemplateUtils
                                .toJson(bucket.orElseGet(() -> _mutable_state.bucket.get())).toString()))
                .withValue(__MY_TECH_LIBRARY_ID, ConfigValueFactory.fromAnyRef(
                        BeanTemplateUtils.toJson(_mutable_state.technology_config.get()).toString()));

        final String ret1 = last_call.root().render(ConfigRenderOptions.concise());
        _mutable_state.signature_override.set(ret1);
        final String ret = this.getClass().getName() + ":" + ret1;

        this.overrideSavedContext(); // (FOR TESTING ONLY - ie BECAUSE THIS IS MOCK ANALYTIC CONTEXT)

        return ret;
    } else {
        throw new RuntimeException(HadoopErrorUtils.TECHNOLOGY_NOT_MODULE);
    }
}

From source file:com.facebook.buck.cli.AuditMbrIsolationCommand.java

@Override
public ExitCode runWithoutHelp(CommandRunnerParams params) {
    try {//from   ww  w .  java 2 s  . co  m
        // Create a TargetGraph that is composed of the transitive closure of all of the dependent
        // BuildRules for the specified BuildTargetPaths.
        ImmutableSet<BuildTarget> targets = convertArgumentsToBuildTargets(params, getArguments());

        if (targets.isEmpty()) {
            throw new CommandLineException("must specify at least one build target");
        }

        TargetGraph targetGraph;
        try (CommandThreadManager pool = new CommandThreadManager("Audit",
                getConcurrencyLimit(params.getBuckConfig()))) {
            targetGraph = params.getParser()
                    .buildTargetGraph(createParsingContext(params.getCell(), pool.getListeningExecutorService())
                            .withSpeculativeParsing(SpeculativeParsing.ENABLED)
                            .withExcludeUnsupportedTargets(false), targets);
        } catch (BuildFileParseException e) {
            params.getBuckEventBus()
                    .post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            return ExitCode.PARSE_ERROR;
        }
        if (params.getBuckConfig().getView(BuildBuckConfig.class).getBuildVersions()) {
            targetGraph = toVersionedTargetGraph(params, TargetGraphAndBuildTargets.of(targetGraph, targets))
                    .getTargetGraph();
        }

        ActionGraphBuilder graphBuilder = Objects.requireNonNull(new ActionGraphProvider(
                params.getBuckEventBus(),
                ActionGraphFactory.create(params.getBuckEventBus(), params.getCell().getCellProvider(),
                        params.getPoolSupplier(), params.getBuckConfig()),
                new ActionGraphCache(
                        params.getBuckConfig().getView(BuildBuckConfig.class).getMaxActionGraphCacheEntries()),
                params.getRuleKeyConfiguration(), params.getBuckConfig()).getFreshActionGraph(targetGraph))
                .getActionGraphBuilder();
        graphBuilder.requireAllRules(targets);

        SerializationReportGenerator reportGenerator = new SerializationReportGenerator();

        SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder);
        IsolationChecker isolationChecker = new IsolationChecker(ruleFinder,
                params.getCell().getCellPathResolver(), reportGenerator.getFailureReporter());
        AbstractBreadthFirstTraversal.<BuildRule>traverse(
                targets.stream().map(graphBuilder::getRule).collect(Collectors.toList()), rule -> {
                    isolationChecker.check(rule);
                    ImmutableList.Builder<BuildRule> depsBuilder = ImmutableList.builder();
                    depsBuilder.addAll(rule.getBuildDeps());
                    if (rule instanceof HasRuntimeDeps) {
                        depsBuilder.addAll(graphBuilder.getAllRules(((HasRuntimeDeps) rule)
                                .getRuntimeDeps(ruleFinder).collect(Collectors.toList())));
                    }
                    return depsBuilder.build();
                });

        String report = Joiner.on("\n").join(reportGenerator.generate());
        params.getConsole().getStdOut().println(report);
    } catch (Exception e) {
        throw new BuckUncheckedExecutionException(e,
                "When inspecting serialization state of the action graph.");
    }

    return ExitCode.SUCCESS;
}

From source file:com.ikanow.aleph2.data_import.services.HarvestContext.java

@Override
public String getHarvestContextSignature(final Optional<DataBucketBean> bucket,
        final Optional<Set<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>> services) {
    if (_state_name == State.IN_TECHNOLOGY) {
        // Returns a config object containing:
        // - set up for any of the services described
        // - all the rest of the configuration
        // - the bucket bean ID

        final Config full_config = ModuleUtils.getStaticConfig()
                .withoutPath(DistributedServicesPropertyBean.APPLICATION_NAME)
                .withoutPath("MongoDbManagementDbService.v1_enabled") // (special workaround for V1 sync service)
        ;/*  ww  w  . j av  a2s. c o m*/

        final Optional<Config> service_config = PropertiesUtils.getSubConfig(full_config, "service");

        final Optional<DataBucketBean> maybe_bucket = bucket.map(Optional::of)
                .orElseGet(() -> _mutable_state.bucket.optional());

        final ImmutableSet<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>> complete_services_set = Optional
                .of(ImmutableSet.<Tuple2<Class<? extends IUnderlyingService>, Optional<String>>>builder()
                        .addAll(services.orElse(Collections.emptySet()))
                        .add(Tuples._2T(ICoreDistributedServices.class, Optional.empty()))
                        .add(Tuples._2T(IManagementDbService.class, Optional.empty()))
                        .add(Tuples._2T(IStorageService.class, Optional.empty()))
                        .add(Tuples._2T(ISecurityService.class, Optional.empty()))
                        .add(Tuples._2T(ILoggingService.class, Optional.empty())) //doesn't pull in ES via getUnderlyingArtefacts, relies on the one here
                        .add(Tuples._2T(IManagementDbService.class, IManagementDbService.CORE_MANAGEMENT_DB)))
                // Optional services:
                //TODO (ALEPH-19): 1) should port this across to the more comprehensive/centralized CSL, 2) Do I need a "support direct output" flag, and not do this if not set?
                // seems like a waste to stick these JARs on the classpath when the Harvester is normally only writing to real-time/file-based queue?
                // (see AnalyticsContext/DataServiceUtils for more details on point #1)
                .map(sb -> (maybe_bucket.map(b -> hasSearchIndexOutput(b)).orElse(false))
                        ? sb.add(Tuples._2T(ISearchIndexService.class, Optional.empty()))
                                .add(Tuples._2T(ITemporalService.class, Optional.empty())).add(
                                        Tuples._2T(IColumnarService.class, Optional.empty()))
                        : sb)
                .map(sb -> (maybe_bucket.map(b -> hasDocumentOutput(b)).orElse(false))
                        ? sb.add(Tuples._2T(IDocumentService.class, Optional.empty()))
                        : sb)
                .map(sb -> sb.build()).get();

        final Config config_no_services = full_config.withoutPath("service");

        if (_mutable_state.service_manifest_override.isSet()) {
            if (!complete_services_set.equals(_mutable_state.service_manifest_override.get())) {
                throw new RuntimeException(ErrorUtils.SERVICE_RESTRICTIONS);
            }
        } else {
            _mutable_state.service_manifest_override.set(complete_services_set);
        }

        // Ugh need to add: core deps, core + underlying management db to this list

        final Config service_defn_subset = complete_services_set.stream() // DON'T MAKE PARALLEL SEE BELOW
                .map(clazz_name -> {
                    final String config_path = clazz_name._2()
                            .orElse(clazz_name._1().getSimpleName().substring(1));
                    return Lambdas
                            .wrap_u(__ -> service_config.get().hasPath(config_path)
                                    ? Tuples._2T(config_path, service_config.get().getConfig(config_path))
                                    : null)
                            //(could add extra transforms here if we wanted)
                            .apply(Unit.unit());
                }).filter(cfg -> null != cfg).reduce(ConfigFactory.empty(),
                        (acc, k_v) -> acc.withValue(k_v._1(), k_v._2().root()), (acc1, acc2) -> acc1 // (This will never be called as long as the above stream is not parallel)
        );

        // Service configuration:
        final Config service_cfgn_subset = _mutable_state.service_manifest_override.get().stream() // DON'T MAKE PARALLEL SEE BELOW
                .reduce(config_no_services, // (leave other configurations, we just transform service specific configuration)
                        (acc, clazz_name) -> {
                            final Optional<? extends IUnderlyingService> underlying_service = _service_context
                                    .getService(clazz_name._1(), clazz_name._2());
                            return underlying_service.map(ds -> ds.createRemoteConfig(bucket, acc)).orElse(acc);
                        }, (acc1, acc2) -> acc1 // (This will never be called as long as the above stream is not parallel)
        );

        final Config config_subset_services = service_cfgn_subset.withValue("service",
                service_defn_subset.root());

        final Config last_call = Lambdas
                .get(() -> _mutable_state.library_configs.isSet()
                        ? config_subset_services
                                .withValue(__MY_MODULE_LIBRARY_ID,
                                        ConfigValueFactory
                                                .fromAnyRef(BeanTemplateUtils
                                                        .toJson(new LibraryContainerBean(
                                                                _mutable_state.library_configs.get().entrySet()
                                                                        .stream()
                                                                        .filter(kv -> kv.getValue().path_name()
                                                                                .equals(kv.getKey()))
                                                                        .map(kv -> kv.getValue())
                                                                        .collect(Collectors.toList())))
                                                        .toString()))
                        : config_subset_services)
                .withValue(__MY_BUCKET_ID,
                        ConfigValueFactory.fromAnyRef(
                                maybe_bucket.map(b -> BeanTemplateUtils.toJson(b).toString()).orElse("{}")))
                .withValue(__MY_TECH_LIBRARY_ID, ConfigValueFactory.fromAnyRef(_mutable_state.technology_config
                        .optional().map(l -> BeanTemplateUtils.toJson(l).toString()).orElse("{}")));

        return this.getClass().getName() + ":" + last_call.root().render(ConfigRenderOptions.concise());
    } else {
        throw new RuntimeException(ErrorUtils.TECHNOLOGY_NOT_MODULE);
    }
}

From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java

private void setAppIconSettings(ImmutableSet<AppleAssetCatalogDescriptionArg> recursiveAssetCatalogs,
        ImmutableSet<AppleAssetCatalogDescriptionArg> directAssetCatalogs, BuildTarget buildTarget,
        ImmutableMap.Builder<String, String> defaultSettingsBuilder) {
    ImmutableList<String> appIcon = Stream.concat(directAssetCatalogs.stream(), recursiveAssetCatalogs.stream())
            .map(x -> x.getAppIcon()).filter(Optional::isPresent).map(Optional::get)
            .collect(ImmutableList.toImmutableList());
    if (appIcon.size() > 1) {
        throw new HumanReadableException(
                "At most one asset catalog in the dependencies of %s " + "can have a app_icon", buildTarget);
    } else if (appIcon.size() == 1) {
        defaultSettingsBuilder.put("ASSETCATALOG_COMPILER_APPICON_NAME", appIcon.get(0));
    }//from  w  ww. ja  va2 s.c  om
}

From source file:com.facebook.buck.features.apple.project.ProjectGenerator.java

private void setLaunchImageSettings(ImmutableSet<AppleAssetCatalogDescriptionArg> recursiveAssetCatalogs,
        ImmutableSet<AppleAssetCatalogDescriptionArg> directAssetCatalogs, BuildTarget buildTarget,
        ImmutableMap.Builder<String, String> defaultSettingsBuilder) {
    ImmutableList<String> launchImage = Stream
            .concat(directAssetCatalogs.stream(), recursiveAssetCatalogs.stream()).map(x -> x.getLaunchImage())
            .filter(Optional::isPresent).map(Optional::get).collect(ImmutableList.toImmutableList());
    if (launchImage.size() > 1) {
        throw new HumanReadableException(
                "At most one asset catalog in the dependencies of %s " + "can have a launch_image",
                buildTarget);/*from   w ww . j  ava2  s  .  c o m*/
    } else if (launchImage.size() == 1) {
        defaultSettingsBuilder.put("ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME", launchImage.get(0));
    }
}