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

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

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedSet 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.apple.AppleLibrarySwiftMetadata.java

public static AppleLibrarySwiftMetadata from(ImmutableSortedSet<SourceWithFlags> allSources,
        SourcePathResolver pathResolver) {
    Map<Boolean, List<SourceWithFlags>> swiftAndNonSwiftSources = allSources.stream()
            .collect(Collectors.partitioningBy(src -> SwiftDescriptions.isSwiftSource(src, pathResolver)));

    ImmutableSet<SourceWithFlags> swiftSources = swiftAndNonSwiftSources
            .getOrDefault(true, Collections.emptyList()).stream().collect(ImmutableSet.toImmutableSet());

    ImmutableSet<SourceWithFlags> nonSwiftSources = swiftAndNonSwiftSources
            .getOrDefault(false, Collections.emptyList()).stream().collect(ImmutableSet.toImmutableSet());

    return new AppleLibrarySwiftMetadata(swiftSources, nonSwiftSources);
}

From source file:com.facebook.buck.features.lua.LuaUtil.java

public static ImmutableList<BuildTarget> getDeps(CxxPlatform cxxPlatform, ImmutableSortedSet<BuildTarget> deps,
        PatternMatchedCollection<ImmutableSortedSet<BuildTarget>> platformDeps) {
    return RichStream
            .<BuildTarget>empty().concat(deps.stream()).concat(platformDeps
                    .getMatchingValues(cxxPlatform.getFlavor().toString()).stream().flatMap(Collection::stream))
            .toImmutableList();/*from ww w . java  2 s  . c  om*/
}

From source file:com.facebook.buck.features.python.PythonUtil.java

public static ImmutableList<BuildTarget> getDeps(PythonPlatform pythonPlatform, CxxPlatform cxxPlatform,
        ImmutableSortedSet<BuildTarget> deps,
        PatternMatchedCollection<ImmutableSortedSet<BuildTarget>> platformDeps) {
    return RichStream.<BuildTarget>empty().concat(deps.stream())
            .concat(platformDeps.getMatchingValues(pythonPlatform.getFlavor().toString()).stream()
                    .flatMap(Collection::stream))
            .concat(platformDeps.getMatchingValues(cxxPlatform.getFlavor().toString()).stream()
                    .flatMap(Collection::stream))
            .toImmutableList();//from www  .ja  v a 2  s.  co m
}

From source file:com.facebook.buck.features.rust.RustCompileUtils.java

static Pair<SourcePath, ImmutableSortedSet<SourcePath>> getRootModuleAndSources(BuildTarget target,
        ActionGraphBuilder graphBuilder, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder,
        CxxPlatform cxxPlatform, String crate, Optional<SourcePath> crateRoot,
        ImmutableSet<String> defaultRoots, ImmutableSortedSet<SourcePath> srcs) {

    ImmutableSortedSet<SourcePath> fixedSrcs = CxxGenruleDescription.fixupSourcePaths(graphBuilder, ruleFinder,
            cxxPlatform, srcs);// ww w  .  jav  a 2  s .c om

    Optional<SourcePath> rootModule = crateRoot.map(Optional::of)
            .orElse(getCrateRoot(pathResolver, crate, defaultRoots, fixedSrcs.stream()));

    return new Pair<>(rootModule.orElseThrow(
            () -> new HumanReadableException("Can't find suitable top-level source file for %s: %s",
                    target.getFullyQualifiedName(), fixedSrcs)),
            fixedSrcs);
}

From source file:com.facebook.buck.rust.RustCompileUtils.java

