Example usage for com.google.common.collect ImmutableMap keySet

List of usage examples for com.google.common.collect ImmutableMap keySet

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap keySet.

Prototype

public ImmutableSet<K> keySet() 

Source Link

Usage

From source file:com.getbase.android.schema.Schemas.java

private ImmutableMap<String, ImmutableList<? extends TableDefinitionOperation>> merge(
        ImmutableMap<String, ImmutableList<? extends TableDefinitionOperation>> schema,
        ImmutableMap<String, ImmutableList<? extends TableDowngradeOperation>> downgrades, int targetRevision) {
    ImmutableMap.Builder<String, ImmutableList<? extends TableDefinitionOperation>> builder = ImmutableMap
            .builder();/*from   w  w  w  . ja v  a  2s  .c o m*/

    for (String unchangedTable : Sets.difference(schema.keySet(), downgrades.keySet())) {
        builder.put(unchangedTable, schema.get(unchangedTable));
    }

    for (String alteredTable : Sets.intersection(downgrades.keySet(), schema.keySet())) {
        ImmutableList<? extends TableDefinitionOperation> mergedOperations = MERGER.merge(
                schema.get(alteredTable), downgrades.get(alteredTable), alteredTable, targetRevision,
                mRevisionDescriptionBuilder);
        if (!mergedOperations.isEmpty()) {
            builder.put(alteredTable, mergedOperations);
        }
    }

    for (String addedTable : Sets.difference(downgrades.keySet(), schema.keySet())) {
        builder.put(addedTable, CONVERTER.convert(downgrades.get(addedTable), addedTable, targetRevision,
                mRevisionDescriptionBuilder));
    }

    return builder.build();
}

From source file:com.qubole.quark.plugins.jdbc.JdbcDB.java

private ImmutableMap<String, Schema> getSchemaFromResultSet(ResultSet rs,
        ImmutableMap<String, Integer> dataTypes) throws SQLException {
    if (rs == null || !rs.next()) {
        return ImmutableMap.of();
    }//from   w  w w . j  a  v a  2  s  . co  m
    ImmutableMap.Builder<String, Schema> schemaBuilder = new ImmutableMap.Builder<>();

    while (!rs.isAfterLast()) {
        String currentSchema = rs.getString(1);
        ImmutableMap.Builder<String, Table> tableBuilder = new ImmutableMap.Builder<>();
        while (!rs.isAfterLast() && rs.getString(1).equals(currentSchema)) {
            ImmutableList.Builder<QuarkColumn> columnBuilder = new ImmutableList.Builder<>();
            String currentTable = rs.getString(2);
            while (rs.getString(2).equals(currentTable)) {
                String columnName = rs.getString(3);
                if (!this.isCaseSensitive()) {
                    columnName = columnName.toUpperCase();
                }
                Integer dataType = null;
                for (String key : dataTypes.keySet()) {
                    if (rs.getString(4).toUpperCase().matches(key)) {
                        dataType = dataTypes.get(key);
                        break;
                    }
                }
                if (dataType == null) {
                    throw new SQLException("DataType `" + rs.getString(4) + "` is not supported");
                }
                columnBuilder.add(new QuarkColumn(columnName, dataType));
                LOG.debug("Adding column:  " + rs.getString(1) + " : " + rs.getString(2) + " : "
                        + rs.getString(3) + " : " + rs.getString(4));
                if (!rs.next()) {
                    break;
                }
            }

            if (!this.isCaseSensitive()) {
                currentTable = currentTable.toUpperCase();
            }
            tableBuilder.put(currentTable, new QuarkTable(columnBuilder.build()));
        }
        if (!this.isCaseSensitive()) {
            currentSchema = currentSchema.toUpperCase();
        }

        schemaBuilder.put(currentSchema,
                new com.qubole.quark.plugins.SimpleSchema(currentSchema.toUpperCase(), tableBuilder.build()));
    }
    return schemaBuilder.build();
}

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

