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

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

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableSortedSet of.

Prototype

public static <E extends Comparable<? super E>> ImmutableSortedSet<E> of(E element) 

Source Link

Usage

From source file:com.facebook.buck.thrift.ThriftJavaEnhancer.java

@Override
public BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver,
        ThriftConstructorArg args, ImmutableMap<String, ThriftSource> sources,
        ImmutableSortedSet<BuildRule> deps) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);

    if (params.getBuildTarget().getFlavors().contains(CalculateAbi.FLAVOR)) {
        BuildTarget libraryTarget = params.getBuildTarget().withoutFlavors(CalculateAbi.FLAVOR);
        resolver.requireRule(libraryTarget);
        return CalculateAbi.of(params.getBuildTarget(), ruleFinder, params,
                new BuildTargetSourcePath(libraryTarget));
    }//ww w.  j  a  v a 2 s  .  com

    // Pack all the generated sources into a single source zip that we'll pass to the
    // java rule below.
    ImmutableSortedSet.Builder<BuildRule> sourceZipsBuilder = ImmutableSortedSet.naturalOrder();
    UnflavoredBuildTarget unflavoredBuildTarget = params.getBuildTarget().getUnflavoredBuildTarget();
    for (ImmutableMap.Entry<String, ThriftSource> ent : sources.entrySet()) {
        String name = ent.getKey();
        BuildRule compilerRule = ent.getValue().getCompileRule();
        Path sourceDirectory = ent.getValue().getOutputDir().resolve("gen-java");

        BuildTarget sourceZipTarget = getSourceZipBuildTarget(unflavoredBuildTarget, name);
        Path sourceZip = getSourceZipOutputPath(params.getProjectFilesystem(), unflavoredBuildTarget, name);

        sourceZipsBuilder.add(new SrcZip(params.copyWithChanges(sourceZipTarget,
                Suppliers.ofInstance(ImmutableSortedSet.of(compilerRule)),
                Suppliers.ofInstance(ImmutableSortedSet.of())), sourceZip, sourceDirectory));
    }
    ImmutableSortedSet<BuildRule> sourceZips = sourceZipsBuilder.build();
    resolver.addAllToIndex(sourceZips);

    // Create to main compile rule.
    BuildRuleParams javaParams = params.copyWithChanges(
            BuildTargets.createFlavoredBuildTarget(unflavoredBuildTarget, getFlavor()),
            Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder().addAll(sourceZips).addAll(deps)
                    .addAll(BuildRules.getExportedRules(deps))
                    .addAll(ruleFinder.filterBuildRuleInputs(templateOptions.getInputs(ruleFinder))).build()),
            Suppliers.ofInstance(ImmutableSortedSet.of()));

    BuildTarget abiJarTarget = params.getBuildTarget().withAppendedFlavors(CalculateAbi.FLAVOR);

    final SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);

    return new DefaultJavaLibrary(javaParams, pathResolver, ruleFinder,
            FluentIterable.from(sourceZips).transform(SourcePaths.getToBuildTargetSourcePath())
                    .toSortedSet(Ordering.natural()),
            /* resources */ ImmutableSet.of(), templateOptions.getGeneratedSourceFolderName(),
            /* proguardConfig */ Optional.empty(), /* postprocessClassesCommands */ ImmutableList.of(),
            /* exportedDeps */ ImmutableSortedSet.of(), /* providedDeps */ ImmutableSortedSet.of(),
            /* abiJar */ abiJarTarget, JavaLibraryRules.getAbiInputs(resolver, javaParams.getDeps()),
            templateOptions.trackClassUsage(), /* additionalClasspathEntries */ ImmutableSet.of(),
            new JavacToJarStepFactory(templateOptions, JavacOptionsAmender.IDENTITY),
            /* resourcesRoot */ Optional.empty(), /* manifest file */ Optional.empty(),
            /* mavenCoords */ Optional.empty(), /* tests */ ImmutableSortedSet.of(),
            /* classesToRemoveFromJar */ ImmutableSet.of());
}

