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

Commit

Permalink
[fix] add support for Scala SDK provided by rules_jvm_external (#403)
Browse files Browse the repository at this point in the history
* Add support for Scala SDK provided by rules_jvm_external

Updated the regex used for determing Scala SDK versions to
allow the jars to optionally include a 'processed_' prefix.
This allows jars provided by rules_jvm_external to be
properly matched by ScalaSdkResolver.

* Run formatter on BepLogger.java

* Update CHANGELOG

---------

Co-authored-by: Marcin Abramowicz <44381959+abrams27@users.noreply.github.com>
  • Loading branch information
dorranh and abrams27 authored Jun 19, 2023
1 parent 22b7951 commit 73b5bcc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 42 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
### Fixes 🛠️
- Collect scalac options from the toolchain
| [#433](https://github.com/JetBrains/bazel-bsp/pull/433)
- Add support for Scala SDK provided by rules_jvm_external
| [#403](https://github.com/JetBrains/bazel-bsp/pull/403)

### Performance
- Reduce peak memory footprint
Expand Down Expand Up @@ -42,7 +44,6 @@
- Fixup failed target names from BEP in bazel 6+ in the bloop mode.
| [#402](https://github.com/JetBrains/bazel-bsp/pull/402)


## [2.6.1]

### SECURITY 🚨
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,58 @@

import ch.epfl.scala.bsp4j.BuildClient;
import com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos;
import java.time.Duration;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jetbrains.bsp.bazel.commons.Format;
import org.jetbrains.bsp.bazel.logger.BspClientLogger;

import java.time.Duration;
import java.util.Arrays;
import java.util.stream.Collectors;

public class BepLogger extends BspClientLogger {

private static final Logger LOGGER = LogManager.getLogger(BspClientLogger.class);
private static final Logger LOGGER = LogManager.getLogger(BspClientLogger.class);

private static final String ADDITIONAL_MESSAGE_PREFIX = " ";
private static final String ADDITIONAL_MESSAGE_PREFIX = " ";

private final BspClientLogger bspClientLogger;
private final BspClientLogger bspClientLogger;

public BepLogger(BuildClient client, String originId) {
super();
bspClientLogger = new BspClientLogger().withOriginId(originId);
bspClientLogger.initialize(client);
}

private BepLogger(BspClientLogger bspClientLogger) {
super();
this.bspClientLogger = bspClientLogger;
}
public BepLogger(BuildClient client, String originId) {
super();
bspClientLogger = new BspClientLogger().withOriginId(originId);
bspClientLogger.initialize(client);
}

@Override
public BepLogger withOriginId(String originId) {
return new BepLogger(super.withOriginId(originId));
}
private BepLogger(BspClientLogger bspClientLogger) {
super();
this.bspClientLogger = bspClientLogger;
}

public void onProgress(BuildEventStreamProtos.Progress progress) {
String output = progress.getStderr();
if (!output.isBlank()) {
logMessage(output);
LOGGER.info(output);
}
}

public void onBuildMetrics(BuildEventStreamProtos.BuildMetrics metrics) {
// TODO: We potentially might want to obtain more metrics data than just running time
Duration duration = Duration.ofMillis(metrics.getTimingMetrics().getWallTimeInMs());
logMessage(String.format("Command completed in %s", Format.duration(duration)));
}
@Override
public BepLogger withOriginId(String originId) {
return new BepLogger(super.withOriginId(originId));
}

private void logMessage(String output) {
bspClientLogger.message(output);
String filteredOutput = Arrays.stream(output.split("\n"))
.filter(element -> !element.startsWith(ADDITIONAL_MESSAGE_PREFIX))
.collect(Collectors.joining("\n"));
LOGGER.info(filteredOutput);
public void onProgress(BuildEventStreamProtos.Progress progress) {
String output = progress.getStderr();
if (!output.isBlank()) {
logMessage(output);
LOGGER.info(output);
}
}

public void onBuildMetrics(BuildEventStreamProtos.BuildMetrics metrics) {
// TODO: We potentially might want to obtain more metrics data than just running time
Duration duration = Duration.ofMillis(metrics.getTimingMetrics().getWallTimeInMs());
logMessage(String.format("Command completed in %s", Format.duration(duration)));
}

private void logMessage(String output) {
bspClientLogger.message(output);
String filteredOutput =
Arrays.stream(output.split("\n"))
.filter(element -> !element.startsWith(ADDITIONAL_MESSAGE_PREFIX))
.collect(Collectors.joining("\n"));
LOGGER.info(filteredOutput);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ class ScalaSdkResolver(private val bazelPathsResolver: BazelPathsResolver) {
0
}
private val VERSION_PATTERN =
Pattern.compile("scala-(?:library|compiler|reflect)-([.\\d]+)\\.jar")
Pattern.compile("(?:processed_)?scala-(?:library|compiler|reflect)-([.\\d]+)\\.jar")
}
}

0 comments on commit 73b5bcc

Please sign in to comment.