Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] project view 2000 #143

Merged
merged 47 commits into from
Feb 11, 2022
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
b6624d1
project view parser major refactor
abrams27 Jan 4, 2022
0f7e558
bazel_path section
abrams27 Jan 13, 2022
852988c
i love java 11
abrams27 Feb 3, 2022
61aa70b
style
abrams27 Feb 3, 2022
ee16b86
buildifier
abrams27 Feb 3, 2022
8a9c8b3
style v2
abrams27 Feb 3, 2022
b533512
debugger_address section
abrams27 Feb 4, 2022
d7aee20
i love java 11 more
abrams27 Feb 4, 2022
e41b98d
debugger_address section part 2
abrams27 Feb 7, 2022
4399fb3
splitter tests update
abrams27 Feb 7, 2022
7267553
splitter test fix
abrams27 Feb 7, 2022
04b1a02
java_path section
abrams27 Feb 7, 2022
bddcfe9
comments
abrams27 Feb 7, 2022
951a15b
project view usages
abrams27 Feb 7, 2022
0409866
scala.md fix
abrams27 Feb 8, 2022
4d39f7a
e2e test resources fix
abrams27 Feb 8, 2022
c1bc876
e2e test resources fix part 2
abrams27 Feb 8, 2022
b7e43ef
[e2e] cleaning environment before installation
abrams27 Feb 8, 2022
f358556
tests update
abrams27 Feb 8, 2022
3adc394
new mechanism usage
abrams27 Feb 8, 2022
c16ddab
fix
abrams27 Feb 8, 2022
37946a2
visibility and toString() impl
abrams27 Feb 8, 2022
c2bba8c
little test change
abrams27 Feb 8, 2022
ae91fee
style
abrams27 Feb 8, 2022
a378c39
another little test fix
abrams27 Feb 8, 2022
5385eed
targets visibility update
abrams27 Feb 9, 2022
db6e49c
i really love tests
abrams27 Feb 9, 2022
930b520
try > java exceptions
abrams27 Feb 9, 2022
563da63
builidier
abrams27 Feb 9, 2022
bc2bb24
visibility update
abrams27 Feb 9, 2022
54047c0
more visibility update
abrams27 Feb 10, 2022
c4180d9
format
abrams27 Feb 10, 2022
d7537f1
java docs
abrams27 Feb 10, 2022
a6561bc
compareByName -> hasName
abrams27 Feb 10, 2022
758b04c
instanceOf -> getInstance
abrams27 Feb 10, 2022
7b48ee9
split -> getRawSectionsForFileContent
abrams27 Feb 10, 2022
c09119d
anoter -> another_
abrams27 Feb 10, 2022
ce73db0
list -> stream
abrams27 Feb 10, 2022
d03410b
commons in ci
abrams27 Feb 10, 2022
736ae2b
getInstance -> createInstance
abrams27 Feb 10, 2022
b8d8f6b
readme update
abrams27 Feb 10, 2022
372e681
format
abrams27 Feb 10, 2022
f343b91
Update CHANGELOG.md
abrams27 Feb 10, 2022
09d9b0b
Update CHANGELOG.md
abrams27 Feb 10, 2022
daca08b
targets validation out
abrams27 Feb 10, 2022
1a4669d
bazel in install update
abrams27 Feb 10, 2022
9990ee3
even more tests
abrams27 Feb 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ jobs:
bazelrunner-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Run tests
run: bazel test //bazelrunner/...
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Run tests
run: bazel test //bazelrunner/...