From source file:com.facebook.buck.cxx.AbstractNativeBuildRule.java

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    ImmutableList.Builder<Step> steps = ImmutableList.builder();
    ImmutableSortedSet.Builder<Path> objectFiles = ImmutableSortedSet.naturalOrder();
    Set<Path> createdDirectories = Sets.newHashSet();

    addMkdirStepIfNeeded(createdDirectories, steps, getPathToOutputFile().getParent());

    for (SourcePath src : srcs) {
        Path srcFile = getResolver().getPath(src);
        // We expect srcFile to be relative to the buck root
        Preconditions.checkState(!srcFile.isAbsolute());
        Path parent = srcFile.getParent();
        if (parent == null) {
            parent = Paths.get("");
        }/*from ww  w .  jav  a 2 s .c o  m*/
        // To avoid collisions, objects files are created in directories that reflects the path to
        // source files rather than the (path-like) name of build targets
        Path targetDir = BuckConstant.GEN_PATH.resolve(parent);
        addMkdirStepIfNeeded(createdDirectories, steps, targetDir);

        Path objectFile = targetDir
                .resolve(Files.getNameWithoutExtension(srcFile.getFileName().toString()) + OBJECT_EXTENSION);
        steps.add(new CompilerStep(/* compiler */ getCompiler(), /* shouldLink */ false,
                /* srcs */ ImmutableSortedSet.of(srcFile), /* outputFile */ objectFile,
                /* shouldAddProjectRootToIncludePaths */ true, /* includePaths */ ImmutableSortedSet.<Path>of(),
                /* commandLineArgs */ commandLineArgsForFile(src, perSrcFileFlags)));
        objectFiles.add(objectFile);
    }

    for (BuildRule dep : getDeps()) {
        // Only c++ static libraries are supported for now.
        if (dep instanceof CxxLibrary) {
            objectFiles.add(Preconditions.checkNotNull(dep.getPathToOutputFile()));
        }
    }

    steps.addAll(getFinalBuildSteps(objectFiles.build(), getPathToOutputFile()));

    return steps.build();
}

From source file:com.facebook.buck.js.JsBundleDescription.java

private static BuildRule createAndroidResources(BuildRuleParams params, BuildRuleResolver resolver,
        JsBundle jsBundle, String rDotJavaPackage) throws NoSuchBuildTargetException {

    return new AndroidResource(
            params.copyReplacingDeclaredAndExtraDeps(ImmutableSortedSet::of,
                    () -> ImmutableSortedSet.of(jsBundle)),
            new SourcePathRuleFinder(resolver), ImmutableSortedSet.of(), // deps
            jsBundle.getSourcePathToResources(), ImmutableSortedMap.of(), // resSrcs
            rDotJavaPackage, null, ImmutableSortedMap.of(), null, false);
}

From source file:com.facebook.buck.android.AndroidBuildConfigDescription.java

/**
 * @param values Collection whose entries identify fields for the generated
 *     {@code BuildConfig} class. The values for fields can be overridden by values from the
 *     {@code valuesFile} file, if present.
 * @param valuesFile Path to a file with values to override those in {@code values}.
 * @param ruleResolver Any intermediate rules introduced by this method will be added to this
 *     {@link BuildRuleResolver}./*w  w  w.j  a  va2 s . c  o  m*/
 */
