Example usage for com.google.common.collect ImmutableMultimap builder

List of usage examples for com.google.common.collect ImmutableMultimap builder

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMultimap builder.

Prototype

public static <K, V> Builder<K, V> builder() 

Source Link

Document

Returns a new builder.

Usage

From source file:com.facebook.buck.apple.ProjectGenerator.java

public ProjectGenerator(TargetGraph targetGraph, Set<BuildTarget> initialTargets,
        ProjectFilesystem projectFilesystem, Path outputDirectory, String projectName, String buildFileName,
        Set<Option> options, Optional<BuildTarget> targetToBuildWithBuck,
        ImmutableList<String> buildWithBuckFlags, ExecutableFinder executableFinder,
        ImmutableMap<String, String> environment, FlavorDomain<CxxPlatform> cxxPlatforms,
        CxxPlatform defaultCxxPlatform,/*w w w  .ja  v  a2  s.c o m*/
        Function<? super TargetNode<?>, SourcePathResolver> sourcePathResolverForNode,
        BuckEventBus buckEventBus, boolean attemptToDetermineBestCxxPlatform, HalideBuckConfig halideBuckConfig,
        CxxBuckConfig cxxBuckConfig) {
    this.sourcePathResolver = new Function<SourcePath, Path>() {
        @Override
        public Path apply(SourcePath input) {
            return resolveSourcePath(input);
        }
    };

    this.targetGraph = targetGraph;
    this.initialTargets = ImmutableSet.copyOf(initialTargets);
    this.projectFilesystem = projectFilesystem;
    this.outputDirectory = outputDirectory;
    this.projectName = projectName;
    this.buildFileName = buildFileName;
    this.options = ImmutableSet.copyOf(options);
    this.targetToBuildWithBuck = targetToBuildWithBuck;
    this.buildWithBuckFlags = buildWithBuckFlags;
    this.executableFinder = executableFinder;
    this.environment = environment;
    this.cxxPlatforms = cxxPlatforms;
    this.defaultCxxPlatform = defaultCxxPlatform;
    this.sourcePathResolverForNode = sourcePathResolverForNode;
    this.buckEventBus = buckEventBus;
    this.attemptToDetermineBestCxxPlatform = attemptToDetermineBestCxxPlatform;

    this.projectPath = outputDirectory.resolve(projectName + ".xcodeproj");
    this.pathRelativizer = new PathRelativizer(outputDirectory, sourcePathResolver);

    LOG.debug("Output directory %s, profile fs root path %s, repo root relative to output dir %s",
            this.outputDirectory, projectFilesystem.getRootPath(),
            this.pathRelativizer.outputDirToRootRelative(Paths.get(".")));

    this.project = new PBXProject(projectName);
    this.headerSymlinkTrees = new ArrayList<>();

    this.targetNodeToGeneratedProjectTargetBuilder = ImmutableMultimap.builder();
    this.targetNodeToProjectTarget = CacheBuilder.newBuilder()
            .build(new CacheLoader<TargetNode<?>, Optional<PBXTarget>>() {
                @Override
                public Optional<PBXTarget> load(TargetNode<?> key) throws Exception {
                    return generateProjectTarget(key);
                }
            });

    targetConfigNamesBuilder = ImmutableSet.builder();
    gidsToTargetNames = new HashMap<>();
    this.halideBuckConfig = halideBuckConfig;
    this.cxxBuckConfig = cxxBuckConfig;
}

From source file:com.google.devtools.build.lib.rules.cpp.FdoSupport.java

/**
 * Recursively extracts a directory from the GCDA ZIP file into a target
 * directory./*ww  w . j  a  v  a2  s.com*/
 *
 * <p>Imports files are not written to disk. Their content is directly added
 * to an internal data structure.
 *
 * <p>The files are written at $EXECROOT/blaze-fdo/_fdo/(base name of profile zip), and the
 * {@code _fdo} directory there is symlinked to from the exec root, so that the file are also
 * available at $EXECROOT/_fdo/..., which is their exec path. We need to jump through these
 * hoops because the FDO root 1. needs to be a source root, thus the exec path of its root is
 * ".", 2. it must not be equal to the exec root so that the artifact factory does not get
 * confused, 3. the files under it must be reachable by their exec path from the exec root.
 *
 * @throws IOException if any of the I/O operations failed
 * @throws FdoException if the FDO ZIP contains a file of unknown type
 */
