Search in sources :

Example 11 with ImmutableSetMultimap

use of com.google.common.collect.ImmutableSetMultimap in project buck by facebook.

the class JavaSymbolFinder method findTargetsForSymbols.

/**
   * Figure out the build targets that provide a set of Java symbols.
   * @param symbols The set of symbols (e.g. "com.example.foo.Bar") to find defining targets for.
   *                This is taken as a collection, rather than as an individual string, because
   *                instantiating a ProjectBuildFileParser is expensive (it spawns a Python
   *                subprocess), and we don't want to encourage the caller to do it more than once.
   * @return A multimap of symbols to the targets that define them, of the form:
   *         {"com.example.a.A": set("//com/example/a:a", "//com/another/a:a")}
   */
public ImmutableSetMultimap<String, BuildTarget> findTargetsForSymbols(Set<String> symbols) throws InterruptedException, IOException {
    // TODO(oconnor663): Handle files that aren't included in any rule.
    // First find all the source roots in the current project.
    Collection<Path> srcRoots;
    try {
        srcRoots = srcRootsFinder.getAllSrcRootPaths(config.getView(JavaBuckConfig.class).getSrcRoots());
    } catch (IOException e) {
        buckEventBus.post(ThrowableConsoleEvent.create(e, "Error while searching for source roots."));
        return ImmutableSetMultimap.of();
    }
    // Now collect all the code files that define our symbols.
    Multimap<String, Path> symbolsToSourceFiles = HashMultimap.create();
    for (String symbol : symbols) {
        symbolsToSourceFiles.putAll(symbol, getDefiningPaths(symbol, srcRoots));
    }
    // Now find all the targets that define all those code files. We do this in one pass because we
    // don't want to instantiate a new parser subprocess for every symbol.
    Set<Path> allSourceFilePaths = ImmutableSet.copyOf(symbolsToSourceFiles.values());
    Multimap<Path, BuildTarget> sourceFilesToTargets = getTargetsForSourceFiles(allSourceFilePaths);
    // Now build the map from from symbols to build targets.
    ImmutableSetMultimap.Builder<String, BuildTarget> symbolsToTargets = ImmutableSetMultimap.builder();
    for (String symbol : symbolsToSourceFiles.keySet()) {
        for (Path sourceFile : symbolsToSourceFiles.get(symbol)) {
            symbolsToTargets.putAll(symbol, sourceFilesToTargets.get(sourceFile));
        }
    }
    return symbolsToTargets.build();
}
Also used : Path(java.nio.file.Path) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) BuildTarget(com.facebook.buck.model.BuildTarget) IOException(java.io.IOException)

Example 12 with ImmutableSetMultimap

use of com.google.common.collect.ImmutableSetMultimap in project buck by facebook.

the class MissingSymbolsHandler method getNeededDependencies.

/**
   * Using missing symbol events from the build and the JavaSymbolFinder class, build a list of
   * missing dependencies for each broken target.
   */
public ImmutableSetMultimap<BuildTarget, BuildTarget> getNeededDependencies(Collection<MissingSymbolEvent> missingSymbolEvents) throws InterruptedException, IOException {
    ImmutableSetMultimap.Builder<BuildTarget, String> targetsMissingSymbolsBuilder = ImmutableSetMultimap.builder();
    for (MissingSymbolEvent event : missingSymbolEvents) {
        if (event.getType() != MissingSymbolEvent.SymbolType.Java) {
            throw new UnsupportedOperationException("Only implemented for Java.");
        }
        targetsMissingSymbolsBuilder.put(event.getTarget(), event.getSymbol());
    }
    ImmutableSetMultimap<BuildTarget, String> targetsMissingSymbols = targetsMissingSymbolsBuilder.build();
    ImmutableSetMultimap<String, BuildTarget> symbolProviders = javaSymbolFinder.findTargetsForSymbols(ImmutableSet.copyOf(targetsMissingSymbols.values()));
    ImmutableSetMultimap.Builder<BuildTarget, BuildTarget> neededDeps = ImmutableSetMultimap.builder();
    for (BuildTarget target : targetsMissingSymbols.keySet()) {
        for (String symbol : targetsMissingSymbols.get(target)) {
            // TODO(oconnor663): Properly handle symbols that are defined in more than one place.
            // TODO(oconnor663): Properly handle target visibility.
            neededDeps.putAll(target, ImmutableSortedSet.copyOf(symbolProviders.get(symbol)));
        }
    }
    return neededDeps.build();
}
Also used : ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) BuildTarget(com.facebook.buck.model.BuildTarget) MissingSymbolEvent(com.facebook.buck.event.MissingSymbolEvent)

Example 13 with ImmutableSetMultimap

use of com.google.common.collect.ImmutableSetMultimap in project buck by facebook.

the class ProjectGenerator method getCopyFilesBuildPhases.

