use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeKotlinTestClassConfigurationProducer method doIsConfigFromContext.
@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
TestLocation testLocation = TestLocation.from(context);
if (testLocation == null) {
return false;
}
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
return handlerState != null && Objects.equals(handlerState.getCommandState().getCommand(), BlazeCommandName.TEST) && Objects.equals(handlerState.getTestFilterFlag(), testLocation.getTestFilterFlag()) && Objects.equals(configuration.getTarget(), testLocation.getTargetInfo().label);
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazeJavaTestClassConfigurationProducerTest method testConfigWithDifferentFilterIgnored.
@Test
public void testConfigWithDifferentFilterIgnored() {
PsiFile javaFile = createAndIndexFile(new WorkspacePath("java/com/google/test/TestClass.java"), "package com.google.test;", "@org.junit.runner.RunWith(org.junit.runners.JUnit4.class)", "public class TestClass {", " @org.junit.Test", " public void testMethod() {}", "}");
MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("java_test").setLabel("//java/com/google/test:TestClass").addSource(sourceRoot("java/com/google/test/TestClass.java")).build()).build());
registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
ConfigurationContext context = createContextFromPsi(javaFile);
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) context.getConfiguration().getConfiguration();
BlazeCommandRunConfigurationCommonState handlerState = config.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
// modify the test filter, and check that is enough for the producer to class it as different.
List<String> flags = new ArrayList<>(handlerState.getBlazeFlagsState().getRawFlags());
flags.removeIf((flag) -> flag.startsWith(BlazeFlags.TEST_FILTER));
flags.add(BlazeFlags.TEST_FILTER + "=com.google.test.OtherTestClass#");
handlerState.getBlazeFlagsState().setRawFlags(flags);
assertThat(new BlazeJavaTestClassConfigurationProducer().doIsConfigFromContext(config, context)).isFalse();
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState 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;
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazePyTestConfigurationProducer method doIsConfigFromContext.
@Override
protected boolean doIsConfigFromContext(BlazeCommandRunConfiguration configuration, ConfigurationContext context) {
BlazeCommandRunConfigurationCommonState handlerState = configuration.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
if (handlerState == null || !BlazeCommandName.TEST.equals(handlerState.getCommandState().getCommand())) {
return false;
}
PsiElement element = selectedPsiElement(context);
if (element == null) {
return false;
}
if (!(element.getContainingFile() instanceof PyFile)) {
return false;
}
TargetInfo testTarget = TestTargetHeuristic.testTargetForPsiElement(element);
if (testTarget == null || !testTarget.label.equals(configuration.getTarget())) {
return false;
}
String filter = testLocation(element).testFilter();
String filterFlag = handlerState.getTestFilterFlag();
return (filterFlag == null && filter == null) || Objects.equals(filterFlag, BlazeFlags.TEST_FILTER + "=" + filter);
}
use of com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState in project intellij by bazelbuild.
the class BlazePyDebugRunner method canRun.
@Override
public boolean canRun(String executorId, RunProfile profile) {
if (!DefaultDebugExecutor.EXECUTOR_ID.equals(executorId) || !(profile instanceof BlazeCommandRunConfiguration)) {
return false;
}
BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) profile;
BlazeCommandRunConfigurationCommonState handlerState = config.getHandlerStateIfType(BlazeCommandRunConfigurationCommonState.class);
BlazeCommandName command = handlerState != null ? handlerState.getCommandState().getCommand() : null;
return PyDebugUtils.canUsePyDebugger(config.getTargetKind()) && (BlazeCommandName.TEST.equals(command) || BlazeCommandName.RUN.equals(command));
}
Aggregations