public static BinaryWrapperRule createBinaryBuildRule(BuildRuleParams params, BuildRuleResolver resolver,
        RustBuckConfig rustBuckConfig, FlavorDomain<CxxPlatform> cxxPlatforms, CxxPlatform defaultCxxPlatform,
        Optional<String> crateName, ImmutableSortedSet<String> features, Iterator<String> rustcFlags,
        Iterator<String> linkerFlags, Linker.LinkableDepType linkStyle, boolean rpath,
        ImmutableSortedSet<SourcePath> srcs, Optional<SourcePath> crateRoot, ImmutableSet<String> defaultRoots)
        throws NoSuchBuildTargetException {
    final BuildTarget buildTarget = params.getBuildTarget();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);

    ImmutableList.Builder<String> rustcArgs = ImmutableList.builder();

    RustCompileUtils.addFeatures(buildTarget, features, rustcArgs);

    rustcArgs.addAll(rustcFlags);// w  ww  . jav  a 2s  .  com

    ImmutableList.Builder<String> linkerArgs = ImmutableList.builder();
    linkerArgs.addAll(linkerFlags);

    String crate = crateName.orElse(ruleToCrateName(buildTarget.getShortName()));

    Optional<SourcePath> rootModule = RustCompileUtils.getCrateRoot(pathResolver, crate, crateRoot,
            defaultRoots, srcs.stream());

    if (!rootModule.isPresent()) {
        throw new HumanReadableException("Can't find suitable top-level source file for %s",
                buildTarget.getShortName());
    }

    CxxPlatform cxxPlatform = cxxPlatforms.getValue(params.getBuildTarget()).orElse(defaultCxxPlatform);

    // The target to use for the link rule.
    BuildTarget binaryTarget = params.getBuildTarget().withAppendedFlavors(cxxPlatform.getFlavor(),
            RustDescriptionEnhancer.RFBIN);

    CommandTool.Builder executableBuilder = new CommandTool.Builder();

    // Add the binary as the first argument.
    executableBuilder.addArg(new SourcePathArg(pathResolver, new BuildTargetSourcePath(binaryTarget)));

    // Special handling for dynamically linked binaries.
    if (linkStyle == Linker.LinkableDepType.SHARED) {

        // Create a symlink tree with for all shared libraries needed by this binary.
        SymlinkTree sharedLibraries = resolver.addToIndex(
                CxxDescriptionEnhancer.createSharedLibrarySymlinkTree(params, pathResolver, cxxPlatform,
                        params.getDeps(), RustLinkable.class::isInstance, RustLinkable.class::isInstance));

        // Embed a origin-relative library path into the binary so it can find the shared libraries.
        // The shared libraries root is absolute. Also need an absolute path to the linkOutput
        Path absBinaryDir = params.getBuildTarget().getCellPath()
                .resolve(RustCompileRule.getOutputDir(binaryTarget, params.getProjectFilesystem()));
        linkerArgs.addAll(Linkers.iXlinker("-rpath",
                String.format("%s/%s", cxxPlatform.getLd().resolve(resolver).origin(),
                        absBinaryDir.relativize(sharedLibraries.getRoot()).toString())));

        // Add all the shared libraries and the symlink tree as inputs to the tool that represents
        // this binary, so that users can attach the proper deps.
        executableBuilder.addDep(sharedLibraries);
        executableBuilder.addInputs(sharedLibraries.getLinks().values());
    }

    final CommandTool executable = executableBuilder.build();

    final RustCompileRule buildRule = RustCompileUtils.createBuild(binaryTarget, crate, params, resolver,
            pathResolver, ruleFinder, cxxPlatform, rustBuckConfig, rustcArgs.build(), linkerArgs.build(),
            /* linkerInputs */ ImmutableList.of(), CrateType.BIN, linkStyle, rpath, srcs, rootModule.get());

    return new BinaryWrapperRule(params.appendExtraDeps(buildRule), pathResolver, ruleFinder) {

        @Override
        public Tool getExecutableCommand() {
            return executable;
        }

        @Override
        public Path getPathToOutput() {
            return buildRule.getPathToOutput();
        }

    };
}

