Search in sources :

Example 16 with ArtifactLocationDecoder

use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.

the class BlazeJavaWorkspaceImporterTest method initTest.

@Override
// False positive on getDeclaredPackageOfJavaFile.
@SuppressWarnings("FunctionalInterfaceClash")
protected void initTest(Container applicationServices, Container projectServices) {
    applicationServices.register(ExperimentService.class, new MockExperimentService());
    BlazeExecutor blazeExecutor = new MockBlazeExecutor();
    applicationServices.register(BlazeExecutor.class, blazeExecutor);
    projectServices.register(BlazeImportSettingsManager.class, new BlazeImportSettingsManager());
    BlazeImportSettingsManager.getInstance(getProject()).setImportSettings(DUMMY_IMPORT_SETTINGS);
    // will silently fall back to FilePathJavaPackageReader
    applicationServices.register(JavaSourcePackageReader.class, new JavaSourcePackageReader() {

        @Nullable
        @Override
        public String getDeclaredPackageOfJavaFile(BlazeContext context, ArtifactLocationDecoder artifactLocationDecoder, SourceArtifact sourceArtifact) {
            return null;
        }
    });
    applicationServices.register(PackageManifestReader.class, new PackageManifestReader());
    applicationServices.register(PrefetchService.class, new MockPrefetchService());
    context = new BlazeContext();
    context.addOutputSink(IssueOutput.class, errorCollector);
    augmenters = registerExtensionPoint(BlazeJavaSyncAugmenter.EP_NAME, BlazeJavaSyncAugmenter.class);
    registerExtensionPoint(JavaLikeLanguage.EP_NAME, JavaLikeLanguage.class).registerExtension(new JavaLikeLanguage.Java());
}
Also used : MockExperimentService(com.google.idea.common.experiments.MockExperimentService) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) JavaLikeLanguage(com.google.idea.blaze.java.sync.source.JavaLikeLanguage) PackageManifestReader(com.google.idea.blaze.java.sync.source.PackageManifestReader) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor) SourceArtifact(com.google.idea.blaze.java.sync.source.SourceArtifact) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) MockPrefetchService(com.google.idea.blaze.base.prefetch.MockPrefetchService) BlazeJavaSyncAugmenter(com.google.idea.blaze.java.sync.BlazeJavaSyncAugmenter) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) JavaSourcePackageReader(com.google.idea.blaze.java.sync.source.JavaSourcePackageReader) Nullable(javax.annotation.Nullable)

Example 17 with ArtifactLocationDecoder

use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.

the class AbstractPyImportResolverStrategy method buildSourcesIndex.

@SuppressWarnings("unused")
private PySourcesIndex buildSourcesIndex(Project project, BlazeProjectData projectData) {
    ImmutableSetMultimap.Builder<String, QualifiedName> shortNames = ImmutableSetMultimap.builder();
    Map<QualifiedName, PsiElementProvider> map = new HashMap<>();
    ArtifactLocationDecoder decoder = projectData.artifactLocationDecoder;
    for (TargetIdeInfo target : projectData.targetMap.targets()) {
        for (ArtifactLocation source : getPySources(target)) {
            QualifiedName name = toImportString(source);
            if (name == null || name.getLastComponent() == null) {
                continue;
            }
            shortNames.put(name.getLastComponent(), name);
            PsiElementProvider psiProvider = psiProviderFromArtifact(decoder, source);
            map.put(name, psiProvider);
            if (includeParentDirectory(source)) {
                map.put(name.removeTail(1), PsiElementProvider.getParent(psiProvider));
            }
        }
    }
    return new PySourcesIndex(shortNames.build(), ImmutableMap.copyOf(map));
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) HashMap(java.util.HashMap) QualifiedName(com.intellij.psi.util.QualifiedName) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)

Example 18 with ArtifactLocationDecoder

use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.

the class TestTargetSourcesHeuristic method matchesSource.

@Override
public boolean matchesSource(Project project, TargetInfo target, @Nullable PsiFile sourcePsiFile, File sourceFile, @Nullable TestSize testSize) {
    Optional<ImmutableList<ArtifactLocation>> sources = target.getSources();
    if (!sources.isPresent()) {
        return false;
    }
    BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (projectData == null) {
        return false;
    }
    ArtifactLocationDecoder decoder = projectData.artifactLocationDecoder;
    for (ArtifactLocation src : sources.get()) {
        if (decoder.decode(src).equals(sourceFile)) {
            return true;
        }
    }
    return false;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)

Example 19 with ArtifactLocationDecoder

use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.

the class MockBlazeProjectDataBuilder method build.

