71
71
import java .io .File ;
72
72
import java .io .IOException ;
73
73
import java .util .ArrayList ;
74
+ import java .util .Arrays ;
75
+ import java .util .Collections ;
74
76
import java .util .List ;
75
77
import javax .annotation .Nullable ;
78
+ import org .jetbrains .annotations .NotNull ;
76
79
77
80
/**
78
81
* A Blaze run configuration set up with an executor, program runner, and other settings, ready to
79
82
* be executed. This class creates a command line for Blaze and exposes debug connection information
80
83
* when using a debug executor.
81
84
*/
82
85
public final class BlazeJavaRunProfileState extends BlazeJavaDebuggableRunProfileState {
86
+
83
87
private static final Logger logger = Logger .getInstance (BlazeJavaRunProfileState .class );
84
88
private static final String JAVA_RUNFILES_ENV = "JAVA_RUNFILES=" ;
85
89
private static final String TEST_DIAGNOSTICS_OUTPUT_DIR_ENV = "TEST_DIAGNOSTICS_OUTPUT_DIR=" ;
@@ -261,6 +265,9 @@ static BlazeCommand.Builder getBlazeCommandBuilder(
261
265
if (isBinary ) {
262
266
command .addExeFlags (debugPortFlag (false , debugPort ));
263
267
} else {
268
+ List <String > debugFlags = getAdditionalBlazeDebugFlags ();
269
+ command .addBlazeFlags (debugFlags );
270
+
264
271
command .addBlazeFlags (BlazeFlags .JAVA_TEST_DEBUG );
265
272
command .addBlazeFlags (debugPortFlag (true , debugPort ));
266
273
}
@@ -273,6 +280,17 @@ static BlazeCommand.Builder getBlazeCommandBuilder(
273
280
return command ;
274
281
}
275
282
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
+
276
294
private ProcessHandler getScopedProcessHandler (
277
295
Project project , ImmutableList <String > command , WorkspaceRoot workspaceRoot )
278
296
throws ExecutionException {
0 commit comments