Search in sources :

Example 26 with TargetIdeInfo

use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.

the class BlazeJavaWorkspaceImporter method addProtoLegacyLibrariesFromDirectDeps.

private void addProtoLegacyLibrariesFromDirectDeps(WorkspaceBuilder workspaceBuilder, TargetMap targetMap, Map<LibraryKey, BlazeJarLibrary> result) {
    List<TargetKey> version1Targets = Lists.newArrayList();
    List<TargetKey> immutableTargets = Lists.newArrayList();
    List<TargetKey> mutableTargets = Lists.newArrayList();
    for (TargetKey targetKey : workspaceBuilder.directDeps) {
        TargetIdeInfo target = targetMap.get(targetKey);
        if (target == null) {
            continue;
        }
        ProtoLibraryLegacyInfo protoLibraryLegacyInfo = target.protoLibraryLegacyInfo;
        if (protoLibraryLegacyInfo == null) {
            continue;
        }
        switch(protoLibraryLegacyInfo.apiFlavor) {
            case VERSION_1:
                version1Targets.add(targetKey);
                break;
            case IMMUTABLE:
                immutableTargets.add(targetKey);
                break;
            case MUTABLE:
                mutableTargets.add(targetKey);
                break;
            case BOTH:
                mutableTargets.add(targetKey);
                immutableTargets.add(targetKey);
                break;
            default:
                // Can't happen
                break;
        }
    }
    addProtoLegacyLibrariesFromDirectDepsForFlavor(targetMap, ProtoLibraryLegacyInfo.ApiFlavor.VERSION_1, version1Targets, result);
    addProtoLegacyLibrariesFromDirectDepsForFlavor(targetMap, ProtoLibraryLegacyInfo.ApiFlavor.IMMUTABLE, immutableTargets, result);
    addProtoLegacyLibrariesFromDirectDepsForFlavor(targetMap, ProtoLibraryLegacyInfo.ApiFlavor.MUTABLE, mutableTargets, result);
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ProtoLibraryLegacyInfo(com.google.idea.blaze.base.ideinfo.ProtoLibraryLegacyInfo)

Example 27 with TargetIdeInfo

use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.

the class BlazeJavaMainClassRunConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    PsiClass mainClass = getMainClass(context);
    if (mainClass == null) {
        return false;
    }
    // Try setting source element to a main method so ApplicationConfigurationProducer
    // can't override our configuration by producing a more specific one.
    PsiMethod mainMethod = PsiMethodUtil.findMainMethod(mainClass);
    if (mainMethod == null) {
        sourceElement.set(mainClass);
    } else {
        sourceElement.set(mainMethod);
    }
    TargetIdeInfo target = getTarget(context.getProject(), mainClass);
    if (target == null) {
        return false;
    }
    configuration.setTargetInfo(target.toTargetInfo());
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    handlerState.getCommandState().setCommand(BlazeCommandName.RUN);
    configuration.setGeneratedName();
    return true;
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass)

Example 28 with TargetIdeInfo

use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.

the class BlazeJavaMainClassRunConfigurationProducer method getTarget.

@Nullable
private static TargetIdeInfo getTarget(Project project, PsiClass mainClass) {
    File mainClassFile = RunUtil.getFileForClass(mainClass);
    if (mainClassFile == null) {
        return null;
    }
    Collection<TargetIdeInfo> javaBinaryTargets = findJavaBinaryTargets(project, mainClassFile);
    String qualifiedName = mainClass.getQualifiedName();
    String className = mainClass.getName();
    if (qualifiedName == null || className == null) {
        // out of date psi element; just take the first match
        return Iterables.getFirst(javaBinaryTargets, null);
    }
    // first look for a matching main_class
    TargetIdeInfo match = javaBinaryTargets.stream().filter(target -> target.javaIdeInfo != null && qualifiedName.equals(target.javaIdeInfo.javaBinaryMainClass)).findFirst().orElse(null);
    if (match != null) {
        return match;
    }
    match = javaBinaryTargets.stream().filter(target -> className.equals(target.key.label.targetName().toString())).findFirst().orElse(null);
    if (match != null) {
        return match;
    }
    return Iterables.getFirst(javaBinaryTargets, null);
}
Also used : TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Iterables(com.google.common.collect.Iterables) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) FilteredTargetMap(com.google.idea.blaze.base.run.testmap.FilteredTargetMap) BlazeCommandRunConfigurationType(com.google.idea.blaze.base.run.BlazeCommandRunConfigurationType) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) PsiClass(com.intellij.psi.PsiClass) ImmutableList(com.google.common.collect.ImmutableList) PsiElement(com.intellij.psi.PsiElement) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) RunUtil(com.google.idea.blaze.java.run.RunUtil) BlazeRunConfigurationProducer(com.google.idea.blaze.base.run.producers.BlazeRunConfigurationProducer) Nullable(javax.annotation.Nullable) ApplicationConfigurationType(com.intellij.execution.application.ApplicationConfigurationType) PsiMethod(com.intellij.psi.PsiMethod) Collection(java.util.Collection) BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) File(java.io.File) BlazeCommandName(com.google.idea.blaze.base.command.BlazeCommandName) Objects(java.util.Objects) SyncCache(com.google.idea.blaze.base.sync.SyncCache) JavaExecutionUtil(com.intellij.execution.JavaExecutionUtil) PsiMethodUtil(com.intellij.psi.util.PsiMethodUtil) Location(com.intellij.execution.Location) Ref(com.intellij.openapi.util.Ref) File(java.io.File) Nullable(javax.annotation.Nullable)

