7171import java .io .File ;
7272import java .io .IOException ;
7373import java .util .ArrayList ;
74+ import java .util .Arrays ;
75+ import java .util .Collections ;
7476import java .util .List ;
7577import javax .annotation .Nullable ;
78+ import org .jetbrains .annotations .NotNull ;
7679
7780/**
7881 * A Blaze run configuration set up with an executor, program runner, and other settings, ready to
7982 * be executed. This class creates a command line for Blaze and exposes debug connection information
8083 * when using a debug executor.
8184 */
8285public final class BlazeJavaRunProfileState extends BlazeJavaDebuggableRunProfileState {
86+
8387 private static final Logger logger = Logger .getInstance (BlazeJavaRunProfileState .class );
8488 private static final String JAVA_RUNFILES_ENV = "JAVA_RUNFILES=" ;
8589 private static final String TEST_DIAGNOSTICS_OUTPUT_DIR_ENV = "TEST_DIAGNOSTICS_OUTPUT_DIR=" ;
@@ -261,6 +265,9 @@ static BlazeCommand.Builder getBlazeCommandBuilder(
261265 if (isBinary ) {
262266 command .addExeFlags (debugPortFlag (false , debugPort ));
263267 } else {
268+ List <String > debugFlags = getAdditionalBlazeDebugFlags ();
269+ command .addBlazeFlags (debugFlags );
270+
264271 command .addBlazeFlags (BlazeFlags .JAVA_TEST_DEBUG );
265272 command .addBlazeFlags (debugPortFlag (true , debugPort ));
266273 }
@@ -273,6 +280,17 @@ static BlazeCommand.Builder getBlazeCommandBuilder(
273280 return command ;
274281 }
275282
283+ @ NotNull
284+ private static List <String > getAdditionalBlazeDebugFlags () {
285+ // Allow adding additional flags when running in debug mode.
286+ // For example, it allows to disable remote execution when debugging.
287+ String additionalDebugFlags = System .getenv ("INTELLIJ_BAZEL_JAVA_DEBUG_FLAGS" );
288+ if (additionalDebugFlags != null ) {
289+ return Arrays .asList (additionalDebugFlags .trim ().split ("\\ s+" ));
290+ }
291+ return Collections .emptyList ();
292+ }
293+
276294 private ProcessHandler getScopedProcessHandler (
277295 Project project , ImmutableList <String > command , WorkspaceRoot workspaceRoot )
278296 throws ExecutionException {
0 commit comments