static AndroidBuildConfigJavaLibrary createBuildRule(BuildRuleParams params, String javaPackage,
        BuildConfigFields values, Optional<SourcePath> valuesFile, boolean useConstantExpressions,
        JavacOptions javacOptions, BuildRuleResolver ruleResolver) throws NoSuchBuildTargetException {
    // Normally, the build target for an intermediate rule is a flavored version of the target for
    // the original rule. For example, if the build target for an android_build_config() were
    // //foo:bar, then the build target for the intermediate AndroidBuildConfig rule created by this
    // method would be //foo:bar#gen_java_android_build_config.
    //
    // However, in the case of an android_binary() with multiple android_build_config() rules in its
    // transitive deps, it must create one intermediate AndroidBuildConfigJavaLibrary for each
    // android_build_config() dependency. The primary difference is that in each of the new versions
    // of the AndroidBuildConfigJavaLibrary, constant expressions will be used so the values can be
    // inlined (whereas non-constant-expressions were used in the original versions). Because there
    // are multiple intermediate rules based on the same android_binary(), the flavor cannot just be
    // #gen_java_android_build_config because that would lead to build target collisions, so the
    // flavor must be parameterized by the java package to ensure it is unique.
    //
    // This fixes the issue, but deviates from the common pattern where a build rule has at most
    // one flavored version of itself for a given flavor.
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    BuildTarget buildConfigBuildTarget;
    if (!params.getBuildTarget().isFlavored()) {
        // android_build_config() case.
        Preconditions.checkArgument(!useConstantExpressions);
        buildConfigBuildTarget = params.getBuildTarget().withFlavors(GEN_JAVA_FLAVOR);
    } else {
        // android_binary() graph enhancement case.
        Preconditions.checkArgument(useConstantExpressions);
        buildConfigBuildTarget = params.getBuildTarget().withFlavors(
                ImmutableFlavor.of(GEN_JAVA_FLAVOR.getName() + '_' + javaPackage.replace('.', '_')));
    }

    // Create one build rule to generate BuildConfig.java.
    BuildRuleParams buildConfigParams = params.copyWithChanges(buildConfigBuildTarget, params.getDeclaredDeps(),
            /* extraDeps */ Suppliers.ofInstance(ImmutableSortedSet.<BuildRule>naturalOrder()
                    .addAll(params.getExtraDeps().get())
                    .addAll(ruleFinder.filterBuildRuleInputs(OptionalCompat.asSet(valuesFile))).build()));
    AndroidBuildConfig androidBuildConfig = new AndroidBuildConfig(buildConfigParams, javaPackage, values,
            valuesFile, useConstantExpressions);
    ruleResolver.addToIndex(androidBuildConfig);

    BuildTarget abiJarTarget = params.getBuildTarget().withAppendedFlavors(CalculateAbi.FLAVOR);

    // Create a second build rule to compile BuildConfig.java and expose it as a JavaLibrary.
    BuildRuleParams javaLibraryParams = params.copyWithChanges(params.getBuildTarget(),
            /* declaredDeps */ Suppliers.ofInstance(ImmutableSortedSet.of(androidBuildConfig)),
            /* extraDeps */ Suppliers.ofInstance(ImmutableSortedSet.of()));
    return new AndroidBuildConfigJavaLibrary(javaLibraryParams, pathResolver, ruleFinder, javacOptions,
            abiJarTarget, JavaLibraryRules.getAbiInputs(ruleResolver, javaLibraryParams.getDeps()),
            androidBuildConfig);
}

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

@SuppressWarnings("unchecked")
private void addAnnotationOutputIfNeeded(IJFolderFactory folderFactory, TargetNode<T, ?> targetNode,
        ModuleBuildContext context) {/*from w ww  .  j  a va2s  .co  m*/
    TargetNode<? extends JvmLibraryArg, ?> jvmLibraryTargetNode = (TargetNode<? extends JvmLibraryArg, ?>) targetNode;

    Optional<Path> annotationOutput = moduleFactoryResolver.getAnnotationOutputPath(jvmLibraryTargetNode);
    if (!annotationOutput.isPresent()) {
        return;
    }

    Path annotationOutputPath = annotationOutput.get();
    context.addGeneratedSourceCodeFolder(
            folderFactory.create(annotationOutputPath, false, ImmutableSortedSet.of(annotationOutputPath)));
}

From source file:org.infoscoop.service.PersonServiceImpl.java

public Set<String> getIdSet(Set<UserId> users, GroupId group, SecurityToken token) throws JSONException {
    Set<String> ids = Sets.newLinkedHashSet();
    for (UserId user : users) {
        String userId = user.getUserId(token);
        ids.addAll(ImmutableSortedSet.of(userId));
        //         ids.addAll(getIdSet(user, group, token));
    }/* ww w.java 2s. c o m*/
    return ids;
}

From source file:com.facebook.buck.android.AndroidBinaryGraphEnhancer.java

