Skip to content

Commit dea06c1

Browse files
java-team-github-botXiaoming Jia
authored and
Xiaoming Jia
committed
Make Guice builds with bazel.
This change only makes it possible to build with bazel and no changes to existing maven setup yet. PiperOrigin-RevId: 422630465
1 parent bbd2f0d commit dea06c1

File tree

68 files changed

+1450
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1450
-14
lines changed

BUILD

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package_group(
2+
name = "src",
3+
packages = ["//..."],
4+
)

WORKSPACE

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2+
3+
RULES_JVM_EXTERNAL_TAG = "4.2"
4+
RULES_JVM_EXTERNAL_SHA = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca"
5+
6+
http_archive(
7+
name = "rules_jvm_external",
8+
strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
9+
sha256 = RULES_JVM_EXTERNAL_SHA,
10+
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
11+
)
12+
13+
load("@rules_jvm_external//:defs.bzl", "maven_install")
14+
load("@rules_jvm_external//:specs.bzl", "maven")
15+
16+
http_archive(
17+
name = "google_bazel_common",
18+
sha256 = "61cd7c2a24a1b066848a68c56deca799dd9d0329cb9032d1686859cdd2c05be2",
19+
strip_prefix = "bazel-common-2e42988b7a3d1e3b11ab4db2d7c28f794500a672",
20+
urls = ["https://github.com/google/bazel-common/archive/2e42988b7a3d1e3b11ab4db2d7c28f794500a672.zip"],
21+
)
22+
23+
load("@google_bazel_common//:workspace_defs.bzl", "google_common_workspace_rules")
24+
25+
google_common_workspace_rules()
26+
27+
maven_install(
28+
artifacts = [
29+
"aopalliance:aopalliance:1.0",
30+
"com.google.auto.value:auto-value:1.6.3",
31+
"com.google.code.findbugs:jsr305:3.0.1",
32+
"com.google.dagger:dagger:2.22.1",
33+
"com.google.dagger:dagger-producers:2.22.1",
34+
"com.google.errorprone:error_prone_annotations:2.0.18",
35+
"com.google.guava:guava:30.1-jre",
36+
"commons-logging:commons-logging:1.2",
37+
"javax.inject:javax.inject:1",
38+
"javax.persistence:javax.persistence-api:2.2",
39+
"javax.servlet:servlet-api:2.5",
40+
"org.apache.struts:struts2-core:2.3.37",
41+
"org.apache.struts.xwork:xwork-core:2.3.37",
42+
"org.ow2.asm:asm:9.2",
43+
"org.springframework:spring-core:3.2.18.RELEASE",
44+
"org.springframework:spring-beans:3.2.18.RELEASE",
45+
maven.artifact(
46+
"biz.aQute", "bnd", "0.0.384", testonly = True
47+
),
48+
maven.artifact(
49+
"com.google.guava", "guava-testlib", "30.1-jre", testonly = True
50+
),
51+
maven.artifact(
52+
"com.google.truth", "truth", "0.45", testonly = True
53+
),
54+
maven.artifact(
55+
"javax.inject", "javax.inject-tck", "1", testonly = True
56+
),
57+
maven.artifact(
58+
"junit", "junit", "4.13.2", testonly = True
59+
),
60+
maven.artifact(
61+
"org.apache.felix", "org.apache.felix.framework", "3.0.5", testonly = True
62+
),
63+
maven.artifact(
64+
"org.easymock", "easymock", "3.1", testonly = True
65+
),
66+
maven.artifact(
67+
"org.hamcrest", "hamcrest", "2.2", testonly = True
68+
),
69+
maven.artifact(
70+
"org.hibernate.javax.persistence", "hibernate-jpa-2.0-api", "1.0.0.Final", testonly = True
71+
),
72+
maven.artifact(
73+
"org.hibernate", "hibernate-core", "5.6.3.Final", testonly = True
74+
),
75+
maven.artifact(
76+
"org.hsqldb", "hsqldb-j5", "2.0.0", testonly = True
77+
),
78+
maven.artifact(
79+
"org.mockito", "mockito-core", "1.9.5", testonly = True
80+
),
81+
],
82+
repositories = [
83+
"https://repo1.maven.org/maven2",
84+
],
85+
)