projectview-test:
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ java_library(
deps = [
"@maven//:ch_epfl_scala_bsp4j",
"@maven//:com_google_guava_guava",
"@maven//:io_vavr_vavr",
abrams27 marked this conversation as resolved.
Show resolved Hide resolved
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.jetbrains.bsp.bazel.commons;

import com.google.common.io.CharSource;
import com.google.common.io.Files;
import io.vavr.control.Try;
import java.nio.charset.Charset;
import java.nio.file.Path;

public final class BetterFiles {

public static Try<String> tryReadFileContent(Path filePath) {
return Try.success(filePath)
.map(Path::toFile)
.map(file -> Files.asCharSource(file, Charset.defaultCharset()))
.mapTry(CharSource::read);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@ public class Constants {

public static final String SCALA_TEST_MAIN_CLASSES_ATTRIBUTE_NAME = "main_class";

public static final String DEFAULT_PROJECT_VIEW_FILE = "projectview.bazelproject";
public static final String PROJECT_VIEW_FILE_PATH = "projectview.bazelproject";
public static final String DEFAULT_PROJECT_VIEW_FILE_PATH =
".bazelbsp/default-projectview.bazelproject";
abrams27 marked this conversation as resolved.
Show resolved Hide resolved
}
14 changes: 14 additions & 0 deletions commons/src/test/java/org/jetbrains/bsp/bazel/commons/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("@rules_java//java:defs.bzl", "java_test")

java_test(
name = "BetterFilesTest",
size = "small",
srcs = ["BetterFilesTest.java"],
runtime_deps = [
"@maven//:junit_junit",
],
deps = [
"//commons/src/main/java/org/jetbrains/bsp/bazel/commons",
"@maven//:io_vavr_vavr",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.jetbrains.bsp.bazel.commons;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Paths;
import org.junit.Test;

public class BetterFilesTest {

@Test
public void shouldReturnFailureForNotExistingFile() {
// given
var filePath = Paths.get("file/doesnt/exist");

// when
var fileContent = BetterFiles.tryReadFileContent(filePath);

// then
assertTrue(fileContent.isFailure());
}

@Test
public void shouldParseExistingFile() throws IOException {
// given
var file = File.createTempFile("test", "file");
file.deleteOnExit();
var filePath = file.toPath();

var fileWriter = new FileWriter(file);

fileWriter.write("test content");
fileWriter.close();

// when
var fileContent = BetterFiles.tryReadFileContent(filePath);

// then
assertTrue(fileContent.isSuccess());
assertEquals("test content", fileContent.get());
}
}
2 changes: 2 additions & 0 deletions docs/BUMPVERSION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Bump Version

If you want to bump version (for example, before a release) you should do this in the following places:

- `central-sync/VERSION`
- `maven_coordinates` in `server/src/main/java/org/jetbrains/bsp/bazel/BUILD`
- `VERSION` in `commons/src/main/java/org/jetbrains/bsp/bazel/commons/Constants.java`
Expand Down
8 changes: 6 additions & 2 deletions docs/kotlin.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# BSP Kotlin
In order to fully have the experience to use BSP over kotlin, make sure that you're using at least version `0da862aaa11db26f6a113dcec5f6828bfd186ac9` of `rules_kotlin`. This will ensure

In order to fully have the experience to use BSP over kotlin, make sure that you're using at least
version `0da862aaa11db26f6a113dcec5f6828bfd186ac9` of `rules_kotlin`. This will ensure
that compilation diagnostics are being delivered to you.

```
rules_kotlin_version = "0da862aaa11db26f6a113dcec5f6828bfd186ac9"
rules_kotlin_sha = "6fda2451b9aaf78a8399e6e5d13c31c8ddc558e87de209a7cfd5ddc777ac7877"
Expand All @@ -15,4 +18,5 @@ kotlin_repositories() # if you want the default
kt_register_toolchains() # to use the default toolchain
```

This changes have not been merged yet and progress can be accompanied [here](https://github.com/bazelbuild/rules_kotlin/pull/359).
This changes have not been merged yet and progress can be
accompanied [here](https://github.com/bazelbuild/rules_kotlin/pull/359).
8 changes: 7 additions & 1 deletion docs/scala.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Toolchain Registration for Scala

In order to fully use Bazel BSP for Scala projects make sure to use at least version
``d8bce245a96ca9ab721324bc8daa984aa13fa0f7`` of `rules_scala`:
`d8bce245a96ca9ab721324bc8daa984aa13fa0f7` of `rules_scala`:

```
http_archive(
name = "io_bazel_rules_scala",
Expand All @@ -13,7 +15,9 @@ bazel_version(name = "bazel_version")
```

Make sure that your registered toolchain has Compilation Diagnostics enabled:

- At a BUILD file:

```
load("@io_bazel_rules_scala//scala:scala_toolchain.bzl", "scala_toolchain")

Expand All @@ -30,7 +34,9 @@ toolchain(
visibility = ["//visibility:public"],
)
```

- At the WORKSPACE file:

```
register_toolchains(
"<label_to_build_file>:diagnostics_reporter_toolchain"
Expand Down
9 changes: 7 additions & 2 deletions e2e/runTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ fi
bsp_path="$(bazel info bazel-bin)/server/src/main/java/org/jetbrains/bsp/bazel/bsp-install"
echo "Building done."

echo "Installing BSP..."
echo "Cleaning project directory..."
if [ "$#" -eq 2 ]; then
cd "$TEST_PROJECT_PATH" || exit
fi
$bsp_path
rm -r .bsp/ > /dev/null 2>&1
abrams27 marked this conversation as resolved.
Show resolved Hide resolved
rm -r .bazelbsp/ > /dev/null 2>&1
echo "Cleaning project directory done!"

echo "Installing BSP..."
$bsp_path || exit
echo "Installing done."
echo "Environment has been prepared!"
echo -e "-----------------------------------\n"
Expand Down
6 changes: 5 additions & 1 deletion install/src/main/java/org/jetbrains/bsp/bazel/install/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ load("@rules_java//java:defs.bzl", "java_library")
java_library(
name = "install",
srcs = glob(["*.java"]),
resources = ["aspects.bzl"],
resources = [
"aspects.bzl",
"default-projectview.bazelproject",
],
visibility = ["//install:__subpackages__"],
deps = [
"//commons",
"//projectview:parser",
"@maven//:ch_epfl_scala_bsp4j",
"@maven//:com_google_code_gson_gson",
"@maven//:com_google_guava_guava",
Expand Down
65 changes: 43 additions & 22 deletions install/src/main/java/org/jetbrains/bsp/bazel/install/Install.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.jetbrains.bsp.bazel.commons.Constants;
import org.jetbrains.bsp.bazel.projectview.model.ProjectView;
import org.jetbrains.bsp.bazel.projectview.parser.ProjectViewDefaultParserProvider;

public class Install {

Expand Down Expand Up @@ -53,15 +55,30 @@ public static void main(String[] args) throws IOException {
if (cmd.hasOption(HELP_SHORT_OPT)) {
formatter.printHelp(INSTALLER_BINARY_NAME, cliOptions);
} else {
addJavaBinary(cmd, argv);
Path rootDir = getRootDir(cmd);
Path bazelbspDir = createDir(rootDir, Constants.BAZELBSP_DIR_NAME);

Path defaultProjectViewFilePath = bazelbspDir.resolve("default-projectview.bazelproject");
Files.copy(
Install.class.getResourceAsStream("default-projectview.bazelproject"),
defaultProjectViewFilePath,
StandardCopyOption.REPLACE_EXISTING);

copyAspects(bazelbspDir);
createEmptyBuildFile(bazelbspDir);

var projectViewProvider = new ProjectViewDefaultParserProvider(rootDir);
// will be handled properly
var projectView = projectViewProvider.create().get();

addJavaBinary(cmd, argv, projectView);
addJavaClasspath(argv);
addDebuggerConnection(cmd, argv);
addDebuggerConnection(cmd, argv, projectView);
argv.add(SERVER_CLASS_NAME);
addBazelBinary(cmd, argv);
addBazelTargets(cmd, argv);

BspConnectionDetails details = createBspConnectionDetails(argv);
Path rootDir = getRootDir(cmd);
writeConfigurationFiles(rootDir, details);

System.out.println("Bazel BSP server installed in '" + rootDir.toAbsolutePath() + "'.");
Expand All @@ -70,7 +87,7 @@ public static void main(String[] args) throws IOException {
writer.println(e.getMessage());
formatter.printUsage(writer, 120, INSTALLER_BINARY_NAME, cliOptions);
hasError = true;
} catch (NoSuchElementException e) {
} catch (NoSuchElementException | IllegalStateException e) {
writer.println(e.getMessage());
hasError = true;
} finally {
Expand Down Expand Up @@ -105,9 +122,11 @@ private static void addBazelBinary(CommandLine cmd, List<String> argv) {
}
}

private static void addJavaBinary(CommandLine cmd, List<String> argv) {
private static void addJavaBinary(CommandLine cmd, List<String> argv, ProjectView projectView) {
if (cmd.hasOption(JAVA_SHORT_OPT)) {
argv.add(cmd.getOptionValue(JAVA_SHORT_OPT));
} else if (projectView.getJavaPath().isPresent()) {
argv.add(projectView.getJavaPath().get().getValue());
} else {
String javaHome = readSystemProperty("java.home");
argv.add(Paths.get(javaHome).resolve("bin").resolve("java").toString());
Expand All @@ -125,9 +144,13 @@ private static void addJavaClasspath(List<String> argv) {
argv.add(classpath);
}

private static void addDebuggerConnection(CommandLine cmd, List<String> argv) {
private static void addDebuggerConnection(
CommandLine cmd, List<String> argv, ProjectView projectView) {
if (cmd.hasOption(DEBUGGER_SHORT_OPT)) {
String debuggerAddress = cmd.getOptionValue(DEBUGGER_SHORT_OPT);
var debuggerAddress = cmd.getOptionValue(DEBUGGER_SHORT_OPT);
argv.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=" + debuggerAddress);
} else if (projectView.getDebuggerAddress().isPresent()) {
var debuggerAddress = projectView.getDebuggerAddress().get().getValue();
argv.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=" + debuggerAddress);
}
}
Expand Down Expand Up @@ -174,10 +197,6 @@ private static void writeBazelbspJson(Path bspDir, Object discoveryDetails) thro

private static void writeConfigurationFiles(Path rootDir, Object discoveryDetails)
throws IOException {
Path bazelbspDir = createDir(rootDir, Constants.BAZELBSP_DIR_NAME);
copyAspects(bazelbspDir);
createEmptyBuildFile(bazelbspDir);

Path bspDir = createDir(rootDir, Constants.BSP_DIR_NAME);
writeBazelbspJson(bspDir, discoveryDetails);
}
Expand All @@ -190,7 +209,9 @@ private static Options getCliOptions() {
.longOpt("java")
.hasArg()
.argName("path")
.desc("Use provided Java executable to run the BSP server")
.desc(
"Deprecated! Use project view file instead. "
+ "(Use provided Java executable to run the BSP server)")
.build();

cliOptions.addOption(java);
Expand All @@ -200,7 +221,9 @@ private static Options getCliOptions() {
.longOpt("bazel")
.hasArg()
.argName("path")
.desc("Make the BSP server use this Bazel executable")
.desc(
"Deprecated! Use project view file instead. "
+ "(Make the BSP server use this Bazel executable)")
.build();

cliOptions.addOption(bazel);
Expand All @@ -210,7 +233,7 @@ private static Options getCliOptions() {
.longOpt("debugger")
.hasArg()
.argName("address (e.g. '127.0.0.1:8000'")
.desc("Allow BSP server debugging")
.desc("Deprecated! Use project view file instead. (Allow BSP server debugging)")
.build();

cliOptions.addOption(debug);
Expand All @@ -221,8 +244,9 @@ private static Options getCliOptions() {
.hasArg()
.argName("path")
.desc(
"Path to directory where bazelbsp server should be setup. "
+ "Current directory will be used by default")
"Deprecated! Use project view file instead. "
+ "(Path to directory where bazelbsp server should be setup. "
+ "Current directory will be used by default)")
.build();

cliOptions.addOption(directory);
Expand All @@ -233,8 +257,9 @@ private static Options getCliOptions() {
.hasArg()
.argName("targets")
.desc(
"Name of the bazel's targets that the server should import. Targets can be"
+ "separated by a comma. The default is to import all targets (//...)")
"Deprecated! Use project view file instead. (Name of the bazel's targets that the"
+ " server should import. Targets can be separated by a comma. The default is"
+ " to import all targets (//...))")
.build();

cliOptions.addOption(targets);
Expand Down Expand Up @@ -264,8 +289,4 @@ private static String readSystemProperty(String name) {
}
return property;
}

private static String getCurrentDirectory() {
return System.getProperty("user.dir");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# this is default project configuration

# all targets in the project are included
targets:
//...
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

<name>Bazel BSP</name>
<description>
An implementation of the Build Server Protocol for Bazel. Allows clients such as IntelliJ to obtain build specific
An implementation of the Build Server Protocol for Bazel. Allows clients such as IntelliJ to obtain build
specific
information in order to improve the experience of users in the IDE.
</description>
<url>https://www.jetbrains.com/</url>
Expand Down
3 changes: 1 addition & 2 deletions projectview/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ java_library(
visibility = ["//visibility:public"],
exports = [
"//projectview/src/main/java/org/jetbrains/bsp/bazel/projectview/model",
"//projectview/src/main/java/org/jetbrains/bsp/bazel/projectview/model/sections",
"//projectview/src/main/java/org/jetbrains/bsp/bazel/projectview/model/sections/specific",
],
)

java_library(
name = "parser",
visibility = ["//visibility:public"],
exports = [
"//projectview/src/main/java/org/jetbrains/bsp/bazel/projectview/model",
"//projectview/src/main/java/org/jetbrains/bsp/bazel/projectview/parser",
],
)
Expand Down
Empty file added projectview/README.md
Empty file.