EnhancementResult createAdditionalBuildables() {
    ImmutableSortedSet.Builder<BuildRule> enhancedDeps = ImmutableSortedSet.naturalOrder();
    enhancedDeps.addAll(originalDeps);//ww  w.  j ava  2 s .  c  o m

    ImmutableSortedSet<BuildRule> resourceRules = getAndroidResourcesAsRules();

    BuildTarget buildTargetForFilterResources = createBuildTargetWithFlavor(RESOURCES_FILTER_FLAVOR);
    FilteredResourcesProvider filteredResourcesProvider;
    boolean needsResourceFiltering = resourceFilter.isEnabled()
            || resourceCompressionMode.isStoreStringsAsAssets();

    if (needsResourceFiltering) {
        ResourcesFilter resourcesFilter = new ResourcesFilter(buildTargetForFilterResources,
                androidResourceDepsFinder, resourceCompressionMode, resourceFilter);
        BuildRule resourcesFilterBuildRule = buildRuleAndAddToIndex(resourcesFilter,
                BuildRuleType.RESOURCES_FILTER, buildTargetForFilterResources, resourceRules);

        filteredResourcesProvider = resourcesFilter;
        enhancedDeps.add(resourcesFilterBuildRule);
        resourceRules = ImmutableSortedSet.of(resourcesFilterBuildRule);
    } else {
        filteredResourcesProvider = new IdentityResourcesProvider(androidResourceDepsFinder);
    }

    BuildTarget buildTargetForUberRDotJava = createBuildTargetWithFlavor(UBER_R_DOT_JAVA_FLAVOR);
    UberRDotJava uberRDotJava = new UberRDotJava(buildTargetForUberRDotJava, filteredResourcesProvider,
            javacOptions, androidResourceDepsFinder, shouldPreDex, shouldBuildStringSourceMap);
    BuildRule uberRDotJavaBuildRule = buildRuleAndAddToIndex(uberRDotJava, BuildRuleType.UBER_R_DOT_JAVA,
            buildTargetForUberRDotJava, resourceRules);
    enhancedDeps.add(uberRDotJavaBuildRule);

    Optional<PackageStringAssets> packageStringAssets = Optional.absent();
    if (resourceCompressionMode.isStoreStringsAsAssets()) {
        BuildTarget buildTargetForPackageStringAssets = createBuildTargetWithFlavor(
                PACKAGE_STRING_ASSETS_FLAVOR);
        packageStringAssets = Optional.of(new PackageStringAssets(buildTargetForPackageStringAssets,
                filteredResourcesProvider, uberRDotJava));
        BuildRule packageStringAssetsRule = buildRuleAndAddToIndex(packageStringAssets.get(),
                BuildRuleType.PACKAGE_STRING_ASSETS, buildTargetForPackageStringAssets,
                ImmutableSortedSet.of(uberRDotJavaBuildRule));
        enhancedDeps.add(packageStringAssetsRule);
    }

    // Create the AaptPackageResourcesBuildable.
    BuildTarget buildTargetForAapt = createBuildTargetWithFlavor(AAPT_PACKAGE_FLAVOR);
    AaptPackageResources aaptPackageResources = new AaptPackageResources(buildTargetForAapt, manifest,
            filteredResourcesProvider, androidResourceDepsFinder.getAndroidTransitiveDependencies(),
            packageType, cpuFilters);
    BuildRule aaptPackageResourcesBuildRule = buildRuleAndAddToIndex(aaptPackageResources,
            BuildRuleType.AAPT_PACKAGE, buildTargetForAapt, getAdditionalAaptDeps(resourceRules));
    enhancedDeps.add(aaptPackageResourcesBuildRule);

    Optional<PreDexMerge> preDexMerge = Optional.absent();
    if (shouldPreDex) {
        BuildRule preDexMergeRule = createPreDexMergeRule(uberRDotJava);
        preDexMerge = Optional.of((PreDexMerge) preDexMergeRule.getBuildable());
        enhancedDeps.add(preDexMergeRule);
    }

    ImmutableSortedSet<BuildRule> finalDeps;
    Optional<ComputeExopackageDepsAbi> computeExopackageDepsAbi = Optional.absent();
    if (exopackage) {
        BuildTarget buildTargetForAbiCalculation = createBuildTargetWithFlavor(CALCULATE_ABI_FLAVOR);
        computeExopackageDepsAbi = Optional
                .of(new ComputeExopackageDepsAbi(buildTargetForAbiCalculation, androidResourceDepsFinder,
                        uberRDotJava, aaptPackageResources, packageStringAssets, preDexMerge, keystore));
        BuildRule computeExopackageDepsAbiRule = buildRuleAndAddToIndex(computeExopackageDepsAbi.get(),
                BuildRuleType.EXOPACKAGE_DEPS_ABI, buildTargetForAbiCalculation, enhancedDeps.build());
        finalDeps = ImmutableSortedSet.of(computeExopackageDepsAbiRule);
    } else {
        finalDeps = enhancedDeps.build();
    }

    return new EnhancementResult(filteredResourcesProvider, uberRDotJava, aaptPackageResources,
            packageStringAssets, preDexMerge, computeExopackageDepsAbi, finalDeps);
}

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