public BlazeProjectData build() {
    TargetMap targetMap = this.targetMap != null ? this.targetMap : new TargetMap(ImmutableMap.of());
    BlazeInfo blazeInfo = this.blazeInfo;
    if (blazeInfo == null) {
        String outputBase = this.outputBase != null ? this.outputBase : "/usr/workspace/1234";
        blazeInfo = BlazeInfo.createMockBlazeInfo(outputBase, outputBase + "/execroot", outputBase + "/execroot/bin", outputBase + "/execroot/gen");
    }
    BlazeVersionData blazeVersionData = this.blazeVersionData != null ? this.blazeVersionData : BlazeVersionData.builder().build();
    WorkspacePathResolver workspacePathResolver = this.workspacePathResolver != null ? this.workspacePathResolver : new WorkspacePathResolverImpl(workspaceRoot);
    ArtifactLocationDecoder artifactLocationDecoder = this.artifactLocationDecoder != null ? this.artifactLocationDecoder : new ArtifactLocationDecoderImpl(blazeInfo, workspacePathResolver);
    WorkspaceLanguageSettings workspaceLanguageSettings = this.workspaceLanguageSettings != null ? this.workspaceLanguageSettings : new WorkspaceLanguageSettings(WorkspaceType.JAVA, ImmutableSet.of());
    SyncState syncState = this.syncState != null ? this.syncState : new SyncState(ImmutableMap.of());
    ImmutableMultimap<TargetKey, TargetKey> reverseDependencies = this.reverseDependencies != null ? this.reverseDependencies : ImmutableMultimap.of();
    return new BlazeProjectData(syncTime, targetMap, blazeInfo, blazeVersionData, workspacePathResolver, artifactLocationDecoder, workspaceLanguageSettings, syncState, reverseDependencies);
}
Also used : BlazeInfo(com.google.idea.blaze.base.command.info.BlazeInfo) WorkspacePathResolverImpl(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolverImpl) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) WorkspacePathResolver(com.google.idea.blaze.base.sync.workspace.WorkspacePathResolver) ArtifactLocationDecoderImpl(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoderImpl) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap)

Example 20 with ArtifactLocationDecoder

use of com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder in project intellij by bazelbuild.

the class JdepsFileReader method loadJdepsFiles.

/**
 * Loads any updated jdeps files since the last invocation of this method.
 */
@Nullable
public JdepsMap loadJdepsFiles(Project project, BlazeContext parentContext, ArtifactLocationDecoder artifactLocationDecoder, Iterable<TargetIdeInfo> targetsToLoad, SyncState.Builder syncStateBuilder, @Nullable SyncState previousSyncState) {
    JdepsState oldState = previousSyncState != null ? previousSyncState.get(JdepsState.class) : null;
    JdepsState jdepsState = Scope.push(parentContext, (context) -> {
        context.push(new TimingScope("LoadJdepsFiles", EventType.Other));
        return doLoadJdepsFiles(project, context, artifactLocationDecoder, oldState, targetsToLoad);
    });
    if (jdepsState == null) {
        return null;
    }
    syncStateBuilder.put(JdepsState.class, jdepsState);
    return targetKey -> jdepsState.targetToJdeps.get(targetKey);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) Callable(java.util.concurrent.Callable) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) Lists(com.google.common.collect.Lists) Scope(com.google.idea.blaze.base.scope.Scope) Map(java.util.Map) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Nullable(javax.annotation.Nullable) FileDiffer(com.google.idea.blaze.base.filecache.FileDiffer) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ImmutableMap(com.google.common.collect.ImmutableMap) FutureUtil(com.google.idea.blaze.base.async.FutureUtil) SyncState(com.google.idea.blaze.base.model.SyncState) FileInputStream(java.io.FileInputStream) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Maps(com.google.common.collect.Maps) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Serializable(java.io.Serializable) ExecutionException(java.util.concurrent.ExecutionException) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Deps(com.google.devtools.build.lib.view.proto.Deps) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) InputStream(java.io.InputStream) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) Nullable(javax.annotation.Nullable)

Aggregations

ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)27 File (java.io.File)15 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)13 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)13 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)12 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)12 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)12 Nullable (javax.annotation.Nullable)12 ImmutableList (com.google.common.collect.ImmutableList)9 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)9 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)8 BlazeImportSettingsManager (com.google.idea.blaze.base.settings.BlazeImportSettingsManager)8 Project (com.intellij.openapi.project.Project)8 List (java.util.List)8 Map (java.util.Map)8 Lists (com.google.common.collect.Lists)6 WorkspaceRoot (com.google.idea.blaze.base.model.primitives.WorkspaceRoot)6 Logger (com.intellij.openapi.diagnostic.Logger)6 Maps (com.google.common.collect.Maps)5 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5