private static void extractFdoZipDirectory(Path sourceDir, Path targetDir,
        ImmutableSet.Builder<PathFragment> gcdaFilesBuilder,
        ImmutableMultimap.Builder<PathFragment, PathFragment> importsBuilder) throws IOException, FdoException {
    for (Path sourceFile : sourceDir.getDirectoryEntries()) {
        Path targetFile = targetDir.getRelative(sourceFile.getBaseName());
        if (sourceFile.isDirectory()) {
            targetFile.createDirectory();
            extractFdoZipDirectory(sourceFile, targetFile, gcdaFilesBuilder, importsBuilder);
        } else {
            if (CppFileTypes.COVERAGE_DATA.matches(sourceFile)) {
                FileSystemUtils.copyFile(sourceFile, targetFile);
                gcdaFilesBuilder.add(sourceFile.relativeTo(sourceFile.getFileSystem().getRootDirectory()));
            } else if (CppFileTypes.COVERAGE_DATA_IMPORTS.matches(sourceFile)) {
                readCoverageImports(sourceFile, importsBuilder);
            } else {
                throw new FdoException("FDO ZIP file contained a file of unknown type: " + sourceFile);
            }
        }
    }
}

From source file:com.facebook.buck.android.SplitZipStep.java

public Supplier<Multimap<Path, Path>> getOutputToInputsMapSupplier(final Path secondaryOutputDir) {
    return new Supplier<Multimap<Path, Path>>() {
        @Override//  w ww .  ja  v  a  2  s.com
        public Multimap<Path, Path> get() {
            Preconditions.checkState(stepFinished,
                    "SplitZipStep must complete successfully before listing its outputs.");
            ImmutableMultimap.Builder<Path, Path> builder = ImmutableMultimap.builder();
            for (File inputFile : secondaryJarDir.toFile().listFiles()) {
                Path outputDexPath = secondaryOutputDir
                        .resolve(transformInputToDexOutput(inputFile, dexSplitMode.getDexStore()));
                builder.put(outputDexPath, Paths.get(inputFile.getPath()));
            }
            return builder.build();
        }
    };
}

From source file:io.prestosql.execution.SqlStageExecution.java

private synchronized RemoteTask scheduleTask(Node node, TaskId taskId, Multimap<PlanNodeId, Split> sourceSplits,
        OptionalInt totalPartitions) {
    checkArgument(!allTasks.contains(taskId), "A task with id %s already exists", taskId);

    ImmutableMultimap.Builder<PlanNodeId, Split> initialSplits = ImmutableMultimap.builder();
    initialSplits.putAll(sourceSplits);//from w  w  w . j  a  v  a  2s .  c o  m

    sourceTasks.forEach((planNodeId, task) -> {
        TaskStatus status = task.getTaskStatus();
        if (status.getState() != TaskState.FINISHED) {
            initialSplits.put(planNodeId, createRemoteSplitFor(taskId, status.getSelf()));
        }
    });

    OutputBuffers outputBuffers = this.outputBuffers.get();
    checkState(outputBuffers != null, "Initial output buffers must be set before a task can be scheduled");

    RemoteTask task = remoteTaskFactory.createRemoteTask(stateMachine.getSession(), taskId, node,
            stateMachine.getFragment(), initialSplits.build(), totalPartitions, outputBuffers,
            nodeTaskMap.createPartitionedSplitCountTracker(node, taskId), summarizeTaskInfo);

    completeSources.forEach(task::noMoreSplits);

    allTasks.add(taskId);
    tasks.computeIfAbsent(node, key -> newConcurrentHashSet()).add(task);
    nodeTaskMap.addTask(node, task);

    task.addStateChangeListener(new StageTaskListener());
    task.addFinalTaskInfoListener(this::updateFinalTaskInfo);

    if (!stateMachine.getState().isDone()) {
        task.start();
    } else {
        // stage finished while we were scheduling this task
        task.abort();
    }

    return task;
}

From source file:com.google.devtools.build.lib.rules.cpp.FdoSupport.java

/**
 * Reads a .gcda.imports file and stores the imports information.
 *
 * @throws FdoException if an auxiliary LIPO input was not found
 *///from  w  w  w  . j  ava2 s  .  c om
