diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index e1dbc444..db900fd3 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -21,7 +21,6 @@ jobs: flags: - "" - --config=jdk11 - - --noenable_bzlmod # The type of runner that the job will run on runs-on: ${{ matrix.runs-on }} @@ -46,3 +45,6 @@ jobs: - name: bazel test //... (Java ${{ matrix.java-major-version }}) run: bazelisk --bazelrc=.github/workflows/ci.bazelrc test ${{ matrix.flags }} //... + + - name: example workspace-based build + run: cd examples/workspace-based && bazel run gazelle && bazel test //java/test/com/github/bazelcontrib/rulesjvm/example:PassingTest diff --git a/.gitignore b/.gitignore index d9c14d63..1356be98 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,8 @@ bazel-* .idea .ijwb .eclipse +*~ /comparative-tests/.gradle/ /MODULE.bazel.lock +/examples/workspace-based/java/src/com/github/bazelcontrib/rulesjvm/example/BUILD.bazel +/examples/workspace-based/java/test/com/github/bazelcontrib/rulesjvm/example/BUILD.bazel diff --git a/README.md b/README.md index 9479041b..388ec7f3 100644 --- a/README.md +++ b/README.md @@ -73,12 +73,14 @@ The gazelle plugin requires Go 1.18 or above. ## checkstyle_config
-checkstyle_config(name, checkstyle_binary, config_file, data, output_format) +load("@contrib_rules_jvm//docs:stardoc-input.bzl", "checkstyle_config") + +checkstyle_config(name, data, checkstyle_binary, config_file, output_format)- Rule allowing checkstyle to be configured. This is typically - used with the linting rules from `@apple_rules_lint` to configure how - checkstyle should run. +Rule allowing checkstyle to be configured. This is typically +used with the linting rules from `@apple_rules_lint` to configure how +checkstyle should run. **ATTRIBUTES** @@ -86,10 +88,10 @@ checkstyle_config(name, name | A unique name for this target. | Name | required | | -| checkstyle_binary | Checkstyle binary to use. | Label | optional |
@contrib_rules_jvm//java:checkstyle_cli
|
+| data | Additional files to make available to Checkstyle such as any included XML files | List of labels | optional | `[]` |
+| checkstyle_binary | Checkstyle binary to use. | Label | optional | `"@contrib_rules_jvm//java:checkstyle_cli"` |
| config_file | The config file to use for all checkstyle tests | Label | required | |
-| data | Additional files to make available to Checkstyle such as any included XML files | List of labels | optional | []
|
-| output_format | Output format to use. Defaults to plain | String | optional | "plain"
|
+| output_format | Output format to use. Defaults to plain | String | optional | `"plain"` |
@@ -97,6 +99,8 @@ checkstyle_config(name, name, format, pmd_binary, rulesets, shallow)
@@ -108,10 +112,10 @@ Select a rule set for PMD tests.
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| name | A unique name for this target. | Name | required | |
-| format | Generate report in the given format. One of html, text, or xml (default is xml) | String | optional | "xml"
|
-| pmd_binary | PMD binary to use. | Label | optional | //java:pmd
|
-| rulesets | Use these rulesets. | List of labels | optional | []
|
-| shallow | Use the targetted output to increase PMD's depth of processing | Boolean | optional | True
|
+| format | Generate report in the given format. One of html, text, or xml (default is xml) | String | optional | `"xml"` |
+| pmd_binary | PMD binary to use. | Label | optional | `"@contrib_rules_jvm//java:pmd"` |
+| rulesets | Use these rulesets. | List of labels | optional | `[]` |
+| shallow | Use the targetted output to increase PMD's depth of processing | Boolean | optional | `True` |
@@ -119,7 +123,9 @@ Select a rule set for PMD tests.
## pmd_test
-pmd_test(name, ruleset, srcs, target) +load("@contrib_rules_jvm//docs:stardoc-input.bzl", "pmd_test") + +pmd_test(name, srcs, ruleset, target)Use PMD to lint the `srcs`. @@ -130,9 +136,9 @@ Use PMD to lint the `srcs`. | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | +| srcs | - | List of labels | optional | `[]` | | ruleset | - | Label | required | | -| srcs | - | List of labels | optional |
[]
|
-| target | - | Label | optional | None
|
+| target | - | Label | optional | `None` |
@@ -140,6 +146,8 @@ Use PMD to lint the `srcs`.
## spotbugs_config
+load("@contrib_rules_jvm//docs:stardoc-input.bzl", "spotbugs_config") + spotbugs_config(name, effort, exclude_filter, fail_on_warning, plugin_list, spotbugs_binary)@@ -151,11 +159,11 @@ Configuration used for spotbugs, typically by the `//lint` rules. | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | -| effort | Effort can be min, less, default, more or max. Defaults to default | String | optional |
"default"
|
-| exclude_filter | Report all bug instances except those matching the filter specified by this filter file | Label | optional | None
|
-| fail_on_warning | Whether to fail on warning, or just create a report. Defaults to True | Boolean | optional | True
|
-| plugin_list | Specify a list of plugin Jar files to load | List of labels | optional | []
|
-| spotbugs_binary | The spotbugs binary to run. | Label | optional | @contrib_rules_jvm//java:spotbugs_cli
|
+| effort | Effort can be min, less, default, more or max. Defaults to default | String | optional | `"default"` |
+| exclude_filter | Report all bug instances except those matching the filter specified by this filter file | Label | optional | `None` |
+| fail_on_warning | Whether to fail on warning, or just create a report. Defaults to True | Boolean | optional | `True` |
+| plugin_list | Specify a list of plugin Jar files to load | List of labels | optional | `[]` |
+| spotbugs_binary | The spotbugs binary to run. | Label | optional | `"@contrib_rules_jvm//java:spotbugs_cli"` |
@@ -163,7 +171,9 @@ Configuration used for spotbugs, typically by the `//lint` rules.
## spotbugs_test
-spotbugs_test(name, config, deps, only_output_jars) +load("@contrib_rules_jvm//docs:stardoc-input.bzl", "spotbugs_test") + +spotbugs_test(name, deps, config, only_output_jars)Use spotbugs to lint the `srcs`. @@ -174,9 +184,9 @@ Use spotbugs to lint the `srcs`. | Name | Description | Type | Mandatory | Default | | :------------- | :------------- | :------------- | :------------- | :------------- | | name | A unique name for this target. | Name | required | | -| config | - | Label | optional |
@contrib_rules_jvm//java:spotbugs-default-config
|
| deps | - | List of labels | required | |
-| only_output_jars | If set to true, only the output jar of the target will be analyzed. Otherwise all transitive runtime dependencies will be analyzed | Boolean | optional | True
|
+| config | - | Label | optional | `"@contrib_rules_jvm//java:spotbugs-default-config"` |
+| only_output_jars | If set to true, only the output jar of the target will be analyzed. Otherwise all transitive runtime dependencies will be analyzed | Boolean | optional | `True` |
@@ -184,6 +194,8 @@ Use spotbugs to lint the `srcs`.
## checkstyle_binary
+load("@contrib_rules_jvm//docs:stardoc-input.bzl", "checkstyle_binary") + checkstyle_binary(name, main_class, deps, runtime_deps, srcs, visibility, kwargs)@@ -213,11 +225,11 @@ checkstyle_binary( | Name | Description | Default Value | | :------------- | :------------- | :------------- | | name | The name of the target | none | -| main_class | The main class to use for checkstyle. |
"com.puppycrawl.tools.checkstyle.Main"
|
-| deps | The deps required for compiling this binary. May be omitted. | None
|
-| runtime_deps | The deps required by checkstyle at runtime. May be omitted. | None
|
-| srcs | If you're compiling your own checkstyle
binary, the sources to use. | None
|
-| visibility | -
|["//visibility:public"]
|
+| main_class | The main class to use for checkstyle. | `"com.puppycrawl.tools.checkstyle.Main"` |
+| deps | The deps required for compiling this binary. May be omitted. | `None` |
+| runtime_deps | The deps required by checkstyle at runtime. May be omitted. | `None` |
+| srcs | If you're compiling your own `checkstyle` binary, the sources to use. | `None` |
+| visibility | -
| `["//visibility:public"]` | | kwargs |-
| none | @@ -226,6 +238,8 @@ checkstyle_binary( ## checkstyle_test+load("@contrib_rules_jvm//docs:stardoc-input.bzl", "checkstyle_test") + checkstyle_test(name, size, timeout, kwargs)@@ -237,8 +251,8 @@ checkstyle_test(name, name |
-
| none | -| size |-
|"medium"
|
-| timeout | -
|"short"
|
+| size | -
| `"medium"` | +| timeout |-
| `"short"` | | kwargs |-
| none | @@ -247,6 +261,8 @@ checkstyle_test(name, name, kwargs) @@ -266,6 +282,8 @@ Adds linting tests to Bazel's own `java_binary` ## java_export+load("@contrib_rules_jvm//docs:stardoc-input.bzl", "java_export") + java_export(name, maven_coordinates, pom_template, deploy_env, visibility, kwargs)@@ -278,9 +296,9 @@ Adds linting tests to `rules_jvm_external`'s `java_export` | :------------- | :------------- | :------------- | | name |
-
| none | | maven_coordinates |-
| none | -| pom_template |-
|None
|
-| deploy_env | -
|None
|
-| visibility | -
|None
|
+| pom_template | -
| `None` | +| deploy_env |-
| `None` | +| visibility |-
| `None` | | kwargs |-
| none | @@ -289,6 +307,8 @@ Adds linting tests to `rules_jvm_external`'s `java_export` ## java_junit5_test+load("@contrib_rules_jvm//docs:stardoc-input.bzl", "java_junit5_test") + java_junit5_test(name, test_class, runtime_deps, package_prefixes, jvm_flags, include_tags, exclude_tags, include_engines, exclude_engines, kwargs)@@ -331,14 +351,14 @@ its goals, but this is not complete or available yet. | Name | Description | Default Value | | :------------- | :------------- | :------------- | | name | The name of the test. | none | -| test_class | The Java class to be loaded by the test runner. If not specified, the class name will be inferred from a combination of the current bazel package and the
name
attribute. | None
|
-| runtime_deps | -
|[]
|
-| package_prefixes | -
|[]
|
-| jvm_flags | -
|[]
|
-| include_tags | Junit5 tag expressions to include execution of tagged tests. | []
|
-| exclude_tags | Junit tag expressions to exclude execution of tagged tests. | []
|
-| include_engines | A list of JUnit Platform test engine IDs to include. | []
|
-| exclude_engines | A list of JUnit Platform test engine IDs to exclude. | []
|
+| test_class | The Java class to be loaded by the test runner. If not specified, the class name will be inferred from a combination of the current bazel package and the `name` attribute. | `None` |
+| runtime_deps | -
| `[]` | +| package_prefixes |-
| `[]` | +| jvm_flags |-
| `[]` | +| include_tags | Junit5 tag expressions to include execution of tagged tests. | `[]` | +| exclude_tags | Junit tag expressions to exclude execution of tagged tests. | `[]` | +| include_engines | A list of JUnit Platform test engine IDs to include. | `[]` | +| exclude_engines | A list of JUnit Platform test engine IDs to exclude. | `[]` | | kwargs |-
| none | @@ -347,6 +367,8 @@ its goals, but this is not complete or available yet. ## java_library+load("@contrib_rules_jvm//docs:stardoc-input.bzl", "java_library") + java_library(name, kwargs)@@ -366,6 +388,8 @@ Adds linting tests to Bazel's own `java_library` ## java_test
+load("@contrib_rules_jvm//docs:stardoc-input.bzl", "java_test") + java_test(name, kwargs)@@ -385,6 +409,8 @@ Adds linting tests to Bazel's own `java_test` ## java_test_suite
+load("@contrib_rules_jvm//docs:stardoc-input.bzl", "java_test_suite") + java_test_suite(name, srcs, runner, test_suffixes, package, deps, runtime_deps, size, kwargs)@@ -409,14 +435,14 @@ attribute to allow all the tests to be run in one go. | Name | Description | Default Value | | :------------- | :------------- | :------------- | -| name | A unique name for this rule. Will be used to generate a
test_suite
| none |
+| name | A unique name for this rule. Will be used to generate a `test_suite` | none |
| srcs | Source files to create test rules for. | none |
-| runner | One of junit4
or junit5
. | "junit4"
|
-| test_suffixes | The file name suffix used to identify if a file contains a test class. | ["Test.java"]
|
-| package | The package name used by the tests. If not set, this is inferred from the current bazel package name. | None
|
-| deps | A list of java_*
dependencies. | None
|
-| runtime_deps | A list of java_*
dependencies needed at runtime. | []
|
-| size | The size of the test, passed to java_test
| None
|
+| runner | One of `junit4` or `junit5`. | `"junit4"` |
+| test_suffixes | The file name suffix used to identify if a file contains a test class. | `["Test.java"]` |
+| package | The package name used by the tests. If not set, this is inferred from the current bazel package name. | `None` |
+| deps | A list of `java_*` dependencies. | `None` |
+| runtime_deps | A list of `java_*` dependencies needed at runtime. | `[]` |
+| size | The size of the test, passed to `java_test` | `None` |
| kwargs | -
| none | @@ -425,6 +451,8 @@ attribute to allow all the tests to be run in one go. ## pmd_binary+load("@contrib_rules_jvm//docs:stardoc-input.bzl", "pmd_binary") + pmd_binary(name, main_class, deps, runtime_deps, srcs, visibility, kwargs)@@ -454,11 +482,11 @@ pmd_binary( | Name | Description | Default Value | | :------------- | :------------- | :------------- | | name | The name of the target | none | -| main_class | The main class to use for PMD. |
"net.sourceforge.pmd.PMD"
|
-| deps | The deps required for compiling this binary. May be omitted. | None
|
-| runtime_deps | The deps required by PMD at runtime. May be omitted. | None
|
-| srcs | If you're compiling your own PMD binary, the sources to use. | None
|
-| visibility | -
|["//visibility:public"]
|
+| main_class | The main class to use for PMD. | `"net.sourceforge.pmd.PMD"` |
+| deps | The deps required for compiling this binary. May be omitted. | `None` |
+| runtime_deps | The deps required by PMD at runtime. May be omitted. | `None` |
+| srcs | If you're compiling your own PMD binary, the sources to use. | `None` |
+| visibility | -
| `["//visibility:public"]` | | kwargs |-
| none | @@ -467,6 +495,8 @@ pmd_binary( ## spotbugs_binary+load("@contrib_rules_jvm//docs:stardoc-input.bzl", "spotbugs_binary") + spotbugs_binary(name, main_class, deps, runtime_deps, srcs, visibility, kwargs)@@ -497,11 +527,11 @@ spotbugs_binary( | Name | Description | Default Value | | :------------- | :------------- | :------------- | | name | The name of the target | none | -| main_class | The main class to use for spotbugs. |
"edu.umd.cs.findbugs.LaunchAppropriateUI"
|
-| deps | The deps required for compiling this binary. May be omitted. | None
|
-| runtime_deps | The deps required by spotbugs at runtime. May be omitted. | None
|
-| srcs | If you're compiling your own spotbugs
binary, the sources to use. | None
|
-| visibility | -
|["//visibility:public"]
|
+| main_class | The main class to use for spotbugs. | `"edu.umd.cs.findbugs.LaunchAppropriateUI"` |
+| deps | The deps required for compiling this binary. May be omitted. | `None` |
+| runtime_deps | The deps required by spotbugs at runtime. May be omitted. | `None` |
+| srcs | If you're compiling your own `spotbugs` binary, the sources to use. | `None` |
+| visibility | -
| `["//visibility:public"]` | | kwargs |-
| none | diff --git a/WORKSPACE b/WORKSPACE index f6b23149..4aeafdf9 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,95 +1 @@ workspace(name = "contrib_rules_jvm") - -load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( - name = "rules_python", - sha256 = "497ca47374f48c8b067d786b512ac10a276211810f4a580178ee9b9ad139323a", - strip_prefix = "rules_python-0.16.1", - url = "https://github.com/bazelbuild/rules_python/archive/refs/tags/0.16.1.tar.gz", -) - -load("//:repositories.bzl", "contrib_rules_jvm_deps", "contrib_rules_jvm_gazelle_deps") - -contrib_rules_jvm_deps() - -contrib_rules_jvm_gazelle_deps() - -load("@apple_rules_lint//lint:repositories.bzl", "lint_deps") - -lint_deps() - -load("@apple_rules_lint//lint:setup.bzl", "lint_setup") - -lint_setup({ - "java-checkstyle": "//java:checkstyle-default-config", - "java-pmd": "//java:pmd-config", - "java-spotbugs": "//java:spotbugs-default-config", -}) - -load("//:setup.bzl", "contrib_rules_jvm_setup") - -# gazelle:repository_macro third_party/go/repositories.bzl%go_deps -contrib_rules_jvm_setup() - -load("//:gazelle_setup.bzl", "contrib_rules_jvm_gazelle_setup") - -contrib_rules_jvm_gazelle_setup() - -load("@io_grpc_grpc_java//:repositories.bzl", "IO_GRPC_GRPC_JAVA_ARTIFACTS") -load("@rules_jvm_external//:defs.bzl", "maven_install") -load("//third_party:protobuf_version.bzl", "PROTOBUF_JAVA_VERSION") - -# These are used for our own tests. -maven_install( - name = "contrib_rules_jvm_tests", - artifacts = [ - # 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.2", - "org.junit.jupiter:junit-jupiter-api:5.8.2", - "org.junit.jupiter:junit-jupiter-params:5.8.2", - "org.junit.platform:junit-platform-launcher:1.8.2", - "org.junit.platform:junit-platform-reporting:1.8.2", - "org.junit.platform:junit-platform-suite:1.8.2", - "org.junit.platform:junit-platform-suite-api:1.8.2", - "org.junit.platform:junit-platform-suite-engine:1.8.2", - "org.junit.vintage:junit-vintage-engine:5.8.2", - "org.mockito:mockito-core:4.8.1", - ], - fail_if_repin_required = True, - fetch_sources = True, - maven_install_json = "@//:contrib_rules_jvm_tests_install.json", - repositories = [ - "https://repo1.maven.org/maven2", - ], -) - -load("@contrib_rules_jvm_tests//:defs.bzl", maven_pmi = "pinned_maven_install") - -maven_pmi() - -load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories") - -stardoc_repositories() - -load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") -load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") - -go_rules_dependencies() - -go_register_toolchains(version = "1.21.5") - -gazelle_dependencies() - -load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains") - -rules_proto_dependencies() - -rules_proto_toolchains() - -load("@googleapis//:repository_rules.bzl", "switched_rules_by_language") - -switched_rules_by_language( - name = "com_google_googleapis_imports", -) diff --git a/WORKSPACE.bzlmod b/WORKSPACE.bzlmod deleted file mode 100644 index 4aeafdf9..00000000 --- a/WORKSPACE.bzlmod +++ /dev/null @@ -1 +0,0 @@ -workspace(name = "contrib_rules_jvm") diff --git a/examples/workspace-based/.bazelrc b/examples/workspace-based/.bazelrc new file mode 100644 index 00000000..1dc93ccb --- /dev/null +++ b/examples/workspace-based/.bazelrc @@ -0,0 +1,11 @@ +common --noenable_bzlmod + +build --java_runtime_version=remotejdk_17 +build --java_language_version=17 +build --tool_java_runtime_version=remotejdk_17 +build --tool_java_language_version=17 + +# Make sure we get something helpful when tests fail +test --verbose_failures +test --test_output=errors + diff --git a/examples/workspace-based/.bazelversion b/examples/workspace-based/.bazelversion new file mode 100644 index 00000000..19b860c1 --- /dev/null +++ b/examples/workspace-based/.bazelversion @@ -0,0 +1 @@ +6.4.0 diff --git a/examples/workspace-based/BUILD.bazel b/examples/workspace-based/BUILD.bazel new file mode 100644 index 00000000..1e915ac0 --- /dev/null +++ b/examples/workspace-based/BUILD.bazel @@ -0,0 +1,24 @@ +load("@bazel_gazelle//:def.bzl", "DEFAULT_LANGUAGES", "gazelle", "gazelle_binary") + +# We can choose where the `maven_install` lock file is read from +# +# gazelle:java_maven_install_file java/maven_install.json + +# And this maps common types to the ones from `contrib_rules_jvm`. By +# doing this we can use the integration with `apple_rules_lint`. +# +# gazelle:map_kind java_binary java_binary @contrib_rules_jvm//java:defs.bzl +# gazelle:map_kind java_library java_library @contrib_rules_jvm//java:defs.bzl +# gazelle:map_kind java_test java_test @contrib_rules_jvm//java:defs.bzl + +gazelle( + name = "gazelle", + gazelle = ":gazelle_bin", +) + +gazelle_binary( + name = "gazelle_bin", + languages = DEFAULT_LANGUAGES + [ + "@contrib_rules_jvm//java/gazelle", + ], +) diff --git a/examples/workspace-based/README.md b/examples/workspace-based/README.md new file mode 100644 index 00000000..ac270c29 --- /dev/null +++ b/examples/workspace-based/README.md @@ -0,0 +1,19 @@ +# Example Workspace-based project + +This is a small example of using the `gazelle` java plugin with a +simple source repository. + +## Steps to use + + 1. Run `bazel test //...` and notice that there's almost no tests. + 1. `bazel run gazelle` and find the new `BUILD.bazel` files that are created + 1. `bazel test //...` + +The final run of `bazel test` will fail, as one of the example tests +is written so it won't pass. Try fixing it! + +This example also shows how you can make use of the linters that are +supplied with `contrib_rules_jvm`. There are directives in the +top-level `BUILD.bazel` that tell the gazelle plugin to use the macros +from `contrib_rules_jvm` and not just `rules_java`. The configuration +of the linters can be found in the `WORKSPACE` file. diff --git a/examples/workspace-based/WORKSPACE b/examples/workspace-based/WORKSPACE new file mode 100644 index 00000000..093db4d9 --- /dev/null +++ b/examples/workspace-based/WORKSPACE @@ -0,0 +1,88 @@ +workspace(name = "contrib_rules_jvm_workspace_example") + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +local_repository( + name = "contrib_rules_jvm", + path = "../..", +) + +http_archive( + name = "apple_rules_lint", + sha256 = "483ea03d73d5fb33275d029da8d36811243fc32dfa4dc73a43acbb6f4b1af621", + strip_prefix = "apple_rules_lint-0.4.0", + url = "https://github.com/apple/apple_rules_lint/releases/download/0.4.0/apple_rules_lint-0.4.0.tar.gz", +) + +load("@apple_rules_lint//lint:repositories.bzl", "lint_deps") + +lint_deps() + +load("@apple_rules_lint//lint:setup.bzl", "lint_setup") + +lint_setup({ + "java-checkstyle": "@contrib_rules_jvm//java:checkstyle-default-config", + "java-pmd": "@contrib_rules_jvm//java:pmd-config", + "java-spotbugs": "@contrib_rules_jvm//java:spotbugs-default-config", +}) + +load("@contrib_rules_jvm//:repositories.bzl", "contrib_rules_jvm_deps", "contrib_rules_jvm_gazelle_deps") + +contrib_rules_jvm_deps() + +load("@contrib_rules_jvm//:setup.bzl", "contrib_rules_jvm_setup") + +contrib_rules_jvm_setup() + +load("@rules_jvm_external//:defs.bzl", "maven_install") + +maven_install( + artifacts = [ + "com.google.guava:guava:33.3.1-jre", + "org.junit.jupiter:junit-jupiter-engine:5.8.2", + "org.junit.jupiter:junit-jupiter-api:5.8.2", + "org.junit.platform:junit-platform-launcher:1.8.2", + "org.junit.platform:junit-platform-reporting:1.8.2", + ], + maven_install_json = "//java:maven_install.json", + repositories = [ + "https://repo1.maven.org/maven2", + ], +) + +load("@maven//:defs.bzl", "pinned_maven_install") + +pinned_maven_install() + +http_archive( + name = "io_bazel_rules_go", + integrity = "sha256-M6zErg9wUC20uJPJ/B3Xqb+ZjCPn/yxFF3QdQEmpdvg=", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.48.0/rules_go-v0.48.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.48.0/rules_go-v0.48.0.zip", + ], +) + +http_archive( + name = "bazel_gazelle", + integrity = "sha256-12v3pg/YsFBEQJDfooN6Tq+YKeEWVhjuNdzspcvfWNU=", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.37.0/bazel-gazelle-v0.37.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.37.0/bazel-gazelle-v0.37.0.tar.gz", + ], +) + +load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository") +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") + +contrib_rules_jvm_gazelle_deps() + +load("@contrib_rules_jvm//:gazelle_setup.bzl", "contrib_rules_jvm_gazelle_setup") + +contrib_rules_jvm_gazelle_setup() + +go_rules_dependencies() + +go_register_toolchains(version = "1.23.2") + +gazelle_dependencies() diff --git a/examples/workspace-based/java/BUILD.bazel b/examples/workspace-based/java/BUILD.bazel new file mode 100644 index 00000000..e69de29b diff --git a/examples/workspace-based/java/maven_install.json b/examples/workspace-based/java/maven_install.json new file mode 100644 index 00000000..355f7d38 --- /dev/null +++ b/examples/workspace-based/java/maven_install.json @@ -0,0 +1,289 @@ +{ + "__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL", + "__INPUT_ARTIFACTS_HASH": 1198363139, + "__RESOLVED_ARTIFACTS_HASH": -862895559, + "artifacts": { + "com.google.code.findbugs:jsr305": { + "shasums": { + "jar": "766ad2a0783f2687962c8ad74ceecc38a28b9f72a2d085ee438b7813e928d0c7" + }, + "version": "3.0.2" + }, + "com.google.errorprone:error_prone_annotations": { + "shasums": { + "jar": "f3fc8a3a0a4020706a373b00e7f57c2512dd26d1f83d28c7d38768f8682b231e" + }, + "version": "2.28.0" + }, + "com.google.guava:failureaccess": { + "shasums": { + "jar": "8a8f81cf9b359e3f6dfa691a1e776985c061ef2f223c9b2c80753e1b458e8064" + }, + "version": "1.0.2" + }, + "com.google.guava:guava": { + "shasums": { + "jar": "4bf0e2c5af8e4525c96e8fde17a4f7307f97f8478f11c4c8e35a0e3298ae4e90" + }, + "version": "33.3.1-jre" + }, + "com.google.guava:listenablefuture": { + "shasums": { + "jar": "b372a037d4230aa57fbeffdef30fd6123f9c0c2db85d0aced00c91b974f33f99" + }, + "version": "9999.0-empty-to-avoid-conflict-with-guava" + }, + "com.google.j2objc:j2objc-annotations": { + "shasums": { + "jar": "88241573467ddca44ffd4d74aa04c2bbfd11bf7c17e0c342c94c9de7a70a7c64" + }, + "version": "3.0.0" + }, + "org.apiguardian:apiguardian-api": { + "shasums": { + "jar": "b509448ac506d607319f182537f0b35d71007582ec741832a1f111e5b5b70b38" + }, + "version": "1.1.2" + }, + "org.checkerframework:checker-qual": { + "shasums": { + "jar": "3fbc2e98f05854c3df16df9abaa955b91b15b3ecac33623208ed6424640ef0f6" + }, + "version": "3.43.0" + }, + "org.junit.jupiter:junit-jupiter-api": { + "shasums": { + "jar": "1808ee87e0f718cd6e25f3b75afc17956ac8a3edc48c7e9bab9f19f9a79e3801" + }, + "version": "5.8.2" + }, + "org.junit.jupiter:junit-jupiter-engine": { + "shasums": { + "jar": "753b7726cdd158bb34cedb94c161e2291896f47832a1e9eda53d970020a8184e" + }, + "version": "5.8.2" + }, + "org.junit.platform:junit-platform-commons": { + "shasums": { + "jar": "d2e015fca7130e79af2f4608dc54415e4b10b592d77333decb4b1a274c185050" + }, + "version": "1.8.2" + }, + "org.junit.platform:junit-platform-engine": { + "shasums": { + "jar": "0b7d000f8c3e8e5f7d6b819649936e7b9938314e87c8f983805218ea57567e59" + }, + "version": "1.8.2" + }, + "org.junit.platform:junit-platform-launcher": { + "shasums": { + "jar": "822156409fd83e682e4c5199b3460054299b538a058c2c6d0f5c9b6a5bdb7594" + }, + "version": "1.8.2" + }, + "org.junit.platform:junit-platform-reporting": { + "shasums": { + "jar": "d28048333b378d166f9ad38c2a8e34ac0fa1a29cc016cb279df53c8b54628fc3" + }, + "version": "1.8.2" + }, + "org.opentest4j:opentest4j": { + "shasums": { + "jar": "58812de60898d976fb81ef3b62da05c6604c18fd4a249f5044282479fc286af2" + }, + "version": "1.2.0" + } + }, + "dependencies": { + "com.google.guava:guava": [ + "com.google.code.findbugs:jsr305", + "com.google.errorprone:error_prone_annotations", + "com.google.guava:failureaccess", + "com.google.guava:listenablefuture", + "com.google.j2objc:j2objc-annotations", + "org.checkerframework:checker-qual" + ], + "org.junit.jupiter:junit-jupiter-api": [ + "org.apiguardian:apiguardian-api", + "org.junit.platform:junit-platform-commons", + "org.opentest4j:opentest4j" + ], + "org.junit.jupiter:junit-jupiter-engine": [ + "org.apiguardian:apiguardian-api", + "org.junit.jupiter:junit-jupiter-api", + "org.junit.platform:junit-platform-engine" + ], + "org.junit.platform:junit-platform-commons": [ + "org.apiguardian:apiguardian-api" + ], + "org.junit.platform:junit-platform-engine": [ + "org.apiguardian:apiguardian-api", + "org.junit.platform:junit-platform-commons", + "org.opentest4j:opentest4j" + ], + "org.junit.platform:junit-platform-launcher": [ + "org.apiguardian:apiguardian-api", + "org.junit.platform:junit-platform-engine" + ], + "org.junit.platform:junit-platform-reporting": [ + "org.apiguardian:apiguardian-api", + "org.junit.platform:junit-platform-launcher" + ] + }, + "packages": { + "com.google.code.findbugs:jsr305": [ + "javax.annotation", + "javax.annotation.concurrent", + "javax.annotation.meta" + ], + "com.google.errorprone:error_prone_annotations": [ + "com.google.errorprone.annotations", + "com.google.errorprone.annotations.concurrent" + ], + "com.google.guava:failureaccess": [ + "com.google.common.util.concurrent.internal" + ], + "com.google.guava:guava": [ + "com.google.common.annotations", + "com.google.common.base", + "com.google.common.base.internal", + "com.google.common.cache", + "com.google.common.collect", + "com.google.common.escape", + "com.google.common.eventbus", + "com.google.common.graph", + "com.google.common.hash", + "com.google.common.html", + "com.google.common.io", + "com.google.common.math", + "com.google.common.net", + "com.google.common.primitives", + "com.google.common.reflect", + "com.google.common.util.concurrent", + "com.google.common.xml", + "com.google.thirdparty.publicsuffix" + ], + "com.google.j2objc:j2objc-annotations": [ + "com.google.j2objc.annotations" + ], + "org.apiguardian:apiguardian-api": [ + "org.apiguardian.api" + ], + "org.checkerframework:checker-qual": [ + "org.checkerframework.checker.builder.qual", + "org.checkerframework.checker.calledmethods.qual", + "org.checkerframework.checker.compilermsgs.qual", + "org.checkerframework.checker.fenum.qual", + "org.checkerframework.checker.formatter.qual", + "org.checkerframework.checker.guieffect.qual", + "org.checkerframework.checker.i18n.qual", + "org.checkerframework.checker.i18nformatter.qual", + "org.checkerframework.checker.index.qual", + "org.checkerframework.checker.initialization.qual", + "org.checkerframework.checker.interning.qual", + "org.checkerframework.checker.lock.qual", + "org.checkerframework.checker.mustcall.qual", + "org.checkerframework.checker.nullness.qual", + "org.checkerframework.checker.optional.qual", + "org.checkerframework.checker.propkey.qual", + "org.checkerframework.checker.regex.qual", + "org.checkerframework.checker.signature.qual", + "org.checkerframework.checker.signedness.qual", + "org.checkerframework.checker.tainting.qual", + "org.checkerframework.checker.units.qual", + "org.checkerframework.common.aliasing.qual", + "org.checkerframework.common.initializedfields.qual", + "org.checkerframework.common.reflection.qual", + "org.checkerframework.common.returnsreceiver.qual", + "org.checkerframework.common.subtyping.qual", + "org.checkerframework.common.util.count.report.qual", + "org.checkerframework.common.value.qual", + "org.checkerframework.dataflow.qual", + "org.checkerframework.framework.qual" + ], + "org.junit.jupiter:junit-jupiter-api": [ + "org.junit.jupiter.api", + "org.junit.jupiter.api.condition", + "org.junit.jupiter.api.extension", + "org.junit.jupiter.api.extension.support", + "org.junit.jupiter.api.function", + "org.junit.jupiter.api.io", + "org.junit.jupiter.api.parallel" + ], + "org.junit.jupiter:junit-jupiter-engine": [ + "org.junit.jupiter.engine", + "org.junit.jupiter.engine.config", + "org.junit.jupiter.engine.descriptor", + "org.junit.jupiter.engine.discovery", + "org.junit.jupiter.engine.discovery.predicates", + "org.junit.jupiter.engine.execution", + "org.junit.jupiter.engine.extension", + "org.junit.jupiter.engine.support" + ], + "org.junit.platform:junit-platform-commons": [ + "org.junit.platform.commons", + "org.junit.platform.commons.annotation", + "org.junit.platform.commons.function", + "org.junit.platform.commons.logging", + "org.junit.platform.commons.support", + "org.junit.platform.commons.util" + ], + "org.junit.platform:junit-platform-engine": [ + "org.junit.platform.engine", + "org.junit.platform.engine.discovery", + "org.junit.platform.engine.reporting", + "org.junit.platform.engine.support.config", + "org.junit.platform.engine.support.descriptor", + "org.junit.platform.engine.support.discovery", + "org.junit.platform.engine.support.filter", + "org.junit.platform.engine.support.hierarchical" + ], + "org.junit.platform:junit-platform-launcher": [ + "org.junit.platform.launcher", + "org.junit.platform.launcher.core", + "org.junit.platform.launcher.listeners", + "org.junit.platform.launcher.listeners.discovery", + "org.junit.platform.launcher.listeners.session", + "org.junit.platform.launcher.tagexpression" + ], + "org.junit.platform:junit-platform-reporting": [ + "org.junit.platform.reporting.legacy", + "org.junit.platform.reporting.legacy.xml" + ], + "org.opentest4j:opentest4j": [ + "org.opentest4j" + ] + }, + "repositories": { + "https://repo1.maven.org/maven2/": [ + "com.google.code.findbugs:jsr305", + "com.google.errorprone:error_prone_annotations", + "com.google.guava:failureaccess", + "com.google.guava:guava", + "com.google.guava:listenablefuture", + "com.google.j2objc:j2objc-annotations", + "org.apiguardian:apiguardian-api", + "org.checkerframework:checker-qual", + "org.junit.jupiter:junit-jupiter-api", + "org.junit.jupiter:junit-jupiter-engine", + "org.junit.platform:junit-platform-commons", + "org.junit.platform:junit-platform-engine", + "org.junit.platform:junit-platform-launcher", + "org.junit.platform:junit-platform-reporting", + "org.opentest4j:opentest4j" + ] + }, + "services": { + "org.junit.jupiter:junit-jupiter-engine": { + "org.junit.platform.engine.TestEngine": [ + "org.junit.jupiter.engine.JupiterTestEngine" + ] + }, + "org.junit.platform:junit-platform-launcher": { + "org.junit.platform.launcher.TestExecutionListener": [ + "org.junit.platform.launcher.listeners.UniqueIdTrackingListener" + ] + } + }, + "version": "2" +} diff --git a/examples/workspace-based/java/src/com/github/bazelcontrib/rulesjvm/example/Main.java b/examples/workspace-based/java/src/com/github/bazelcontrib/rulesjvm/example/Main.java new file mode 100644 index 00000000..3a7c00b9 --- /dev/null +++ b/examples/workspace-based/java/src/com/github/bazelcontrib/rulesjvm/example/Main.java @@ -0,0 +1,9 @@ +package com.github.bazelcontrib.rulesjvm.example; + +import com.google.common.base.Joiner; + +public class Main { + public static void main(String[] args) { + System.out.println(Joiner.on(" ").join("Hello,", "World!")); + } +} diff --git a/examples/workspace-based/java/test/com/github/bazelcontrib/rulesjvm/example/FailingTest.java b/examples/workspace-based/java/test/com/github/bazelcontrib/rulesjvm/example/FailingTest.java new file mode 100644 index 00000000..4441e701 --- /dev/null +++ b/examples/workspace-based/java/test/com/github/bazelcontrib/rulesjvm/example/FailingTest.java @@ -0,0 +1,13 @@ +package com.github.bazelcontrib.rulesjvm.example; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class FailingTest { + + @Test + public void passingText() { + assertEquals("one", "two"); + } +} diff --git a/examples/workspace-based/java/test/com/github/bazelcontrib/rulesjvm/example/PassingTest.java b/examples/workspace-based/java/test/com/github/bazelcontrib/rulesjvm/example/PassingTest.java new file mode 100644 index 00000000..53147863 --- /dev/null +++ b/examples/workspace-based/java/test/com/github/bazelcontrib/rulesjvm/example/PassingTest.java @@ -0,0 +1,13 @@ +package com.github.bazelcontrib.rulesjvm.example; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class PassingTest { + + @Test + public void passingText() { + assertEquals("one", "one"); + } +} diff --git a/gazelle_setup.bzl b/gazelle_setup.bzl index 13d20a56..76adb56b 100644 --- a/gazelle_setup.bzl +++ b/gazelle_setup.bzl @@ -1,6 +1,18 @@ +load("@bazel_features//:deps.bzl", "bazel_features_deps") +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") load("@io_grpc_grpc_java//:repositories.bzl", "io_grpc_grpc_proto") +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") +load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies") +load("@rules_proto//proto:setup.bzl", "rules_proto_setup") +load("@rules_python//python:repositories.bzl", "py_repositories") load("//third_party/go:repositories.bzl", "go_deps") def contrib_rules_jvm_gazelle_setup(): + bazel_features_deps() + rules_pkg_dependencies() + protobuf_deps() + py_repositories() + rules_proto_dependencies() + rules_proto_setup() io_grpc_grpc_proto() go_deps() diff --git a/repositories.bzl b/repositories.bzl index 1b9a5927..792a5d03 100644 --- a/repositories.bzl +++ b/repositories.bzl @@ -127,11 +127,60 @@ def contrib_rules_jvm_gazelle_deps(): maybe( http_archive, name = "rules_proto", - sha256 = "dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd", - # We intentionally format it with the protobuf version to ensure that, - # if we try to upgrade protobuf without upgrading rules_proto, it crashes. - strip_prefix = "rules_proto-5.3.0-{}".format(PROTOBUF_VERSION), - url = "https://github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-{}.tar.gz".format(PROTOBUF_VERSION), + sha256 = "6fb6767d1bef535310547e03247f7518b03487740c11b6c6adb7952033fe1295", + strip_prefix = "rules_proto-6.0.2", + url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.2/rules_proto-6.0.2.tar.gz", + ) + + # We need to expand the contents of `@rules_proto//proto:repositories.bzl" here so + # we can continue the two-step initialisation process + maybe( + http_archive, + name = "rules_license", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_license/releases/download/0.0.7/rules_license-0.0.7.tar.gz", + "https://github.com/bazelbuild/rules_license/releases/download/0.0.7/rules_license-0.0.7.tar.gz", + ], + sha256 = "4531deccb913639c30e5c7512a054d5d875698daeb75d8cf90f284375fe7c360", + ) + + maybe( + http_archive, + name = "rules_cc", + sha256 = "4aeb102efbcfad509857d7cb9c5456731e8ce566bfbf2960286a2ec236796cc3", + strip_prefix = "rules_cc-2f8c04c04462ab83c545ab14c0da68c3b4c96191", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/2f8c04c04462ab83c545ab14c0da68c3b4c96191.tar.gz", + "https://github.com/bazelbuild/rules_cc/archive/2f8c04c04462ab83c545ab14c0da68c3b4c96191.tar.gz", + ], + ) + + maybe( + http_archive, + name = "rules_python", + sha256 = "d70cd72a7a4880f0000a6346253414825c19cdd40a28289bdf67b8e6480edff8", + strip_prefix = "rules_python-0.28.0", + url = "https://github.com/bazelbuild/rules_python/releases/download/0.28.0/rules_python-0.28.0.tar.gz", + ) + + # And other repos we need, apparently + + maybe( + http_archive, + name = "bazel_features", + sha256 = "3646ffd447753490b77d2380fa63f4d55dd9722e565d84dfda01536b48e183da", + strip_prefix = "bazel_features-1.19.0", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.19.0/bazel_features-v1.19.0.tar.gz", + ) + + maybe( + http_archive, + name = "rules_pkg", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/1.0.1/rules_pkg-1.0.1.tar.gz", + "https://github.com/bazelbuild/rules_pkg/releases/download/1.0.1/rules_pkg-1.0.1.tar.gz", + ], + sha256 = "d20c951960ed77cb7b341c2a59488534e494d5ad1d30c4818c736d57772a9fef", ) def io_grpc_grpc_java(): diff --git a/tools/format.sh b/tools/format.sh index 5ee2392c..1f5daf5e 100755 --- a/tools/format.sh +++ b/tools/format.sh @@ -28,4 +28,4 @@ bazel run //:buildifier section "Docs" echo " readme" >&2 -bazel run --noenable_bzlmod //tools:update-docs +bazel run //tools:update-docs