@Override
public PythonTest createBuildRule(BuildRuleCreationContextWithTargetGraph context, BuildTarget buildTarget,
        BuildRuleParams params, PythonTestDescriptionArg args) {

    FlavorDomain<PythonPlatform> pythonPlatforms = toolchainProvider
            .getByName(PythonPlatformsProvider.DEFAULT_NAME, PythonPlatformsProvider.class)
            .getPythonPlatforms();/*  w  ww .  j  a v a2 s .c o m*/

    ActionGraphBuilder graphBuilder = context.getActionGraphBuilder();
    PythonPlatform pythonPlatform = pythonPlatforms.getValue(buildTarget)
            .orElse(pythonPlatforms.getValue(args.getPlatform().<Flavor>map(InternalFlavor::of)
                    .orElse(pythonPlatforms.getFlavors().iterator().next())));
    CxxPlatform cxxPlatform = getCxxPlatform(buildTarget, args).resolve(graphBuilder);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder);
    SourcePathResolver pathResolver = DefaultSourcePathResolver.from(ruleFinder);
    Path baseModule = PythonUtil.getBasePath(buildTarget, args.getBaseModule());
    Optional<ImmutableMap<BuildTarget, Version>> selectedVersions = context.getTargetGraph().get(buildTarget)
            .getSelectedVersions();

    ImmutableMap<Path, SourcePath> srcs = PythonUtil.getModules(buildTarget, graphBuilder, ruleFinder,
            pathResolver, pythonPlatform, cxxPlatform, "srcs", baseModule, args.getSrcs(),
            args.getPlatformSrcs(), args.getVersionedSrcs(), selectedVersions);

    ImmutableMap<Path, SourcePath> resources = PythonUtil.getModules(buildTarget, graphBuilder, ruleFinder,
            pathResolver, pythonPlatform, cxxPlatform, "resources", baseModule, args.getResources(),
            args.getPlatformResources(), args.getVersionedResources(), selectedVersions);

    // Convert the passed in module paths into test module names.
    ImmutableSet.Builder<String> testModulesBuilder = ImmutableSet.builder();
    for (Path name : srcs.keySet()) {
        testModulesBuilder.add(PythonUtil.toModuleName(buildTarget, name.toString()));
    }
    ImmutableSet<String> testModules = testModulesBuilder.build();

    ProjectFilesystem projectFilesystem = context.getProjectFilesystem();

    // Construct a build rule to generate the test modules list source file and
    // add it to the build.
    BuildRule testModulesBuildRule = createTestModulesSourceBuildRule(buildTarget, projectFilesystem,
            getTestModulesListPath(buildTarget, projectFilesystem), testModules);
    graphBuilder.addToIndex(testModulesBuildRule);

    String mainModule;
    if (args.getMainModule().isPresent()) {
        mainModule = args.getMainModule().get();
    } else {
        mainModule = PythonUtil.toModuleName(buildTarget, getTestMainName().toString());
    }

    // Build up the list of everything going into the python test.
    PythonPackageComponents testComponents = PythonPackageComponents.of(
            ImmutableMap.<Path, SourcePath>builder()
                    .put(getTestModulesListName(), testModulesBuildRule.getSourcePathToOutput())
                    .put(getTestMainName(), requireTestMain(buildTarget, projectFilesystem, graphBuilder))
                    .putAll(srcs).build(),
            resources, ImmutableMap.of(), ImmutableMultimap.of(), args.getZipSafe());
    ImmutableList<BuildRule> deps = RichStream
            .from(PythonUtil.getDeps(pythonPlatform, cxxPlatform, args.getDeps(), args.getPlatformDeps()))
            .concat(args.getNeededCoverage().stream().map(NeededCoverageSpec::getBuildTarget))
            .map(graphBuilder::getRule).collect(ImmutableList.toImmutableList());

    CellPathResolver cellRoots = context.getCellPathResolver();
    StringWithMacrosConverter macrosConverter = StringWithMacrosConverter.builder().setBuildTarget(buildTarget)
            .setCellPathResolver(cellRoots).setExpanders(PythonUtil.MACRO_EXPANDERS).build();
    PythonPackageComponents allComponents = PythonUtil.getAllComponents(cellRoots, buildTarget,
            projectFilesystem, params, graphBuilder, ruleFinder, deps, testComponents, pythonPlatform,
            cxxBuckConfig, cxxPlatform,
            args.getLinkerFlags().stream().map(x -> macrosConverter.convert(x, graphBuilder))
                    .collect(ImmutableList.toImmutableList()),
            pythonBuckConfig.getNativeLinkStrategy(), args.getPreloadDeps());

    // Build the PEX using a python binary rule with the minimum dependencies.
    buildTarget.assertUnflavored();
    PythonBinary binary = binaryDescription.createPackageRule(buildTarget.withAppendedFlavors(BINARY_FLAVOR),
            projectFilesystem, params, graphBuilder, ruleFinder, pythonPlatform, cxxPlatform, mainModule,
            args.getExtension(), allComponents, args.getBuildArgs(),
            args.getPackageStyle().orElse(pythonBuckConfig.getPackageStyle()),
            PythonUtil.getPreloadNames(graphBuilder, cxxPlatform, args.getPreloadDeps()));
    graphBuilder.addToIndex(binary);

    ImmutableList.Builder<Pair<Float, ImmutableSet<Path>>> neededCoverageBuilder = ImmutableList.builder();
    for (NeededCoverageSpec coverageSpec : args.getNeededCoverage()) {
        BuildRule buildRule = graphBuilder.getRule(coverageSpec.getBuildTarget());
        if (deps.contains(buildRule) && buildRule instanceof PythonLibrary) {
            PythonLibrary pythonLibrary = (PythonLibrary) buildRule;
            ImmutableSortedSet<Path> paths;
            if (coverageSpec.getPathName().isPresent()) {
                Path path = coverageSpec.getBuildTarget().getBasePath()
                        .resolve(coverageSpec.getPathName().get());
                if (!pythonLibrary.getPythonPackageComponents(pythonPlatform, cxxPlatform, graphBuilder)
                        .getModules().keySet().contains(path)) {
                    throw new HumanReadableException(
                            "%s: path %s specified in needed_coverage not found in target %s", buildTarget,
                            path, buildRule.getBuildTarget());
                }
                paths = ImmutableSortedSet.of(path);
            } else {
                paths = ImmutableSortedSet.copyOf(
                        pythonLibrary.getPythonPackageComponents(pythonPlatform, cxxPlatform, graphBuilder)
                                .getModules().keySet());
            }
            neededCoverageBuilder
                    .add(new Pair<>(coverageSpec.getNeededCoverageRatioPercentage() / 100.f, paths));
        } else {
            throw new HumanReadableException(
                    "%s: needed_coverage requires a python library dependency. Found %s instead", buildTarget,
                    buildRule);
        }
    }

    Function<BuildRuleResolver, ImmutableMap<String, Arg>> testEnv = (ruleResolverInner) -> ImmutableMap
            .copyOf(Maps.transformValues(args.getEnv(), x -> macrosConverter.convert(x, graphBuilder)));

    // Additional CXX Targets used to generate CXX coverage.
    ImmutableSet<UnflavoredBuildTarget> additionalCoverageTargets = RichStream
            .from(args.getAdditionalCoverageTargets()).map(target -> target.getUnflavoredBuildTarget())
            .collect(ImmutableSet.toImmutableSet());
    ImmutableSortedSet<SourcePath> additionalCoverageSourcePaths = additionalCoverageTargets.isEmpty()
            ? ImmutableSortedSet.of()
            : binary.getRuntimeDeps(ruleFinder)
                    .filter(target -> additionalCoverageTargets.contains(target.getUnflavoredBuildTarget()))
                    .map(target -> DefaultBuildTargetSourcePath.of(target))
                    .collect(ImmutableSortedSet.toImmutableSortedSet(Ordering.natural()));

    // Generate and return the python test rule, which depends on the python binary rule above.
    return PythonTest.from(buildTarget, projectFilesystem, params, graphBuilder, testEnv, binary,
            args.getLabels(), neededCoverageBuilder.build(), additionalCoverageSourcePaths,
            args.getTestRuleTimeoutMs().map(Optional::of).orElse(
                    cxxBuckConfig.getDelegate().getView(TestBuckConfig.class).getDefaultTestRuleTimeoutMs()),
            args.getContacts());
}