private static void readCoverageImports(Path importsFile,
        ImmutableMultimap.Builder<PathFragment, PathFragment> importsBuilder) throws IOException, FdoException {
    PathFragment key = importsFile.asFragment().relativeTo(ZIP_ROOT);
    String baseName = key.getBaseName();
    String ext = Iterables.getOnlyElement(CppFileTypes.COVERAGE_DATA_IMPORTS.getExtensions());
    key = key.replaceName(baseName.substring(0, baseName.length() - ext.length()));

    for (String line : FileSystemUtils.iterateLinesAsLatin1(importsFile)) {
        if (!line.isEmpty()) {
            // We can't yet fully check the validity of a line. this is done later
            // when we actually parse the contained paths.
            PathFragment execPath = new PathFragment(line);
            if (execPath.isAbsolute()) {
                throw new FdoException(
                        "Absolute paths not allowed in gcda imports file " + importsFile + ": " + execPath);
            }
            importsBuilder.put(key, new PathFragment(line));
        }
    }
}

From source file:com.facebook.buck.apple.project_generator.ProjectGenerator.java

public ProjectGenerator(TargetGraph targetGraph, AppleDependenciesCache dependenciesCache,
        Set<BuildTarget> initialTargets, Cell cell, Path outputDirectory, String projectName,
        String buildFileName, Set<Option> options, Optional<BuildTarget> targetToBuildWithBuck,
        ImmutableList<String> buildWithBuckFlags, ImmutableSet<UnflavoredBuildTarget> focusModules,
        ExecutableFinder executableFinder, ImmutableMap<String, String> environment,
        FlavorDomain<CxxPlatform> cxxPlatforms, CxxPlatform defaultCxxPlatform,
        Function<? super TargetNode<?, ?>, SourcePathResolver> sourcePathResolverForNode,
        BuckEventBus buckEventBus, HalideBuckConfig halideBuckConfig, CxxBuckConfig cxxBuckConfig,
        AppleConfig appleConfig, SwiftBuckConfig swiftBuckConfig) {
    this.sourcePathResolver = this::resolveSourcePath;

    this.targetGraph = targetGraph;
    this.dependenciesCache = dependenciesCache;
    this.initialTargets = ImmutableSet.copyOf(initialTargets);
    this.projectCell = cell;
    this.projectFilesystem = cell.getFilesystem();
    this.outputDirectory = outputDirectory;
    this.projectName = projectName;
    this.buildFileName = buildFileName;
    this.options = ImmutableSet.copyOf(options);
    this.targetToBuildWithBuck = targetToBuildWithBuck;
    this.buildWithBuckFlags = buildWithBuckFlags;
    this.executableFinder = executableFinder;
    this.environment = environment;
    this.cxxPlatforms = cxxPlatforms;
    this.defaultCxxPlatform = defaultCxxPlatform;
    this.sourcePathResolverForNode = sourcePathResolverForNode;
    this.buckEventBus = buckEventBus;

    this.projectPath = outputDirectory.resolve(projectName + ".xcodeproj");
    this.pathRelativizer = new PathRelativizer(outputDirectory, sourcePathResolver);

    LOG.debug("Output directory %s, profile fs root path %s, repo root relative to output dir %s",
            this.outputDirectory, projectFilesystem.getRootPath(),
            this.pathRelativizer.outputDirToRootRelative(Paths.get(".")));

    this.project = new PBXProject(projectName);
    this.headerSymlinkTrees = new ArrayList<>();

    this.targetNodeToGeneratedProjectTargetBuilder = ImmutableMultimap.builder();
    this.targetNodeToProjectTarget = CacheBuilder.newBuilder()
            .build(new CacheLoader<TargetNode<?, ?>, Optional<PBXTarget>>() {
                @Override/*from ww w .  ja  va 2s.co  m*/
                public Optional<PBXTarget> load(TargetNode<?, ?> key) throws Exception {
                    return generateProjectTarget(key);
                }
            });

    targetConfigNamesBuilder = ImmutableSet.builder();
    gidsToTargetNames = new HashMap<>();
    this.halideBuckConfig = halideBuckConfig;
    this.cxxBuckConfig = cxxBuckConfig;
    this.appleConfig = appleConfig;
    this.swiftBuckConfig = swiftBuckConfig;
    this.focusModules = focusModules;
}

From source file:com.sun.tools.hat.internal.server.QueryHandler.java