Example 29 with TargetIdeInfo

use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.

the class BlazeJavaMainClassRunConfigurationProducer method doIsConfigFromContext.

@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    if (!Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.RUN)) {
        return false;
    }
    PsiClass mainClass = getMainClass(context);
    if (mainClass == null) {
        return false;
    }
    TargetIdeInfo target = getTarget(context.getProject(), mainClass);
    if (target == null) {
        return false;
    }
    return Objects.equals(configuration.getTarget(), target.key.label);
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) PsiClass(com.intellij.psi.PsiClass)

Example 30 with TargetIdeInfo

use of com.google.idea.blaze.base.ideinfo.TargetIdeInfo in project intellij by bazelbuild.

the class BlazeAndroidWorkspaceImporterTest method testIdlClassJarIsAddedAsLibrary.

@Test
public void testIdlClassJarIsAddedAsLibrary() {
    ProjectView projectView = ProjectView.builder().add(ListSection.builder(DirectorySection.KEY).add(DirectoryEntry.include(new WorkspacePath("example")))).build();
    TargetMapBuilder targetMapBuilder = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setLabel("//example:lib").setBuildFile(source("example/BUILD")).setKind("android_binary").addSource(source("example/MainActivity.java")).setAndroidInfo(AndroidIdeInfo.builder().setResourceJavaPackage("example").setIdlJar(LibraryArtifact.builder().setInterfaceJar(gen("example/libidl.jar")).addSourceJar(gen("example/libidl.srcjar")).build()).setHasIdlSources(true)));
    TargetMap targetMap = targetMapBuilder.build();
    BlazeAndroidJavaSyncAugmenter syncAugmenter = new BlazeAndroidJavaSyncAugmenter();
    List<BlazeJarLibrary> jars = Lists.newArrayList();
    List<BlazeJarLibrary> genJars = Lists.newArrayList();
    ImportRoots importRoots = ImportRoots.builder(workspaceRoot, BuildSystem.Blaze).add(ProjectViewSet.builder().add(projectView).build()).build();
    ProjectViewSet projectViewSet = ProjectViewSet.builder().add(projectView).build();
    for (TargetIdeInfo target : targetMap.targets()) {
        if (importRoots.importAsSource(target.key.label)) {
            syncAugmenter.addJarsForSourceTarget(workspaceLanguageSettings, projectViewSet, target, jars, genJars);
        }
    }
    assertThat(genJars.stream().map(library -> library.libraryArtifact.interfaceJar).map(artifactLocation -> new File(artifactLocation.relativePath).getName()).collect(Collectors.toList())).containsExactly("libidl.jar");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) GeneratedAndroidResourcesSection(com.google.idea.blaze.android.projectview.GeneratedAndroidResourcesSection) BlazeAndroidJavaSyncAugmenter(com.google.idea.blaze.android.sync.BlazeAndroidJavaSyncAugmenter) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) JavaWorkingSet(com.google.idea.blaze.java.sync.workingset.JavaWorkingSet) WorkingSet(com.google.idea.blaze.base.sync.workspace.WorkingSet) JavaLikeLanguage(com.google.idea.blaze.java.sync.source.JavaLikeLanguage) BlazeAndroidLibrarySource(com.google.idea.blaze.android.sync.BlazeAndroidLibrarySource) JavaSourceFilter(com.google.idea.blaze.java.sync.importer.JavaSourceFilter) ImmutableSet(com.google.common.collect.ImmutableSet) AndroidResourceModule(com.google.idea.blaze.android.sync.model.AndroidResourceModule) Predicate(java.util.function.Predicate) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) WorkspaceLanguageSettings(com.google.idea.blaze.base.sync.projectview.WorkspaceLanguageSettings) Collectors(java.util.stream.Collectors) FileOperationProvider(com.google.idea.blaze.base.io.FileOperationProvider) BlazeAndroidImportResult(com.google.idea.blaze.android.sync.model.BlazeAndroidImportResult) SourceArtifact(com.google.idea.blaze.java.sync.source.SourceArtifact) List(java.util.List) ErrorCollector(com.google.idea.blaze.base.scope.ErrorCollector) ProjectViewSet(com.google.idea.blaze.base.projectview.ProjectViewSet) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) JavaSourcePackageReader(com.google.idea.blaze.java.sync.source.JavaSourcePackageReader) PackageManifestReader(com.google.idea.blaze.java.sync.source.PackageManifestReader) LibraryArtifact(com.google.idea.blaze.base.ideinfo.LibraryArtifact) DirectorySection(com.google.idea.blaze.base.projectview.section.sections.DirectorySection) RunWith(org.junit.runner.RunWith) BlazeJavaWorkspaceImporter(com.google.idea.blaze.java.sync.importer.BlazeJavaWorkspaceImporter) MockJdepsMap(com.google.idea.blaze.java.sync.jdeps.MockJdepsMap) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) BlazeJavaImportResult(com.google.idea.blaze.java.sync.model.BlazeJavaImportResult) ExperimentService(com.google.idea.common.experiments.ExperimentService) BlazeResourceLibrary(com.google.idea.blaze.android.sync.model.BlazeResourceLibrary) MockBlazeExecutor(com.google.idea.blaze.base.async.executor.MockBlazeExecutor) AndroidIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidIdeInfo) Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) WorkspaceType(com.google.idea.blaze.base.model.primitives.WorkspaceType) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) BuildSystem(com.google.idea.blaze.base.settings.Blaze.BuildSystem) AarLibrary(com.google.idea.blaze.android.sync.model.AarLibrary) IssueOutput(com.google.idea.blaze.base.scope.output.IssueOutput) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Nullable(javax.annotation.Nullable) LanguageClass(com.google.idea.blaze.base.model.primitives.LanguageClass) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) BlazeImportSettingsManager(com.google.idea.blaze.base.settings.BlazeImportSettingsManager) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) AndroidAarIdeInfo(com.google.idea.blaze.base.ideinfo.AndroidAarIdeInfo) MockPrefetchService(com.google.idea.blaze.base.prefetch.MockPrefetchService) BlazeJavaSyncAugmenter(com.google.idea.blaze.java.sync.BlazeJavaSyncAugmenter) File(java.io.File) BlazeImportSettings(com.google.idea.blaze.base.settings.BlazeImportSettings) BlazeExecutor(com.google.idea.blaze.base.async.executor.BlazeExecutor) DirectoryEntry(com.google.idea.blaze.base.projectview.section.sections.DirectoryEntry) Label(com.google.idea.blaze.base.model.primitives.Label) MockExperimentService(com.google.idea.common.experiments.MockExperimentService) GenfilesPath(com.google.idea.blaze.android.projectview.GenfilesPath) WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ListSection(com.google.idea.blaze.base.projectview.section.ListSection) ImportRoots(com.google.idea.blaze.base.sync.projectview.ImportRoots) BlazeAndroidJavaSyncAugmenter(com.google.idea.blaze.android.sync.BlazeAndroidJavaSyncAugmenter) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary) ProjectView(com.google.idea.blaze.base.projectview.ProjectView) File(java.io.File) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) Test(org.junit.Test)

Aggregations

TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)57 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)28 File (java.io.File)20 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)19 Nullable (javax.annotation.Nullable)16 Kind (com.google.idea.blaze.base.model.primitives.Kind)15 ImmutableList (com.google.common.collect.ImmutableList)14 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)14 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)14 ArtifactLocationDecoder (com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder)14 Project (com.intellij.openapi.project.Project)14 List (java.util.List)12 LibraryArtifact (com.google.idea.blaze.base.ideinfo.LibraryArtifact)11 ProjectViewSet (com.google.idea.blaze.base.projectview.ProjectViewSet)11 LanguageClass (com.google.idea.blaze.base.model.primitives.LanguageClass)10 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)10 Collection (java.util.Collection)10 AndroidIdeInfo (com.google.idea.blaze.base.ideinfo.AndroidIdeInfo)9 BlazeJarLibrary (com.google.idea.blaze.java.sync.model.BlazeJarLibrary)9 Set (java.util.Set)9