From source file:com.facebook.buck.core.cell.impl.DistributedCellProviderFactory.java

public static CellProvider create(DistBuildCellParams rootCell,
        ImmutableMap<Path, DistBuildCellParams> cellParams) {
    Map<String, Path> cellPaths = cellParams.values().stream().filter(p -> p.getCanonicalName().isPresent())
            .collect(Collectors.toMap(p -> p.getCanonicalName().get(), p -> p.getFilesystem().getRootPath()));
    ImmutableSet<String> declaredCellNames = ImmutableSet.copyOf(cellPaths.keySet());
    Path rootCellPath = rootCell.getFilesystem().getRootPath();
    DefaultCellPathResolver rootCellResolver = DefaultCellPathResolver.of(rootCellPath, cellPaths);

    return new CellProvider(cellProvider -> CacheLoader.from(cellPath -> {
        DistBuildCellParams cellParam = Preconditions.checkNotNull(cellParams.get(cellPath),
                "This should only be called for secondary cells.");
        Path currentCellRoot = cellParam.getFilesystem().getRootPath();
        Preconditions.checkState(!currentCellRoot.equals(rootCellPath));
        CellPathResolver currentCellResolver = rootCellResolver;
        // The CellPathResolverView is required because it makes the
        // [RootPath<->CanonicalName] resolver methods non-symmetrical to handle the
        // fact/*from w ww  .jav a  2  s.c  o  m*/
        // that relative main cell from inside a secondary cell resolves actually to
        // secondary cell. If the DefaultCellPathResolver is used, then it would return
        // a BuildTarget as if it belonged to the main cell.
        currentCellResolver = new CellPathResolverView(rootCellResolver, declaredCellNames, currentCellRoot);
        BuckConfig configWithResolver = cellParam.getConfig().withCellPathResolver(currentCellResolver);
        RuleKeyConfiguration ruleKeyConfiguration = ConfigRuleKeyConfigurationFactory.create(configWithResolver,
                cellParam.getBuckModuleManager());
        ToolchainProvider toolchainProvider = new DefaultToolchainProvider(cellParam.getPluginManager(),
                cellParam.getEnvironment(), configWithResolver, cellParam.getFilesystem(),
                cellParam.getProcessExecutor(), cellParam.getExecutableFinder(), ruleKeyConfiguration);

        return ImmutableCell.of(cellParams.keySet(),
                // Distributed builds don't care about cell names, use a sentinel value that
                // will show up if it actually does care about them.
                cellParam.getCanonicalName(), WatchmanFactory.NULL_WATCHMAN, cellProvider, toolchainProvider,
                ruleKeyConfiguration, cellParam.getFilesystem(), configWithResolver);
    }), cellProvider -> RootCellFactory.create(cellProvider, rootCellResolver, rootCell.getFilesystem(),
            rootCell.getBuckModuleManager(), rootCell.getPluginManager(), rootCell.getConfig(),
            rootCell.getEnvironment(), rootCell.getProcessExecutor(), rootCell.getExecutableFinder(),
            WatchmanFactory.NULL_WATCHMAN));
}

