From c66358e0e847bfdd5c35c98adf7e2adb6460a84f Mon Sep 17 00:00:00 2001 From: Marcin Abramowicz Date: Wed, 20 Mar 2024 17:22:20 +0000 Subject: [PATCH] [fix] ijars are included in libraries even better now it works! does it work? Merge-request: BAZEL-MR-941 Merged-by: Marcin Abramowicz --- aspects/rules/jvm/jvm_info.bzl | 14 +++++++++----- .../kotlin/org/jetbrains/bsp/WorkspaceLibraries.kt | 1 + .../bsp/bazel/server/sync/BspProjectMapper.kt | 6 ++++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/aspects/rules/jvm/jvm_info.bzl b/aspects/rules/jvm/jvm_info.bzl index 08d6bcee9..e997cb644 100644 --- a/aspects/rules/jvm/jvm_info.bzl +++ b/aspects/rules/jvm/jvm_info.bzl @@ -17,13 +17,17 @@ def map_with_resolve_files(f, xs): return results, resolve_files def get_interface_jars(output): - if hasattr(output, "compile_jar") and output.compile_jar: - return [output.compile_jar] - elif hasattr(output, "ijar") and output.ijar: + if hasattr(output, "ijar") and output.ijar: return [output.ijar] else: return [] +def get_binary_jars(output): + if output.class_jar: + return [output.class_jar] + else: + return [] + def get_source_jars(output): if hasattr(output, "source_jars"): source_jars = output.source_jars @@ -74,10 +78,10 @@ def get_generated_jars(provider): return [], [] def to_jvm_outputs(output): - if output == None or output.class_jar == None: + if output == None: return None - binary_jars = [output.class_jar] + binary_jars = get_binary_jars(output) interface_jars = get_interface_jars(output) source_jars = get_source_jars(output) output = struct( diff --git a/protocol/src/main/kotlin/org/jetbrains/bsp/WorkspaceLibraries.kt b/protocol/src/main/kotlin/org/jetbrains/bsp/WorkspaceLibraries.kt index 54cf5885e..ca9efa4a2 100644 --- a/protocol/src/main/kotlin/org/jetbrains/bsp/WorkspaceLibraries.kt +++ b/protocol/src/main/kotlin/org/jetbrains/bsp/WorkspaceLibraries.kt @@ -5,6 +5,7 @@ import ch.epfl.scala.bsp4j.BuildTargetIdentifier public data class LibraryItem( val id: BuildTargetIdentifier, val dependencies: List, + val ijars: List, val jars: List, val sourceJars: List, ) diff --git a/server/src/main/kotlin/org/jetbrains/bsp/bazel/server/sync/BspProjectMapper.kt b/server/src/main/kotlin/org/jetbrains/bsp/bazel/server/sync/BspProjectMapper.kt index 88b0f3446..43f5f1594 100644 --- a/server/src/main/kotlin/org/jetbrains/bsp/bazel/server/sync/BspProjectMapper.kt +++ b/server/src/main/kotlin/org/jetbrains/bsp/bazel/server/sync/BspProjectMapper.kt @@ -75,6 +75,7 @@ import org.jetbrains.bsp.bazel.workspacecontext.WorkspaceContextProvider import java.net.URI import java.nio.file.Path import java.nio.file.Paths +import kotlin.io.path.exists import kotlin.io.path.name import kotlin.io.path.relativeToOrNull import kotlin.io.path.toPath @@ -122,8 +123,9 @@ class BspProjectMapper( LibraryItem( id = BuildTargetIdentifier(it.label), dependencies = it.dependencies.map { dep -> BuildTargetIdentifier(dep) }, - jars = it.outputs.map { uri -> uri.toString() }, - sourceJars = it.sources.map { uri -> uri.toString() }, + ijars = it.interfaceJars.filter { o -> o.toPath().exists() }.map { o -> o.toString() }, + jars = it.outputs.filter { o -> o.toPath().exists() }.map { uri -> uri.toString() }, + sourceJars = it.sources.filter { o -> o.toPath().exists() }.map { uri -> uri.toString() }, ) } return WorkspaceLibrariesResult(libraries)