Allow tests to inject their own BugReporter object. This allows Java integration tests to trigger sending bug reports without crashing, and to assert that those reports were actually generated.
@@ -34,6 +34,7 @@ import com.google.devtools.build.lib.analysis.config.BuildOptions;
import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactory;
import com.google.devtools.build.lib.analysis.test.CoverageReportActionFactory;
import com.google.devtools.build.lib.bugreport.BugReport;
+import com.google.devtools.build.lib.bugreport.BugReporter;
import com.google.devtools.build.lib.clock.BlazeClock;
import com.google.devtools.build.lib.clock.Clock;
import com.google.devtools.build.lib.events.Event;
@@ -160,6 +161,7 @@ public final class BlazeRuntime implements BugReport.BlazeRuntimeInterface {
private final QueryRuntimeHelper.Factory queryRuntimeHelperFactory;
@Nullable private final InvocationPolicy moduleInvocationPolicy;
private final SubscriberExceptionHandler eventBusExceptionHandler;
+ private final BugReporter bugReporter;
private final String productName;
private final BuildEventArtifactUploaderFactoryMap buildEventArtifactUploaderFactoryMap;
private final ActionKeyContext actionKeyContext;
@@ -184,6 +186,7 @@ public final class BlazeRuntime implements BugReport.BlazeRuntimeInterface {
OptionsParsingResult startupOptionsProvider,
Iterable<BlazeModule> blazeModules,
SubscriberExceptionHandler eventBusExceptionHandler,
+ BugReporter bugReporter,
ProjectFile.Provider projectFileProvider,
QueryRuntimeHelper.Factory queryRuntimeHelperFactory,
InvocationPolicy moduleInvocationPolicy,
@@ -212,6 +215,7 @@ public final class BlazeRuntime implements BugReport.BlazeRuntimeInterface {
this.queryFunctions = queryFunctions;
this.queryOutputFormatters = queryOutputFormatters;
this.eventBusExceptionHandler = eventBusExceptionHandler;
+ this.bugReporter = bugReporter;
CommandNameCache.CommandNameCacheInstance.INSTANCE.setCommandNameCache(
new CommandNameCacheImpl(getCommandMap()));
@@ -714,6 +718,15 @@ public final class BlazeRuntime implements BugReport.BlazeRuntimeInterface {
return clock;
}
+ /**
+ * Returns the {@link BugReporter} that should be used when filing bug reports, if possible. Use
+ * this in preference to {@link BugReport#sendBugReport} for ease of testing codepaths that file
+ * bug reports.
+ */
+ public BugReporter getBugReporter() {
+ return bugReporter;
+ }
+
public OptionsParsingResult getStartupOptionsProvider() {
return startupOptionsProvider;
}
@@ -1459,6 +1472,7 @@ public final class BlazeRuntime implements BugReport.BlazeRuntimeInterface {
private UUID instanceId;
private String productName;
private ActionKeyContext actionKeyContext;
+ private BugReporter bugReporter = BugReporter.defaultInstance();
public BlazeRuntime build() throws AbruptExitException {
Preconditions.checkNotNull(productName);
@@ -1561,6 +1575,7 @@ public final class BlazeRuntime implements BugReport.BlazeRuntimeInterface {
startupOptionsProvider,
ImmutableList.copyOf(blazeModules),
eventBusExceptionHandler,
+ bugReporter,
projectFileProvider,
queryRuntimeHelperFactory,
serverBuilder.getInvocationPolicy(),
@@ -1617,6 +1632,12 @@ public final class BlazeRuntime implements BugReport.BlazeRuntimeInterface {
return this;
}
+ @VisibleForTesting
+ public Builder setBugReporter(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ return this;
+ }
+
public Builder setActionKeyContext(ActionKeyContext actionKeyContext) {
this.actionKeyContext = actionKeyContext;
return this;
