Skip to content

Commit 8caea3d

Browse files
committed
Add a module extension for registering local/remote jdks
1 parent c0462f0 commit 8caea3d

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

java/extensions.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ load(
2323
"remote_jdk21_repos",
2424
"remote_jdk8_repos",
2525
)
26+
load("//toolchains:extensions.bzl", _java_repository = "java_repository")
2627

2728
def _toolchains_impl(module_ctx):
2829
java_tools_repos()
@@ -38,3 +39,5 @@ def _toolchains_impl(module_ctx):
3839
return None
3940

4041
toolchains = module_extension(_toolchains_impl)
42+
43+
java_repository = _java_repository

toolchains/extensions.bzl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Module extensions for local and remote java repositories"""
2+
3+
load(":local_java_repository.bzl", "local_java_repository")
4+
load(":remote_java_repository.bzl", "remote_java_repository")
5+
6+
visibility(["//java"])
7+
8+
def _java_repository_impl(mctx):
9+
for mod in mctx.modules:
10+
for local in mod.tags.local:
11+
local_java_repository(
12+
local.name,
13+
java_home = local.java_home,
14+
version = local.version,
15+
build_file = local.build_file,
16+
build_file_content = local.build_file_content,
17+
)
18+
for remote in mod.tags.remote:
19+
remote_java_repository(
20+
remote.name,
21+
remote.version,
22+
target_compatible_with = remote.target_compatible_with,
23+
prefix = remote.prefix,
24+
sha256 = remote.sha256,
25+
strip_prefix = remote.strip_prefix,
26+
urls = remote.urls,
27+
)
28+
29+
_local = tag_class(attrs = {
30+
"name": attr.string(mandatory = True),
31+
"build_file": attr.label(default = None),
32+
"build_file_content": attr.string(default = ""),
33+
"java_home": attr.string(default = ""),
34+
"version": attr.string(default = ""),
35+
})
36+
37+
_remote = tag_class(attrs = {
38+
"name": attr.string(mandatory = True),
39+
"version": attr.string(mandatory = True),
40+
"urls": attr.string_list(mandatory = True),
41+
"prefix": attr.string(default = ""),
42+
"sha256": attr.string(default = ""),
43+
"strip_prefix": attr.string(default = ""),
44+
"target_compatible_with": attr.label_list(default = []),
45+
})
46+
47+
java_repository = module_extension(
48+
_java_repository_impl,
49+
tag_classes = {
50+
"local": _local,
51+
"remote": _remote,
52+
},
53+
)

0 commit comments

Comments
 (0)