List of usage examples for com.google.common.collect ImmutableSetMultimap get
@Override
public ImmutableSet<V> get(@Nullable K key)
From source file:org.graylog.plugins.pipelineprocessor.processors.PipelineInterpreter.java
private ImmutableSet<Pipeline> selectPipelines(InterpreterListener interpreterListener, Set<Tuple2<String, String>> processingBlacklist, Message message, Set<String> initialStreamIds, ImmutableSetMultimap<String, Pipeline> streamConnection) { final String msgId = message.getId(); // if a message-stream combination has already been processed (is in the set), skip that execution final Set<String> streamsIds = initialStreamIds.stream() .filter(streamId -> !processingBlacklist.contains(tuple(msgId, streamId))) .filter(streamConnection::containsKey).collect(Collectors.toSet()); final ImmutableSet<Pipeline> pipelinesToRun = ImmutableSet.copyOf(streamsIds.stream() .flatMap(streamId -> streamConnection.get(streamId).stream()).collect(Collectors.toSet())); interpreterListener.processStreams(message, pipelinesToRun, streamsIds); log.debug("[{}] running pipelines {} for streams {}", msgId, pipelinesToRun, streamsIds); return pipelinesToRun; }
From source file:com.facebook.buck.maven.Resolver.java
private void createBuckFiles(ImmutableSetMultimap<Path, Prebuilt> buckFilesData) throws IOException { URL templateUrl = Resources.getResource(TEMPLATE); String template = Resources.toString(templateUrl, UTF_8); STGroupString groups = new STGroupString("prebuilt-template", template); for (Path key : buckFilesData.keySet()) { Path buckFile = key.resolve("BUCK"); if (Files.exists(buckFile)) { Files.delete(buckFile); }// www . j a v a 2 s . c o m ST st = Preconditions.checkNotNull(groups.getInstanceOf("/prebuilts")); st.add("data", buckFilesData.get(key)); Files.write(buckFile, st.render().getBytes(UTF_8)); } }
From source file:com.facebook.buck.apple.project_generator.WorkspaceAndProjectGenerator.java
private void buildWorkspaceSchemeTests(Optional<BuildTarget> mainTarget, TargetGraph projectGraph, boolean includeProjectTests, boolean includeDependenciesTests, ImmutableSetMultimap<String, Optional<TargetNode<?, ?>>> schemeNameToSrcTargetNode, ImmutableSetMultimap<String, TargetNode<AppleTestDescription.Arg, ?>> extraTestNodes, ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescription.Arg, ?>> selectedTestsBuilder, ImmutableSetMultimap.Builder<String, TargetNode<?, ?>> buildForTestNodesBuilder) { for (String schemeName : schemeNameToSrcTargetNode.keySet()) { ImmutableSet<TargetNode<?, ?>> targetNodes = schemeNameToSrcTargetNode.get(schemeName).stream() .flatMap(Optionals::toStream).collect(MoreCollectors.toImmutableSet()); ImmutableSet<TargetNode<AppleTestDescription.Arg, ?>> testNodes = getOrderedTestNodes(mainTarget, projectGraph, includeProjectTests, includeDependenciesTests, targetNodes, extraTestNodes.get(schemeName)); selectedTestsBuilder.putAll(schemeName, testNodes); buildForTestNodesBuilder.putAll(schemeName, Iterables.filter(TopologicalSort.sort(projectGraph), getTransitiveDepsAndInputs(projectGraph, dependenciesCache, testNodes, targetNodes)::contains)); }// www. j a va 2 s. c om }
From source file:com.facebook.buck.android.AndroidBinary.java
/** * @return the resulting set of ProGuarded classpath entries to dex. *//*from w w w .j ava2 s .co m*/ @VisibleForTesting ImmutableSet<Path> addProguardCommands(Set<Path> classpathEntriesToDex, Set<Path> depsProguardConfigs, ImmutableList.Builder<Step> steps, Set<Path> resDirectories, BuildableContext buildableContext) { final ImmutableSetMultimap<JavaLibrary, Path> classpathEntriesMap = getTransitiveClasspathEntries(); ImmutableSet.Builder<Path> additionalLibraryJarsForProguardBuilder = ImmutableSet.builder(); for (JavaLibrary buildRule : rulesToExcludeFromDex) { additionalLibraryJarsForProguardBuilder.addAll(classpathEntriesMap.get(buildRule)); } // Clean out the directory for generated ProGuard files. Path proguardDirectory = getPathForProGuardDirectory(); steps.add(new MakeCleanDirectoryStep(proguardDirectory)); // Generate a file of ProGuard config options using aapt. Path generatedProGuardConfig = proguardDirectory.resolve("proguard.txt"); GenProGuardConfigStep genProGuardConfig = new GenProGuardConfigStep( aaptPackageResources.getAndroidManifestXml(), resDirectories, generatedProGuardConfig); steps.add(genProGuardConfig); // Create list of proguard Configs for the app project and its dependencies ImmutableSet.Builder<Path> proguardConfigsBuilder = ImmutableSet.builder(); proguardConfigsBuilder.addAll(depsProguardConfigs); if (proguardConfig.isPresent()) { proguardConfigsBuilder.add(proguardConfig.get().resolve()); } // Transform our input classpath to a set of output locations for each input classpath. // TODO(devjasta): the output path we choose is the result of a slicing function against // input classpath. This is fragile and should be replaced with knowledge of the BuildTarget. final ImmutableMap<Path, Path> inputOutputEntries = FluentIterable.from(classpathEntriesToDex) .toMap(new Function<Path, Path>() { @Override public Path apply(Path classpathEntry) { return getProguardOutputFromInputClasspath(classpathEntry); } }); // Run ProGuard on the classpath entries. // TODO(user): ProGuardObfuscateStep's final argument should be a Path Step obfuscateCommand = ProGuardObfuscateStep.create(proguardJarOverride, generatedProGuardConfig, proguardConfigsBuilder.build(), useAndroidProguardConfigWithOptimizations, optimizationPasses, inputOutputEntries, additionalLibraryJarsForProguardBuilder.build(), proguardDirectory, buildableContext); steps.add(obfuscateCommand); // Apply the transformed inputs to the classpath (this will modify deps.classpathEntriesToDex // so that we're now dexing the proguarded artifacts). return ImmutableSet.copyOf(inputOutputEntries.values()); }
From source file:com.facebook.buck.features.apple.project.WorkspaceAndProjectGenerator.java
private void buildWorkspaceSchemeTests(Optional<BuildTarget> mainTarget, TargetGraph projectGraph, boolean includeProjectTests, boolean includeDependenciesTests, ImmutableSetMultimap<String, Optional<TargetNode<?>>> schemeNameToSrcTargetNode, ImmutableSetMultimap<String, TargetNode<AppleTestDescriptionArg>> extraTestNodes, ImmutableSetMultimap.Builder<String, TargetNode<AppleTestDescriptionArg>> selectedTestsBuilder, ImmutableSetMultimap.Builder<String, TargetNode<?>> buildForTestNodesBuilder) { for (String schemeName : schemeNameToSrcTargetNode.keySet()) { ImmutableSet<TargetNode<?>> targetNodes = schemeNameToSrcTargetNode.get(schemeName).stream() .flatMap(Optionals::toStream).collect(ImmutableSet.toImmutableSet()); ImmutableSet<TargetNode<AppleTestDescriptionArg>> testNodes = getOrderedTestNodes(mainTarget, projectGraph, includeProjectTests, includeDependenciesTests, targetNodes, extraTestNodes.get(schemeName)); selectedTestsBuilder.putAll(schemeName, testNodes); buildForTestNodesBuilder.putAll(schemeName, Iterables.filter(TopologicalSort.sort(projectGraph), getTransitiveDepsAndInputs(xcodeDescriptions, projectGraph, dependenciesCache, testNodes, targetNodes)::contains)); }/*from w w w . j a v a2s . c o m*/ }
From source file:com.facebook.buck.features.apple.project.WorkspaceAndProjectGenerator.java
/** * Create individual schemes for each project and associated tests. Provided as a workaround for a * change in Xcode 10 where Apple started building all scheme targets and tests when clicking on a * single item from the test navigator./*from ww w.j a va 2s.co m*/ * * @param workspaceName * @param outputDirectory * @param schemeTargets Targets to be considered for scheme. Allows external filtering of targets * included in the project's scheme. * @param generatedProjectToPbxTargets * @param targetToProjectPathMap * @param buildForTestTargets * @param ungroupedTestTargets * @throws IOException */ private void writeWorkspaceSchemesForProjects(String workspaceName, Path outputDirectory, ImmutableSet<PBXTarget> schemeTargets, ImmutableSetMultimap<PBXProject, PBXTarget> generatedProjectToPbxTargets, ImmutableMap<PBXTarget, Path> targetToProjectPathMap, ImmutableSetMultimap<String, PBXTarget> buildForTestTargets, ImmutableSetMultimap<String, PBXTarget> ungroupedTestTargets) throws IOException { for (PBXProject project : generatedProjectToPbxTargets.keys()) { String schemeName = project.getName(); ImmutableSet<PBXTarget> projectTargets = generatedProjectToPbxTargets.get(project); ImmutableSet<PBXTarget> orderedBuildTestTargets = projectTargets.stream() .filter(pbxTarget -> buildForTestTargets.values().contains(pbxTarget)) .collect(ImmutableSet.toImmutableSet()); ImmutableSet<PBXTarget> orderedRunTestTargets = projectTargets.stream() .filter(pbxTarget -> ungroupedTestTargets.values().contains(pbxTarget)) .collect(ImmutableSet.toImmutableSet()); // add all non-test targets as full build targets ImmutableSet<PBXTarget> orderedBuildTargets = projectTargets.stream() .filter(pbxTarget -> schemeTargets.contains(pbxTarget)) .filter(pbxTarget -> !orderedBuildTestTargets.contains(pbxTarget)) .collect(ImmutableSet.toImmutableSet()); SchemeGenerator schemeGenerator = buildSchemeGenerator(targetToProjectPathMap, workspaceName, outputDirectory, schemeName, Optional.empty(), Optional.empty(), orderedBuildTargets, orderedBuildTestTargets, orderedRunTestTargets, Optional.empty(), Optional.empty()); schemeGenerator.writeScheme(); schemeGenerators.put(schemeName, schemeGenerator); } }
From source file:com.google.auto.value.processor.AutoValueProcessor.java
/** * Returns all method annotations that should be imported in the generated class. Doesn't include * AutoValue itself (and its nested annotations), any @Inherited annotations, and anything that's * in excludedAnnotationsMap./* w w w .j a va 2s . c o m*/ */ private Set<TypeMirror> allMethodAnnotationTypes(Iterable<ExecutableElement> methods, ImmutableSetMultimap<ExecutableElement, String> excludedAnnotationsMap) { Set<TypeMirror> annotationTypes = new TypeMirrorSet(); for (ExecutableElement method : methods) { ImmutableSet<String> excludedAnnotations = excludedAnnotationsMap.get(method); for (AnnotationMirror annotationMirror : method.getAnnotationMirrors()) { String annotationFqName = getAnnotationFqName(annotationMirror); if (excludedAnnotations.contains(annotationFqName)) { continue; } if (isAnnotationPresent(annotationMirror.getAnnotationType().asElement(), Inherited.class)) { continue; } if (AUTO_VALUE_CLASSNAME_PATTERN.matcher(annotationFqName).matches()) { continue; } annotationTypes.add(annotationMirror.getAnnotationType()); } for (AnnotationMirror annotationMirror : Java8Support.getAnnotationMirrors(method.getReturnType())) { annotationTypes.add(annotationMirror.getAnnotationType()); } } return annotationTypes; }
From source file:dagger.internal.codegen.BasicProcessor.java
/** * Returns the valid annotated elements contained in all of the deferred elements. If none are * found for a deferred element, defers it again. *//* ww w . j a v a2 s .co m*/ private ImmutableSetMultimap<Class<? extends Annotation>, Element> validElements( ImmutableMap<String, Optional<? extends Element>> deferredElements, RoundEnvironment roundEnv) { ImmutableSetMultimap.Builder<Class<? extends Annotation>, Element> deferredElementsByAnnotationBuilder = ImmutableSetMultimap .builder(); for (Entry<String, Optional<? extends Element>> deferredTypeElementEntry : deferredElements.entrySet()) { Optional<? extends Element> deferredElement = deferredTypeElementEntry.getValue(); if (deferredElement.isPresent()) { findAnnotatedElements(deferredElement.get(), getSupportedAnnotationClasses(), deferredElementsByAnnotationBuilder); } else { deferredElementNames.add(ElementName.forTypeName(deferredTypeElementEntry.getKey())); } } ImmutableSetMultimap<Class<? extends Annotation>, Element> deferredElementsByAnnotation = deferredElementsByAnnotationBuilder .build(); ImmutableSetMultimap.Builder<Class<? extends Annotation>, Element> validElements = ImmutableSetMultimap .builder(); Set<ElementName> validElementNames = new LinkedHashSet<ElementName>(); // Look at the elements we've found and the new elements from this round and validate them. for (Class<? extends Annotation> annotationClass : getSupportedAnnotationClasses()) { // This should just call roundEnv.getElementsAnnotatedWith(Class) directly, but there is a bug // in some versions of eclipse that cause that method to crash. TypeElement annotationType = elements.getTypeElement(annotationClass.getCanonicalName()); Set<? extends Element> elementsAnnotatedWith = (annotationType == null) ? ImmutableSet.<Element>of() : roundEnv.getElementsAnnotatedWith(annotationType); for (Element annotatedElement : Sets.union(elementsAnnotatedWith, deferredElementsByAnnotation.get(annotationClass))) { if (annotatedElement.getKind().equals(PACKAGE)) { PackageElement annotatedPackageElement = (PackageElement) annotatedElement; ElementName annotatedPackageName = ElementName .forPackageName(annotatedPackageElement.getQualifiedName().toString()); boolean validPackage = validElementNames.contains(annotatedPackageName) || (!deferredElementNames.contains(annotatedPackageName) && validateElement(annotatedPackageElement)); if (validPackage) { validElements.put(annotationClass, annotatedPackageElement); validElementNames.add(annotatedPackageName); } else { deferredElementNames.add(annotatedPackageName); } } else { TypeElement enclosingType = getEnclosingType(annotatedElement); ElementName enclosingTypeName = ElementName .forTypeName(enclosingType.getQualifiedName().toString()); boolean validEnclosingType = validElementNames.contains(enclosingTypeName) || (!deferredElementNames.contains(enclosingTypeName) && validateElement(enclosingType)); if (validEnclosingType) { validElements.put(annotationClass, annotatedElement); validElementNames.add(enclosingTypeName); } else { deferredElementNames.add(enclosingTypeName); } } } } return validElements.build(); }
From source file:com.google.devtools.build.lib.rules.cpp.CcLinkingHelper.java
/** * Create the C++ link actions, and the corresponding linking related providers. * * @throws RuleErrorException/*ww w . ja va2 s. c o m*/ */ // TODO(b/73997894): Try to remove CcCompilationContext. Right now headers are passed as non // code // inputs to the linker. public LinkingInfo link(CcCompilationOutputs ccOutputs, CcCompilationContext ccCompilationContext) throws RuleErrorException, InterruptedException { Preconditions.checkNotNull(ccOutputs); Preconditions.checkNotNull(ccCompilationContext); if (checkDepsGenerateCpp) { for (LanguageDependentFragment dep : AnalysisUtils.getProviders(deps, LanguageDependentFragment.class)) { LanguageDependentFragment.Checker.depSupportsLanguage(ruleContext, dep, CppRuleClasses.LANGUAGE, "deps"); } } // Create link actions (only if there are object files or if explicitly requested). CcLinkingOutputs ccLinkingOutputs = CcLinkingOutputs.EMPTY; if (emitLinkActionsIfEmpty || !ccOutputs.isEmpty()) { // On some systems, the linker gives an error message if there are no input files. Even with // the check above, this can still happen if there is a .nopic.o or .o files in srcs, but no // other files. To fix that, we'd have to check for each link action individually. // // An additional pre-existing issue is that the header check tokens are dropped if we don't // generate any link actions, effectively disabling header checking in some cases. if (linkType.linkerOrArchiver() == LinkerOrArchiver.ARCHIVER) { // TODO(bazel-team): This can't create the link action for a cc_binary yet. ccLinkingOutputs = createCcLinkActions(ccOutputs, nonCodeLinkerInputs); } } CcLinkingOutputs originalLinkingOutputs = ccLinkingOutputs; if (!(staticLibraries.isEmpty() && picStaticLibraries.isEmpty() && dynamicLibraries.isEmpty() && executionDynamicLibraries.isEmpty())) { CcLinkingOutputs.Builder newOutputsBuilder = new CcLinkingOutputs.Builder(); if (!ccOutputs.isEmpty()) { // Add the linked outputs of this rule iff we had anything to put in them, but then // make sure we're not colliding with some library added from the inputs. newOutputsBuilder.merge(originalLinkingOutputs); ImmutableSetMultimap<String, LibraryToLink> precompiledLibraryMap = CcLinkingOutputs .getLibrariesByIdentifier(Iterables.concat(staticLibraries, picStaticLibraries, dynamicLibraries, executionDynamicLibraries)); ImmutableSetMultimap<String, LibraryToLink> linkedLibraryMap = originalLinkingOutputs .getLibrariesByIdentifier(); for (String matchingIdentifier : Sets.intersection(precompiledLibraryMap.keySet(), linkedLibraryMap.keySet())) { Iterable<Artifact> matchingInputLibs = LinkerInputs .toNonSolibArtifacts(precompiledLibraryMap.get(matchingIdentifier)); Iterable<Artifact> matchingOutputLibs = LinkerInputs .toNonSolibArtifacts(linkedLibraryMap.get(matchingIdentifier)); ruleContext.ruleError("Can't put " + Streams.stream(matchingInputLibs).map(Artifact::getFilename).collect(joining(", ")) + " into the srcs of a " + ruleContext.getRuleClassNameForLogging() + " with the same name (" + ruleContext.getRule().getName() + ") which also contains other code or objects to link; it shares a name with " + Streams.stream(matchingOutputLibs).map(Artifact::getFilename).collect(joining(", ")) + " (output compiled and linked from the non-library sources of this rule), " + "which could cause confusion"); } } // Merge the pre-compiled libraries (static & dynamic) into the linker outputs. ccLinkingOutputs = newOutputsBuilder.addStaticLibraries(staticLibraries) .addPicStaticLibraries(picStaticLibraries).addDynamicLibraries(dynamicLibraries) .addExecutionDynamicLibraries(executionDynamicLibraries).build(); } Map<String, NestedSet<Artifact>> outputGroups = new TreeMap<>(); if (shouldAddLinkerOutputArtifacts(ruleContext, ccOutputs)) { addLinkerOutputArtifacts(outputGroups, ccOutputs); } // Be very careful when adding new providers here - it can potentially affect a lot of rules. // We should consider merging most of these providers into a single provider. TransitiveInfoProviderMapBuilder providers = new TransitiveInfoProviderMapBuilder(); // TODO(bazel-team): Maybe we can infer these from other data at the places where they are // used. if (emitCcNativeLibrariesProvider) { providers.add(new CcNativeLibraryProvider(collectNativeCcLibraries(ccLinkingOutputs))); } Runfiles cppStaticRunfiles = collectCppRunfiles(ccLinkingOutputs, true); Runfiles cppSharedRunfiles = collectCppRunfiles(ccLinkingOutputs, false); CcLinkingInfo.Builder ccLinkingInfoBuilder = CcLinkingInfo.Builder.create(); ccLinkingInfoBuilder.setCcRunfiles(new CcRunfiles(cppStaticRunfiles, cppSharedRunfiles)); ccLinkingInfoBuilder.setCcExecutionDynamicLibraries( collectExecutionDynamicLibraryArtifacts(ccLinkingOutputs.getDynamicLibrariesForRuntime())); CppConfiguration cppConfiguration = ruleContext.getFragment(CppConfiguration.class); boolean forcePic = cppConfiguration.forcePic(); if (emitCcSpecificLinkParamsProvider) { providers.add(new CcSpecificLinkParamsProvider( createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContext, forcePic))); } else { ccLinkingInfoBuilder.setCcLinkParamsStore(new CcLinkParamsStore( createCcLinkParamsStore(ccLinkingOutputs, ccCompilationContext, forcePic))); } providers.put(ccLinkingInfoBuilder.build()); return new LinkingInfo(providers.build(), outputGroups, ccLinkingOutputs, originalLinkingOutputs); }
From source file:com.facebook.buck.android.AndroidBinaryRule.java
/** * @return the resulting set of ProGuarded classpath entries to dex. *//*www. ja v a2 s . c o m*/ @VisibleForTesting ImmutableSet<String> addProguardCommands(BuildContext context, Set<String> classpathEntriesToDex, Set<String> depsProguardConfigs, ImmutableList.Builder<Step> steps, Set<String> resDirectories) { final ImmutableSetMultimap<JavaLibraryRule, String> classpathEntriesMap = getTransitiveClasspathEntries(); ImmutableSet.Builder<String> additionalLibraryJarsForProguardBuilder = ImmutableSet.builder(); for (BuildRule buildRule : buildRulesToExcludeFromDex) { if (buildRule instanceof JavaLibraryRule) { additionalLibraryJarsForProguardBuilder .addAll(classpathEntriesMap.get((JavaLibraryRule) buildRule)); } } // Clean out the directory for generated ProGuard files. Path proguardDirectory = getPathForProGuardDirectory(); steps.add(new MakeCleanDirectoryStep(proguardDirectory)); // Generate a file of ProGuard config options using aapt. String generatedProGuardConfig = proguardDirectory + "/proguard.txt"; GenProGuardConfigStep genProGuardConfig = new GenProGuardConfigStep(getAndroidManifestXml(), resDirectories, generatedProGuardConfig); steps.add(genProGuardConfig); // Create list of proguard Configs for the app project and its dependencies ImmutableSet.Builder<String> proguardConfigsBuilder = ImmutableSet.builder(); proguardConfigsBuilder.addAll(depsProguardConfigs); if (proguardConfig.isPresent()) { proguardConfigsBuilder.add(proguardConfig.get().resolve(context).toString()); } // Transform our input classpath to a set of output locations for each input classpath. // TODO(devjasta): the output path we choose is the result of a slicing function against // input classpath. This is fragile and should be replaced with knowledge of the BuildTarget. final ImmutableMap<String, String> inputOutputEntries = FluentIterable.from(classpathEntriesToDex) .toMap(new Function<String, String>() { @Override public String apply(String classpathEntry) { return getProguardOutputFromInputClasspath(classpathEntry).toString(); } }); // Run ProGuard on the classpath entries. // TODO: ProGuardObfuscateStep's final argument should be a Path Step obfuscateCommand = ProGuardObfuscateStep.create(generatedProGuardConfig, proguardConfigsBuilder.build(), useAndroidProguardConfigWithOptimizations, inputOutputEntries, additionalLibraryJarsForProguardBuilder.build(), proguardDirectory.toString()); steps.add(obfuscateCommand); // Apply the transformed inputs to the classpath (this will modify deps.classpathEntriesToDex // so that we're now dexing the proguarded artifacts). return ImmutableSet.copyOf(inputOutputEntries.values()); }