Search in sources :

Example 16 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class TestMapTest method testSourceIncludedMultipleTimesFindsAll.

@Test
public void testSourceIncludedMultipleTimesFindsAll() throws Exception {
    mockBlazeProjectDataManager.targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:test").setKind("java_test").addDependency("//test:lib")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:test2").setKind("java_test").addDependency("//test:lib2")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:lib").setKind("java_library").addSource(sourceRoot("test/Test.java"))).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:lib2").setKind("java_library").addSource(sourceRoot("test/Test.java"))).build();
    Collection<TargetInfo> targets = SourceToTargetFinder.findTargetsForSourceFile(project, new File("/test/Test.java"), Optional.of(RuleType.TEST));
    assertThat(targets.stream().map(t -> t.label).collect(Collectors.toList())).containsExactly(Label.create("//test:test"), Label.create("//test:test2"));
}
Also used : RuleType(com.google.idea.blaze.base.model.primitives.RuleType) SourceToTargetFinder(com.google.idea.blaze.base.run.SourceToTargetFinder) RunWith(org.junit.runner.RunWith) ExperimentService(com.google.idea.common.experiments.ExperimentService) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ReverseDependencyMap(com.google.idea.blaze.base.targetmaps.ReverseDependencyMap) Nullable(javax.annotation.Nullable) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ImmutableMap(com.google.common.collect.ImmutableMap) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) Collection(java.util.Collection) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) SyncCache(com.google.idea.blaze.base.sync.SyncCache) ExtensionPointImpl(com.intellij.openapi.extensions.impl.ExtensionPointImpl) Label(com.google.idea.blaze.base.model.primitives.Label) MockExperimentService(com.google.idea.common.experiments.MockExperimentService) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) File(java.io.File) Test(org.junit.Test)

Example 17 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class TestMapTest method testSourceIncludedMultipleTimesShouldOnlyGiveOneInstanceOfTest.

@Test
public void testSourceIncludedMultipleTimesShouldOnlyGiveOneInstanceOfTest() throws Exception {
    mockBlazeProjectDataManager.targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:test").setKind("java_test").addDependency("//test:lib").addDependency("//test:lib2")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:lib").setKind("java_library").addSource(sourceRoot("test/Test.java"))).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:lib2").setKind("java_library").addSource(sourceRoot("test/Test.java"))).build();
    Collection<TargetInfo> targets = SourceToTargetFinder.findTargetsForSourceFile(project, new File("/test/Test.java"), Optional.of(RuleType.TEST));
    assertThat(targets.stream().map(t -> t.label).collect(Collectors.toList())).containsExactly(Label.create("//test:test"));
}
Also used : RuleType(com.google.idea.blaze.base.model.primitives.RuleType) SourceToTargetFinder(com.google.idea.blaze.base.run.SourceToTargetFinder) RunWith(org.junit.runner.RunWith) ExperimentService(com.google.idea.common.experiments.ExperimentService) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ReverseDependencyMap(com.google.idea.blaze.base.targetmaps.ReverseDependencyMap) Nullable(javax.annotation.Nullable) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ImmutableMap(com.google.common.collect.ImmutableMap) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) Collection(java.util.Collection) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) SyncCache(com.google.idea.blaze.base.sync.SyncCache) ExtensionPointImpl(com.intellij.openapi.extensions.impl.ExtensionPointImpl) Label(com.google.idea.blaze.base.model.primitives.Label) MockExperimentService(com.google.idea.common.experiments.MockExperimentService) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) File(java.io.File) Test(org.junit.Test)

Example 18 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class TestMapTest method testTwoCandidatesTestMap.

@Test
public void testTwoCandidatesTestMap() throws Exception {
    mockBlazeProjectDataManager.targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:test").setKind("java_test").addDependency("//test:lib")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:test2").setKind("java_test").addDependency("//test:lib")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:lib").setKind("java_library").addSource(sourceRoot("test/Test.java"))).build();
    Collection<TargetInfo> targets = SourceToTargetFinder.findTargetsForSourceFile(project, new File("/test/Test.java"), Optional.of(RuleType.TEST));
    assertThat(targets.stream().map(t -> t.label).collect(Collectors.toList())).containsExactly(Label.create("//test:test"), Label.create("//test:test2"));
}
Also used : RuleType(com.google.idea.blaze.base.model.primitives.RuleType) SourceToTargetFinder(com.google.idea.blaze.base.run.SourceToTargetFinder) RunWith(org.junit.runner.RunWith) ExperimentService(com.google.idea.common.experiments.ExperimentService) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ReverseDependencyMap(com.google.idea.blaze.base.targetmaps.ReverseDependencyMap) Nullable(javax.annotation.Nullable) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ImmutableMap(com.google.common.collect.ImmutableMap) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) Collection(java.util.Collection) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) SyncCache(com.google.idea.blaze.base.sync.SyncCache) ExtensionPointImpl(com.intellij.openapi.extensions.impl.ExtensionPointImpl) Label(com.google.idea.blaze.base.model.primitives.Label) MockExperimentService(com.google.idea.common.experiments.MockExperimentService) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) File(java.io.File) Test(org.junit.Test)