core/src/com/google/inject/BUILD

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Copyright 2011 Google Inc. All rights reserved.
2+
# Author: [email protected] (Sam Berlin)
3+
load("@rules_java//java:defs.bzl", "java_library")
4+
5+
package(
6+
default_visibility = ["//:src"],
7+
)
8+
9+
ANNOTATION_SRCS = [
10+
"BindingAnnotation.java",
11+
"Exposed.java",
12+
"Inject.java",
13+
"ProvidedBy.java",
14+
"Provides.java",
15+
"ScopeAnnotation.java",
16+
"Singleton.java",
17+
]
18+
19+
IMPLEMENTED_BY_SRCS = [
20+
"ImplementedBy.java",
21+
]
22+
23+
java_library(
24+
name = "implemented_by",
25+
srcs = IMPLEMENTED_BY_SRCS,
26+
)
27+
28+
# TODO(lukes,user): It'd be nice if this wasn't one big rule.
29+
# Unfortunately, splitting it apart would not be easy. We looked into
30+
# it and the main issues appear to be:
31+
# - Utility classes like internal/MoreTypes (choke point dependencies)
32+
# - Cyclical dependencies between Binder and spi/Element
33+
java_library(
34+
name = "inject",
35+
srcs = glob(
36+
["**/*.java"],
37+
exclude = IMPLEMENTED_BY_SRCS + ANNOTATION_SRCS,
38+
),
39+
plugins = [
40+
],
41+
exports = [
42+
":annotations",
43+
":implemented_by",
44+
],
45+
deps = [
46+
# Warning: Be very careful adding new dependencies,
47+
# These all have to mirrored in the open-source
48+
# build (and jarjar'd up).
49+
":annotations",
50+
":implemented_by",
51+
"//third_party/java/guava/annotations",
52+
"//third_party/java/guava/base",
53+
"//third_party/java/guava/cache",
54+
"//third_party/java/guava/collect",
55+
"//third_party/java/guava/primitives",
56+
"//third_party/java/aopalliance",
57+
"//third_party/java/asm",
58+
"//third_party/java/error_prone:annotations",
59+
"//third_party/java/jsr305_annotations",
60+
"//third_party/java/jsr330_inject",
61+
],
62+
)
63+
64+
java_library(
65+
name = "annotations",
66+
srcs = ANNOTATION_SRCS,
67+
plugins = [
68+
],
69+
deps = [
70+
"//third_party/java/error_prone:annotations",
71+
"//third_party/java/jsr330_inject",
72+
],
73+
)

