xref: /aosp_15_r20/build/soong/java/sdk_test.go (revision 333d2b3687b3a337dbcca9d65000bca186795e39)
1// Copyright 2019 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package java
16
17import (
18	"path/filepath"
19	"strings"
20	"testing"
21
22	"github.com/google/blueprint/proptools"
23
24	"android/soong/android"
25	"android/soong/java/config"
26)
27
28type classpathTestCase struct {
29	name       string
30	unbundled  bool
31	moduleType string
32	host       android.OsClass
33	properties string
34
35	// for java 8
36	bootclasspath  []string
37	java8classpath []string
38
39	// for java 9
40	system         string
41	java9classpath []string
42
43	forces8 bool // if set, javac will always be called with java 8 arguments
44
45	aidl string
46
47	// Indicates how this test case is affected by the setting of Always_use_prebuilt_sdks.
48	//
49	// If this is nil then the test case is unaffected by the setting of Always_use_prebuilt_sdks.
50	// Otherwise, the test case can only be used when
51	// Always_use_prebuilt_sdks=*forAlwaysUsePrebuiltSdks.
52	forAlwaysUsePrebuiltSdks *bool
53}
54
55func TestClasspath(t *testing.T) {
56	const frameworkAidl = "-I" + defaultJavaDir + "/framework/aidl"
57	var classpathTestcases = []classpathTestCase{
58		{
59			name:           "default",
60			bootclasspath:  config.StableCorePlatformBootclasspathLibraries,
61			system:         config.StableCorePlatformSystemModules,
62			java8classpath: config.FrameworkLibraries,
63			java9classpath: config.FrameworkLibraries,
64			aidl:           frameworkAidl,
65		},
66		{
67			name:           `sdk_version:"core_platform"`,
68			properties:     `sdk_version:"core_platform"`,
69			bootclasspath:  config.StableCorePlatformBootclasspathLibraries,
70			system:         config.StableCorePlatformSystemModules,
71			java8classpath: []string{},
72			aidl:           "",
73		},
74		{
75			name:           "blank sdk version",
76			properties:     `sdk_version: "",`,
77			bootclasspath:  config.StableCorePlatformBootclasspathLibraries,
78			system:         config.StableCorePlatformSystemModules,
79			java8classpath: config.FrameworkLibraries,
80			java9classpath: config.FrameworkLibraries,
81			aidl:           frameworkAidl,
82		},
83		{
84
85			name:           "sdk v29",
86			properties:     `sdk_version: "29",`,
87			bootclasspath:  []string{`""`},
88			forces8:        true,
89			java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
90			aidl:           "-pprebuilts/sdk/29/public/framework.aidl",
91		},
92		{
93
94			name:           "sdk v30",
95			properties:     `sdk_version: "30",`,
96			bootclasspath:  []string{`""`},
97			system:         "sdk_public_30_system_modules",
98			java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
99			java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
100			aidl:           "-pprebuilts/sdk/30/public/framework.aidl",
101		},
102		{
103			// Test case only applies when Always_use_prebuilt_sdks=false (the default).
104			forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
105
106			name:           "current",
107			properties:     `sdk_version: "current",`,
108			bootclasspath:  []string{"android_stubs_current", "core-lambda-stubs"},
109			system:         "core-public-stubs-system-modules",
110			java9classpath: []string{"android_stubs_current"},
111			aidl:           "-pout/soong/framework.aidl",
112		},
113		{
114			// Test case only applies when Always_use_prebuilt_sdks=true.
115			forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
116
117			name:           "current",
118			properties:     `sdk_version: "current",`,
119			bootclasspath:  []string{`""`},
120			system:         "sdk_public_current_system_modules",
121			java8classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
122			java9classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
123			aidl:           "-pprebuilts/sdk/current/public/framework.aidl",
124		},
125		{
126			// Test case only applies when Always_use_prebuilt_sdks=false (the default).
127			forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
128
129			name:           "system_current",
130			properties:     `sdk_version: "system_current",`,
131			bootclasspath:  []string{"android_system_stubs_current", "core-lambda-stubs"},
132			system:         "core-public-stubs-system-modules",
133			java9classpath: []string{"android_system_stubs_current"},
134			aidl:           "-pout/soong/framework.aidl",
135		},
136		{
137			// Test case only applies when Always_use_prebuilt_sdks=true.
138			forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
139
140			name:           "system_current",
141			properties:     `sdk_version: "system_current",`,
142			bootclasspath:  []string{`""`},
143			system:         "sdk_public_current_system_modules",
144			java8classpath: []string{"prebuilts/sdk/current/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
145			java9classpath: []string{"prebuilts/sdk/current/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
146			aidl:           "-pprebuilts/sdk/current/public/framework.aidl",
147		},
148		{
149			name:           "system_29",
150			properties:     `sdk_version: "system_29",`,
151			bootclasspath:  []string{`""`},
152			forces8:        true,
153			java8classpath: []string{"prebuilts/sdk/29/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
154			aidl:           "-pprebuilts/sdk/29/public/framework.aidl",
155		},
156		{
157			name:           "system_30",
158			properties:     `sdk_version: "system_30",`,
159			bootclasspath:  []string{`""`},
160			system:         "sdk_public_30_system_modules",
161			java8classpath: []string{"prebuilts/sdk/30/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
162			java9classpath: []string{"prebuilts/sdk/30/system/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
163			aidl:           "-pprebuilts/sdk/30/public/framework.aidl",
164		},
165		{
166			// Test case only applies when Always_use_prebuilt_sdks=false (the default).
167			forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
168
169			name:           "test_current",
170			properties:     `sdk_version: "test_current",`,
171			bootclasspath:  []string{"android_test_stubs_current", "core-lambda-stubs"},
172			system:         "core-public-stubs-system-modules",
173			java9classpath: []string{"android_test_stubs_current"},
174			aidl:           "-pout/soong/framework.aidl",
175		},
176		{
177			// Test case only applies when Always_use_prebuilt_sdks=true.
178			forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
179
180			name:           "test_current",
181			properties:     `sdk_version: "test_current",`,
182			bootclasspath:  []string{`""`},
183			system:         "sdk_public_current_system_modules",
184			java8classpath: []string{"prebuilts/sdk/current/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
185			java9classpath: []string{"prebuilts/sdk/current/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
186			aidl:           "-pprebuilts/sdk/current/public/framework.aidl",
187		},
188		{
189			name:           "test_30",
190			properties:     `sdk_version: "test_30",`,
191			bootclasspath:  []string{`""`},
192			system:         "sdk_public_30_system_modules",
193			java8classpath: []string{"prebuilts/sdk/30/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
194			java9classpath: []string{"prebuilts/sdk/30/test/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
195			aidl:           "-pprebuilts/sdk/30/public/framework.aidl",
196		},
197		{
198			// Test case only applies when Always_use_prebuilt_sdks=false (the default).
199			forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
200
201			name:          "core_current",
202			properties:    `sdk_version: "core_current",`,
203			bootclasspath: []string{"core.current.stubs", "core-lambda-stubs"},
204			system:        "core-public-stubs-system-modules",
205		},
206		{
207			// Test case only applies when Always_use_prebuilt_sdks=true.
208			forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
209
210			name:           "core_current",
211			properties:     `sdk_version: "core_current",`,
212			bootclasspath:  []string{`""`},
213			system:         "sdk_public_current_system_modules",
214			java8classpath: []string{"prebuilts/sdk/current/core/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
215			java9classpath: []string{"prebuilts/sdk/current/core/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
216			aidl:           "-pprebuilts/sdk/current/public/framework.aidl",
217		},
218		{
219
220			name:           "nostdlib",
221			properties:     `sdk_version: "none", system_modules: "none"`,
222			system:         "none",
223			bootclasspath:  []string{`""`},
224			java8classpath: []string{},
225		},
226		{
227
228			name:           "nostdlib system_modules",
229			properties:     `sdk_version: "none", system_modules: "stable-core-platform-api-stubs-system-modules"`,
230			system:         "stable-core-platform-api-stubs-system-modules",
231			bootclasspath:  []string{"stable-core-platform-api-stubs-system-modules-lib"},
232			java8classpath: []string{},
233		},
234		{
235
236			name:           "host default",
237			moduleType:     "java_library_host",
238			properties:     ``,
239			host:           android.Host,
240			bootclasspath:  []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"},
241			java8classpath: []string{},
242		},
243		{
244
245			name:           "host supported default",
246			host:           android.Host,
247			properties:     `host_supported: true,`,
248			java8classpath: []string{},
249			bootclasspath:  []string{"jdk8/jre/lib/jce.jar", "jdk8/jre/lib/rt.jar"},
250		},
251		{
252			name:           "host supported nostdlib",
253			host:           android.Host,
254			properties:     `host_supported: true, sdk_version: "none", system_modules: "none"`,
255			java8classpath: []string{},
256		},
257		{
258
259			name:           "unbundled sdk v29",
260			unbundled:      true,
261			properties:     `sdk_version: "29",`,
262			bootclasspath:  []string{`""`},
263			forces8:        true,
264			java8classpath: []string{"prebuilts/sdk/29/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
265			aidl:           "-pprebuilts/sdk/29/public/framework.aidl",
266		},
267		{
268
269			name:           "unbundled sdk v30",
270			unbundled:      true,
271			properties:     `sdk_version: "30",`,
272			bootclasspath:  []string{`""`},
273			system:         "sdk_public_30_system_modules",
274			java8classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
275			java9classpath: []string{"prebuilts/sdk/30/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
276			aidl:           "-pprebuilts/sdk/30/public/framework.aidl",
277		},
278		{
279
280			name:           "unbundled current",
281			unbundled:      true,
282			properties:     `sdk_version: "current",`,
283			bootclasspath:  []string{`""`},
284			system:         "sdk_public_current_system_modules",
285			java8classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
286			java9classpath: []string{"prebuilts/sdk/current/public/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
287			aidl:           "-pprebuilts/sdk/current/public/framework.aidl",
288		},
289		{
290			// Test case only applies when Always_use_prebuilt_sdks=false (the default).
291			forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
292
293			name:           "module_current",
294			properties:     `sdk_version: "module_current",`,
295			bootclasspath:  []string{"android_module_lib_stubs_current", "core-lambda-stubs"},
296			system:         "core-module-lib-stubs-system-modules",
297			java9classpath: []string{"android_module_lib_stubs_current"},
298			aidl:           "-pout/soong/framework_non_updatable.aidl",
299		},
300		{
301			// Test case only applies when Always_use_prebuilt_sdks=true.
302			forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
303
304			name:           "module_current",
305			properties:     `sdk_version: "module_current",`,
306			bootclasspath:  []string{`""`},
307			system:         "sdk_module-lib_current_system_modules",
308			java8classpath: []string{"prebuilts/sdk/current/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
309			java9classpath: []string{"prebuilts/sdk/current/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
310			aidl:           "-pprebuilts/sdk/current/public/framework.aidl",
311		},
312		{
313			name:           "module_30",
314			properties:     `sdk_version: "module_30",`,
315			bootclasspath:  []string{`""`},
316			system:         "sdk_public_30_system_modules",
317			java8classpath: []string{"prebuilts/sdk/30/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
318			java9classpath: []string{"prebuilts/sdk/30/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
319			aidl:           "-pprebuilts/sdk/30/public/framework.aidl",
320		},
321		{
322			name:           "module_31",
323			properties:     `sdk_version: "module_31",`,
324			bootclasspath:  []string{`""`},
325			system:         "sdk_public_31_system_modules",
326			java8classpath: []string{"prebuilts/sdk/31/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
327			java9classpath: []string{"prebuilts/sdk/31/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
328			aidl:           "-pprebuilts/sdk/31/public/framework.aidl",
329		},
330		{
331			name:           "module_32",
332			properties:     `sdk_version: "module_32",`,
333			bootclasspath:  []string{`""`},
334			system:         "sdk_module-lib_32_system_modules",
335			java8classpath: []string{"prebuilts/sdk/32/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
336			java9classpath: []string{"prebuilts/sdk/32/module-lib/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
337			aidl:           "-pprebuilts/sdk/32/public/framework.aidl",
338		},
339		{
340			// Test case only applies when Always_use_prebuilt_sdks=false (the default).
341			forAlwaysUsePrebuiltSdks: proptools.BoolPtr(false),
342
343			name:           "system_server_current",
344			properties:     `sdk_version: "system_server_current",`,
345			bootclasspath:  []string{"android_system_server_stubs_current", "core-lambda-stubs"},
346			system:         "core-module-lib-stubs-system-modules",
347			java9classpath: []string{"android_system_server_stubs_current"},
348			aidl:           "-pout/soong/framework.aidl",
349		},
350		{
351			// Test case only applies when Always_use_prebuilt_sdks=true.
352			forAlwaysUsePrebuiltSdks: proptools.BoolPtr(true),
353
354			name:           "system_server_current",
355			properties:     `sdk_version: "system_server_current",`,
356			bootclasspath:  []string{`""`},
357			system:         "sdk_module-lib_current_system_modules",
358			java8classpath: []string{"prebuilts/sdk/current/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
359			java9classpath: []string{"prebuilts/sdk/current/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
360			aidl:           "-pprebuilts/sdk/current/public/framework.aidl",
361		},
362		{
363			name:           "system_server_30",
364			properties:     `sdk_version: "system_server_30",`,
365			bootclasspath:  []string{`""`},
366			system:         "sdk_public_30_system_modules",
367			java8classpath: []string{"prebuilts/sdk/30/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
368			java9classpath: []string{"prebuilts/sdk/30/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
369			aidl:           "-pprebuilts/sdk/30/public/framework.aidl",
370		},
371		{
372			name:           "system_server_31",
373			properties:     `sdk_version: "system_server_31",`,
374			bootclasspath:  []string{`""`},
375			system:         "sdk_public_31_system_modules",
376			java8classpath: []string{"prebuilts/sdk/31/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
377			java9classpath: []string{"prebuilts/sdk/31/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
378			aidl:           "-pprebuilts/sdk/31/public/framework.aidl",
379		},
380		{
381			name:           "system_server_32",
382			properties:     `sdk_version: "system_server_32",`,
383			bootclasspath:  []string{`""`},
384			system:         "sdk_module-lib_32_system_modules",
385			java8classpath: []string{"prebuilts/sdk/32/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
386			java9classpath: []string{"prebuilts/sdk/32/system-server/android.jar", "prebuilts/sdk/tools/core-lambda-stubs.jar"},
387			aidl:           "-pprebuilts/sdk/32/public/framework.aidl",
388		},
389	}
390
391	t.Parallel()
392	t.Run("basic", func(t *testing.T) {
393		t.Parallel()
394		testClasspathTestCases(t, classpathTestcases, false, false)
395	})
396
397	t.Run("Always_use_prebuilt_sdks=true", func(t *testing.T) {
398		testClasspathTestCases(t, classpathTestcases, true, false)
399	})
400
401	t.Run("UseTransitiveJarsInClasspath", func(t *testing.T) {
402		testClasspathTestCases(t, classpathTestcases, false, true)
403	})
404}
405
406func testClasspathTestCases(t *testing.T, classpathTestcases []classpathTestCase, alwaysUsePrebuiltSdks, useTransitiveJarsInClasspath bool) {
407	for _, testcase := range classpathTestcases {
408		if testcase.forAlwaysUsePrebuiltSdks != nil && *testcase.forAlwaysUsePrebuiltSdks != alwaysUsePrebuiltSdks {
409			continue
410		}
411
412		t.Run(testcase.name, func(t *testing.T) {
413			t.Parallel()
414			moduleType := "java_library"
415			if testcase.moduleType != "" {
416				moduleType = testcase.moduleType
417			}
418
419			props := `
420				name: "foo",
421				srcs: ["a.java"],
422				target: {
423					android: {
424						srcs: ["bar-doc/IFoo.aidl"],
425					},
426				},
427				`
428			bp := moduleType + " {" + props + testcase.properties + `
429			}`
430			bpJava8 := moduleType + " {" + props + `java_version: "1.8",
431				` + testcase.properties + `
432			}`
433
434			variant := func(result *android.TestResult) string {
435				if testcase.host == android.Host {
436					return result.Config.BuildOS.String() + "_common"
437				}
438				return "android_common"
439			}
440
441			convertModulesToPaths := func(cp []string) []string {
442				ret := make([]string, len(cp))
443				for i, e := range cp {
444					switch {
445					case e == `""`, strings.HasSuffix(e, ".jar"):
446						ret[i] = e
447					case useTransitiveJarsInClasspath:
448						ret[i] = filepath.Join("out", "soong", ".intermediates", defaultJavaDir, e, "android_common", "turbine", e+".jar")
449					default:
450						ret[i] = filepath.Join("out", "soong", ".intermediates", defaultJavaDir, e, "android_common", "turbine-combined", e+".jar")
451					}
452				}
453				return ret
454			}
455
456			bootclasspath := convertModulesToPaths(testcase.bootclasspath)
457			java8classpath := convertModulesToPaths(testcase.java8classpath)
458			java9classpath := convertModulesToPaths(testcase.java9classpath)
459
460			bc := ""
461			var bcDeps []string
462			if len(bootclasspath) > 0 {
463				bc = "-bootclasspath " + strings.Join(bootclasspath, ":")
464				if bootclasspath[0] != `""` {
465					bcDeps = bootclasspath
466				}
467			}
468
469			j8c := ""
470			if len(java8classpath) > 0 {
471				j8c = "-classpath " + strings.Join(java8classpath, ":")
472			}
473
474			j9c := ""
475			if len(java9classpath) > 0 {
476				j9c = "-classpath " + strings.Join(java9classpath, ":")
477			}
478
479			system := ""
480			var systemDeps []string
481			if testcase.system == "none" {
482				system = "--system=none"
483			} else if testcase.system != "" {
484				dir := ""
485				// If the system modules name starts with sdk_ then it is a prebuilt module and so comes
486				// from the prebuilt directory.
487				if strings.HasPrefix(testcase.system, "sdk_") {
488					dir = "prebuilts/sdk"
489				} else {
490					dir = defaultJavaDir
491				}
492				system = "--system=" + filepath.Join("out", "soong", ".intermediates", dir, testcase.system, "android_common", "system")
493				// The module-relative parts of these paths are hardcoded in system_modules.go:
494				systemDeps = []string{
495					filepath.Join("out", "soong", ".intermediates", dir, testcase.system, "android_common", "system", "lib", "modules"),
496					filepath.Join("out", "soong", ".intermediates", dir, testcase.system, "android_common", "system", "lib", "jrt-fs.jar"),
497					filepath.Join("out", "soong", ".intermediates", dir, testcase.system, "android_common", "system", "release"),
498				}
499			}
500
501			checkClasspath := func(t *testing.T, result *android.TestResult, isJava8 bool) {
502				foo := result.ModuleForTests("foo", variant(result))
503				javac := foo.Rule("javac")
504				var deps []string
505
506				aidl := foo.MaybeRule("aidl")
507				if aidl.Rule != nil {
508					deps = append(deps, android.PathRelativeToTop(aidl.Output))
509				}
510
511				got := javac.Args["bootClasspath"]
512				expected := ""
513				if isJava8 || testcase.forces8 {
514					expected = bc
515					deps = append(deps, bcDeps...)
516				} else {
517					expected = system
518					deps = append(deps, systemDeps...)
519				}
520				if got != expected {
521					t.Errorf("bootclasspath expected %q != got %q", expected, got)
522				}
523
524				if isJava8 || testcase.forces8 {
525					expected = j8c
526					deps = append(deps, java8classpath...)
527				} else {
528					expected = j9c
529					deps = append(deps, java9classpath...)
530				}
531				got = javac.Args["classpath"]
532				if got != expected {
533					t.Errorf("classpath expected %q != got %q", expected, got)
534				}
535
536				android.AssertPathsRelativeToTopEquals(t, "implicits", deps, javac.Implicits)
537			}
538
539			preparer := android.NullFixturePreparer
540			if alwaysUsePrebuiltSdks {
541				preparer = android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
542					variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
543				})
544			}
545			if useTransitiveJarsInClasspath {
546				preparer = PrepareForTestWithTransitiveClasspathEnabled
547			}
548
549			fixtureFactory := android.GroupFixturePreparers(
550				prepareForJavaTest,
551				FixtureWithPrebuiltApis(map[string][]string{
552					"29":      {},
553					"30":      {},
554					"31":      {},
555					"32":      {},
556					"current": {},
557				}),
558				android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
559					if testcase.unbundled {
560						variables.Unbundled_build = proptools.BoolPtr(true)
561						variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
562					}
563				}),
564				android.FixtureModifyEnv(func(env map[string]string) {
565					if env["ANDROID_JAVA8_HOME"] == "" {
566						env["ANDROID_JAVA8_HOME"] = "jdk8"
567					}
568				}),
569				preparer,
570			)
571
572			// Test with legacy javac -source 1.8 -target 1.8
573			t.Run("Java language level 8", func(t *testing.T) {
574				result := fixtureFactory.RunTestWithBp(t, bpJava8)
575
576				checkClasspath(t, result, true /* isJava8 */)
577
578				if testcase.host != android.Host {
579					aidl := result.ModuleForTests("foo", variant(result)).Rule("aidl")
580
581					android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.")
582				}
583			})
584
585			// Test with default javac -source 9 -target 9
586			t.Run("Java language level 9", func(t *testing.T) {
587				result := fixtureFactory.RunTestWithBp(t, bp)
588
589				checkClasspath(t, result, false /* isJava8 */)
590
591				if testcase.host != android.Host {
592					aidl := result.ModuleForTests("foo", variant(result)).Rule("aidl")
593
594					android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.")
595				}
596			})
597
598			prepareWithPlatformVersionRel := android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
599				variables.Platform_sdk_codename = proptools.StringPtr("REL")
600				variables.Platform_sdk_final = proptools.BoolPtr(true)
601			})
602
603			// Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 8 -target 8
604			t.Run("REL + Java language level 8", func(t *testing.T) {
605				result := android.GroupFixturePreparers(
606					fixtureFactory, prepareWithPlatformVersionRel).RunTestWithBp(t, bpJava8)
607
608				checkClasspath(t, result, true /* isJava8 */)
609			})
610
611			// Test again with PLATFORM_VERSION_CODENAME=REL, javac -source 9 -target 9
612			t.Run("REL + Java language level 9", func(t *testing.T) {
613				result := android.GroupFixturePreparers(
614					fixtureFactory, prepareWithPlatformVersionRel).RunTestWithBp(t, bp)
615
616				checkClasspath(t, result, false /* isJava8 */)
617			})
618		})
619	}
620}
621