-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example with a java library that doesn't contain any sources
Merge-request: BAZEL-MR-1033 Merged-by: Tomasz Pasternak <Tomasz.Pasternak@jetbrains.com>
- Loading branch information
1 parent
2483bab
commit ac69b36
Showing
3 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
load(":generator.bzl", "animals_library_source") | ||
|
||
java_library( | ||
name = "consumer", | ||
srcs = glob(["src/java/org/jetbrains/bsp/example/animals/consumer/LibraryConsumer.java"]), | ||
deps = [":animals_lib"], | ||
) | ||
|
||
# This is a jvm library that doesn't have file sources. We must ensure we import it as a library, not as sources | ||
# even if it is directly referred in projectview's targets section. | ||
java_library( | ||
name = "animals_lib", | ||
srcs = [":animals"], | ||
) | ||
|
||
animals_library_source( | ||
name = "animals", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
def _animals_library_source_impl(ctx): | ||
tc = ctx.toolchains["@bazel_tools//tools/jdk:toolchain_type"] | ||
cat_java = ctx.actions.declare_file("Cat.java") | ||
ctx.actions.write(cat_java, """ | ||
package org.jetbrains.bsp.example.animals; | ||
public class Cat {}; | ||
""") | ||
src_jar = ctx.actions.declare_file("animals.srcjar") | ||
java_common.pack_sources(ctx.actions, sources = [cat_java], java_toolchain = tc.java, output_source_jar = src_jar) | ||
|
||
return [ | ||
DefaultInfo(files = depset([src_jar])), | ||
] | ||
|
||
animals_library_source = rule( | ||
implementation = _animals_library_source_impl, | ||
fragments = ["java"], | ||
toolchains = ["@bazel_tools//tools/jdk:toolchain_type"], | ||
attrs = { | ||
"_java_toolchain": attr.label( | ||
default = Label("@bazel_tools//tools/jdk:current_java_toolchain"), | ||
), | ||
}, | ||
) |
5 changes: 5 additions & 0 deletions
5
example/animals/src/java/org/jetbrains/bsp/example/animals/consumer/LibraryConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.jetbrains.bsp.example.animals.consumer; | ||
|
||
class LibraryConsumer { | ||
org.jetbrains.bsp.example.animals.Cat cat; | ||
} |