From source file:com.facebook.buck.ide.intellij.DefaultIjModuleFactory.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private IjModule createModuleUsingSortedTargetNodes(Path moduleBasePath,
        ImmutableSortedSet<TargetNode<?, ?>> targetNodes, Set<Path> excludes) {
    Preconditions.checkArgument(!targetNodes.isEmpty());

    ImmutableSet<BuildTarget> moduleBuildTargets = targetNodes.stream().map(TargetNode::getBuildTarget)
            .collect(MoreCollectors.toImmutableSet());

    ModuleBuildContext context = new ModuleBuildContext(moduleBuildTargets);

    Set<Class<?>> seenTypes = new HashSet<>();
    for (TargetNode<?, ?> targetNode : targetNodes) {
        Class<?> nodeType = targetNode.getDescription().getClass();
        seenTypes.add(nodeType);/*w w w . j av  a 2s  .  co m*/
        IjModuleRule<?> rule = Preconditions.checkNotNull(typeRegistry.getModuleRuleByTargetNodeType(nodeType));
        rule.apply((TargetNode) targetNode, context);
        context.setModuleType(rule.detectModuleType((TargetNode) targetNode));
    }

    if (seenTypes.size() > 1) {
        LOG.debug("Multiple types at the same path. Path: %s, types: %s", moduleBasePath, seenTypes);
    }

    if (context.isAndroidFacetBuilderPresent()) {
        context.getOrCreateAndroidFacetBuilder().setGeneratedSourcePath(
                IjAndroidHelper.createAndroidGenPath(projectFilesystem, moduleBasePath));
    }

    excludes.stream().map(moduleBasePath::resolve).map(ExcludeFolder::new).forEach(context::addSourceFolder);

    return IjModule.builder().setModuleBasePath(moduleBasePath).setTargets(moduleBuildTargets)
            .addAllFolders(context.getSourceFolders()).putAllDependencies(context.getDependencies())
            .setAndroidFacet(context.getAndroidFacet())
            .addAllExtraClassPathDependencies(context.getExtraClassPathDependencies())
            .addAllGeneratedSourceCodeFolders(context.getGeneratedSourceCodeFolders())
            .setLanguageLevel(context.getJavaLanguageLevel()).setModuleType(context.getModuleType())
            .setMetaInfDirectory(context.getMetaInfDirectory()).build();
}

From source file:com.facebook.buck.features.project.intellij.DefaultIjModuleFactory.java

@SuppressWarnings({ "unchecked", "rawtypes" })
private IjModule createModuleUsingSortedTargetNodes(Path moduleBasePath,
        ImmutableSortedSet<TargetNode> targetNodes, Set<Path> excludes) {
    Preconditions.checkArgument(!targetNodes.isEmpty());

    ImmutableSet<BuildTarget> moduleBuildTargets = targetNodes.stream().map(TargetNode::getBuildTarget)
            .collect(ImmutableSet.toImmutableSet());

    ModuleBuildContext context = new ModuleBuildContext(moduleBuildTargets);

    Set<Class<?>> seenTypes = new HashSet<>();
    for (TargetNode<?> targetNode : targetNodes) {
        Class<?> nodeType = targetNode.getDescription().getClass();
        seenTypes.add(nodeType);//from   ww w .  ja va 2s  .  c  o  m
        IjModuleRule<?> rule = Objects.requireNonNull(typeRegistry.getModuleRuleByTargetNodeType(nodeType));
        rule.apply((TargetNode) targetNode, context);
        context.setModuleType(rule.detectModuleType((TargetNode) targetNode));
    }

    if (seenTypes.size() > 1) {
        LOG.debug("Multiple types at the same path. Path: %s, types: %s", moduleBasePath, seenTypes);
    }

    if (context.isAndroidFacetBuilderPresent()) {
        context.getOrCreateAndroidFacetBuilder().setGeneratedSourcePath(
                IjAndroidHelper.createAndroidGenPath(projectFilesystem, moduleBasePath));
    }

    excludes.stream().map(moduleBasePath::resolve).map(ExcludeFolder::new).forEach(context::addSourceFolder);

    return IjModule.builder().setModuleBasePath(moduleBasePath).setTargets(moduleBuildTargets)
            .setNonSourceBuildTargets(context.getNonSourceBuildTargets())
            .addAllFolders(context.getSourceFolders()).putAllDependencies(context.getDependencies())
            .setAndroidFacet(context.getAndroidFacet())
            .addAllExtraClassPathDependencies(context.getExtraClassPathDependencies())
            .addAllExtraModuleDependencies(context.getExtraModuleDependencies())
            .addAllGeneratedSourceCodeFolders(context.getGeneratedSourceCodeFolders())
            .setLanguageLevel(context.getJavaLanguageLevel()).setModuleType(context.getModuleType())
            .setMetaInfDirectory(context.getMetaInfDirectory())
            .setCompilerOutputPath(context.getCompilerOutputPath()).build();
}

From source file:org.onosproject.onosjar.OnosJarStepFactory.java

private ImmutableSortedSet<Path> findSwaggerModelDefs(SourcePathResolver resolver,
        ImmutableSortedSet<SourcePath> resourcePaths) {
    if (resourcePaths == null) {
        return ImmutableSortedSet.of();
    }/*  w w w.  j  av  a 2  s. c o m*/
    return ImmutableSortedSet.copyOf(resourcePaths.stream().filter(sp -> sp.toString().contains(DEFINITIONS))
            .map(resolver::getRelativePath).collect(Collectors.toList()));
}

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

