forked from bazel-contrib/rules_jvm_external
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefs.bzl
More file actions
82 lines (68 loc) · 2.78 KB
/
defs.bzl
File metadata and controls
82 lines (68 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright 2019 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
load("@rules_jvm_external//:coursier.bzl", "coursier_fetch")
load("@rules_jvm_external//:specs.bzl", "maven", "parse", "json")
def gmaven_artifact(fqn):
parts = fqn.split(":")
packaging = "jar"
if len(parts) == 3:
group_id, artifact_id, version = parts
elif len(parts) == 4:
group_id, artifact_id, packaging, version = parts
elif len(parts) == 5:
_, _, _, classifier, _ = parts
fail("Classifiers are currently not supported. Please remove it from the coordinate: %s" % classifier)
else:
fail("Invalid qualified name for artifact: %s" % fqn)
return "@%s_%s_%s//%s" % (
escape(group_id),
escape(artifact_id),
escape(version),
packaging
)
def escape(string):
return string.replace(".", "_").replace("-", "_")
DEFAULT_REPOSITORY_NAME = "maven"
def maven_install(
name = DEFAULT_REPOSITORY_NAME,
repositories = [],
artifacts = [],
fetch_sources = False,
use_unsafe_shared_cache = False):
repositories_json_strings = []
for repository in parse.parse_repository_spec_list(repositories):
repositories_json_strings.append(json.write_repository_spec(repository))
artifacts_json_strings = []
for artifact in parse.parse_artifact_spec_list(artifacts):
artifacts_json_strings.append(json.write_artifact_spec(artifact))
coursier_fetch(
name = name,
repositories = repositories_json_strings,
artifacts = artifacts_json_strings,
fetch_sources = fetch_sources,
use_unsafe_shared_cache = use_unsafe_shared_cache,
)
def artifact(a, repository_name = DEFAULT_REPOSITORY_NAME):
artifact_obj = _parse_artifact_str(a) if type(a) == "string" else a
return "@%s//:%s" % (repository_name, _escape(artifact_obj["group"] + ":" + artifact_obj["artifact"]))
def maven_artifact(a):
return artifact(a, repository_name = DEFAULT_REPOSITORY_NAME)
def _escape(string):
return string.replace(".", "_").replace("-", "_").replace(":", "_")
def _parse_artifact_str(artifact_str):
pieces = artifact_str.split(":")
if len(pieces) == 2:
return { "group": pieces[0], "artifact": pieces[1] }
else:
return parse.parse_maven_coordinate(artifact_str)