use of com.google.common.collect.ImmutableMultimap in project graylog2-server by Graylog2.
the class ContentPackPersistenceService method loadAllLatest.
public Set<ContentPack> loadAllLatest() {
final Set<ContentPack> allContentPacks = loadAll();
final ImmutableMultimap.Builder<ModelId, ContentPack> byIdBuilder = ImmutableMultimap.builder();
for (ContentPack contentPack : allContentPacks) {
byIdBuilder.put(contentPack.id(), contentPack);
}
final ImmutableMultimap<ModelId, ContentPack> contentPacksById = byIdBuilder.build();
final ImmutableSet.Builder<ContentPack> latestContentPacks = ImmutableSet.builderWithExpectedSize(contentPacksById.keySet().size());
for (ModelId id : contentPacksById.keySet()) {
final ImmutableCollection<ContentPack> contentPacks = contentPacksById.get(id);
final ContentPack latestContentPackRevision = Collections.max(contentPacks, Comparator.comparingInt(Revisioned::revision));
latestContentPacks.add(latestContentPackRevision);
}
return latestContentPacks.build();
}
use of com.google.common.collect.ImmutableMultimap in project RecurrentComplex by Ivorforce.
the class RCSaplingGenerator method findRandomSapling.
@Nullable
public static Pair<Structure<?>, SaplingGeneration> findRandomSapling(WorldServer world, BlockPos pos, Random random, boolean considerVanilla) {
Environment baseEnv = Environment.inNature(world, new StructureBoundingBox(pos, pos));
List<Pair<Structure<?>, SaplingGeneration>> applicable = StructureRegistry.INSTANCE.getGenerationTypes(SaplingGeneration.class).stream().filter(pair1 -> pair1.getRight().generatesIn(baseEnv.withGeneration(pair1.getRight()))).collect(Collectors.toCollection(ArrayList::new));
// Hackily consider big vanilla trees too
int vanillaComplexity = complexity(world, pos, random, predictors);
ImmutableMultimap<Integer, Pair<Structure<?>, SaplingGeneration>> groups = IvFunctions.groupMap(applicable, pair -> pair.getRight().pattern.pattern.compile(true).size());
List<Integer> complexities = Lists.newArrayList(groups.keySet());
if (vanillaComplexity > 0)
complexities.add(vanillaComplexity);
Collections.sort(complexities);
Pair<Structure<?>, SaplingGeneration> pair = null;
while (complexities.size() > 0 && pair == null) {
Integer complexity = complexities.remove(complexities.size() - 1);
Set<Pair<Structure<?>, SaplingGeneration>> placeable = groups.get(complexity).stream().filter(p -> p.getRight().pattern.canPlace(world, pos, p.getLeft().size(), p.getLeft().isRotatable(), p.getLeft().isMirrorable())).collect(Collectors.toSet());
double totalWeight = placeable.stream().mapToDouble(RCSaplingGenerator::getSpawnWeight).sum();
if (complexity == vanillaComplexity && considerVanilla) {
if (random.nextDouble() * (totalWeight * RCConfig.baseSaplingSpawnWeight + 1) < 1)
break;
}
if (totalWeight > 0)
pair = WeightedSelector.select(random, placeable, RCSaplingGenerator::getSpawnWeight);
}
return pair;
}
use of com.google.common.collect.ImmutableMultimap in project bazel by bazelbuild.
the class SkyframeExecutor method getConfiguredTargetMap.
/**
* Returns a map from {@link Dependency} inputs to the {@link ConfiguredTarget}s corresponding to
* those dependencies.
*
* <p>For use for legacy support and tests calling through {@code BuildView} only.
*
* <p>If a requested configured target is in error, the corresponding value is omitted from the
* returned list.
*/
@ThreadSafety.ThreadSafe
public ImmutableMultimap<Dependency, ConfiguredTarget> getConfiguredTargetMap(ExtendedEventHandler eventHandler, BuildConfiguration originalConfig, Iterable<Dependency> keys, boolean useOriginalConfig) {
checkActive();
Multimap<Dependency, BuildConfiguration> configs;
if (originalConfig != null) {
if (useOriginalConfig) {
// This flag is used because of some unfortunate complexity in the configuration machinery:
// Most callers of this method pass a <Label, Configuration> pair to directly create a
// ConfiguredTarget from, but happen to use the Dependency data structure to pass that
// info (even though the data has nothing to do with dependencies). If this configuration
// includes a split transition, a dynamic configuration created from it will *not*
// include that transition (because dynamic configurations don't embed transitions to
// other configurations. In that case, we need to preserve the original configuration.
// TODO(bazel-team); make this unnecessary once split transition logic is properly ported
// out of configurations.
configs = ArrayListMultimap.<Dependency, BuildConfiguration>create();
configs.put(Iterables.getOnlyElement(keys), originalConfig);
} else {
configs = getConfigurations(eventHandler, originalConfig.getOptions(), keys);
}
} else {
configs = ArrayListMultimap.<Dependency, BuildConfiguration>create();
for (Dependency key : keys) {
configs.put(key, null);
}
}
final List<SkyKey> skyKeys = new ArrayList<>();
for (Dependency key : keys) {
if (!configs.containsKey(key)) {
// it couldn't be loaded). Exclude it from the results.
continue;
}
for (BuildConfiguration depConfig : configs.get(key)) {
skyKeys.add(ConfiguredTargetValue.key(key.getLabel(), depConfig));
for (AspectDescriptor aspectDescriptor : key.getAspects().getAllAspects()) {
skyKeys.add(ActionLookupValue.key(AspectValue.createAspectKey(key.getLabel(), depConfig, aspectDescriptor, depConfig)));
}
}
}
EvaluationResult<SkyValue> result = evaluateSkyKeys(eventHandler, skyKeys);
for (Map.Entry<SkyKey, ErrorInfo> entry : result.errorMap().entrySet()) {
reportCycles(eventHandler, entry.getValue().getCycleInfo(), entry.getKey());
}
ImmutableMultimap.Builder<Dependency, ConfiguredTarget> cts = ImmutableMultimap.<Dependency, ConfiguredTarget>builder();
DependentNodeLoop: for (Dependency key : keys) {
if (!configs.containsKey(key)) {
// it couldn't be loaded). Exclude it from the results.
continue;
}
for (BuildConfiguration depConfig : configs.get(key)) {
SkyKey configuredTargetKey = ConfiguredTargetValue.key(key.getLabel(), depConfig);
if (result.get(configuredTargetKey) == null) {
continue;
}
ConfiguredTarget configuredTarget = ((ConfiguredTargetValue) result.get(configuredTargetKey)).getConfiguredTarget();
List<ConfiguredAspect> configuredAspects = new ArrayList<>();
for (AspectDescriptor aspectDescriptor : key.getAspects().getAllAspects()) {
SkyKey aspectKey = ActionLookupValue.key(AspectValue.createAspectKey(key.getLabel(), depConfig, aspectDescriptor, depConfig));
if (result.get(aspectKey) == null) {
continue DependentNodeLoop;
}
configuredAspects.add(((AspectValue) result.get(aspectKey)).getConfiguredAspect());
}
try {
cts.put(key, MergedConfiguredTarget.of(configuredTarget, configuredAspects));
} catch (DuplicateException e) {
throw new IllegalStateException(String.format("Error creating %s", configuredTarget.getTarget().getLabel()), e);
}
}
}
return cts.build();
}
use of com.google.common.collect.ImmutableMultimap in project buck by facebook.
the class APKModuleGraph method getAPKModuleToClassesMap.
/**
* Group the classes in the input jars into a multimap based on the APKModule they belong to
*
* @param apkModuleToJarPathMap the mapping of APKModules to the path for the jar files
* @param translatorFunction function used to translate obfuscated names
* @param filesystem filesystem representation for resolving paths
* @return The mapping of APKModules to the class names they contain
* @throws IOException
*/
public static ImmutableMultimap<APKModule, String> getAPKModuleToClassesMap(final ImmutableMultimap<APKModule, Path> apkModuleToJarPathMap, final Function<String, String> translatorFunction, final ProjectFilesystem filesystem) throws IOException {
final ImmutableMultimap.Builder<APKModule, String> builder = ImmutableMultimap.builder();
if (!apkModuleToJarPathMap.isEmpty()) {
for (final APKModule dexStore : apkModuleToJarPathMap.keySet()) {
for (Path jarFilePath : apkModuleToJarPathMap.get(dexStore)) {
ClasspathTraverser classpathTraverser = new DefaultClasspathTraverser();
classpathTraverser.traverse(new ClasspathTraversal(ImmutableSet.of(jarFilePath), filesystem) {
@Override
public void visit(FileLike entry) {
if (!entry.getRelativePath().endsWith(".class")) {
// ignore everything but class files in the jar.
return;
}
builder.put(dexStore, translatorFunction.apply(entry.getRelativePath()));
}
});
}
}
}
return builder.build();
}
use of com.google.common.collect.ImmutableMultimap in project buck by facebook.
the class AndroidBinary method addFinalDxSteps.
/**
* Adds steps to do the final dexing or dex merging before building the apk.
*/
private DexFilesInfo addFinalDxSteps(BuildableContext buildableContext, SourcePathResolver resolver, ImmutableList.Builder<Step> steps) {
AndroidPackageableCollection packageableCollection = enhancementResult.getPackageableCollection();
ImmutableSet<Path> classpathEntriesToDex = Stream.concat(enhancementResult.getClasspathEntriesToDex().stream(), RichStream.of(enhancementResult.getCompiledUberRDotJava().getSourcePathToOutput())).map(resolver::getRelativePath).collect(MoreCollectors.toImmutableSet());
ImmutableMultimap.Builder<APKModule, Path> additionalDexStoreToJarPathMapBuilder = ImmutableMultimap.builder();
additionalDexStoreToJarPathMapBuilder.putAll(enhancementResult.getPackageableCollection().getModuleMappedClasspathEntriesToDex().entries().stream().map(input -> new AbstractMap.SimpleEntry<>(input.getKey(), resolver.getRelativePath(input.getValue()))).collect(MoreCollectors.toImmutableSet()));
ImmutableMultimap<APKModule, Path> additionalDexStoreToJarPathMap = additionalDexStoreToJarPathMapBuilder.build();
// Execute preprocess_java_classes_binary, if appropriate.
if (preprocessJavaClassesBash.isPresent()) {
// Symlink everything in dexTransitiveDependencies.classpathEntriesToDex to the input
// directory. Expect parallel outputs in the output directory and update classpathEntriesToDex
// to reflect that.
final Path preprocessJavaClassesInDir = getBinPath("java_classes_preprocess_in_%s");
final Path preprocessJavaClassesOutDir = getBinPath("java_classes_preprocess_out_%s");
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), preprocessJavaClassesInDir));
steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), preprocessJavaClassesOutDir));
steps.add(new SymlinkFilesIntoDirectoryStep(getProjectFilesystem(), getProjectFilesystem().getRootPath(), classpathEntriesToDex, preprocessJavaClassesInDir));
classpathEntriesToDex = classpathEntriesToDex.stream().map(preprocessJavaClassesOutDir::resolve).collect(MoreCollectors.toImmutableSet());
AbstractGenruleStep.CommandString commandString = new AbstractGenruleStep.CommandString(/* cmd */
Optional.empty(), /* bash */
preprocessJavaClassesBash.map(macroExpander::apply), /* cmdExe */
Optional.empty());
steps.add(new AbstractGenruleStep(getProjectFilesystem(), this.getBuildTarget(), commandString, getProjectFilesystem().getRootPath().resolve(preprocessJavaClassesInDir)) {
@Override
protected void addEnvironmentVariables(ExecutionContext context, ImmutableMap.Builder<String, String> environmentVariablesBuilder) {
environmentVariablesBuilder.put("IN_JARS_DIR", getProjectFilesystem().resolve(preprocessJavaClassesInDir).toString());
environmentVariablesBuilder.put("OUT_JARS_DIR", getProjectFilesystem().resolve(preprocessJavaClassesOutDir).toString());
AndroidPlatformTarget platformTarget = context.getAndroidPlatformTarget();
String bootclasspath = Joiner.on(':').join(Iterables.transform(platformTarget.getBootclasspathEntries(), getProjectFilesystem()::resolve));
environmentVariablesBuilder.put("ANDROID_BOOTCLASSPATH", bootclasspath);
}
});
}
// Execute proguard if desired (transforms input classpaths).
if (packageType.isBuildWithObfuscation()) {
classpathEntriesToDex = addProguardCommands(classpathEntriesToDex, packageableCollection.getProguardConfigs().stream().map(resolver::getAbsolutePath).collect(MoreCollectors.toImmutableSet()), skipProguard, steps, buildableContext, resolver);
}
Supplier<ImmutableMap<String, HashCode>> classNamesToHashesSupplier;
boolean classFilesHaveChanged = preprocessJavaClassesBash.isPresent() || packageType.isBuildWithObfuscation();
if (classFilesHaveChanged) {
classNamesToHashesSupplier = addAccumulateClassNamesStep(classpathEntriesToDex, steps);
} else {
classNamesToHashesSupplier = packageableCollection.getClassNamesToHashesSupplier();
}
// Create the final DEX (or set of DEX files in the case of split dex).
// The APK building command needs to take a directory of raw files, so primaryDexPath
// can only contain .dex files from this build rule.
// Create dex artifacts. If split-dex is used, the assets/ directory should contain entries
// that look something like the following:
//
// assets/secondary-program-dex-jars/metadata.txt
// assets/secondary-program-dex-jars/secondary-1.dex.jar
// assets/secondary-program-dex-jars/secondary-2.dex.jar
// assets/secondary-program-dex-jars/secondary-3.dex.jar
//
// The contents of the metadata.txt file should look like:
// secondary-1.dex.jar fffe66877038db3af2cbd0fe2d9231ed5912e317 secondary.dex01.Canary
// secondary-2.dex.jar b218a3ea56c530fed6501d9f9ed918d1210cc658 secondary.dex02.Canary
// secondary-3.dex.jar 40f11878a8f7a278a3f12401c643da0d4a135e1a secondary.dex03.Canary
//
// The scratch directories that contain the metadata.txt and secondary-N.dex.jar files must be
// listed in secondaryDexDirectoriesBuilder so that their contents will be compressed
// appropriately for Froyo.
ImmutableSet.Builder<Path> secondaryDexDirectoriesBuilder = ImmutableSet.builder();
Optional<PreDexMerge> preDexMerge = enhancementResult.getPreDexMerge();
if (!preDexMerge.isPresent()) {
steps.add(new MkdirStep(getProjectFilesystem(), primaryDexPath.getParent()));
addDexingSteps(classpathEntriesToDex, classNamesToHashesSupplier, secondaryDexDirectoriesBuilder, steps, primaryDexPath, dexReorderToolFile, dexReorderDataDumpFile, additionalDexStoreToJarPathMap, resolver);
} else if (!ExopackageMode.enabledForSecondaryDexes(exopackageModes)) {
secondaryDexDirectoriesBuilder.addAll(preDexMerge.get().getSecondaryDexDirectories());
}
return new DexFilesInfo(primaryDexPath, secondaryDexDirectoriesBuilder.build());
}
Aggregations