Search in sources :

Example 21 with TargetKey

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;
}
Also used : ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ExecutionException(java.util.concurrent.ExecutionException) File(java.io.File) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 22 with TargetKey

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);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ArrayListMultimap(com.google.common.collect.ArrayListMultimap) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) TransientExecutor(com.google.idea.blaze.base.async.executor.TransientExecutor) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Multiset(com.google.common.collect.Multiset) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) HashMultiset(com.google.common.collect.HashMultiset) Scope(com.google.idea.blaze.base.scope.Scope) Map(java.util.Map) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) Project(com.intellij.openapi.project.Project) Objects(com.google.common.base.Objects) Logger(com.intellij.openapi.diagnostic.Logger) Splitter(com.google.common.base.Splitter) Nullable(javax.annotation.Nullable) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) Predicate(java.util.function.Predicate) Collection(java.util.Collection) Set(java.util.Set) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BlazeSourceDirectory(com.google.idea.blaze.java.sync.model.BlazeSourceDirectory) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Comparator(java.util.Comparator) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) PackagePrefixCalculator(com.google.idea.blaze.base.util.PackagePrefixCalculator) Collections(java.util.Collections) Joiner(com.google.common.base.Joiner) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) BlazeContentEntry(com.google.idea.blaze.java.sync.model.BlazeContentEntry) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) BlazeSourceDirectory(com.google.idea.blaze.java.sync.model.BlazeSourceDirectory) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) HashMap(java.util.HashMap) Map(java.util.Map) File(java.io.File)

Example 23 with TargetKey

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));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) PsiClass(com.intellij.psi.PsiClass) PsiManager(com.intellij.psi.PsiManager) MockPsiManager(com.intellij.mock.MockPsiManager) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) MockPsiManager(com.intellij.mock.MockPsiManager) VirtualFile(com.intellij.openapi.vfs.VirtualFile) MockVirtualFile(com.intellij.mock.MockVirtualFile) MockPsiFile(com.intellij.mock.MockPsiFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File)

Example 24 with TargetKey

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);
            }
        }
    }
}
Also used : AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) TransitiveResourceMap(com.google.idea.blaze.android.sync.importer.aggregators.TransitiveResourceMap) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo)

Example 25 with TargetKey

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);
}
Also used : TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey)

Aggregations

TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)52 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)25 File (java.io.File)19 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)14 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)14 Nullable (javax.annotation.Nullable)12 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)11 List (java.util.List)11 Test (org.junit.Test)11 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)9 Project (com.intellij.openapi.project.Project)9 Map (java.util.Map)9 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 Collection (java.util.Collection)8 Set (java.util.Set)8 Sets (com.google.common.collect.Sets)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)7 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)7 ExecutionException (java.util.concurrent.ExecutionException)7