Skip to content

Commit

Permalink
Add gazelle extension for Java (#19)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Jones-Low <[email protected]>
  • Loading branch information
stevebarrau and tjoneslo authored May 9, 2022
1 parent 77bbdf3 commit 07c621c
Show file tree
Hide file tree
Showing 157 changed files with 11,871 additions and 224 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ jobs:

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- uses: bazelbuild/setup-bazelisk@v2

- name: Mount bazel action cache
uses: actions/cache@v2
with:
path: "~/.cache/bazel"
key: bazel

- name: Mount bazel repo cache
uses: actions/cache@v2
with:
path: "~/.cache/bazel-repo"
key: bazel-repo

- name: bazel test //...
env:
# Bazelisk will download bazel to here, ensure it is cached between runs.
Expand Down
54 changes: 50 additions & 4 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,14 +1,60 @@
load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_gazelle//:def.bzl", "gazelle", "gazelle_binary")
load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")

gazelle_binary(
name = "gazelle_bin",
languages = ["@bazel_skylib//gazelle/bzl"],
buildifier(
name = "buildifier",
visibility = ["//visibility:private"],
)

# gazelle:java_maven_install_file frozen_deps_install.json
# gazelle:java_maven_manifest_file frozen_deps_manifest.json
# gazelle:prefix github.com/bazel-contrib/rules_jvm

# gazelle:resolve go github.com/bazelbuild/buildtools/build @com_github_bazelbuild_buildtools//build:go_default_library
# gazelle:resolve go github.com/bazelbuild/tools_jvm_autodeps/listclassesinjar @com_github_bazelbuild_tools_jvm_autodeps//listclassesinjar:go_default_library
# gazelle:resolve java com.beust.jcommander @contrib_rules_jvm_deps//:com_beust_jcommander
# gazelle:resolve java com.beust.jcommander.converters @contrib_rules_jvm_deps//:com_beust_jcommander
# gazelle:resolve java com.gazelle.java.javaparser.v0 //java/gazelle/private/javaparser/proto/gazelle/java/javaparser/v0:gazelle_java_build_v0_java_library
# gazelle:resolve java com.github.javaparser @contrib_rules_jvm_deps//:com_github_javaparser_javaparser_core
# gazelle:resolve java com.github.javaparser.ast @contrib_rules_jvm_deps//:com_github_javaparser_javaparser_core
# gazelle:resolve java com.github.javaparser.ast.body @contrib_rules_jvm_deps//:com_github_javaparser_javaparser_core
# gazelle:resolve java com.github.javaparser.ast.type @contrib_rules_jvm_deps//:com_github_javaparser_javaparser_core
# gazelle:resolve java com.github.javaparser.resolution @contrib_rules_jvm_deps//:com_github_javaparser_javaparser_core
# gazelle:resolve java com.github.javaparser.resolution.declarations @contrib_rules_jvm_deps//:com_github_javaparser_javaparser_core
# gazelle:resolve java com.github.javaparser.resolution.types @contrib_rules_jvm_deps//:com_github_javaparser_javaparser_core
# gazelle:resolve java com.github.javaparser.symbolsolver @contrib_rules_jvm_deps//:com_github_javaparser_javaparser_symbol_solver_core
# gazelle:resolve java com.github.javaparser.symbolsolver.model.resolution @contrib_rules_jvm_deps//:com_github_javaparser_javaparser_symbol_solver_core
# gazelle:resolve java com.github.javaparser.symbolsolver.resolution.typesolvers @contrib_rules_jvm_deps//:com_github_javaparser_javaparser_symbol_solver_core
# gazelle:resolve java com.github.javaparser.utils @contrib_rules_jvm_deps//:com_github_javaparser_javaparser_core
# gazelle:resolve java com.google.common.annotations @contrib_rules_jvm_deps//:com_google_guava_guava
# gazelle:resolve java com.google.common.collect @contrib_rules_jvm_deps//:com_google_guava_guava
# gazelle:resolve java com.google.gson @contrib_rules_jvm_deps//:com_google_code_gson_gson
# gazelle:resolve java io.grpc @contrib_rules_jvm_deps//:io_grpc_grpc_api
# gazelle:resolve java io.grpc.stub @contrib_rules_jvm_deps//:io_grpc_grpc_stub
# gazelle:resolve java javax.annotation @contrib_rules_jvm_deps//:com_google_code_findbugs_jsr305
# gazelle:resolve java org.apache.commons.cli @contrib_rules_jvm_deps//:commons_cli_commons_cli
# gazelle:resolve java org.junit.jupiter.api @maven//:org_junit_jupiter_junit_jupiter_api
# gazelle:resolve java org.slf4j @contrib_rules_jvm_deps//:org_slf4j_slf4j_api

gazelle(
name = "gazelle",
gazelle = ":gazelle_bin",
visibility = ["//visibility:private"],
)

gazelle_binary(
name = "gazelle_bin",
languages = DEFAULT_LANGUAGES + [
"@bazel_skylib//gazelle/bzl",
"//java/gazelle",
],
)

# This is used in ./tools/update-dependencies.sh to update the go dependencies
# and BUILD files.
gazelle(
name = "gazelle_go",
)

bzl_library(
Expand Down
101 changes: 62 additions & 39 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,39 @@ http_archive(
url = "https://github.com/apple/apple_rules_lint/archive/0.1.1.zip",
)

http_archive(
name = "bazel_gazelle",
sha256 = "cb1f888a5363f89945ece2254576bd84730aac2642d64ee1bbcfb500735a8beb",
strip_prefix = "bazel-gazelle-2190265f2fabd2383765fdfbed158106ebe81e9b",
url = "https://github.com/bazelbuild/bazel-gazelle/archive/2190265f2fabd2383765fdfbed158106ebe81e9b.tar.gz",
)

http_archive(
name = "io_bazel_rules_go",
sha256 = "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f",
url = "https://github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip",
)

http_archive(
name = "io_bazel_stardoc",
sha256 = "c9794dcc8026a30ff67cf7cf91ebe245ca294b20b071845d12c192afe243ad72",
url = "https://github.com/bazelbuild/stardoc/releases/download/0.5.0/stardoc-0.5.0.tar.gz",
)

http_archive(
name = "rules_proto",
sha256 = "66bfdf8782796239d3875d37e7de19b1d94301e8972b3cbd2446b332429b4df1",
strip_prefix = "rules_proto-4.0.0",
url = "https://github.com/bazelbuild/rules_proto/archive/refs/tags/4.0.0.tar.gz",
)

http_archive(
name = "rules_python",
sha256 = "cdf6b84084aad8f10bf20b46b77cb48d83c319ebe6458a18e9d2cebf57807cdd",
strip_prefix = "rules_python-0.8.1",
url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.8.1.tar.gz",
)

load("@apple_rules_lint//lint:repositories.bzl", "lint_deps")

lint_deps()
Expand All @@ -27,16 +60,28 @@ contrib_rules_jvm_deps()

load("//:setup.bzl", "contrib_rules_jvm_setup")

# gazelle:repository_macro third_party/go/repositories.bzl%go_deps
contrib_rules_jvm_setup()

load("@rules_jvm_external//:defs.bzl", "maven_install")
load("@io_grpc_grpc_java//:repositories.bzl", "IO_GRPC_GRPC_JAVA_ARTIFACTS")

# This only exists to give us a target to use with `//bin:freeze-deps.py` If
# you update this, then please re-run that script and commit the changes to
# repo
# This only exists to give us a target to use with `./tools/update-dependencies.sh`.
# If you update this, then please re-run that script and commit the changes to repo.
maven_install(
name = "frozen_deps",
artifacts = [
"com.github.javaparser:javaparser-core:3.22.1",
"com.github.javaparser:javaparser-symbol-solver-core:3.22.1",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.guava:guava:30.1.1-jre",
"commons-cli:commons-cli:1.5.0",
"io.grpc:grpc-api:1.40.0",
"io.grpc:grpc-core:1.40.0",
"io.grpc:grpc-netty:1.40.0",
"io.grpc:grpc-stub:1.40.0",
"org.slf4j:slf4j-simple:1.7.32",

# These can be versioned independently of the versions in `repositories.bzl`
# so long as the version numbers are higher.
"org.junit.jupiter:junit-jupiter-engine:5.8.1",
Expand Down Expand Up @@ -69,22 +114,24 @@ maven_install(
},
"org.slf4j:slf4j-api:1.7.32",
"org.slf4j:slf4j-jdk14:1.7.32",
],
] + IO_GRPC_GRPC_JAVA_ARTIFACTS,
fail_if_repin_required = True,
fetch_sources = True,
generate_compat_repositories = True,
maven_install_json = "@contrib_rules_jvm//:frozen_deps_install.json",
repositories = [
"https://repo1.maven.org/maven2",
],
)

load("@frozen_deps//:defs.bzl", "pinned_maven_install")
load("@frozen_deps//:defs.bzl", frozen_deps_pmi = "pinned_maven_install")

pinned_maven_install()
frozen_deps_pmi()

# These are used for our own tests.
maven_install(
artifacts = [
"com.google.code.findbugs:annotations:3.0.1",
"com.google.googlejavaformat:google-java-format:1.15.0",

# These can be versioned independently of the versions in `repositories.bzl`
Expand All @@ -103,49 +150,25 @@ maven_install(
],
)

load("@maven//:defs.bzl", "pinned_maven_install")
load("@maven//:defs.bzl", maven_pmi = "pinned_maven_install")

pinned_maven_install()

# Dependencies for generating `bzl_library` targets using Gazelle
http_archive(
name = "io_bazel_rules_go",
sha256 = "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip",
],
)

http_archive(
name = "bazel_gazelle",
sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
],
)

http_archive(
name = "io_bazel_stardoc",
sha256 = "c9794dcc8026a30ff67cf7cf91ebe245ca294b20b071845d12c192afe243ad72",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.0/stardoc-0.5.0.tar.gz",
"https://github.com/bazelbuild/stardoc/releases/download/0.5.0/stardoc-0.5.0.tar.gz",
],
)
maven_pmi()

load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

############################################
# Gazelle, for generating bzl_library targets
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.17.2")
go_register_toolchains(version = "1.18")

gazelle_dependencies()

load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

rules_proto_dependencies()

rules_proto_toolchains()
2 changes: 1 addition & 1 deletion docs/postfix.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ file you need to do the following:

pinned_maven_install()
```
2. Run `./tools/frozen-deps.py --repo <repo name> --zip
2. Run `./tools/freeze-deps.py --repo <repo name> --zip
<path/to/dependency.zip>`. The `<repo name>` matches the name used
for the `maven_install()` rule above. This will pin the
dependencies then collect them into the zip file.
Expand Down
Loading

0 comments on commit 07c621c

Please sign in to comment.