/**
 * Prints out breadcrumbs for accessing previous elements in the
 * referrer chain.// w  ww .j a  v a2 s. co  m
 *
 * <p>For queries that support referrer chains, there is a primary
 * class that the query works on, followed by a referrer chain that
 * further filters instances. The primary class is specified as
 * {@code clazz}.
 *
 * <p>The referrer chain is always written with parameter name
 * {@code referrer}, so the query handler should use that name to get
 * the referrer chain. Additionally, if the primary class is omitted,
 * then the referrer chain is irrelevant and will not be printed.
 *
 * @param path the static portion of the link target (see {@link #formatLink})
 * @param pathInfo the non-static portion of the link target
 *                 (see {@link #formatLink}); ignored if {@code name}
 *                 is omitted
 * @param name the parameter name for referring to the primary class;
 *             if omitted, place the class reference in {@code pathInfo}
 * @param clazz the primary class in use
 * @param referrers the referrer chain in use
 * @param params any further parameters to be prepended
 */
protected void printBreadcrumbs(String path, String pathInfo, String name, JavaClass clazz,
        Iterable<JavaClass> referrers, Multimap<String, String> params) {
    ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();
    if (params != null) {
        builder.putAll(params);
    }
    if (clazz != null) {
        out.print("<p align='center'>");
        if (name != null) {
            builder.put(name, clazz.getIdString());
        } else {
            pathInfo = clazz.getIdString();
        }
        out.print(formatLink(path, pathInfo, clazz.getName(), builder.build()));
        for (JavaClass referrer : referrers) {
            out.print(" &rarr; ");
            builder.put("referrer", referrer.getIdString());
            out.print(formatLink(path, pathInfo, referrer.getName(), builder.build()));
        }
        out.println("</p>");
    }
}

From source file:com.facebook.buck.apple.project_generator.WorkspaceAndProjectGenerator.java

private void processGenerationResult(
        ImmutableMultimap.Builder<BuildTarget, PBXTarget> buildTargetToPbxTargetMapBuilder,
        ImmutableMap.Builder<PBXTarget, Path> targetToProjectPathMapBuilder, GenerationResult result) {
    requiredBuildTargetsBuilder.addAll(result.getRequiredBuildTargets());
    buildTargetToPbxTargetMapBuilder.putAll(result.getBuildTargetToGeneratedTargetMap());
    for (PBXTarget target : result.getBuildTargetToGeneratedTargetMap().values()) {
        targetToProjectPathMapBuilder.put(target, result.getProjectPath());
    }//from   w ww  .j a v  a  2s.com
}

From source file:com.facebook.buck.apple.ProjectGenerator.java

public ImmutableMultimap<BuildTarget, PBXTarget> getBuildTargetToGeneratedTargetMap() {
    Preconditions.checkState(projectGenerated, "Must have called createXcodeProjects");
    ImmutableMultimap.Builder<BuildTarget, PBXTarget> buildTargetToPbxTargetMap = ImmutableMultimap.builder();
    for (Map.Entry<TargetNode<?>, PBXTarget> entry : targetNodeToGeneratedProjectTargetBuilder.build()
            .entries()) {//from  ww  w .j  a  v a2s .  c  om
        buildTargetToPbxTargetMap.put(entry.getKey().getBuildTarget(), entry.getValue());
    }
    return buildTargetToPbxTargetMap.build();
}

From source file:com.google.devtools.build.lib.rules.cpp.FdoSupport.java

/**
 * Reads a .afdo.imports file and stores the imports information.
 *///from  w w  w  .j  a  v  a  2s  . c  om
private static ImmutableMultimap<PathFragment, PathFragment> readAutoFdoImports(Path importsFile)
        throws IOException, FdoException {
    ImmutableMultimap.Builder<PathFragment, PathFragment> importBuilder = ImmutableMultimap.builder();
    for (String line : FileSystemUtils.iterateLinesAsLatin1(importsFile)) {
        if (!line.isEmpty()) {
            PathFragment key = new PathFragment(line.substring(0, line.indexOf(':')));
            if (key.isAbsolute()) {
                throw new FdoException(
                        "Absolute paths not allowed in afdo imports file " + importsFile + ": " + key);
            }
            for (String auxFile : line.substring(line.indexOf(':') + 1).split(" ")) {
                if (auxFile.length() == 0) {
                    continue;
                }

                importBuilder.put(key, new PathFragment(auxFile));
            }
        }
    }
    return importBuilder.build();
}