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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations