Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
[fix] Fix 'this.bepLogger is null' error on project sync
Browse files Browse the repository at this point in the history
Merge-request: BAZEL-MR-430
Merged-by: Tomasz Pasternak <Tomasz.Pasternak@jetbrains.com>
  • Loading branch information
tpasternak authored and qodana-bot committed Aug 7, 2023
1 parent 8e4cff4 commit 956bc00
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
### Fixes 🛠️
- Now we report the failure of the whole test target and binaries are reporting stdout.
- Aspects don't throw an exception for kotlin rules if an attr doesn't exist.

- Fix 'this.bepLogger is null' error on project sync

## [2.7.2]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
import java.time.Duration;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -18,9 +19,10 @@ public class BepLogger extends BspClientLogger {

private final BspClientLogger bspClientLogger;

public BepLogger(BuildClient client, String originId) {
public BepLogger(BuildClient client, Optional<String> originId) {
super();
bspClientLogger = new BspClientLogger().withOriginId(originId);
bspClientLogger =
originId.map(oid -> new BspClientLogger().withOriginId(oid)).orElse(new BspClientLogger());
bspClientLogger.initialize(client);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.bsp.bazel.commons.Constants;
Expand All @@ -39,23 +38,27 @@ public class BepServer extends PublishBuildEventGrpc.PublishBuildEventImplBase {
private static final Logger LOGGER = LogManager.getLogger(BepServer.class);

private final BuildClient bspClient;

private final Optional<String> originId;
private BepLogger bepLogger;

private final Deque<Map.Entry<TaskId, String>> startedEvents = new ArrayDeque<>();
private final Deque<Map.Entry<TaskId, Optional<String>>> startedEvents = new ArrayDeque<>();
private final DiagnosticsService diagnosticsService;
private BepOutputBuilder bepOutputBuilder = new BepOutputBuilder();

public BepServer(BuildClient bspClient, DiagnosticsService diagnosticsService) {
public BepServer(
BuildClient bspClient, DiagnosticsService diagnosticsService, Optional<String> originId) {
this.bspClient = bspClient;
this.diagnosticsService = diagnosticsService;
this.originId = originId;
this.bepLogger = new BepLogger(bspClient, originId);
}

public static BepServer newBepServer(
BuildClient client,
Path workspaceRoot,
Map<String, Set<TextDocumentIdentifier>> hasAnyProblems) {
return new BepServer(client, new DiagnosticsService(workspaceRoot, hasAnyProblems));
Map<String, Set<TextDocumentIdentifier>> hasAnyProblems,
Optional<String> originId) {
return new BepServer(client, new DiagnosticsService(workspaceRoot, hasAnyProblems), originId);
}

public static NettyServerBuilder nettyServerBuilder() {
Expand Down Expand Up @@ -124,8 +127,6 @@ private void processBuildMetrics(BuildEventStreamProtos.BuildEvent event) {
private void consumeBuildStartedEvent(BuildEventStreamProtos.BuildStarted buildStarted) {
bepOutputBuilder = new BepOutputBuilder();
TaskId taskId = new TaskId(buildStarted.getUuid());
String originId = extractOriginIdFromOptions(buildStarted.getOptionsDescription());
bepLogger = new BepLogger(bspClient, originId);
TaskStartParams startParams = new TaskStartParams(taskId);
startParams.setEventTime(buildStarted.getStartTimeMillis());

Expand Down Expand Up @@ -168,15 +169,6 @@ private void processActionCompletedEvent(BuildEventStreamProtos.BuildEvent event
}
}

private String extractOriginIdFromOptions(String optionsDescription) {
Pattern pattern = Pattern.compile("(?<=ORIGINID=)(.*?)(?=')");
Matcher matcher = pattern.matcher(optionsDescription);
if (matcher.find()) {
return matcher.group();
}
return null;
}

private void consumeActionCompletedEvent(BuildEventStreamProtos.BuildEvent event) {
var label = event.getId().getActionCompleted().getLabel();
var actionEvent = event.getAction();
Expand Down Expand Up @@ -206,7 +198,7 @@ private void consumeUnsuccessfulActionCompletedEvent(
private void processDiagnosticText(String stdErrText, String targetLabel) {
var events =
diagnosticsService.extractDiagnostics(
stdErrText, targetLabel, startedEvents.getFirst().getValue());
stdErrText, targetLabel, startedEvents.getFirst().getValue().orElse(null));
events.forEach(bspClient::onBuildPublishDiagnostics);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
Expand Down Expand Up @@ -39,7 +40,9 @@ public BepBuildResult buildTargetsWithBep(
TargetsSpec targetSpecs,
Seq<String> extraFlags,
String originId) {
var bepServer = BepServer.newBepServer(client, workspaceRoot, hasAnyProblems);
var bepServer =
BepServer.newBepServer(
client, workspaceRoot, hasAnyProblems, Optional.ofNullable(originId));
var executor = Executors.newFixedThreadPool(4, threadFactory());
var nettyServer =
BepServer.nettyServerBuilder().addService(bepServer).executor(executor).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.jetbrains.bsp.bazel.server.sync.model.Module
import org.jetbrains.bsp.bazel.server.sync.model.Tag
import org.jetbrains.bsp.bazel.workspacecontext.TargetsSpec
import org.jetbrains.bsp.bazel.workspacecontext.WorkspaceContextProvider
import java.util.Optional

class ExecuteService(
private val compilationManager: BazelBspCompilationManager,
Expand All @@ -39,7 +40,7 @@ class ExecuteService(
private val hasAnyProblems: Map<String, Set<TextDocumentIdentifier>>
) {
private fun <T> withBepServer(body : (Server) -> T) :T {
val server = BepServer.newBepServer(compilationManager.client, compilationManager.workspaceRoot, hasAnyProblems)
val server = BepServer.newBepServer(compilationManager.client, compilationManager.workspaceRoot, hasAnyProblems, Optional.empty())
val nettyServer = BepServer.nettyServerBuilder().addService(server).build()
nettyServer.start()
try {
Expand Down Expand Up @@ -125,7 +126,8 @@ class ExecuteService(

fun clean(cancelChecker: CancelChecker, params: CleanCacheParams?): CleanCacheResult {
val bazelResult = withBepServer { server ->
bazelRunner.commandBuilder().clean().executeBazelBesCommand(bazelBesPort = server.port).waitAndGetResult(cancelChecker)
bazelRunner.commandBuilder().clean()
.executeBazelBesCommand(bazelBesPort = server.port).waitAndGetResult(cancelChecker)
}
return CleanCacheResult(bazelResult.stdout, true)
}
Expand Down

0 comments on commit 956bc00

Please sign in to comment.