Example 19 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class TestMapTest method testOneStepRemovedTestMap.

@Test
public void testOneStepRemovedTestMap() throws Exception {
    mockBlazeProjectDataManager.targetMap = TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:test").setKind("java_test").addDependency("//test:lib")).addTarget(TargetIdeInfo.builder().setBuildFile(sourceRoot("test/BUILD")).setLabel("//test:lib").setKind("java_library").addSource(sourceRoot("test/Test.java"))).build();
    Collection<TargetInfo> targets = SourceToTargetFinder.findTargetsForSourceFile(project, new File("/test/Test.java"), Optional.of(RuleType.TEST));
    assertThat(targets.stream().map(t -> t.label).collect(Collectors.toList())).containsExactly(Label.create("//test:test"));
}
Also used : RuleType(com.google.idea.blaze.base.model.primitives.RuleType) SourceToTargetFinder(com.google.idea.blaze.base.run.SourceToTargetFinder) RunWith(org.junit.runner.RunWith) ExperimentService(com.google.idea.common.experiments.ExperimentService) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ReverseDependencyMap(com.google.idea.blaze.base.targetmaps.ReverseDependencyMap) Nullable(javax.annotation.Nullable) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) ArtifactLocation(com.google.idea.blaze.base.ideinfo.ArtifactLocation) ImmutableMap(com.google.common.collect.ImmutableMap) BlazeTestCase(com.google.idea.blaze.base.BlazeTestCase) Collection(java.util.Collection) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) BlazeProjectDataManager(com.google.idea.blaze.base.sync.data.BlazeProjectDataManager) File(java.io.File) SyncCache(com.google.idea.blaze.base.sync.SyncCache) ExtensionPointImpl(com.intellij.openapi.extensions.impl.ExtensionPointImpl) Label(com.google.idea.blaze.base.model.primitives.Label) MockExperimentService(com.google.idea.common.experiments.MockExperimentService) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) TargetMap(com.google.idea.blaze.base.ideinfo.TargetMap) TargetMapBuilder(com.google.idea.blaze.base.ideinfo.TargetMapBuilder) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) File(java.io.File) Test(org.junit.Test)

Example 20 with TargetInfo

use of com.google.idea.blaze.base.dependencies.TargetInfo in project intellij by bazelbuild.

the class BlazePyBinaryConfigurationProducer method doSetupConfigFromContext.

@Override
protected boolean doSetupConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
    Location<?> location = context.getLocation();
    if (location == null) {
        return false;
    }
    PsiElement element = location.getPsiElement();
    PsiFile file = element.getContainingFile();
    if (!(file instanceof PyFile)) {
        return false;
    }
    TargetInfo binaryTarget = getTargetLabel(file);
    if (binaryTarget == null) {
        return false;
    }
    configuration.setTargetInfo(binaryTarget);
    sourceElement.set(file);
    BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
    if (handlerState == null) {
        return false;
    }
    handlerState.getCommandState().setCommand(BlazeCommandName.RUN);
    configuration.setGeneratedName();
    return true;
}
Also used : BlazeCommandRunConfigurationCommonState(com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState) TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) PsiFile(com.intellij.psi.PsiFile) PyFile(com.jetbrains.python.psi.PyFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

TargetInfo (com.google.idea.blaze.base.dependencies.TargetInfo)69 File (java.io.File)43 Test (org.junit.Test)40 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)19 PsiFile (com.intellij.psi.PsiFile)18 Nullable (javax.annotation.Nullable)15 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)14 PsiElement (com.intellij.psi.PsiElement)9 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)7 Label (com.google.idea.blaze.base.model.primitives.Label)7 PsiClass (com.intellij.psi.PsiClass)7 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)6 RuleType (com.google.idea.blaze.base.model.primitives.RuleType)6 BlazeProjectDataManager (com.google.idea.blaze.base.sync.data.BlazeProjectDataManager)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)5 BlazeTestCase (com.google.idea.blaze.base.BlazeTestCase)5 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)5 TargetMapBuilder (com.google.idea.blaze.base.ideinfo.TargetMapBuilder)5