List of usage examples for com.google.common.collect ImmutableMultimap of
public static <K, V> ImmutableMultimap<K, V> of()
From source file:com.facebook.buck.features.python.CxxPythonExtensionDescription.java
@Override public BuildRule createBuildRule(BuildRuleCreationContextWithTargetGraph context, BuildTarget buildTarget, BuildRuleParams params, CxxPythonExtensionDescriptionArg args) { ActionGraphBuilder graphBuilderLocal = context.getActionGraphBuilder(); ProjectFilesystem projectFilesystem = context.getProjectFilesystem(); CellPathResolver cellRoots = context.getCellPathResolver(); // See if we're building a particular "type" of this library, and if so, extract it as an enum. Optional<Type> type = LIBRARY_TYPE.getValue(buildTarget); if (type.isPresent()) { FlavorDomain<UnresolvedCxxPlatform> cxxPlatforms = getCxxPlatforms(); FlavorDomain<PythonPlatform> pythonPlatforms = getPythonPlatforms(); // If we *are* building a specific type of this lib, call into the type specific rule builder // methods. switch (type.get()) { case EXTENSION: return createExtensionBuildRule(buildTarget, projectFilesystem, graphBuilderLocal, cellRoots, pythonPlatforms.getRequiredValue(buildTarget), cxxPlatforms.getRequiredValue(buildTarget).resolve(graphBuilderLocal), args); case COMPILATION_DATABASE: // so for the moment, when we get a target whose flavor is just #compilation-database // we'll give it the default C++ and Python platforms to build with. // of course, these may not be the desired/correct ones, but up until now // the target would often end up without a Python platform at all, causing // us to miss out on the compilation database altogether. BuildTarget target = buildTarget; if (!cxxPlatforms.containsAnyOf(target.getFlavors())) { // constructor args *should* contain a default flavor, but // we keep the platform default as a final fallback ImmutableSet<Flavor> defaultCxxFlavors = args.getDefaultFlavors(); if (!cxxPlatforms.containsAnyOf(defaultCxxFlavors)) { defaultCxxFlavors = ImmutableSet.of(getDefaultCxxPlatform().getFlavor()); }/* w ww . j a v a 2s . c om*/ target = target.withAppendedFlavors(defaultCxxFlavors); } if (!pythonPlatforms.containsAnyOf(target.getFlavors())) { target = target.withAppendedFlavors(PythonBuckConfig.DEFAULT_PYTHON_PLATFORM); } return createCompilationDatabase(target, projectFilesystem, graphBuilderLocal, cellRoots, pythonPlatforms.getRequiredValue(target), cxxPlatforms.getRequiredValue(target).resolve(graphBuilderLocal), args); } } // Otherwise, we return the generic placeholder of this library, that dependents can use // get the real build rules via querying the action graph. Path baseModule = PythonUtil.getBasePath(buildTarget, args.getBaseModule()); String moduleName = args.getModuleName().orElse(buildTarget.getShortName()); Path module = baseModule.resolve(getExtensionName(moduleName)); return new CxxPythonExtension(buildTarget, projectFilesystem, params) { @Override protected BuildRule getExtension(PythonPlatform pythonPlatform, CxxPlatform cxxPlatform, ActionGraphBuilder graphBuilder) { return graphBuilder.requireRule(getBuildTarget().withAppendedFlavors(pythonPlatform.getFlavor(), cxxPlatform.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR)); } @Override public Path getModule() { return module; } @Override public Iterable<BuildRule> getPythonPackageDeps(PythonPlatform pythonPlatform, CxxPlatform cxxPlatform, ActionGraphBuilder graphBuilder) { return PythonUtil.getDeps(pythonPlatform, cxxPlatform, args.getDeps(), args.getPlatformDeps()) .stream().map(graphBuilder::getRule).filter(PythonPackagable.class::isInstance) .collect(ImmutableList.toImmutableList()); } @Override public PythonPackageComponents getPythonPackageComponents(PythonPlatform pythonPlatform, CxxPlatform cxxPlatform, ActionGraphBuilder graphBuilder) { BuildRule extension = getExtension(pythonPlatform, cxxPlatform, graphBuilder); SourcePath output = extension.getSourcePathToOutput(); return PythonPackageComponents.of(ImmutableMap.of(module, output), ImmutableMap.of(), ImmutableMap.of(), ImmutableMultimap.of(), Optional.of(false)); } @Override public NativeLinkTarget getNativeLinkTarget(PythonPlatform pythonPlatform) { return new NativeLinkTarget() { @Override public BuildTarget getBuildTarget() { return buildTarget.withAppendedFlavors(pythonPlatform.getFlavor()); } @Override public NativeLinkTargetMode getNativeLinkTargetMode(CxxPlatform cxxPlatform) { return NativeLinkTargetMode.library(); } @Override public Iterable<? extends NativeLinkable> getNativeLinkTargetDeps(CxxPlatform cxxPlatform, ActionGraphBuilder graphBuilder) { return RichStream.from(getPlatformDeps(graphBuilder, pythonPlatform, cxxPlatform, args)) .filter(NativeLinkable.class).toImmutableList(); } @Override public NativeLinkableInput getNativeLinkTargetInput(CxxPlatform cxxPlatform, ActionGraphBuilder graphBuilder, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder) { return NativeLinkableInput.builder() .addAllArgs(getExtensionArgs( buildTarget.withAppendedFlavors(pythonPlatform.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR), projectFilesystem, graphBuilder, pathResolver, ruleFinder, cellRoots, cxxPlatform, args, getPlatformDeps(graphBuilder, pythonPlatform, cxxPlatform, args))) .addAllFrameworks(args.getFrameworks()).build(); } @Override public Optional<Path> getNativeLinkTargetOutputPath(CxxPlatform cxxPlatform) { return Optional.empty(); } }; } @Override public Stream<BuildTarget> getRuntimeDeps(SourcePathRuleFinder ruleFinder) { return getDeclaredDeps().stream().map(BuildRule::getBuildTarget); } }; }
From source file:com.facebook.buck.apple.project_generator.WorkspaceAndProjectGenerator.java
private GenerationResult generateProjectForDirectory(Map<Path, ProjectGenerator> projectGenerators, Optional<BuildTarget> targetToBuildWithBuck, Cell projectCell, Path projectDirectory, final ImmutableSet<BuildTarget> rules) throws IOException { boolean shouldGenerateProjects = false; ProjectGenerator generator;/* ww w . j av a2s. c o m*/ synchronized (projectGenerators) { generator = projectGenerators.get(projectDirectory); if (generator != null) { LOG.debug("Already generated project for target %s, skipping", projectDirectory); } else { LOG.debug("Generating project for directory %s with targets %s", projectDirectory, rules); String projectName; if (projectDirectory.getFileName().toString().equals("")) { // If we're generating a project in the root directory, use a generic name. projectName = "Project"; } else { // Otherwise, name the project the same thing as the directory we're in. projectName = projectDirectory.getFileName().toString(); } generator = new ProjectGenerator(projectGraph, dependenciesCache, rules, projectCell, projectDirectory, projectName, buildFileName, projectGeneratorOptions, Optionals.bind(targetToBuildWithBuck, input -> rules.contains(input) ? Optional.of(input) : Optional.empty()), buildWithBuckFlags, focusModules, executableFinder, environment, cxxPlatforms, defaultCxxPlatform, sourcePathResolverForNode, buckEventBus, halideBuckConfig, cxxBuckConfig, appleConfig, swiftBuckConfig); projectGenerators.put(projectDirectory, generator); shouldGenerateProjects = true; } } ImmutableSet<BuildTarget> requiredBuildTargets = ImmutableSet.of(); ImmutableMultimap<BuildTarget, PBXTarget> buildTargetToGeneratedTargetMap = ImmutableMultimap.of(); if (shouldGenerateProjects) { generator.createXcodeProjects(); } if (generator.isProjectGenerated()) { requiredBuildTargets = generator.getRequiredBuildTargets(); buildTargetToGeneratedTargetMap = generator.getBuildTargetToGeneratedTargetMap(); } return GenerationResult.of(generator.getProjectPath(), generator.isProjectGenerated(), requiredBuildTargets, buildTargetToGeneratedTargetMap); }
From source file:com.facebook.buck.features.go.GoDescriptors.java
private static SymlinkTree makeSymlinkTree(BuildTarget buildTarget, ProjectFilesystem projectFilesystem, SourcePathRuleFinder ruleFinder, SourcePathResolver pathResolver, ImmutableSet<GoLinkable> linkables) { ImmutableMap<Path, SourcePath> treeMap; try {/*from w w w. jav a 2 s.c o m*/ treeMap = linkables.stream().flatMap(linkable -> linkable.getGoLinkInput().entrySet().stream()) .collect(ImmutableMap.toImmutableMap( entry -> getPathInSymlinkTree(pathResolver, entry.getKey(), entry.getValue()), entry -> entry.getValue())); } catch (IllegalArgumentException ex) { throw new HumanReadableException(ex, "Multiple go targets have the same package name when compiling %s", buildTarget.getFullyQualifiedName()); } Path root = BuildTargetPaths.getScratchPath(projectFilesystem, buildTarget, "__%s__tree"); return new SymlinkTree("go_linkable", buildTarget, projectFilesystem, root, treeMap, ImmutableMultimap.of(), ruleFinder); }
From source file:com.isotrol.impe3.freemarker.FreeMarker.java
private static Multimap<String, String> getParameters(List<String> args, int index) { if (args == null || (args.size() - index) < 2) { return ImmutableMultimap.of(); }/*w ww . j a va2 s .c o m*/ final int n = args.size(); final Multimap<String, String> map = LinkedListMultimap.create(n / 2); for (int i = index; (args.size() - i) >= 2; i += 2) { String p = args.get(i); String v = args.get(i + 1); if (p != null && v != null) { map.put(p, v); } } return map; }
From source file:io.prestosql.execution.scheduler.SourcePartitionedScheduler.java
private Set<RemoteTask> finalizeTaskCreationIfNecessary() { // only lock down tasks if there is a sub stage that could block waiting for this stage to create all tasks if (stage.getFragment().isLeaf()) { return ImmutableSet.of(); }/*from w ww.java 2 s .c o m*/ splitPlacementPolicy.lockDownNodes(); Set<Node> scheduledNodes = stage.getScheduledNodes(); Set<RemoteTask> newTasks = splitPlacementPolicy.allNodes().stream() .filter(node -> !scheduledNodes.contains(node)) .flatMap( node -> stage.scheduleSplits(node, ImmutableMultimap.of(), ImmutableMultimap.of()).stream()) .collect(toImmutableSet()); // notify listeners that we have scheduled all tasks so they can set no more buffers or exchange splits stage.transitionToSchedulingSplits(); return newTasks; }
From source file:com.facebook.buck.features.lua.LuaBinaryDescription.java
private SymlinkTree createSymlinkTree(BuildTarget linkTreeTarget, ProjectFilesystem filesystem, ActionGraphBuilder graphBuilder, SourcePathRuleFinder ruleFinder, Path root, ImmutableMap<String, SourcePath> components) { return graphBuilder.addToIndex(new SymlinkTree("lua_binary", linkTreeTarget, filesystem, root, MoreMaps.transformKeys(components, MorePaths.toPathFn(root.getFileSystem())), ImmutableMultimap.of(), ruleFinder)); }
From source file:com.facebook.buck.cxx.CxxDescriptionEnhancer.java
public static ImmutableMap<CxxPreprocessAndCompile, SourcePath> requireObjects(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathResolver sourcePathResolver, SourcePathRuleFinder ruleFinder, CxxBuckConfig cxxBuckConfig, CxxPlatform cxxPlatform, CxxSourceRuleFactory.PicType pic, CxxConstructorArg args) throws NoSuchBuildTargetException { ImmutableMultimap<CxxSource.Type, String> exportedPreprocessorFlags; ImmutableMap<Path, SourcePath> exportedHeaders; boolean shouldCreatePrivateHeadersSymlinks = true; boolean shouldCreatePublicHeadersSymlinks = true; if (args instanceof CxxLibraryDescription.Arg) { CxxLibraryDescription.Arg hasExportedArgs = (CxxLibraryDescription.Arg) args; exportedPreprocessorFlags = CxxFlags.getLanguageFlags(hasExportedArgs.exportedPreprocessorFlags, hasExportedArgs.exportedPlatformPreprocessorFlags, hasExportedArgs.exportedLangPreprocessorFlags, cxxPlatform); exportedHeaders = CxxDescriptionEnhancer.parseExportedHeaders(params.getBuildTarget(), sourcePathResolver, Optional.of(cxxPlatform), hasExportedArgs); shouldCreatePrivateHeadersSymlinks = hasExportedArgs.xcodePrivateHeadersSymlinks.orElse(true); shouldCreatePublicHeadersSymlinks = hasExportedArgs.xcodePublicHeadersSymlinks.orElse(true); } else {/*from w w w .j a v a 2 s. com*/ exportedPreprocessorFlags = ImmutableMultimap.of(); exportedHeaders = ImmutableMap.of(); } HeaderSymlinkTree headerSymlinkTree = CxxDescriptionEnhancer.requireHeaderSymlinkTree(params, ruleResolver, sourcePathResolver, cxxPlatform, CxxDescriptionEnhancer.parseHeaders(params.getBuildTarget(), sourcePathResolver, Optional.of(cxxPlatform), args), HeaderVisibility.PRIVATE, shouldCreatePrivateHeadersSymlinks); Optional<SymlinkTree> sandboxTree = Optional.empty(); if (cxxBuckConfig.sandboxSources()) { sandboxTree = createSandboxTree(params, ruleResolver, cxxPlatform); } ImmutableList<CxxPreprocessorInput> cxxPreprocessorInputFromDependencies = CxxDescriptionEnhancer .collectCxxPreprocessorInput(params, cxxPlatform, CxxFlags.getLanguageFlags(args.preprocessorFlags, args.platformPreprocessorFlags, args.langPreprocessorFlags, cxxPlatform), ImmutableList.of(headerSymlinkTree), ImmutableSet.of(), CxxLibraryDescription.getTransitiveCxxPreprocessorInput(params, ruleResolver, sourcePathResolver, cxxPlatform, exportedPreprocessorFlags, exportedHeaders, args.frameworks, shouldCreatePublicHeadersSymlinks), args.includeDirs, sandboxTree); // Create rule to build the object files. return CxxSourceRuleFactory.requirePreprocessAndCompileRules(params, ruleResolver, sourcePathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, cxxPreprocessorInputFromDependencies, CxxFlags.getLanguageFlags(args.compilerFlags, args.platformCompilerFlags, args.langCompilerFlags, cxxPlatform), args.prefixHeader, args.precompiledHeader, CxxDescriptionEnhancer.parseCxxSources( params.getBuildTarget(), sourcePathResolver, cxxPlatform, args), pic, sandboxTree); }
From source file:io.prestosql.plugin.hive.HiveMetadata.java
private static PrincipalPrivileges buildInitialPrivilegeSet(String tableOwner) { PrestoPrincipal owner = new PrestoPrincipal(USER, tableOwner); return new PrincipalPrivileges( ImmutableMultimap.<String, HivePrivilegeInfo>builder() .put(tableOwner, new HivePrivilegeInfo(HivePrivilege.SELECT, true, owner, owner)) .put(tableOwner, new HivePrivilegeInfo(HivePrivilege.INSERT, true, owner, owner)) .put(tableOwner, new HivePrivilegeInfo(HivePrivilege.UPDATE, true, owner, owner)) .put(tableOwner, new HivePrivilegeInfo(HivePrivilege.DELETE, true, owner, owner)).build(), ImmutableMultimap.of()); }
From source file:io.prestosql.plugin.hive.AbstractTestHiveClient.java
License:asdf
private PrincipalPrivileges testingPrincipalPrivilege(String tableOwner, String grantor) { return new PrincipalPrivileges( ImmutableMultimap.<String, HivePrivilegeInfo>builder() .put(tableOwner,// ww w .j a v a2s .c o m new HivePrivilegeInfo(HivePrivilege.SELECT, true, new PrestoPrincipal(USER, grantor), new PrestoPrincipal(USER, grantor))) .put(tableOwner, new HivePrivilegeInfo(HivePrivilege.INSERT, true, new PrestoPrincipal(USER, grantor), new PrestoPrincipal(USER, grantor))) .put(tableOwner, new HivePrivilegeInfo(HivePrivilege.UPDATE, true, new PrestoPrincipal(USER, grantor), new PrestoPrincipal(USER, grantor))) .put(tableOwner, new HivePrivilegeInfo(HivePrivilege.DELETE, true, new PrestoPrincipal(USER, grantor), new PrestoPrincipal(USER, grantor))) .build(), ImmutableMultimap.of()); }