From source file:org.elasticsearch.index.gateway.blobstore.BlobStoreIndexShardGateway.java

@Override
public void recover(boolean indexShouldExists, RecoveryStatus recoveryStatus)
        throws IndexShardGatewayRecoveryException {
    this.recoveryStatus = recoveryStatus;

    final ImmutableMap<String, BlobMetaData> blobs;
    try {//www. ja v  a 2  s  . c o m
        blobs = blobContainer.listBlobs();
    } catch (IOException e) {
        throw new IndexShardGatewayRecoveryException(shardId, "Failed to list content of gateway", e);
    }

    List<CommitPoint> commitPointsList = Lists.newArrayList();
    boolean atLeastOneCommitPointExists = false;
    for (String name : blobs.keySet()) {
        if (name.startsWith("commit-")) {
            atLeastOneCommitPointExists = true;
            try {
                commitPointsList.add(CommitPoints.fromXContent(blobContainer.readBlobFully(name)));
            } catch (Exception e) {
                logger.warn("failed to read commit point [{}]", e, name);
            }
        }
    }
    if (atLeastOneCommitPointExists && commitPointsList.isEmpty()) {
        // no commit point managed to load, bail so we won't corrupt the index, will require manual intervention
        throw new IndexShardGatewayRecoveryException(shardId, "Commit points exists but none could be loaded",
                null);
    }
    CommitPoints commitPoints = new CommitPoints(commitPointsList);

    if (commitPoints.commits().isEmpty()) {
        // no commit points, clean the store just so we won't recover wrong files
        try {
            indexShard.store().deleteContent();
        } catch (IOException e) {
            logger.warn("failed to clean store before starting shard", e);
        }
        recoveryStatus.index().startTime(System.currentTimeMillis());
        recoveryStatus.index().time(System.currentTimeMillis() - recoveryStatus.index().startTime());
        return;
    }

    for (CommitPoint commitPoint : commitPoints) {
        if (!commitPointExistsInBlobs(commitPoint, blobs)) {
            logger.warn("listed commit_point [{}]/[{}], but not all files exists, ignoring", commitPoint.name(),
                    commitPoint.version());
            continue;
        }
        try {
            recoveryStatus.index().startTime(System.currentTimeMillis());
            recoverIndex(commitPoint, blobs);
            recoveryStatus.index().time(System.currentTimeMillis() - recoveryStatus.index().startTime());

            recoverTranslog(commitPoint, blobs);
            return;
        } catch (Exception e) {
            throw new IndexShardGatewayRecoveryException(shardId, "failed to recover commit_point ["
                    + commitPoint.name() + "]/[" + commitPoint.version() + "]", e);
        }
    }
    throw new IndexShardGatewayRecoveryException(shardId, "No commit point data is available in gateway", null);
}

From source file:com.facebook.buck.config.BuckConfig.java

public ImmutableMap<String, ImmutableMap<String, String>> getRawConfigForParser() {
    ImmutableMap<String, ImmutableMap<String, String>> rawSections = config.getSectionToEntries();

    // If the raw config doesn't have sections which have ignored fields, then just return it as-is.
    ImmutableSet<String> sectionsWithIgnoredFields = IGNORE_FIELDS_FOR_DAEMON_RESTART.keySet();
    if (Sets.intersection(rawSections.keySet(), sectionsWithIgnoredFields).isEmpty()) {
        return rawSections;
    }// w  ww .j  a  va  2s.  c  o m

    // Otherwise, iterate through the config to do finer-grain filtering.
    ImmutableMap.Builder<String, ImmutableMap<String, String>> filtered = ImmutableMap.builder();
    for (Map.Entry<String, ImmutableMap<String, String>> sectionEnt : rawSections.entrySet()) {
        String sectionName = sectionEnt.getKey();

        // If this section doesn't have a corresponding ignored section, then just add it as-is.
        if (!sectionsWithIgnoredFields.contains(sectionName)) {
            filtered.put(sectionEnt);
            continue;
        }

        // If none of this section's entries are ignored, then add it as-is.
        ImmutableMap<String, String> fields = sectionEnt.getValue();
        ImmutableSet<String> ignoredFieldNames = IGNORE_FIELDS_FOR_DAEMON_RESTART.getOrDefault(sectionName,
                ImmutableSet.of());
        if (Sets.intersection(fields.keySet(), ignoredFieldNames).isEmpty()) {
            filtered.put(sectionEnt);
            continue;
        }

        // Otherwise, filter out the ignored fields.
        ImmutableMap<String, String> remainingKeys = ImmutableMap
                .copyOf(Maps.filterKeys(fields, Predicates.not(ignoredFieldNames::contains)));

        if (!remainingKeys.isEmpty()) {
            filtered.put(sectionName, remainingKeys);
        }
    }

    return filtered.build();
}

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