private ImmutableList<PBXBuildPhase> getCopyFilesBuildPhases(Iterable<TargetNode<?, ?>> copiedNodes) {
    // Bucket build rules into bins by their destinations
    ImmutableSetMultimap.Builder<CopyFilePhaseDestinationSpec, TargetNode<?, ?>> ruleByDestinationSpecBuilder = ImmutableSetMultimap.builder();
    for (TargetNode<?, ?> copiedNode : copiedNodes) {
        Optional<CopyFilePhaseDestinationSpec> optionalDestinationSpec = getDestinationSpec(copiedNode);
        if (optionalDestinationSpec.isPresent()) {
            ruleByDestinationSpecBuilder.put(optionalDestinationSpec.get(), copiedNode);
        }
    }
    ImmutableList.Builder<PBXBuildPhase> phases = ImmutableList.builder();
    ImmutableSetMultimap<CopyFilePhaseDestinationSpec, TargetNode<?, ?>> ruleByDestinationSpec = ruleByDestinationSpecBuilder.build();
    // Emit a copy files phase for each destination.
    for (CopyFilePhaseDestinationSpec destinationSpec : ruleByDestinationSpec.keySet()) {
        Iterable<TargetNode<?, ?>> targetNodes = ruleByDestinationSpec.get(destinationSpec);
        phases.add(getSingleCopyFilesBuildPhase(destinationSpec, targetNodes));
    }
    return phases.build();
}
Also used : CopyFilePhaseDestinationSpec(com.facebook.buck.apple.xcode.xcodeproj.CopyFilePhaseDestinationSpec) TargetNode(com.facebook.buck.rules.TargetNode) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) ImmutableList(com.google.common.collect.ImmutableList) PBXBuildPhase(com.facebook.buck.apple.xcode.xcodeproj.PBXBuildPhase)

Example 14 with ImmutableSetMultimap

use of com.google.common.collect.ImmutableSetMultimap in project SpongeForge by SpongePowered.

the class SpongeChunkTicketManager method getForcedChunks.

@Override
public ImmutableSetMultimap<Vector3i, LoadingTicket> getForcedChunks(World world) {
    ImmutableSetMultimap<ChunkPos, Ticket> forgeForcedChunks = ForgeChunkManager.getPersistentChunksFor((net.minecraft.world.World) world);
    ImmutableSetMultimap.Builder<Vector3i, LoadingTicket> spongeForcedChunks = ImmutableSetMultimap.builder();
    for (Map.Entry<ChunkPos, Ticket> ticketPair : forgeForcedChunks.entries()) {
        spongeForcedChunks.put(new Vector3i(ticketPair.getKey().x, 0, ticketPair.getKey().z), new SpongeLoadingTicket(ticketPair.getValue()));
    }
    return spongeForcedChunks.build();
}
Also used : MixinForgeChunkManager$Ticket(org.spongepowered.mod.mixin.core.forge.common.MixinForgeChunkManager$Ticket) Ticket(net.minecraftforge.common.ForgeChunkManager.Ticket) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) Vector3i(com.flowpowered.math.vector.Vector3i) ChunkPos(net.minecraft.util.math.ChunkPos) Map(java.util.Map)

Example 15 with ImmutableSetMultimap

use of com.google.common.collect.ImmutableSetMultimap in project auto by google.

the class BasicAnnotationProcessor method validElements.

/**
 * Returns the valid annotated elements contained in all of the deferred elements. If none are
 * found for a deferred element, defers it again.
 */
private ImmutableSetMultimap<TypeElement, Element> validElements(RoundEnvironment roundEnv) {
    ImmutableSet<ElementName> prevDeferredElementNames = ImmutableSet.copyOf(deferredElementNames);
    deferredElementNames.clear();
    ImmutableSetMultimap.Builder<TypeElement, Element> deferredElementsByAnnotationBuilder = ImmutableSetMultimap.builder();
    for (ElementName deferredElementName : prevDeferredElementNames) {
        Optional<? extends Element> deferredElement = deferredElementName.getElement(elements);
        if (deferredElement.isPresent()) {
            findAnnotatedElements(deferredElement.get(), getSupportedAnnotationTypeElements(), deferredElementsByAnnotationBuilder);
        } else {
            deferredElementNames.add(deferredElementName);
        }
    }
    ImmutableSetMultimap<TypeElement, Element> deferredElementsByAnnotation = deferredElementsByAnnotationBuilder.build();
    ImmutableSetMultimap.Builder<TypeElement, Element> validElements = ImmutableSetMultimap.builder();
    Set<ElementName> validElementNames = new LinkedHashSet<>();
    // Look at the elements we've found and the new elements from this round and validate them.
    for (TypeElement annotationType : getSupportedAnnotationTypeElements()) {
        Set<? extends Element> roundElements = roundEnv.getElementsAnnotatedWith(annotationType);
        ImmutableSet<Element> prevRoundElements = deferredElementsByAnnotation.get(annotationType);
        for (Element element : Sets.union(roundElements, prevRoundElements)) {
            ElementName elementName = ElementName.forAnnotatedElement(element);
            boolean isValidElement = validElementNames.contains(elementName) || (!deferredElementNames.contains(elementName) && validateElement(element.getKind().equals(PACKAGE) ? element : getEnclosingType(element)));
            if (isValidElement) {
                validElements.put(annotationType, element);
                validElementNames.add(elementName);
            } else {
                deferredElementNames.add(elementName);
            }
        }
    }
    return validElements.build();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) TypeElement(javax.lang.model.element.TypeElement) PackageElement(javax.lang.model.element.PackageElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) SuperficialValidation.validateElement(com.google.auto.common.SuperficialValidation.validateElement)

Aggregations

ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)15 BuildTarget (com.facebook.buck.model.BuildTarget)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 IOException (java.io.IOException)3 Set (java.util.Set)3 Element (javax.lang.model.element.Element)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 TypeElement (javax.lang.model.element.TypeElement)3 TargetNode (com.facebook.buck.rules.TargetNode)2 Path (java.nio.file.Path)2 HashSet (java.util.HashSet)2 Binding (org.openrdf.query.Binding)2 BindingSet (org.openrdf.query.BindingSet)2 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)2 FatalException (org.wikidata.query.rdf.tool.exception.FatalException)2 Options (com.b2international.commons.options.Options)1 Expression (com.b2international.index.query.Expression)1 Expressions (com.b2international.index.query.Expressions)1 Query (com.b2international.index.query.Query)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1