forked from bazelbuild/rules_java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjava_plugin_info_tests.bzl
More file actions
191 lines (171 loc) · 6.9 KB
/
Copy pathjava_plugin_info_tests.bzl
File metadata and controls
191 lines (171 loc) · 6.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""Tests for the JavaPluginInfo provider"""
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
load("@rules_testing//lib:util.bzl", "util")
load("//java:java_library.bzl", "java_library")
load("//java:java_plugin.bzl", "java_plugin")
load("//java/common:java_plugin_info.bzl", "JavaPluginInfo")
load("//java/test/testutil:java_info_subject.bzl", "java_plugin_info_subject")
load("//java/test/testutil:rules/custom_plugin.bzl", "custom_plugin")
def _test_exposes_java_outputs(name):
util.helper_target(
java_library,
name = name + "/lib",
srcs = ["Lib.java"],
)
util.helper_target(
java_plugin,
name = name + "/dep",
srcs = ["Dep.java"],
deps = [name + "/lib"],
)
analysis_test(
name = name,
impl = _test_exposes_java_outputs_impl,
target = name + "/dep",
)
def _test_exposes_java_outputs_impl(env, target):
assert_output = java_plugin_info_subject.from_target(env, target).java_outputs().singleton()
assert_output.class_jar().short_path_equals("{package}/lib{name}.jar")
assert_output.compile_jar().short_path_equals("{package}/lib{name}-hjar.jar")
assert_output.source_jars().contains_exactly(["{package}/lib{name}-src.jar"])
assert_output.jdeps().short_path_equals("{package}/lib{name}.jdeps")
assert_output.compile_jdeps().short_path_equals("{package}/lib{name}-hjar.jdeps")
def _test_provider_contstructor(name):
target_name = name + "/plugin"
util.helper_target(
java_library,
name = target_name + "/plugin_dep1",
srcs = ["A.java"],
data = ["depfile1.dat"],
)
util.helper_target(
custom_plugin,
name = target_name,
data = ["pluginfile1.dat"],
processor_class = "com.google.process.stuff",
deps = [target_name + "/plugin_dep1"],
)
analysis_test(
name = name,
impl = _test_provider_contstructor_impl,
target = target_name,
)
def _test_provider_contstructor_impl(env, target):
assert_plugin_data = java_plugin_info_subject.from_target(env, target).plugins()
assert_plugin_data.processor_classes().contains_exactly(["com.google.process.stuff"])
assert_plugin_data.processor_jars().contains_exactly([
"{package}/{name}/lib.jar",
"{package}/lib{name}/plugin_dep1.jar",
])
assert_plugin_data.processor_data().contains_exactly(["{package}/pluginfile1.dat"])
assert_api_plugin_data = java_plugin_info_subject.from_target(env, target).api_generating_plugins()
assert_api_plugin_data.processor_classes().contains_exactly([])
assert_api_plugin_data.processor_jars().contains_exactly([])
assert_api_plugin_data.processor_data().contains_exactly([])
def _test_api_generating_provider_constructor(name):
target_name = name + "/plugin"
util.helper_target(
java_library,
name = target_name + "/plugin_dep1",
srcs = ["A.java"],
data = ["depfile1.dat"],
)
util.helper_target(
custom_plugin,
name = target_name,
data = ["pluginfile1.dat"],
processor_class = "com.google.process.stuff",
deps = [target_name + "/plugin_dep1"],
generates_api = True,
)
analysis_test(
name = name,
impl = _test_api_generating_provider_constructor_impl,
target = target_name,
)
def _test_api_generating_provider_constructor_impl(env, target):
assert_api_plugin_data = java_plugin_info_subject.from_target(env, target).api_generating_plugins()
assert_api_plugin_data.processor_classes().contains_exactly(["com.google.process.stuff"])
assert_api_plugin_data.processor_jars().contains_exactly([
"{package}/{name}/lib.jar",
"{package}/lib{name}/plugin_dep1.jar",
])
assert_api_plugin_data.processor_data().contains_exactly(["{package}/pluginfile1.dat"])
assert_api_plugin_data.equals(target[JavaPluginInfo].plugins)
def _test_without_processor_class(name):
target_name = name + "/plugin"
util.helper_target(
java_library,
name = target_name + "/plugin_dep1",
srcs = ["A.java"],
data = ["depfile1.dat"],
)
util.helper_target(
custom_plugin,
name = target_name,
processor_class = None,
data = ["pluginfile1.dat"],
deps = [target_name + "/plugin_dep1"],
)
analysis_test(
name = name,
impl = _test_without_processor_class_impl,
target = target_name,
attr_values = {"tags": ["min_bazel_7"]},
)
def _test_without_processor_class_impl(env, target):
assert_plugin_data = java_plugin_info_subject.from_target(env, target).plugins()
assert_plugin_data.processor_classes().contains_exactly([])
assert_plugin_data.processor_jars().contains_exactly([
"{package}/{name}/lib.jar",
"{package}/lib{name}/plugin_dep1.jar",
])
assert_plugin_data.processor_data().contains_exactly(["{package}/pluginfile1.dat"])
assert_api_plugin_data = java_plugin_info_subject.from_target(env, target).api_generating_plugins()
assert_api_plugin_data.processor_classes().contains_exactly([])
assert_api_plugin_data.processor_jars().contains_exactly([])
assert_api_plugin_data.processor_data().contains_exactly([])
def _test_constructor_with_data_depset(name):
target_name = name + "/plugin"
util.helper_target(
java_library,
name = target_name + "/plugin_dep1",
srcs = ["A.java"],
data = ["depfile1.dat"],
)
util.helper_target(
custom_plugin,
name = target_name,
processor_class = "com.google.process.stuff",
data = ["pluginfile1.dat"],
deps = [target_name + "/plugin_dep1"],
data_as_depset = True,
)
analysis_test(
name = name,
impl = _test_constructor_with_data_depset_impl,
target = target_name,
)
def _test_constructor_with_data_depset_impl(env, target):
assert_plugin_data = java_plugin_info_subject.from_target(env, target).plugins()
assert_plugin_data.processor_classes().contains_exactly(["com.google.process.stuff"])
assert_plugin_data.processor_jars().contains_exactly([
"{package}/{name}/lib.jar",
"{package}/lib{name}/plugin_dep1.jar",
])
assert_plugin_data.processor_data().contains_exactly(["{package}/pluginfile1.dat"])
assert_api_plugin_data = java_plugin_info_subject.from_target(env, target).api_generating_plugins()
assert_api_plugin_data.processor_classes().contains_exactly([])
assert_api_plugin_data.processor_jars().contains_exactly([])
assert_api_plugin_data.processor_data().contains_exactly([])
def java_plugin_info_tests(name):
test_suite(
name = name,
tests = [
_test_exposes_java_outputs,
_test_provider_contstructor,
_test_api_generating_provider_constructor,
_test_without_processor_class,
_test_constructor_with_data_depset,
],
)