Search in sources :

Example 16 with ImmutableMultimap

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) ContentPack(org.graylog2.contentpacks.model.ContentPack) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) ModelId(org.graylog2.contentpacks.model.ModelId)

Example 17 with ImmutableMultimap

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;
}
Also used : BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) java.util(java.util) Blocks(net.minecraft.init.Blocks) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) World(net.minecraft.world.World) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) BlockPos(net.minecraft.util.math.BlockPos) Multimap(com.google.common.collect.Multimap) WeightedSelector(ivorius.ivtoolkit.random.WeightedSelector) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) IBlockState(net.minecraft.block.state.IBlockState) IvFunctions(ivorius.ivtoolkit.util.IvFunctions) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) WorldServer(net.minecraft.world.WorldServer) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) Nullable(javax.annotation.Nullable) SaplingGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.SaplingGeneration) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) SaplingGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.SaplingGeneration) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) Pair(org.apache.commons.lang3.tuple.Pair) Nullable(javax.annotation.Nullable)

Example 18 with ImmutableMultimap

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();
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) ErrorInfo(com.google.devtools.build.skyframe.ErrorInfo) ArrayList(java.util.ArrayList) ConfiguredTarget(com.google.devtools.build.lib.analysis.ConfiguredTarget) MergedConfiguredTarget(com.google.devtools.build.lib.analysis.MergedConfiguredTarget) Dependency(com.google.devtools.build.lib.analysis.Dependency) BuildConfiguration(com.google.devtools.build.lib.analysis.config.BuildConfiguration) SkyValue(com.google.devtools.build.skyframe.SkyValue) DuplicateException(com.google.devtools.build.lib.analysis.MergedConfiguredTarget.DuplicateException) AspectDescriptor(com.google.devtools.build.lib.packages.AspectDescriptor) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Example 19 with ImmutableMultimap

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();
}
Also used : Path(java.nio.file.Path) ClasspathTraversal(com.facebook.buck.jvm.java.classes.ClasspathTraversal) DefaultClasspathTraverser(com.facebook.buck.jvm.java.classes.DefaultClasspathTraverser) ClasspathTraverser(com.facebook.buck.jvm.java.classes.ClasspathTraverser) DefaultClasspathTraverser(com.facebook.buck.jvm.java.classes.DefaultClasspathTraverser) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) FileLike(com.facebook.buck.jvm.java.classes.FileLike)

Example 20 with ImmutableMultimap

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());
}
Also used : MkdirStep(com.facebook.buck.step.fs.MkdirStep) AbstractMap(java.util.AbstractMap) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SymlinkFilesIntoDirectoryStep(com.facebook.buck.shell.SymlinkFilesIntoDirectoryStep) AbstractGenruleStep(com.facebook.buck.shell.AbstractGenruleStep) ImmutableMap(com.google.common.collect.ImmutableMap) ExecutionContext(com.facebook.buck.step.ExecutionContext) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep)

Aggregations

ImmutableMultimap (com.google.common.collect.ImmutableMultimap)30 Path (java.nio.file.Path)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 ImmutableSet (com.google.common.collect.ImmutableSet)7 Map (java.util.Map)6 BuildTarget (com.facebook.buck.model.BuildTarget)4 ImmutableList (com.google.common.collect.ImmutableList)4 SourcePath (com.facebook.buck.rules.SourcePath)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 Multimap (com.google.common.collect.Multimap)3 IOException (java.io.IOException)3 List (java.util.List)3 ClasspathTraversal (com.facebook.buck.jvm.java.classes.ClasspathTraversal)2 ClasspathTraverser (com.facebook.buck.jvm.java.classes.ClasspathTraverser)2 DefaultClasspathTraverser (com.facebook.buck.jvm.java.classes.DefaultClasspathTraverser)2 FileLike (com.facebook.buck.jvm.java.classes.FileLike)2 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)2 Column (com.facebook.presto.hive.metastore.Column)2 ExtendedHiveMetastore (com.facebook.presto.hive.metastore.ExtendedHiveMetastore)2 HivePrivilegeInfo (com.facebook.presto.hive.metastore.HivePrivilegeInfo)2