private void addGeneratedOutputIfNeeded(IJFolderFactory folderFactory, TargetNode<T, ?> targetNode,
        ModuleBuildContext context) {// ww w  .  j  a  va 2  s .c o  m

    ImmutableSet<Path> generatedSourcePaths = findConfiguredGeneratedSourcePaths(targetNode);

    for (Path generatedSourcePath : generatedSourcePaths) {
        context.addGeneratedSourceCodeFolder(
                folderFactory.create(generatedSourcePath, false, ImmutableSortedSet.of(generatedSourcePath)));
    }
}

From source file:com.facebook.buck.android.AndroidPrebuiltAarDescription.java

private PrebuiltJar createPrebuiltJar(UnzipAar unzipAar, BuildRuleParams params, SourcePathResolver resolver,
        BuildTarget abiJar, ImmutableSortedSet<BuildRule> deps) {
    BuildRuleParams buildRuleParams = params.copyWithChanges(
            /* buildTarget */ BuildTargets.createFlavoredBuildTarget(params.getBuildTarget().checkUnflavored(),
                    AAR_PREBUILT_JAR_FLAVOR),
            /* declaredDeps */ Suppliers.ofInstance(deps),
            /* extraDeps */ Suppliers.ofInstance(ImmutableSortedSet.of(unzipAar)));
    return new PrebuiltJar(/* params */ buildRuleParams, /* resolver */ resolver,
            /* binaryJar */ new BuildTargetSourcePath(unzipAar.getBuildTarget(),
                    unzipAar.getPathToClassesJar()),
            abiJar, /* sourceJar */ Optional.empty(), /* gwtJar */ Optional.empty(),
            /* javadocUrl */ Optional.empty(), /* mavenCoords */ Optional.empty(), /* provided */ false);

}

From source file:com.google.enterprise.connector.persist.MigrateStore.java

@Override
public void run(CommandLine commandLine) throws Exception {
    initStandAloneContext(false);//from ww w  .j  a v a2 s. c  o m
    // Since we did not start the Context, we need to init TypeMap
    // for PersistentStores to function correctly.
    getTypeMap().init();

    try {
        // If user asks for a list of available PersitentStores,
        // print it and exit.
        if (commandLine.hasOption("list")) {
            listStores();
            return;
        }

        // Get then names of the source and destination PersitentStores.
        String sourceName = null;
        String destName = null;
        String[] args = commandLine.getArgs();
        if ((args.length == 1) || (args.length > 2)) {
            printUsageAndExit(-1);
        }
        if (args.length == 2) {
            sourceName = args[0];
            destName = args[1];
        } else {
            Collection<String> storeNames = getStoreNames();
            sourceName = selectStoreName("source", storeNames);
            if (sourceName == null) {
                return;
            }
            storeNames.remove(sourceName);
            destName = selectStoreName("destination", storeNames);
            if (destName == null) {
                return;
            }
        }
        if (sourceName.equals(destName)) {
            System.err.println("Source and destination PersistentStores must be different.");
            return;
        }

        PersistentStore sourceStore = getPersistentStoreByName(sourceName);

        // Determine which connectors to migrate.
        Collection<String> connectors = null;
        String[] connectorNames = commandLine.getOptionValues('c');
        if (connectorNames != null) {
            connectors = ImmutableSortedSet.copyOf(connectorNames);
        } else if (args.length != 2) {
            // If no connectors were specified on the command line, and we had
            // to prompt the user for the source and destination stores, then also
            // prompt the user for a connector to migrate.
            String name = selectConnectorName(getConnectorNames(sourceStore));
            if (name != null) {
                connectors = ImmutableSortedSet.of(name);
            }
        }

        // Actually perform the migration.
        PersistentStore destStore = getPersistentStoreByName(destName);
        if (sourceStore != null && destStore != null) {
            // Adjust the logging levels so that StoreMigrator messages are logged
            // to the Console.
            Logger.getLogger(StoreMigrator.class.getName()).setLevel(Level.INFO);
            StoreMigrator.migrate(sourceStore, destStore, connectors, commandLine.hasOption("force"));
            StoreMigrator.checkMissing(destStore, connectors);
        }
    } finally {
        shutdown();
    }
}