Search in sources :

Example 21 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class BlazeCoverageProgramRunner method doExecute.

@Nullable
@Override
protected RunContentDescriptor doExecute(RunProfileState profile, ExecutionEnvironment env) throws ExecutionException {
    WorkspaceRoot root = WorkspaceRoot.fromProjectSafe(env.getProject());
    if (root == null) {
        return null;
    }
    RunContentDescriptor result = super.doExecute(profile, env);
    if (result == null) {
        return null;
    }
    // remove any old copy of the coverage data
    // retrieve coverage data and copy locally
    BlazeCommandRunConfiguration blazeConfig = (BlazeCommandRunConfiguration) env.getRunProfile();
    BlazeCoverageEnabledConfiguration config = (BlazeCoverageEnabledConfiguration) CoverageEnabledConfiguration.getOrCreate(blazeConfig);
    String coverageFilePath = config.getCoverageFilePath();
    File blazeOutputFile = CoverageUtils.getOutputFile(root);
    ProcessHandler handler = result.getProcessHandler();
    if (handler != null) {
        ProcessHandler wrappedHandler = new ProcessHandlerWrapper(handler, exitCode -> copyCoverageOutput(blazeOutputFile, coverageFilePath, exitCode));
        CoverageHelper.attachToProcess(blazeConfig, wrappedHandler, env.getRunnerSettings());
    }
    return result;
}
Also used : RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessHandler(com.intellij.execution.process.ProcessHandler) WorkspaceRoot(com.google.idea.blaze.base.model.primitives.WorkspaceRoot) File(java.io.File) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Nullable(javax.annotation.Nullable)

Example 22 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class BlazeJavaAbstractTestCaseConfigurationProducer method chooseSubclass.

@VisibleForTesting
static void chooseSubclass(ConfigurationFromContext configuration, ConfigurationContext context, Runnable startRunnable) {
    RunConfiguration config = configuration.getConfiguration();
    if (!(config instanceof BlazeCommandRunConfiguration)) {
        return;
    }
    AbstractTestLocation location = locationFromConfiguration(configuration);
    if (location == null) {
        return;
    }
    SubclassTestChooser.chooseSubclass(context, location.abstractClass, (psiClass) -> {
        if (psiClass != null) {
            setupContext((BlazeCommandRunConfiguration) config, psiClass, location.method);
        }
        startRunnable.run();
    });
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 23 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class BlazeJavaDebuggerRunner method canRun.

@Override
public boolean canRun(final String executorId, final RunProfile profile) {
    if (!executorId.equals(DefaultDebugExecutor.EXECUTOR_ID) || !(profile instanceof BlazeCommandRunConfiguration)) {
        return false;
    }
    BlazeCommandRunConfiguration configuration = (BlazeCommandRunConfiguration) profile;
    Kind kind = configuration.getTargetKind();
    if (kind == null || !BlazeJavaRunConfigurationHandlerProvider.supportsKind(kind)) {
        return false;
    }
    return canDebug(configuration.getHandler().getCommandName());
}
Also used : Kind(com.google.idea.blaze.base.model.primitives.Kind) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)

Example 24 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class TestRecorderBlazeCommandRunConfigurationTest method testLaunchActivityClass.

@Test
public void testLaunchActivityClass() {
    BlazeCommandRunConfiguration blazeConfiguration = BlazeCommandRunConfigurationType.getInstance().getFactory().createTemplateConfiguration(getProject());
    blazeConfiguration.setTarget(Label.create("//label:android_binary_rule"));
    BlazeAndroidBinaryRunConfigurationState configurationState = ((BlazeAndroidBinaryRunConfigurationHandler) blazeConfiguration.getHandler()).getState();
    configurationState.setMode(BlazeAndroidBinaryRunConfigurationState.LAUNCH_SPECIFIC_ACTIVITY);
    configurationState.setActivityClass("MyAppMainActivity");
    TestRecorderRunConfigurationProxy proxy = TestRecorderRunConfigurationProxy.getInstance(blazeConfiguration);
    assertThat(proxy).isNotNull();
    assertThat(proxy.getLaunchActivityClass()).isEqualTo("MyAppMainActivity");
}
Also used : BlazeAndroidBinaryRunConfigurationHandler(com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationHandler) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) BlazeAndroidBinaryRunConfigurationState(com.google.idea.blaze.android.run.binary.BlazeAndroidBinaryRunConfigurationState) TestRecorderRunConfigurationProxy(com.google.gct.testrecorder.run.TestRecorderRunConfigurationProxy) Test(org.junit.Test)

