Skip to content

Commit 8bfa229

Browse files
liucijusWixBuildServer
authored andcommitted
Add env var to pass additional debug flags for Java
1 parent 39e048b commit 8bfa229

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

java/src/com/google/idea/blaze/java/run/BlazeJavaRunProfileState.java

+18
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,19 @@
7171
import java.io.File;
7272
import java.io.IOException;
7373
import java.util.ArrayList;
74+
import java.util.Arrays;
75+
import java.util.Collections;
7476
import java.util.List;
7577
import 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
*/
8285
public 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

Comments
 (0)