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"));
}
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"));
}
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"));
}
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"));
}
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;
}
Aggregations