public JarBuilder setEntriesToJar(ImmutableSortedSet<Path> entriesToJar) {
    sourceContainers.clear();//  w w w  . j a  v  a 2s  . c  om

    entriesToJar.stream().map(filesystem::getPathForRelativePath).map(JarEntryContainer::of)
            .forEach(sourceContainers::add);

    return this;
}

From source file:org.onosproject.onosjar.OnosJarStepFactory.java

@Override
public void createCompileToJarStep(BuildContext context, ImmutableSortedSet<Path> sourceFilePaths,
        BuildTarget invokingRule, SourcePathResolver resolver, ProjectFilesystem filesystem,
        ImmutableSortedSet<Path> declaredClasspathEntries, Path outputDirectory,
        Optional<Path> workingDirectory, Path pathToSrcsList, Optional<SuggestBuildRules> suggestBuildRules,
        ImmutableList<String> postprocessClassesCommands, ImmutableSortedSet<Path> entriesToJar,
        Optional<String> mainClass, Optional<Path> manifestFile, Path outputJar,
        ClassUsageFileWriter usedClassesFileWriter, ImmutableList.Builder<Step> steps,
        BuildableContext buildableContext, ImmutableSet<Pattern> classesToRemoveFromJar) {

    ImmutableSet.Builder<Path> sourceFilePathBuilder = ImmutableSet.builder();
    sourceFilePathBuilder.addAll(sourceFilePaths);

    ImmutableSet.Builder<Pattern> blacklistBuilder = ImmutableSet.builder();
    blacklistBuilder.addAll(classesToRemoveFromJar);

    // precompilation steps
    //   - generate sources
    //     add all generated sources ot pathToSrcsList
    if (webContext != null && apiTitle != null && resources.isPresent()) {
        ImmutableSortedSet<Path> resourceFilePaths = findSwaggerModelDefs(resolver, resources.get());
        blacklistBuilder.addAll(resourceFilePaths.stream()
                .map(rp -> Pattern.compile(rp.getFileName().toString(), Pattern.LITERAL))
                .collect(Collectors.toSet()));
        Path genSourcesOutput = workingDirectory.get();

        SwaggerStep swaggerStep = new SwaggerStep(filesystem, sourceFilePaths, resourceFilePaths,
                genSourcesOutput, outputDirectory, webContext, apiTitle, apiVersion, apiPackage,
                apiDescription);/*  w ww.j a  va 2  s.c o  m*/
        sourceFilePathBuilder.add(swaggerStep.apiRegistratorPath());
        steps.add(swaggerStep);

        //            steps.addAll(sourceFilePaths.stream()
        //                    .filter(sp -> sp.startsWith("src/main/webapp/"))
        //                    .map(sp -> CopyStep.forFile(filesystem, sp, outputDirectory))
        //                    .iterator());
    }

    createCompileStep(context, ImmutableSortedSet.copyOf(sourceFilePathBuilder.build()), invokingRule, resolver,
            filesystem, declaredClasspathEntries, outputDirectory, workingDirectory, pathToSrcsList,
            suggestBuildRules, usedClassesFileWriter, steps, buildableContext);

    // post compilation steps

    // FIXME BOC: add mechanism to inject new Steps
    //context.additionalStepFactory(JavaStep.class);

    // build the jar
    steps.add(new JarDirectoryStep(filesystem, outputJar, ImmutableSortedSet.of(outputDirectory),
            mainClass.orNull(), manifestFile.orNull(), true, blacklistBuilder.build()));

    OSGiWrapper osgiStep = new OSGiWrapper(outputJar, //input jar
            outputJar, //Paths.get(outputJar.toString() + ".jar"), //output jar
            invokingRule.getBasePath(), // sources dir
            outputDirectory, // classes dir
            declaredClasspathEntries, // classpath
            bundleName, // bundle name
            groupId, // groupId
            bundleVersion, // bundle version
            bundleLicense, // bundle license
            importPackages, // import packages
            exportPackages, // export packages
            includeResources, // include resources
            webContext, // web context
            dynamicimportPackages, // dynamic import packages
            bundleDescription // bundle description
    );
    steps.add(osgiStep);

    //steps.add(CopyStep.forFile(filesystem, Paths.get(outputJar.toString() + ".jar"), outputJar));

}