diff --git a/java/src/com/google/idea/blaze/java/run/BlazeJavaRunProfileState.java b/java/src/com/google/idea/blaze/java/run/BlazeJavaRunProfileState.java index 7ced8164183..4c5d61878c4 100644 --- a/java/src/com/google/idea/blaze/java/run/BlazeJavaRunProfileState.java +++ b/java/src/com/google/idea/blaze/java/run/BlazeJavaRunProfileState.java @@ -100,7 +100,6 @@ public void addKotlinxCoroutinesJavaAgent(String kotlinxCoroutinesJavaAgent) { protected ProcessHandler startProcess() throws ExecutionException { Project project = getConfiguration().getProject(); - BlazeCommand.Builder blazeCommand; BuildInvoker invoker = Blaze.getBuildSystemProvider(project) .getBuildSystem() @@ -110,39 +109,48 @@ protected ProcessHandler startProcess() throws ExecutionException { getExecutorType(), getConfiguration().getTargetKind()); BlazeTestUiSession testUiSession = null; - if (TargetKindUtil.isLocalTest(getConfiguration().getTargetKind()) - && !invoker.getCommandRunner().canUseCli() - && getExecutorType().isDebugType()) { - File downloadDir = getDownloadDir(); - WorkspaceRoot workspaceRoot = - new WorkspaceRoot( - new File(downloadDir, WorkspaceRoot.fromProject(project).directory().getName())); - ImmutableList.Builder commandBuilder = - ImmutableList.builder() - .add("env") - .add("-") - .add(JAVA_RUNFILES_ENV + downloadDir.getAbsolutePath()); + boolean debuggingLocalTest = TargetKindUtil.isLocalTest(getConfiguration().getTargetKind()) + && getExecutorType().isDebugType(); + if (debuggingLocalTest && !invoker.getCommandRunner().canUseCli()) { + return startProcessRunfilesCase(project); + } + return startProcessBazelCliCase(invoker, project, testUiSession); + } - // android_local_tests need additional env variables - if (TargetKindUtil.isAndroidLocalTest(getConfiguration().getTargetKind())) { - commandBuilder - .add(TEST_TIMEOUT_ENV + "300") - .add(TEST_SIZE_ENV + "medium") - .add( - TEST_DIAGNOSTICS_OUTPUT_DIR_ENV - + downloadDir.getAbsolutePath() - + TEST_DIAGNOSTICS_OUTPUT_DIR); - } + private ProcessHandler startProcessRunfilesCase(Project project) throws ExecutionException { + File downloadDir = getDownloadDir(); + WorkspaceRoot workspaceRoot = + new WorkspaceRoot( + new File(downloadDir, WorkspaceRoot.fromProject(project).directory().getName())); + ImmutableList.Builder commandBuilder = + ImmutableList.builder() + .add("env") + .add("-") + .add(JAVA_RUNFILES_ENV + downloadDir.getAbsolutePath()); + + // android_local_tests need additional env variables + if (TargetKindUtil.isAndroidLocalTest(getConfiguration().getTargetKind())) { commandBuilder - .add(getEntryPointScript()) - .add(debugPortFlag(false, getState(getConfiguration()).getDebugPortState().port)); - if (TargetKindUtil.isAndroidLocalTest(getConfiguration().getTargetKind()) - && BlazeCommandRunnerExperiments.USE_SINGLEJAR_FOR_DEBUGGING.getValue()) { - commandBuilder.add("--singlejar"); - } - return getScopedProcessHandler(project, commandBuilder.build(), workspaceRoot); + .add(TEST_TIMEOUT_ENV + "300") + .add(TEST_SIZE_ENV + "medium") + .add( + TEST_DIAGNOSTICS_OUTPUT_DIR_ENV + + downloadDir.getAbsolutePath() + + TEST_DIAGNOSTICS_OUTPUT_DIR); } + commandBuilder + .add(getEntryPointScript()) + .add(debugPortFlag(false, getState(getConfiguration()).getDebugPortState().port)); + if (TargetKindUtil.isAndroidLocalTest(getConfiguration().getTargetKind()) + && BlazeCommandRunnerExperiments.USE_SINGLEJAR_FOR_DEBUGGING.getValue()) { + commandBuilder.add("--singlejar"); + } + return getScopedProcessHandler(project, commandBuilder.build(), workspaceRoot); + } + private ProcessHandler startProcessBazelCliCase(BuildInvoker invoker, Project project, BlazeTestUiSession testUiSession) + throws ExecutionException { + BlazeCommand.Builder blazeCommand; try (BuildResultHelper buildResultHelper = invoker.createBuildResultHelper()) { if (useTestUi() && BlazeTestEventsHandler.targetsSupported(project, getConfiguration().getTargets())) { @@ -159,24 +167,24 @@ && getExecutorType().isDebugType()) { if (testUiSession != null) { blazeCommand = getBlazeCommandBuilder( - project, - getConfiguration(), - testUiSession.getBlazeFlags(), - getExecutorType(), - kotlinxCoroutinesJavaAgent); + project, + getConfiguration(), + testUiSession.getBlazeFlags(), + getExecutorType(), + kotlinxCoroutinesJavaAgent); final BlazeTestUiSession finalTestUiSession = testUiSession; setConsoleBuilder( new TextConsoleBuilderImpl(project) { @Override protected ConsoleView createConsole() { return SmRunnerUtils.getConsoleView( - project, getConfiguration(), getEnvironment().getExecutor(), finalTestUiSession); + project, getConfiguration(), getEnvironment().getExecutor(), finalTestUiSession); } }); } else { blazeCommand = getBlazeCommandBuilder( - project, + project, getConfiguration(), ImmutableList.of(), getExecutorType(), @@ -184,7 +192,7 @@ protected ConsoleView createConsole() { } addConsoleFilters( ToolWindowTaskIssueOutputFilter.createWithDefaultParsers( - project, + project, WorkspaceRoot.fromProject(project), BlazeInvocationContext.ContextType.RunConfiguration));