public BuildRule createBuildRule(BuildTarget buildTarget, ProjectFilesystem projectFilesystem,
        BuildRuleParams metadataRuleParams, ActionGraphBuilder graphBuilder, CellPathResolver cellRoots,
        CxxLibraryDescriptionArg args, Optional<Linker.LinkableDepType> linkableDepType,
        Optional<SourcePath> bundleLoader, ImmutableSet<BuildTarget> blacklist,
        ImmutableSortedSet<BuildTarget> extraDeps,
        CxxLibraryDescription.TransitiveCxxPreprocessorInputFunction transitiveCxxPreprocessorInputFunction,
        Optional<CxxLibraryDescriptionDelegate> delegate) {

    CxxPlatformsProvider cxxPlatformsProvider = getCxxPlatformsProvider();
    FlavorDomain<CxxPlatform> cxxPlatforms = cxxPlatformsProvider.getResolvedCxxPlatforms(graphBuilder);
    Flavor defaultCxxFlavor = cxxPlatformsProvider.getDefaultUnresolvedCxxPlatform().getFlavor();

    // See if we're building a particular "type" and "platform" of this library, and if so, extract
    // them from the flavors attached to the build target.
    Optional<Map.Entry<Flavor, CxxLibraryDescription.Type>> type = CxxLibraryDescription
            .getLibType(buildTarget);//from www  . ja  va 2  s  . c  o  m
    Optional<CxxPlatform> platform = cxxPlatforms.getValue(buildTarget);
    CxxDeps cxxDeps = CxxDeps.builder().addDeps(args.getCxxDeps()).addDeps(extraDeps).build();

    Supplier<CxxPlatform> cxxPlatformOrDefaultSupplier = () -> platform
            .orElse(cxxPlatforms.getValue(args.getDefaultPlatform().orElse(defaultCxxFlavor)));
    if (buildTarget.getFlavors().contains(CxxCompilationDatabase.COMPILATION_DATABASE)) {
        CxxPlatform cxxPlatformOrDefault = cxxPlatformOrDefaultSupplier.get();
        // XXX: This needs bundleLoader for tests..
        SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder);
        SourcePathResolver sourcePathResolver = DefaultSourcePathResolver.from(ruleFinder);
        // TODO(T21900763): We should be using `requireObjects` instead but those would not
        // necessarily be `CxxPreprocessAndCompile` rules (e.g., Swift in `apple_library`).
        ImmutableMap<CxxPreprocessAndCompile, SourcePath> objects = requireCxxObjects(
                buildTarget.withoutFlavors(CxxCompilationDatabase.COMPILATION_DATABASE), projectFilesystem,
                graphBuilder, sourcePathResolver, ruleFinder, cellRoots, cxxBuckConfig, cxxPlatformOrDefault,
                cxxPlatformOrDefault.getPicTypeForSharedLinking(), args,
                cxxDeps.get(graphBuilder, cxxPlatformOrDefault), transitiveCxxPreprocessorInputFunction,
                delegate);
        return CxxCompilationDatabase.createCompilationDatabase(buildTarget, projectFilesystem,
                objects.keySet());
    } else if (buildTarget.getFlavors().contains(CxxCompilationDatabase.UBER_COMPILATION_DATABASE)) {
        return CxxDescriptionEnhancer
                .createUberCompilationDatabase(
                        platform.isPresent() ? buildTarget
                                : buildTarget.withAppendedFlavors(
                                        args.getDefaultPlatform().orElse(defaultCxxFlavor)),
                        projectFilesystem, graphBuilder);
    } else if (CxxInferEnhancer.INFER_FLAVOR_DOMAIN.containsAnyOf(buildTarget.getFlavors())) {
        return CxxInferEnhancer.requireInferRule(buildTarget, projectFilesystem, graphBuilder, cellRoots,
                cxxBuckConfig, cxxPlatformOrDefaultSupplier.get(), args, inferBuckConfig);
    } else if (type.isPresent() && !platform.isPresent()) {
        BuildTarget untypedBuildTarget = CxxLibraryDescription.getUntypedBuildTarget(buildTarget);
        switch (type.get().getValue()) {
        case EXPORTED_HEADERS:
            Optional<HeaderMode> mode = CxxLibraryDescription.HEADER_MODE.getValue(buildTarget);
            if (mode.isPresent()) {
                return createExportedHeaderSymlinkTreeBuildRule(untypedBuildTarget, projectFilesystem,
                        graphBuilder, mode.get(), args);
            }
            break;
        // $CASES-OMITTED$
        default:
        }

    } else if (type.isPresent() && platform.isPresent()) {
        // If we *are* building a specific type of this lib, call into the type specific
        // rule builder methods.

        BuildTarget untypedBuildTarget = CxxLibraryDescription.getUntypedBuildTarget(buildTarget);
        switch (type.get().getValue()) {
        case HEADERS:
            return createHeaderSymlinkTreeBuildRule(untypedBuildTarget, projectFilesystem, graphBuilder,
                    platform.get(), args);
        case EXPORTED_HEADERS:
            return createExportedPlatformHeaderSymlinkTreeBuildRule(untypedBuildTarget, projectFilesystem,
                    graphBuilder, platform.get(), args);
        case SHARED:
            return createSharedLibraryBuildRule(untypedBuildTarget, projectFilesystem, graphBuilder, cellRoots,
                    cxxBuckConfig, platform.get(), args, cxxDeps.get(graphBuilder, platform.get()),
                    Linker.LinkType.SHARED, linkableDepType.orElse(Linker.LinkableDepType.SHARED),
                    Optional.empty(), blacklist, transitiveCxxPreprocessorInputFunction, delegate);
        case SHARED_INTERFACE:
            return createSharedLibraryInterface(untypedBuildTarget, projectFilesystem, graphBuilder,
                    platform.get(), cxxBuckConfig.isIndependentSharedLibraryInterfaces());
        case MACH_O_BUNDLE:
            return createSharedLibraryBuildRule(untypedBuildTarget, projectFilesystem, graphBuilder, cellRoots,
                    cxxBuckConfig, platform.get(), args, cxxDeps.get(graphBuilder, platform.get()),
                    Linker.LinkType.MACH_O_BUNDLE, linkableDepType.orElse(Linker.LinkableDepType.SHARED),
                    bundleLoader, blacklist, transitiveCxxPreprocessorInputFunction, delegate);
        case STATIC:
            return createStaticLibraryBuildRule(untypedBuildTarget, projectFilesystem, graphBuilder, cellRoots,
                    cxxBuckConfig, platform.get(), args, cxxDeps.get(graphBuilder, platform.get()), PicType.PDC,
                    transitiveCxxPreprocessorInputFunction, delegate);
        case STATIC_PIC:
            return createStaticLibraryBuildRule(untypedBuildTarget, projectFilesystem, graphBuilder, cellRoots,
                    cxxBuckConfig, platform.get(), args, cxxDeps.get(graphBuilder, platform.get()), PicType.PIC,
                    transitiveCxxPreprocessorInputFunction, delegate);
        }
        throw new RuntimeException("unhandled library build type");
    }

    boolean hasObjectsForAnyPlatform = !args.getSrcs().isEmpty();
    Predicate<CxxPlatform> hasObjects;
    if (hasObjectsForAnyPlatform) {
        hasObjects = x -> true;
    } else {
        hasObjects = input -> !args.getPlatformSrcs().getMatchingValues(input.getFlavor().toString()).isEmpty();
    }

    // Otherwise, we return the generic placeholder of this library, that dependents can use
    // get the real build rules via querying the action graph.
    return new CxxLibrary(buildTarget, projectFilesystem, metadataRuleParams, args.getPrivateCxxDeps(),
            args.getExportedCxxDeps(), hasObjects.negate(), (input, graphBuilderInner) -> {
                ImmutableList<Arg> delegateExportedLinkerFlags = delegate
                        .map(d -> d.getAdditionalExportedLinkerFlags(buildTarget, graphBuilderInner, input))
                        .orElse(ImmutableList.of());

                ImmutableList<StringWithMacros> flags = CxxFlags.getFlagsWithMacrosWithPlatformMacroExpansion(
                        args.getExportedLinkerFlags(), args.getExportedPlatformLinkerFlags(), input);
                return RichStream.from(flags)
                        .map(f -> CxxDescriptionEnhancer.toStringWithMacrosArgs(buildTarget, cellRoots,
                                graphBuilderInner, input, f))
                        .concat(RichStream.from(delegateExportedLinkerFlags)).toImmutableList();
            }, (input, graphBuilderInner) -> {
                ImmutableList<Arg> delegatePostExportedLinkerFlags = delegate
                        .map(d -> d.getAdditionalPostExportedLinkerFlags(buildTarget, graphBuilderInner, input))
                        .orElse(ImmutableList.of());

                ImmutableList<StringWithMacros> flags = CxxFlags.getFlagsWithMacrosWithPlatformMacroExpansion(
                        args.getExportedPostLinkerFlags(), args.getExportedPostPlatformLinkerFlags(), input);
                return RichStream.from(flags)
                        .map(f -> CxxDescriptionEnhancer.toStringWithMacrosArgs(buildTarget, cellRoots,
                                graphBuilderInner, input, f))
                        .concat(RichStream.from(delegatePostExportedLinkerFlags)).toImmutableList();
            }, (cxxPlatform, ruleResolverInner, pathResolverInner, ruleFinderInner) -> {
                return getSharedLibraryNativeLinkTargetInput(buildTarget, projectFilesystem, ruleResolverInner,
                        pathResolverInner, ruleFinderInner, cellRoots, cxxBuckConfig, cxxPlatform, args,
                        cxxDeps.get(ruleResolverInner, cxxPlatform),
                        CxxFlags.getFlagsWithMacrosWithPlatformMacroExpansion(args.getLinkerFlags(),
                                args.getPlatformLinkerFlags(), cxxPlatform),
                        CxxFlags.getFlagsWithMacrosWithPlatformMacroExpansion(args.getExportedLinkerFlags(),
                                args.getExportedPlatformLinkerFlags(), cxxPlatform),
                        CxxFlags.getFlagsWithMacrosWithPlatformMacroExpansion(args.getPostLinkerFlags(),
                                args.getPostPlatformLinkerFlags(), cxxPlatform),
                        CxxFlags.getFlagsWithMacrosWithPlatformMacroExpansion(args.getExportedPostLinkerFlags(),
                                args.getExportedPostPlatformLinkerFlags(), cxxPlatform),
                        args.getFrameworks(), args.getLibraries(), transitiveCxxPreprocessorInputFunction,
                        delegate);
            }, args.getSupportedPlatformsRegex(), args.getFrameworks(), args.getLibraries(),
            args.getForceStatic().orElse(false) ? NativeLinkable.Linkage.STATIC
                    : args.getPreferredLinkage().orElse(NativeLinkable.Linkage.ANY),
            args.getLinkWhole().orElse(false), args.getSoname(), args.getTests(),
            args.getCanBeAsset().orElse(false),
            !buildTarget.getFlavors().contains(CxxDescriptionEnhancer.EXPORTED_HEADER_SYMLINK_TREE_FLAVOR),
            args.isReexportAllHeaderDependencies()
                    .orElse(cxxBuckConfig.getDefaultReexportAllHeaderDependencies()),
            args.getSupportsMergedLinking().orElse(true), delegate);
}