Example 25 with BlazeCommandRunConfiguration

use of com.google.idea.blaze.base.run.BlazeCommandRunConfiguration in project intellij by bazelbuild.

the class BlazePyTestConfigurationProducerTest method testProducedFromTestCase.

@Test
public void testProducedFromTestCase() {
    PsiFile pyFile = createAndIndexFile(new WorkspacePath("py/test/unittest.py"), "class UnitTest(googletest.TestCase):", "  def testSomething():", "    return");
    MockBlazeProjectDataBuilder builder = MockBlazeProjectDataBuilder.builder(workspaceRoot);
    builder.setTargetMap(TargetMapBuilder.builder().addTarget(TargetIdeInfo.builder().setKind("py_test").setLabel("//py/test:unittests").addSource(sourceRoot("py/test/unittest.py")).build()).build());
    registerProjectService(BlazeProjectDataManager.class, new MockBlazeProjectDataManager(builder.build()));
    PyFunction function = PsiUtils.findFirstChildOfClassRecursive(pyFile, PyFunction.class);
    assertThat(function).isNotNull();
    ConfigurationContext context = createContextFromPsi(function);
    List<ConfigurationFromContext> configurations = context.getConfigurationsFromContext();
    assertThat(configurations).hasSize(1);
    ConfigurationFromContext fromContext = configurations.get(0);
    assertThat(fromContext.isProducedBy(BlazePyTestConfigurationProducer.class)).isTrue();
    assertThat(fromContext.getConfiguration()).isInstanceOf(BlazeCommandRunConfiguration.class);
    BlazeCommandRunConfiguration config = (BlazeCommandRunConfiguration) fromContext.getConfiguration();
    assertThat(config.getTarget()).isEqualTo(TargetExpression.fromStringSafe("//py/test:unittests"));
    assertThat(getTestFilterContents(config)).isEqualTo("--test_filter=UnitTest.testSomething");
    assertThat(getCommandType(config)).isEqualTo(BlazeCommandName.TEST);
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) PyFunction(com.jetbrains.python.psi.PyFunction) MockBlazeProjectDataBuilder(com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) PsiFile(com.intellij.psi.PsiFile) MockBlazeProjectDataManager(com.google.idea.blaze.base.model.MockBlazeProjectDataManager) BlazeCommandRunConfiguration(com.google.idea.blaze.base.run.BlazeCommandRunConfiguration) Test(org.junit.Test)

Aggregations

BlazeCommandRunConfiguration (com.google.idea.blaze.base.run.BlazeCommandRunConfiguration)52 Test (org.junit.Test)36 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)33 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)29 PsiFile (com.intellij.psi.PsiFile)26 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)24 MockBlazeProjectDataBuilder (com.google.idea.blaze.base.model.MockBlazeProjectDataBuilder)23 MockBlazeProjectDataManager (com.google.idea.blaze.base.model.MockBlazeProjectDataManager)23 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)9 BlazeCommandRunConfigurationCommonState (com.google.idea.blaze.base.run.state.BlazeCommandRunConfigurationCommonState)8 PsiClass (com.intellij.psi.PsiClass)8 PsiMethod (com.intellij.psi.PsiMethod)5 StringLiteral (com.google.idea.blaze.base.lang.buildfile.psi.StringLiteral)4 PsiDirectory (com.intellij.psi.PsiDirectory)4 Nullable (javax.annotation.Nullable)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)3 BlazeBuildFileRunConfigurationProducer (com.google.idea.blaze.base.run.producers.BlazeBuildFileRunConfigurationProducer)3 File (java.io.File)3 ScalaFile (org.jetbrains.plugins.scala.lang.psi.api.ScalaFile)3 BlazeCommandName (com.google.idea.blaze.base.command.BlazeCommandName)2