Skip to content

Commit cff5907

Browse files
benjaminpcopybara-github
authored andcommitted
Add ImportDepsChecker to java_tools.
Bazel has a handy utility for checking that java_import rules have the correct dependencies. But it wasn't packaged with java_tools, and therefore very hard to use. Closes #25664. PiperOrigin-RevId: 760711733 Change-Id: I9efd029c7310efd2f5cd6d914619884a08e6c8a5
1 parent 908b28d commit cff5907

File tree

5 files changed

+11
-6
lines changed

5 files changed

+11
-6
lines changed

src/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,7 @@ JAVA_TOOLS_DEPLOY_JARS = [
517517
"//src/java_tools/buildjar:VanillaJavaBuilder_deploy.jar",
518518
"//src/java_tools/buildjar/java/com/google/devtools/build/buildjar/genclass:GenClass_deploy.jar",
519519
"//src/java_tools/buildjar/java/com/google/devtools/build/java/turbine:turbine_direct_binary_deploy.jar",
520+
"//src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps:ImportDepsChecker_deploy.jar",
520521
"//src/java_tools/junitrunner/java/com/google/testing/coverage:JacocoCoverage_jarjar_deploy.jar",
521522
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner:Runner_deploy.jar",
522523
]

src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/BUILD

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ java_binary(
4848
"--add-opens=java.base/java.lang=ALL-UNNAMED",
4949
],
5050
main_class = "com.google.devtools.build.importdeps.Main",
51-
visibility = [
52-
"//src/java_tools/import_deps_checker:__subpackages__",
53-
"//tools/android:__pkg__",
54-
"//tools/android/runtime_deps:__pkg__",
55-
],
5651
deps = [
5752
":import_deps_checker",
5853
"//src/main/java/com/google/devtools/common/options",

src/java_tools/import_deps_checker/java/com/google/devtools/build/importdeps/ImportDepsChecker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.InputStream;
3030
import java.io.UncheckedIOException;
3131
import java.nio.file.Path;
32+
import java.util.Collection;
3233
import java.util.LinkedHashSet;
3334
import java.util.Map;
3435
import java.util.Set;
@@ -141,7 +142,7 @@ private void emitAddDepCommandForIndirectJars(String ruleLabel, StringBuilder bu
141142
ImmutableMultimap<Path, String> indirectJars = resultCollector.getSortedIndirectDeps();
142143
if (!indirectJars.isEmpty()) {
143144
Set<String> labels = new LinkedHashSet<>();
144-
for (var e : indirectJars.asMap().entrySet()) {
145+
for (Map.Entry<Path, Collection<String>> e : indirectJars.asMap().entrySet()) {
145146
Path jar = e.getKey();
146147
String label = extractLabel(jar);
147148
builder.append("Indirect reference to classes from ");

src/test/shell/bazel/bazel_java_tools_test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ function expect_path_in_java_tools_prebuilt() {
102102
[[ "$count" -gt 0 ]] || fail "Path $path not found in java_tools_prebuilt.zip"
103103
}
104104

105+
function test_java_tools_has_import_deps_checker() {
106+
expect_path_in_java_tools "java_tools/ImportDepsChecker_deploy.jar"
107+
}
105108

106109
function test_java_tools_has_ijar() {
107110
expect_path_in_java_tools "java_tools/ijar"

tools/jdk/BUILD.java_tools

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ SUPRESSED_WARNINGS = select({
1919
],
2020
})
2121

22+
filegroup(
23+
name = "ImportDepsChecker",
24+
srcs = ["java_tools/ImportDepsChecker_deploy.jar"],
25+
)
26+
2227
filegroup(
2328
name = "GenClass",
2429
srcs = ["java_tools/GenClass_deploy.jar"],

0 commit comments

Comments
 (0)