From source file:com.spectralogic.ds3cli.command.GetBulk.java

private Iterable<Contents> getObjectsByPipe() throws CommandException {
    final ImmutableMap<String, String> pipedObjectMap = FileUtils.normalizedObjectNames(this.pipedFileNames);

    final FluentIterable<Contents> objectList = FluentIterable
            .from(new LazyIterable<>(
                    new GetBucketLoaderFactory(getClient(), this.bucketName, null, null, 100, 5)))
            .filter(new Predicate<Contents>() {
                @Override/*ww  w . jav  a 2s.c  om*/
                public boolean apply(@Nullable final Contents bulkObject) {
                    return pipedObjectMap.containsKey(bulkObject.getKey());
                }
            });

    // look for objects in the piped list not in bucket
    final FluentIterable<String> objectNameList = FluentIterable.from(objectList)
            .transform(new Function<Contents, String>() {
                @Override
                public String apply(@Nullable final Contents bulkObject) {
                    return bulkObject.getKey();
                }
            });

    for (final String object : pipedObjectMap.keySet()) {
        if (objectNameList.contains(object)) {
            LOG.info("Restore: {}", object);
        } else {
            throw new CommandException("Object: " + object + " not found in bucket");
        }
    }
    return objectList;
}

From source file:org.glowroot.transaction.AdviceCache.java

