Thomas Vachuska | 16b669f | 2018-07-20 09:32:51 -0700 | [diff] [blame] | 1 | load("//tools/build/bazel:generate_workspace.bzl", "maven_coordinates") |
| 2 | |
| 3 | # Example invocation: |
| 4 | # bazel build $(bazel query 'kind("_bnd rule", //...)') \ |
| 5 | # --aspects tools/build/bazel/publish_catalog.bzl%publish_catalog 2>&1 | \ |
| 6 | # egrep "DEBUG: .*mvn_jar.bzl" | cut -d\ -f3- |
| 7 | |
| 8 | def _remote(group_id, artifact_id, version, packaging, classifier): |
Thomas Vachuska | 2988e14 | 2018-07-23 16:20:01 -0700 | [diff] [blame] | 9 | p = group_id.replace(".", "/") + "/" + artifact_id + "/" + version + "/" + artifact_id + "-" + version |
Thomas Vachuska | 16b669f | 2018-07-20 09:32:51 -0700 | [diff] [blame] | 10 | if classifier != None: |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 11 | p += "-" + classifier |
Thomas Vachuska | 16b669f | 2018-07-20 09:32:51 -0700 | [diff] [blame] | 12 | p += "." + packaging |
| 13 | return p |
| 14 | |
| 15 | def _impl(target, ctx): |
| 16 | coords = maven_coordinates(target.label) |
| 17 | mvn = coords.split(":") |
| 18 | group_id = mvn[1] |
| 19 | artifact_id = mvn[2] |
| 20 | version = mvn[len(mvn) - 1] |
Thomas Vachuska | b2f489f | 2018-08-10 11:03:44 -0700 | [diff] [blame] | 21 | packaging = "oar" if target.label.name.endswith("-oar") else "jar" |
Thomas Vachuska | 16b669f | 2018-07-20 09:32:51 -0700 | [diff] [blame] | 22 | classifier = None |
| 23 | |
| 24 | if len(mvn) > 4: |
| 25 | packaging = mvn[3] |
| 26 | |
| 27 | c = artifact_id.split("-") |
| 28 | |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 29 | if len(c) > 1 and c[len(c) - 1] in ("javadoc", "sources", "tests", "pom"): |
| 30 | classifier = c[len(c) - 1] |
| 31 | artifact_id = "-".join(c[:len(c) - 1]) |
Thomas Vachuska | 16b669f | 2018-07-20 09:32:51 -0700 | [diff] [blame] | 32 | if classifier == "pom": |
| 33 | packaging = classifier |
| 34 | classifier = None |
| 35 | |
| 36 | for f in target.files: |
Ray Milkey | 5063f5b | 2018-08-15 16:22:30 -0700 | [diff] [blame] | 37 | print("%s\t%s" % (f.path, _remote(group_id, artifact_id, version, packaging, classifier))) |
Thomas Vachuska | 16b669f | 2018-07-20 09:32:51 -0700 | [diff] [blame] | 38 | return [] |
| 39 | |
| 40 | publish_catalog = aspect( |
| 41 | implementation = _impl, |
| 42 | ) |