use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class PackageManifestReader method readPackageManifestFiles.
/**
* @return A map from java source absolute file path to declared package string.
*/
public Map<TargetKey, Map<ArtifactLocation, String>> readPackageManifestFiles(Project project, BlazeContext context, ArtifactLocationDecoder decoder, Map<TargetKey, ArtifactLocation> javaPackageManifests, ListeningExecutorService executorService) {
Map<File, TargetKey> fileToLabelMap = Maps.newHashMap();
for (Map.Entry<TargetKey, ArtifactLocation> entry : javaPackageManifests.entrySet()) {
TargetKey key = entry.getKey();
File file = decoder.decode(entry.getValue());
fileToLabelMap.put(file, key);
}
List<File> updatedFiles = Lists.newArrayList();
List<File> removedFiles = Lists.newArrayList();
fileDiffState = FileDiffer.updateFiles(fileDiffState, fileToLabelMap.keySet(), updatedFiles, removedFiles);
ListenableFuture<?> fetchFuture = PrefetchService.getInstance().prefetchFiles(project, updatedFiles, true, false);
if (!FutureUtil.waitForFuture(context, fetchFuture).timed("FetchPackageManifests", EventType.Prefetching).withProgressMessage("Reading package manifests...").run().success()) {
return null;
}
List<ListenableFuture<Void>> futures = Lists.newArrayList();
for (File file : updatedFiles) {
futures.add(executorService.submit(() -> {
Map<ArtifactLocation, String> manifest = parseManifestFile(file);
manifestMap.put(fileToLabelMap.get(file), manifest);
return null;
}));
}
for (File file : removedFiles) {
TargetKey key = this.fileToLabelMap.get(file);
if (key != null) {
manifestMap.remove(key);
}
}
this.fileToLabelMap = fileToLabelMap;
try {
Futures.allAsList(futures).get();
} catch (ExecutionException | InterruptedException e) {
logger.error(e);
throw new IllegalStateException("Could not read sources");
}
return manifestMap;
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class SourceDirectoryCalculator method calculateContentEntries.
public ImmutableList<BlazeContentEntry> calculateContentEntries(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ArtifactLocationDecoder artifactLocationDecoder, ImportRoots importRoots, Collection<SourceArtifact> sources, Map<TargetKey, ArtifactLocation> javaPackageManifests) {
ManifestFilePackageReader manifestFilePackageReader = Scope.push(context, (childContext) -> {
childContext.push(new TimingScope("ReadPackageManifests", EventType.Other));
Map<TargetKey, Map<ArtifactLocation, String>> manifestMap = PackageManifestReader.getInstance().readPackageManifestFiles(project, childContext, artifactLocationDecoder, javaPackageManifests, packageReaderExecutorService);
return new ManifestFilePackageReader(manifestMap);
});
final List<JavaPackageReader> javaPackageReaders = Lists.newArrayList(manifestFilePackageReader, JavaSourcePackageReader.getInstance(), generatedFileJavaPackageReader);
Collection<SourceArtifact> nonGeneratedSources = filterGeneratedArtifacts(sources);
// Sort artifacts and excludes into their respective workspace paths
Multimap<WorkspacePath, SourceArtifact> sourcesUnderDirectoryRoot = sortArtifactLocationsByRootDirectory(context, importRoots, nonGeneratedSources);
List<BlazeContentEntry> result = Lists.newArrayList();
Scope.push(context, (childContext) -> {
childContext.push(new TimingScope("CalculateSourceDirectories", EventType.Other));
for (WorkspacePath workspacePath : importRoots.rootDirectories()) {
File contentRoot = workspaceRoot.fileForPath(workspacePath);
ImmutableList<BlazeSourceDirectory> sourceDirectories = calculateSourceDirectoriesForContentRoot(context, workspaceRoot, artifactLocationDecoder, workspacePath, sourcesUnderDirectoryRoot.get(workspacePath), javaPackageReaders);
if (!sourceDirectories.isEmpty()) {
result.add(new BlazeContentEntry(contentRoot, sourceDirectories));
}
}
result.sort(Comparator.comparing(lhs -> lhs.contentRoot));
});
return ImmutableList.copyOf(result);
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class BlazeRenderErrorContributorTest method createPsiClassesAndSourceToTargetMap.
private void createPsiClassesAndSourceToTargetMap(Container projectServices) {
PsiManager psiManager = new MockPsiManager(project);
VirtualFile independentLibraryView = new MockVirtualFile("src/com/google/example/independent/LibraryView.java");
VirtualFile independentLibraryView2 = new MockVirtualFile("src/com/google/example/independent/LibraryView2.java");
VirtualFile independentLibrary2View = new MockVirtualFile("src/com/google/example/independent/Library2View.java");
VirtualFile dependentLibraryView = new MockVirtualFile("src/com/google/example/dependent/LibraryView.java");
VirtualFile resourceView = new MockVirtualFile("src/com/google/example/ResourceView.java");
ImmutableMap<String, PsiClass> classes = ImmutableMap.of("com.google.example.independent.LibraryView", mockPsiClass(independentLibraryView), "com.google.example.independent.LibraryView2", mockPsiClass(independentLibraryView2), "com.google.example.independent.Library2View", mockPsiClass(independentLibrary2View), "com.google.example.dependent.LibraryView", mockPsiClass(dependentLibraryView), "com.google.example.ResourceView", mockPsiClass(resourceView));
ImmutableMap<File, TargetKey> sourceToTarget = ImmutableMap.of(VfsUtilCore.virtualToIoFile(independentLibraryView), TargetKey.forPlainTarget(Label.create("//com/google/example/independent:library")), VfsUtilCore.virtualToIoFile(independentLibraryView2), TargetKey.forPlainTarget(Label.create("//com/google/example/independent:library")), VfsUtilCore.virtualToIoFile(independentLibrary2View), TargetKey.forPlainTarget(Label.create("//com/google/example/independent:library2")), VfsUtilCore.virtualToIoFile(dependentLibraryView), TargetKey.forPlainTarget(Label.create("//com/google/example/dependent:library")), VfsUtilCore.virtualToIoFile(resourceView), TargetKey.forPlainTarget(Label.create("//com/google/example:resources")));
projectServices.register(JavaPsiFacade.class, new MockJavaPsiFacade(project, psiManager, classes));
projectServices.register(SourceToTargetMap.class, new MockSourceToTargetMap(sourceToTarget));
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class BlazeAndroidWorkspaceImporter method addSourceTarget.
private void addSourceTarget(WorkspaceBuilder workspaceBuilder, TransitiveResourceMap transitiveResourceMap, TargetIdeInfo target) {
AndroidIdeInfo androidIdeInfo = target.androidIdeInfo;
assert androidIdeInfo != null;
if (shouldGenerateResources(androidIdeInfo) && shouldGenerateResourceModule(androidIdeInfo, whitelistedGenResourcePaths)) {
AndroidResourceModule.Builder builder = new AndroidResourceModule.Builder(target.key);
workspaceBuilder.androidResourceModules.add(builder);
for (ArtifactLocation artifactLocation : androidIdeInfo.resources) {
if (artifactLocation.isSource()) {
builder.addResource(artifactLocation);
} else {
workspaceBuilder.generatedResourceLocations.add(artifactLocation);
if (whitelistedGenResourcePaths.contains(artifactLocation.relativePath)) {
// Still track location in generatedResourceLocations, so that we can warn if a
// whitelist entry goes unused and can be removed.
builder.addResource(artifactLocation);
}
}
}
TransitiveResourceMap.TransitiveResourceInfo transitiveResourceInfo = transitiveResourceMap.get(target.key);
for (ArtifactLocation artifactLocation : transitiveResourceInfo.transitiveResources) {
if (artifactLocation.isSource()) {
builder.addTransitiveResource(artifactLocation);
} else {
workspaceBuilder.generatedResourceLocations.add(artifactLocation);
if (whitelistedGenResourcePaths.contains(artifactLocation.relativePath)) {
builder.addTransitiveResource(artifactLocation);
}
}
}
for (TargetKey resourceDependency : transitiveResourceInfo.transitiveResourceTargets) {
if (!resourceDependency.equals(target.key)) {
builder.addTransitiveResourceDependency(resourceDependency);
}
}
}
}
use of com.google.idea.blaze.base.ideinfo.TargetKey in project intellij by bazelbuild.
the class TransitiveAggregator method aggregate.
private void aggregate(TargetIdeInfo target) {
T result = createForTarget(target);
for (TargetKey dep : getDependencies(target)) {
// Since we aggregate dependencies first, this should already be in the map.
T depResult = targetKeyToResult.get(dep);
if (depResult != null) {
result = reduce(result, depResult);
}
}
targetKeyToResult.put(target.key, result);
}
Aggregations