@EnsuresNonNull({ "reweavableAdvisors", "reweavableConfigVersions", "allAdvisors" })
public void updateAdvisors(/*>>>@UnknownInitialization(AdviceCache.class) AdviceCache this,*/
        List<InstrumentationConfig> reweavableConfigs, boolean cleanTmpDir) throws Exception {
    ImmutableMap<Advice, LazyDefinedClass> advisors = AdviceGenerator.createAdvisors(reweavableConfigs, null);
    if (instrumentation == null) {
        // this is for tests that don't run with javaagent container
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        checkNotNull(loader, "Context class loader must be set");
        ClassLoaders.defineClassesInClassLoader(advisors.values(), loader);
    } else {//from ww  w . j a va2 s .  c  om
        File generatedJarDir = new File(dataDir, "tmp");
        if (cleanTmpDir) {
            ClassLoaders.createDirectoryOrCleanPreviousContentsWithPrefix(generatedJarDir, "config-pointcuts");
        }
        if (!advisors.isEmpty()) {
            String suffix = "";
            int count = jarFileCounter.incrementAndGet();
            if (count > 1) {
                suffix = "-" + count;
            }
            File jarFile = new File(generatedJarDir, "config-pointcuts" + suffix + ".jar");
            ClassLoaders.defineClassesInBootstrapClassLoader(advisors.values(), instrumentation, jarFile);
        }
    }
    reweavableAdvisors = advisors.keySet().asList();
    reweavableConfigVersions = createReweavableConfigVersions(reweavableConfigs);
    allAdvisors = ImmutableList.copyOf(Iterables.concat(pluginAdvisors, reweavableAdvisors));
}

