Skip to content

Commit

Permalink
Add bazel-sonatype target
Browse files Browse the repository at this point in the history
  • Loading branch information
SocksDevil committed May 24, 2021
1 parent d511fb5 commit b21b64d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 24 deletions.
9 changes: 0 additions & 9 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,9 +0,0 @@
load("@rules_jvm_external//:defs.bzl", "java_export")

java_export(
name = "bsp",
maven_coordinates = "org.jetbrains.bsp:bazel-bsp:0.1.0",
runtime_deps = [
"//main/src/org/jetbrains/bsp/bazel:bsp",
],
)
22 changes: 17 additions & 5 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ workspace(name = "bazel_bsp")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# For maven:
RULES_JVM_EXTERNAL_TAG = "3bb065efc666579fc2eb4e154f9b7b6bf334af27"
RULES_JVM_EXTERNAL_TAG = "4.0"
RULES_JVM_EXTERNAL_SHA = "31701ad93dbfe544d597dbe62c9a1fdd76d81d8a9150c2bf1ecf928ecdf97169"

http_archive(
name = "rules_jvm_external",
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
sha256 = RULES_JVM_EXTERNAL_SHA,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
)

Expand Down Expand Up @@ -118,9 +119,9 @@ load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repositories")
scala_repositories((
"2.12.11",
{
"scala_compiler": "3e892546b72ab547cb77de4d840bcfd05c853e73390fed7370a8f19acb0735a0",
"scala_library": "0b3d6fd42958ee98715ba2ec5fe221f4ca1e694d7c981b0ae0cd68e97baf6dce",
"scala_reflect": "6ba385b450a6311a15c918cf8688b9af9327c6104f0ecbd35933cfcd3095fe04",
"scala_compiler": "e901937dbeeae1715b231a7cfcd547a10d5bbf0dfb9d52d2886eae18b4d62ab6",
"scala_library": "dbfe77a3fc7a16c0c7cb6cb2b91fecec5438f2803112a744cb1b187926a138be",
"scala_reflect": "5f9e156aeba45ef2c4d24b303405db259082739015190b3b334811843bd90d6a",
},
))

Expand All @@ -139,3 +140,14 @@ local_repository(
name = "sample_repo",
path = "sample-repo",
)

BAZEL_SONATYPE_TAG = "8c4bfd2a4c03c212446da134e0be3ab1ac605289"
http_archive(
name = "bazel_sonatype",
strip_prefix = "bazel-sonatype-%s" % BAZEL_SONATYPE_TAG,
url = "https://github.com/JetBrains/bazel-sonatype/archive/%s.zip" % BAZEL_SONATYPE_TAG,
)

load("@bazel_sonatype//:defs.bzl", "sonatype_dependencies")

sonatype_dependencies()
33 changes: 31 additions & 2 deletions main/src/org/jetbrains/bsp/bazel/BUILD
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
java_library(
load("@bazel_sonatype//:defs.bzl", "sonatype_java_export")


sonatype_java_export(
name = "bsp",
srcs = glob(["*.java"]),
resources = ["aspects.bzl"],
tags = ["maven_coordinates=org.jetbrains.bsp:bazel-bsp:{pom_version}"],
maven_coordinates = "org.jetbrains.bsp:bazel-bsp:0.1.0",
maven_profile = "org.jetbrains",
visibility = ["//visibility:public"],
deps = [
"@com_google_protobuf//:protobuf_java",
"@googleapis//:google_devtools_build_v1_build_events_java_proto",
"@googleapis//:google_devtools_build_v1_publish_build_event_java_grpc",
"@googleapis//:google_devtools_build_v1_publish_build_event_java_proto",
"@googleapis//:google_devtools_build_v1_publish_build_event_proto",
"@io_bazel//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto",
"@io_bazel//src/main/protobuf:analysis_java_proto",
"@io_bazel//src/main/protobuf:build_java_proto",
"@io_bazel//third_party/grpc:grpc-jar",
"@io_bazel_rules_scala//src/protobuf/io/bazel/rules_scala:diagnostics_java_proto",
"@maven//:ch_epfl_scala_bsp4j",
"@maven//:com_google_code_gson_gson",
"@maven//:com_google_guava_guava",
"@maven//:org_eclipse_lsp4j_org_eclipse_lsp4j_jsonrpc",
"@maven//:org_eclipse_xtext_org_eclipse_xtext_xbase_lib",
],
)

java_binary(
name = "bsp-install",
srcs = glob(["*.java"]),
resources = ["aspects.bzl"],
main_class = "org.jetbrains.bsp.bazel.Install",
visibility = ["//visibility:public"],
deps = [
"@com_google_protobuf//:protobuf_java",
Expand Down
9 changes: 6 additions & 3 deletions main/src/org/jetbrains/bsp/bazel/Install.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;

public class Install {
public static void main(String[] args) throws IOException {
List<String> argv = new ArrayList<>();
argv.add(Paths.get(System.getProperty("java.home")).resolve("bin").resolve("java").toString());
argv.add("-classpath");
Splitter.on(":").splitToList(System.getProperty("java.class.path")).stream()
.map(elem -> Paths.get(elem).toAbsolutePath().toString())
.forEach(argv::add);
String classpath =
Splitter.on(":").splitToList(System.getProperty("java.class.path")).stream()
.map(elem -> Paths.get(elem).toAbsolutePath().toString())
.collect(Collectors.joining(":"));
argv.add(classpath);
argv.add("org.jetbrains.bsp.bazel.Server");
argv.add("bsp");
argv.add(findOnPath("bazel"));
Expand Down
3 changes: 1 addition & 2 deletions main/test/org/jetbrains/bsp/bazel/BazelBspServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import ch.epfl.scala.bsp.testkit.client.TestClient$;
import ch.epfl.scala.bsp4j.*;
import com.google.common.collect.Lists;
import scala.concurrent.ExecutionContext;

import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import scala.concurrent.ExecutionContext;

public class BazelBspServerTest {
private final String outDirectory = "bazel-out";
Expand Down
6 changes: 3 additions & 3 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ echo $dir
. "${dir}"/test_runner.sh

test_bsp_server() {
bazel run --define "maven_repo=file://$HOME/.m2/repository" //:bsp.publish
bsp_path="$(bazel info bazel-bin)/bsp-project.jar"
bazel build //main/src/org/jetbrains/bsp/bazel:bsp-install
bsp_path="$(bazel info bazel-bin)/main/src/org/jetbrains/bsp/bazel/bsp-install"
cd sample-repo
java -cp $bsp_path org.jetbrains.bsp.bazel.Install
$bsp_path
cd ..
bazel run //main/test/org/jetbrains/bsp/bazel:bsp-test
}
Expand Down

0 comments on commit b21b64d

Please sign in to comment.