core/test/com/google/inject/BUILD

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Copyright 2011 Google Inc. All rights reserved.
2+
# Author: [email protected] (Sam Berlin)
3+
load("@rules_java//java:defs.bzl", "java_library")
4+
load("//:test_defs.bzl", "guice_test_suites")
5+
6+
package(default_testonly = 1)
7+
8+
TEST_SUPPORT_SRCS = [
9+
"Asserts.java",
10+
"internal/WeakKeySetUtils.java",
11+
]
12+
13+
# Files that are shared by extensions also.
14+
# Typically this would go in a java/../testing package,
15+
# but we need to work with the open-source code structure,
16+
# so it is here.
17+
java_library(
18+
name = "testsupport",
19+
srcs = TEST_SUPPORT_SRCS,
20+
javacopts = ["-Xep:BetaApi:OFF"],
21+
visibility = [
22+
"//:src",
23+
],
24+
deps = [
25+
"//core/src/com/google/inject",
26+
"//third_party/java/guava/base",
27+
"//third_party/java/guava/collect",
28+
"//third_party/java/guava/testing",
29+
"//third_party/java/junit",
30+
"//third_party/java/truth",
31+
],
32+
)
33+
34+
# All the actual XTest classes & friends.
35+
java_library(
36+
name = "tests",
37+
srcs = glob(
38+
["**/*.java"], # glob ignores subfolder that has its own BUILD files
39+
exclude = TEST_SUPPORT_SRCS + [
40+
"AllTests.java",
41+
],
42+
),
43+
javacopts = ["-Xep:BetaApi:OFF"],
44+
plugins = [
45+
],
46+
deps = [
47+
":testsupport",
48+
"//core/src/com/google/inject",
49+
"//third_party/java/aopalliance",
50+
"//third_party/java/asm",
51+
"//third_party/java/guava/base",
52+
"//third_party/java/guava/collect",
53+
"//third_party/java/guava/testing",
54+
"//third_party/java/guava/util/concurrent",
55+
"//third_party/java/jsr330_inject",
56+
"//third_party/java/junit",
57+
"//third_party/java/truth",
58+
],
59+
)
60+
61+
# This target is unused, but exists so that we can more easily
62+
# ensure the opensource build maintains compiling code.
63+
java_library(
64+
name = "AllTests",
65+
srcs = ["AllTests.java"],
66+
deps = [
67+
":tests",
68+
"//core/test/com/googlecode/guice:tests",
69+
"//third_party/java/junit",
70+
],
71+
)
72+
73+
guice_test_suites(
74+
name = "gen_tests",
75+
sizes = [
76+
"small",
77+
"medium",
78+
],
79+
deps = [":tests"],
80+
)
81+
82+
[guice_test_suites(
83+
name = "gen_tests_stack_trace_%s" % include_stack_trace_option,
84+
args = [
85+
"--guice_include_stack_traces=%s" % include_stack_trace_option,
86+
],
87+
sizes = [
88+
"small",
89+
"medium",
90+
],
91+
suffix = "_stack_trace_%s" % include_stack_trace_option,
92+
deps = [":tests"],
93+
) for include_stack_trace_option in [
94+
"OFF",
95+
]]
96+
97+
[guice_test_suites(
98+
name = "gen_tests_class_loading_%s" % custom_class_loading_option,
99+
args = [
100+
"--guice_custom_class_loading=%s" % custom_class_loading_option,
101+
],
102+
sizes = [
103+
"small",
104+
"medium",
105+
],
106+
suffix = "_custom_class_loading_%s" % custom_class_loading_option,
107+
deps = [":tests"],
108+
) for custom_class_loading_option in [
109+
"OFF",
110+
"CHILD",
111+
"ANONYMOUS",
112+
]]
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
load("@rules_java//java:defs.bzl", "java_library")
2+
load("//:test_defs.bzl", "guice_test_suites")
3+
4+
package(
5+
default_testonly = 1,
6+
)
7+
8+
java_library(
9+
name = "tests",
10+
srcs = glob(["*.java"]),
11+
javacopts = ["-Xep:BetaApi:OFF"],
12+
plugins = [
13+
],
14+
resources = [
15+
":test_error_files",
16+
],
17+
deps = [
18+
"//core/src/com/google/inject",
19+
"//third_party/java/guava/annotations",
20+
"//third_party/java/guava/collect",
21+
"//third_party/java/guava/io",
22+
"//third_party/java/jsr330_inject",
23+
"//third_party/java/junit",
24+
"//third_party/java/truth",
25+
],
26+
)
27+
28+
filegroup(
29+
name = "test_error_files",
30+
srcs = glob(["testdata/*.txt"]),
31+
)
32+
33+
[guice_test_suites(
34+
name = "gen_tests_stack_trace%s" % include_stack_trace_option,
35+
args = [
36+
"--guice_include_stack_traces=%s" % include_stack_trace_option,
37+
],
38+
sizes = [
39+
"small",
40+
],
41+
suffix = "_stack_trace_%s" % include_stack_trace_option,
42+
deps = [":tests"],
43+
) for include_stack_trace_option in [
44+
"OFF",
45+
"ONLY_FOR_DECLARING_SOURCE",
46+
]]

core/test/com/google/inject/errors/ErrorMessageTestUtils.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.google.common.io.Resources;
77
import java.io.IOException;
8+
import java.net.URL;
89

910
final class ErrorMessageTestUtils {
1011
private static final String LINE_NUMBER_REGEX = ":\\d+";
@@ -38,7 +39,14 @@ private static void assertErrorMessage(String actual, String expected) {
3839
}
3940

4041
private static String getExpectedError(String fileName) throws IOException {
41-
return Resources.toString(
42-
ErrorMessageTestUtils.class.getResource("testdata/" + fileName), UTF_8);
42+
URL resource = ErrorMessageTestUtils.class.getResource("testdata/" + fileName);
43+
// The location of the resource depends on if we are using maven or bazel.
44+
// TODO: remove this once we no longer use maven.
45+
if (resource == null) {
46+
resource =
47+
ErrorMessageTestUtils.class.getResource(
48+
"/core/test/com/google/inject/errors/testdata/" + fileName);
49+
}
50+
return Resources.toString(resource, UTF_8);
4351
}
4452
}

0 commit comments

Comments
 (0)