From source file:org.jclouds.s3.filters.Aws4SignerForQueryString.java

protected HttpRequest sign(HttpRequest request, long timeInSeconds) throws HttpException {
    checkNotNull(request, "request is not ready to sign");
    checkNotNull(request.getEndpoint(), "request is not ready to sign, request.endpoint not present.");

    // get host from request endpoint.
    String host = request.getEndpoint().getHost();

    Date date = timestampProvider.get();
    String timestamp = timestampFormat.format(date);
    String datestamp = dateFormat.format(date);

    String service = serviceAndRegion.service();
    String region = serviceAndRegion.region(host);
    String credentialScope = Joiner.on('/').join(datestamp, region, service, "aws4_request");

    // different with signature with Authorization header
    HttpRequest.Builder<?> requestBuilder = request.toBuilder() //
            // sign for temporary access use query string parameter:
            // X-Amz-Algorithm, X-Amz-Credential, X-Amz-Date, X-Amz-Expires, X-Amz-SignedHeaders, X-Amz-Signature
            // remove Authorization, x-amz-content-sha256, X-Amz-Date headers
            .removeHeader(AUTHORIZATION_HEADER).removeHeader(AMZ_CONTENT_SHA256_HEADER)
            .removeHeader(AMZ_DATE_HEADER);

    ImmutableMap.Builder<String, String> signedHeadersBuilder = ImmutableSortedMap
            .<String, String>naturalOrder(); //
    Uris.UriBuilder endpointBuilder = Uris.uriBuilder(request.getEndpoint());

    // Canonical Headers
    // must include the HTTP host header.
    // If you plan to include any of the x-amz-* headers, these headers must also be added for signature calculation.
    // You can optionally add all other headers that you plan to include in your request.
    // For added security, you should sign as many headers as possible.

    // HOST/*from w w w.j  a  v  a2  s  .c om*/
    signedHeadersBuilder.put("host", host);
    ImmutableMap<String, String> signedHeaders = signedHeadersBuilder.build();

    Credentials credentials = creds.get();

    if (credentials instanceof SessionCredentials) {
        String token = SessionCredentials.class.cast(credentials).getSessionToken();
        // different with signature with Authorization header
        endpointBuilder.replaceQuery(AMZ_SECURITY_TOKEN_PARAM, token);
    }

    // X-Amz-Algorithm=HMAC-SHA256
    endpointBuilder.replaceQuery(AMZ_ALGORITHM_PARAM, AwsSignatureV4Constants.AMZ_ALGORITHM_HMAC_SHA256);

    // X-Amz-Credential=<your-access-key-id>/<date>/<AWS-region>/<AWS-service>/aws4_request.
    String credential = Joiner.on("/").join(credentials.identity, credentialScope);
    endpointBuilder.replaceQuery(AMZ_CREDENTIAL_PARAM, credential);

    // X-Amz-Date=ISO 8601 format, for example, 20130721T201207Z
    endpointBuilder.replaceQuery(AMZ_DATE_PARAM, timestamp);

    // X-Amz-Expires=time in seconds
    endpointBuilder.replaceQuery(AMZ_EXPIRES_PARAM, String.valueOf(timeInSeconds));

    // X-Amz-SignedHeaders=HTTP host header is required.
    endpointBuilder.replaceQuery(AMZ_SIGNEDHEADERS_PARAM, Joiner.on(';').join(signedHeaders.keySet()));

    String stringToSign = createStringToSign(request.getMethod(), endpointBuilder.build(), signedHeaders,
            timestamp, credentialScope, getPayloadHash());

    signatureWire.getWireLog().debug("<< " + stringToSign);

    byte[] signatureKey = signatureKey(credentials.credential, datestamp, region, service);
    String signature = base16().lowerCase().encode(hmacSHA256(stringToSign, signatureKey));

    // X-Amz-Signature=Signature
    endpointBuilder.replaceQuery(AMZ_SIGNATURE_PARAM, signature);

    return requestBuilder.endpoint(endpointBuilder.build()).build();
}