• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (C) 2019 The Android Open Source Project
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 sdk
16
17import (
18	"fmt"
19	"testing"
20
21	"android/soong/android"
22	"android/soong/java"
23)
24
25var prepareForSdkTestWithJava = android.GroupFixturePreparers(
26	java.PrepareForTestWithJavaBuildComponents,
27	PrepareForTestWithSdkBuildComponents,
28
29	// Ensure that all source paths are provided. This helps ensure that the snapshot generation is
30	// consistent and all files referenced from the snapshot's Android.bp file have actually been
31	// copied into the snapshot.
32	android.PrepareForTestDisallowNonExistentPaths,
33
34	// Files needs by most of the tests.
35	android.MockFS{
36		"Test.java": nil,
37	}.AddToFixture(),
38)
39
40var prepareForSdkTestWithJavaSdkLibrary = android.GroupFixturePreparers(
41	prepareForSdkTestWithJava,
42	java.PrepareForTestWithJavaDefaultModules,
43	java.PrepareForTestWithJavaSdkLibraryFiles,
44	java.FixtureWithLastReleaseApis("myjavalib"),
45)
46
47// Contains tests for SDK members provided by the java package.
48
49func TestSdkDependsOnSourceEvenWhenPrebuiltPreferred(t *testing.T) {
50	result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, `
51		sdk {
52			name: "mysdk",
53			java_header_libs: ["sdkmember"],
54		}
55
56		java_library {
57			name: "sdkmember",
58			srcs: ["Test.java"],
59			system_modules: "none",
60			sdk_version: "none",
61		}
62	`)
63
64	// Make sure that the mysdk module depends on "sdkmember" and not "prebuilt_sdkmember".
65	sdkChecker := func(t *testing.T, result *android.TestResult) {
66		java.CheckModuleDependencies(t, result.TestContext, "mysdk", "android_common", []string{"sdkmember"})
67	}
68
69	CheckSnapshot(t, result, "mysdk", "",
70		snapshotTestChecker(checkSnapshotWithSourcePreferred, sdkChecker),
71		snapshotTestChecker(checkSnapshotPreferredWithSource, sdkChecker),
72	)
73}
74
75func TestSnapshotWithJavaHeaderLibrary(t *testing.T) {
76	result := android.GroupFixturePreparers(
77		prepareForSdkTestWithJava,
78		android.FixtureAddFile("aidl/foo/bar/Test.aidl", nil),
79	).RunTestWithBp(t, `
80		sdk {
81			name: "mysdk",
82			java_header_libs: ["myjavalib"],
83		}
84
85		java_library {
86			name: "myjavalib",
87			srcs: ["Test.java"],
88			aidl: {
89				export_include_dirs: ["aidl"],
90			},
91			system_modules: "none",
92			sdk_version: "none",
93			compile_dex: true,
94			host_supported: true,
95			permitted_packages: ["pkg.myjavalib"],
96		}
97	`)
98
99	CheckSnapshot(t, result, "mysdk", "",
100		checkUnversionedAndroidBpContents(`
101// This is auto-generated. DO NOT EDIT.
102
103java_import {
104    name: "myjavalib",
105    prefer: false,
106    visibility: ["//visibility:public"],
107    apex_available: ["//apex_available:platform"],
108    jars: ["java/myjavalib.jar"],
109    permitted_packages: ["pkg.myjavalib"],
110}
111`),
112		checkVersionedAndroidBpContents(`
113// This is auto-generated. DO NOT EDIT.
114
115java_import {
116    name: "mysdk_myjavalib@current",
117    sdk_member_name: "myjavalib",
118    visibility: ["//visibility:public"],
119    apex_available: ["//apex_available:platform"],
120    jars: ["java/myjavalib.jar"],
121    permitted_packages: ["pkg.myjavalib"],
122}
123
124sdk_snapshot {
125    name: "mysdk@current",
126    visibility: ["//visibility:public"],
127    java_header_libs: ["mysdk_myjavalib@current"],
128}
129`),
130		checkAllCopyRules(`
131.intermediates/myjavalib/android_common/turbine-combined/myjavalib.jar -> java/myjavalib.jar
132aidl/foo/bar/Test.aidl -> aidl/aidl/foo/bar/Test.aidl
133`),
134	)
135}
136
137func TestHostSnapshotWithJavaHeaderLibrary(t *testing.T) {
138	result := android.GroupFixturePreparers(
139		prepareForSdkTestWithJava,
140		android.FixtureAddFile("aidl/foo/bar/Test.aidl", nil),
141	).RunTestWithBp(t, `
142		sdk {
143			name: "mysdk",
144			device_supported: false,
145			host_supported: true,
146			java_header_libs: ["myjavalib"],
147		}
148
149		java_library {
150			name: "myjavalib",
151			device_supported: false,
152			host_supported: true,
153			srcs: ["Test.java"],
154			aidl: {
155				export_include_dirs: ["aidl"],
156			},
157			system_modules: "none",
158			sdk_version: "none",
159			compile_dex: true,
160		}
161	`)
162
163	CheckSnapshot(t, result, "mysdk", "",
164		checkUnversionedAndroidBpContents(`
165// This is auto-generated. DO NOT EDIT.
166
167java_import {
168    name: "myjavalib",
169    prefer: false,
170    visibility: ["//visibility:public"],
171    apex_available: ["//apex_available:platform"],
172    device_supported: false,
173    host_supported: true,
174    jars: ["java/myjavalib.jar"],
175}
176`),
177		checkVersionedAndroidBpContents(`
178// This is auto-generated. DO NOT EDIT.
179
180java_import {
181    name: "mysdk_myjavalib@current",
182    sdk_member_name: "myjavalib",
183    visibility: ["//visibility:public"],
184    apex_available: ["//apex_available:platform"],
185    device_supported: false,
186    host_supported: true,
187    jars: ["java/myjavalib.jar"],
188}
189
190sdk_snapshot {
191    name: "mysdk@current",
192    visibility: ["//visibility:public"],
193    device_supported: false,
194    host_supported: true,
195    java_header_libs: ["mysdk_myjavalib@current"],
196}
197`),
198		checkAllCopyRules(`
199.intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/myjavalib.jar
200aidl/foo/bar/Test.aidl -> aidl/aidl/foo/bar/Test.aidl
201`),
202	)
203}
204
205func TestDeviceAndHostSnapshotWithJavaHeaderLibrary(t *testing.T) {
206	result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, `
207		sdk {
208			name: "mysdk",
209			host_supported: true,
210			java_header_libs: ["myjavalib"],
211		}
212
213		java_library {
214			name: "myjavalib",
215			host_supported: true,
216			srcs: ["Test.java"],
217			system_modules: "none",
218			sdk_version: "none",
219			compile_dex: true,
220		}
221	`)
222
223	CheckSnapshot(t, result, "mysdk", "",
224		checkUnversionedAndroidBpContents(`
225// This is auto-generated. DO NOT EDIT.
226
227java_import {
228    name: "myjavalib",
229    prefer: false,
230    visibility: ["//visibility:public"],
231    apex_available: ["//apex_available:platform"],
232    host_supported: true,
233    target: {
234        android: {
235            jars: ["java/android/myjavalib.jar"],
236        },
237        linux_glibc: {
238            jars: ["java/linux_glibc/myjavalib.jar"],
239        },
240    },
241}
242`),
243		checkVersionedAndroidBpContents(`
244// This is auto-generated. DO NOT EDIT.
245
246java_import {
247    name: "mysdk_myjavalib@current",
248    sdk_member_name: "myjavalib",
249    visibility: ["//visibility:public"],
250    apex_available: ["//apex_available:platform"],
251    host_supported: true,
252    target: {
253        android: {
254            jars: ["java/android/myjavalib.jar"],
255        },
256        linux_glibc: {
257            jars: ["java/linux_glibc/myjavalib.jar"],
258        },
259    },
260}
261
262sdk_snapshot {
263    name: "mysdk@current",
264    visibility: ["//visibility:public"],
265    host_supported: true,
266    java_header_libs: ["mysdk_myjavalib@current"],
267}
268`),
269		checkAllCopyRules(`
270.intermediates/myjavalib/android_common/turbine-combined/myjavalib.jar -> java/android/myjavalib.jar
271.intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/linux_glibc/myjavalib.jar
272`),
273	)
274}
275
276func TestSnapshotWithJavaImplLibrary(t *testing.T) {
277	result := android.GroupFixturePreparers(
278		prepareForSdkTestWithJava,
279		android.FixtureAddFile("aidl/foo/bar/Test.aidl", nil),
280		android.FixtureAddFile("resource.txt", nil),
281	).RunTestWithBp(t, `
282		module_exports {
283			name: "myexports",
284			java_libs: ["myjavalib"],
285		}
286
287		java_library {
288			name: "myjavalib",
289			srcs: ["Test.java"],
290			java_resources: ["resource.txt"],
291			aidl: {
292				export_include_dirs: ["aidl"],
293			},
294			system_modules: "none",
295			sdk_version: "none",
296			compile_dex: true,
297			host_supported: true,
298		}
299	`)
300
301	CheckSnapshot(t, result, "myexports", "",
302		checkUnversionedAndroidBpContents(`
303// This is auto-generated. DO NOT EDIT.
304
305java_import {
306    name: "myjavalib",
307    prefer: false,
308    visibility: ["//visibility:public"],
309    apex_available: ["//apex_available:platform"],
310    jars: ["java/myjavalib.jar"],
311}
312`),
313		checkVersionedAndroidBpContents(`
314// This is auto-generated. DO NOT EDIT.
315
316java_import {
317    name: "myexports_myjavalib@current",
318    sdk_member_name: "myjavalib",
319    visibility: ["//visibility:public"],
320    apex_available: ["//apex_available:platform"],
321    jars: ["java/myjavalib.jar"],
322}
323
324module_exports_snapshot {
325    name: "myexports@current",
326    visibility: ["//visibility:public"],
327    java_libs: ["myexports_myjavalib@current"],
328}
329`),
330		checkAllCopyRules(`
331.intermediates/myjavalib/android_common/withres/myjavalib.jar -> java/myjavalib.jar
332aidl/foo/bar/Test.aidl -> aidl/aidl/foo/bar/Test.aidl
333`),
334	)
335}
336
337func TestSnapshotWithJavaBootLibrary(t *testing.T) {
338	result := android.GroupFixturePreparers(
339		prepareForSdkTestWithJava,
340		android.FixtureAddFile("aidl", nil),
341		android.FixtureAddFile("resource.txt", nil),
342	).RunTestWithBp(t, `
343		sdk {
344			name: "mysdk",
345			java_boot_libs: ["myjavalib"],
346		}
347
348		java_library {
349			name: "myjavalib",
350			srcs: ["Test.java"],
351			java_resources: ["resource.txt"],
352			// The aidl files should not be copied to the snapshot because a java_boot_libs member is not
353			// intended to be used for compiling Java, only for accessing the dex implementation jar.
354			aidl: {
355				export_include_dirs: ["aidl"],
356			},
357			system_modules: "none",
358			sdk_version: "none",
359			compile_dex: true,
360			permitted_packages: ["pkg.myjavalib"],
361		}
362	`)
363
364	CheckSnapshot(t, result, "mysdk", "",
365		checkUnversionedAndroidBpContents(`
366// This is auto-generated. DO NOT EDIT.
367
368java_import {
369    name: "myjavalib",
370    prefer: false,
371    visibility: ["//visibility:public"],
372    apex_available: ["//apex_available:platform"],
373    jars: ["java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar"],
374    permitted_packages: ["pkg.myjavalib"],
375}
376`),
377		checkVersionedAndroidBpContents(`
378// This is auto-generated. DO NOT EDIT.
379
380java_import {
381    name: "mysdk_myjavalib@current",
382    sdk_member_name: "myjavalib",
383    visibility: ["//visibility:public"],
384    apex_available: ["//apex_available:platform"],
385    jars: ["java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar"],
386    permitted_packages: ["pkg.myjavalib"],
387}
388
389sdk_snapshot {
390    name: "mysdk@current",
391    visibility: ["//visibility:public"],
392    java_boot_libs: ["mysdk_myjavalib@current"],
393}
394
395`),
396		checkAllCopyRules(`
397.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/myjavalib.jar
398`),
399	)
400}
401
402func TestSnapshotWithJavaBootLibrary_UpdatableMedia(t *testing.T) {
403	runTest := func(t *testing.T, targetBuildRelease, expectedJarPath, expectedCopyRule string) {
404		result := android.GroupFixturePreparers(
405			prepareForSdkTestWithJava,
406			android.FixtureMergeEnv(map[string]string{
407				"SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": targetBuildRelease,
408			}),
409		).RunTestWithBp(t, `
410		sdk {
411			name: "mysdk",
412			java_boot_libs: ["updatable-media"],
413		}
414
415		java_library {
416			name: "updatable-media",
417			srcs: ["Test.java"],
418			system_modules: "none",
419			sdk_version: "none",
420			compile_dex: true,
421			permitted_packages: ["pkg.media"],
422			apex_available: ["com.android.media"],
423		}
424	`)
425
426		CheckSnapshot(t, result, "mysdk", "",
427			checkUnversionedAndroidBpContents(fmt.Sprintf(`
428// This is auto-generated. DO NOT EDIT.
429
430java_import {
431    name: "updatable-media",
432    prefer: false,
433    visibility: ["//visibility:public"],
434    apex_available: ["com.android.media"],
435    jars: ["%s"],
436    permitted_packages: ["pkg.media"],
437}
438`, expectedJarPath)),
439			checkAllCopyRules(expectedCopyRule),
440		)
441	}
442
443	t.Run("updatable-media in S", func(t *testing.T) {
444		runTest(t, "S", "java/updatable-media.jar", `
445.intermediates/updatable-media/android_common/package-check/updatable-media.jar -> java/updatable-media.jar
446`)
447	})
448
449	t.Run("updatable-media in T", func(t *testing.T) {
450		runTest(t, "Tiramisu", "java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar", `
451.intermediates/mysdk/common_os/empty -> java_boot_libs/snapshot/jars/are/invalid/updatable-media.jar
452`)
453	})
454}
455
456func TestSnapshotWithJavaSystemserverLibrary(t *testing.T) {
457	result := android.GroupFixturePreparers(
458		prepareForSdkTestWithJava,
459		android.FixtureAddFile("aidl", nil),
460		android.FixtureAddFile("resource.txt", nil),
461	).RunTestWithBp(t, `
462		module_exports {
463			name: "myexports",
464			java_systemserver_libs: ["myjavalib"],
465		}
466
467		java_library {
468			name: "myjavalib",
469			srcs: ["Test.java"],
470			java_resources: ["resource.txt"],
471			// The aidl files should not be copied to the snapshot because a java_systemserver_libs member
472			// is not intended to be used for compiling Java, only for accessing the dex implementation
473			// jar.
474			aidl: {
475				export_include_dirs: ["aidl"],
476			},
477			system_modules: "none",
478			sdk_version: "none",
479			compile_dex: true,
480			permitted_packages: ["pkg.myjavalib"],
481		}
482	`)
483
484	CheckSnapshot(t, result, "myexports", "",
485		checkUnversionedAndroidBpContents(`
486// This is auto-generated. DO NOT EDIT.
487
488java_import {
489    name: "myjavalib",
490    prefer: false,
491    visibility: ["//visibility:public"],
492    apex_available: ["//apex_available:platform"],
493    jars: ["java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar"],
494    permitted_packages: ["pkg.myjavalib"],
495}
496`),
497		checkVersionedAndroidBpContents(`
498// This is auto-generated. DO NOT EDIT.
499
500java_import {
501    name: "myexports_myjavalib@current",
502    sdk_member_name: "myjavalib",
503    visibility: ["//visibility:public"],
504    apex_available: ["//apex_available:platform"],
505    jars: ["java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar"],
506    permitted_packages: ["pkg.myjavalib"],
507}
508
509module_exports_snapshot {
510    name: "myexports@current",
511    visibility: ["//visibility:public"],
512    java_systemserver_libs: ["myexports_myjavalib@current"],
513}
514`),
515		checkAllCopyRules(`
516.intermediates/myexports/common_os/empty -> java_systemserver_libs/snapshot/jars/are/invalid/myjavalib.jar
517`),
518	)
519}
520
521func TestHostSnapshotWithJavaImplLibrary(t *testing.T) {
522	result := android.GroupFixturePreparers(
523		prepareForSdkTestWithJava,
524		android.FixtureAddFile("aidl/foo/bar/Test.aidl", nil),
525	).RunTestWithBp(t, `
526		module_exports {
527			name: "myexports",
528			device_supported: false,
529			host_supported: true,
530			java_libs: ["myjavalib"],
531		}
532
533		java_library {
534			name: "myjavalib",
535			device_supported: false,
536			host_supported: true,
537			srcs: ["Test.java"],
538			aidl: {
539				export_include_dirs: ["aidl"],
540			},
541			system_modules: "none",
542			sdk_version: "none",
543			compile_dex: true,
544		}
545	`)
546
547	CheckSnapshot(t, result, "myexports", "",
548		checkUnversionedAndroidBpContents(`
549// This is auto-generated. DO NOT EDIT.
550
551java_import {
552    name: "myjavalib",
553    prefer: false,
554    visibility: ["//visibility:public"],
555    apex_available: ["//apex_available:platform"],
556    device_supported: false,
557    host_supported: true,
558    jars: ["java/myjavalib.jar"],
559}
560`),
561		checkVersionedAndroidBpContents(`
562// This is auto-generated. DO NOT EDIT.
563
564java_import {
565    name: "myexports_myjavalib@current",
566    sdk_member_name: "myjavalib",
567    visibility: ["//visibility:public"],
568    apex_available: ["//apex_available:platform"],
569    device_supported: false,
570    host_supported: true,
571    jars: ["java/myjavalib.jar"],
572}
573
574module_exports_snapshot {
575    name: "myexports@current",
576    visibility: ["//visibility:public"],
577    device_supported: false,
578    host_supported: true,
579    java_libs: ["myexports_myjavalib@current"],
580}
581`),
582		checkAllCopyRules(`
583.intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/myjavalib.jar
584aidl/foo/bar/Test.aidl -> aidl/aidl/foo/bar/Test.aidl
585`),
586	)
587}
588
589func TestSnapshotWithJavaTest(t *testing.T) {
590	result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, `
591		module_exports {
592			name: "myexports",
593			java_tests: ["myjavatests"],
594		}
595
596		java_test {
597			name: "myjavatests",
598			srcs: ["Test.java"],
599			system_modules: "none",
600			sdk_version: "none",
601			compile_dex: true,
602			host_supported: true,
603		}
604	`)
605
606	CheckSnapshot(t, result, "myexports", "",
607		checkUnversionedAndroidBpContents(`
608// This is auto-generated. DO NOT EDIT.
609
610java_test_import {
611    name: "myjavatests",
612    prefer: false,
613    visibility: ["//visibility:public"],
614    apex_available: ["//apex_available:platform"],
615    jars: ["java/myjavatests.jar"],
616    test_config: "java/myjavatests-AndroidTest.xml",
617}
618`),
619		checkVersionedAndroidBpContents(`
620// This is auto-generated. DO NOT EDIT.
621
622java_test_import {
623    name: "myexports_myjavatests@current",
624    sdk_member_name: "myjavatests",
625    visibility: ["//visibility:public"],
626    apex_available: ["//apex_available:platform"],
627    jars: ["java/myjavatests.jar"],
628    test_config: "java/myjavatests-AndroidTest.xml",
629}
630
631module_exports_snapshot {
632    name: "myexports@current",
633    visibility: ["//visibility:public"],
634    java_tests: ["myexports_myjavatests@current"],
635}
636`),
637		checkAllCopyRules(`
638.intermediates/myjavatests/android_common/javac/myjavatests.jar -> java/myjavatests.jar
639.intermediates/myjavatests/android_common/myjavatests.config -> java/myjavatests-AndroidTest.xml
640`),
641	)
642}
643
644func TestHostSnapshotWithJavaTest(t *testing.T) {
645	result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, `
646		module_exports {
647			name: "myexports",
648			device_supported: false,
649			host_supported: true,
650			java_tests: ["myjavatests"],
651		}
652
653		java_test {
654			name: "myjavatests",
655			device_supported: false,
656			host_supported: true,
657			srcs: ["Test.java"],
658			system_modules: "none",
659			sdk_version: "none",
660			compile_dex: true,
661		}
662	`)
663
664	CheckSnapshot(t, result, "myexports", "",
665		checkUnversionedAndroidBpContents(`
666// This is auto-generated. DO NOT EDIT.
667
668java_test_import {
669    name: "myjavatests",
670    prefer: false,
671    visibility: ["//visibility:public"],
672    apex_available: ["//apex_available:platform"],
673    device_supported: false,
674    host_supported: true,
675    jars: ["java/myjavatests.jar"],
676    test_config: "java/myjavatests-AndroidTest.xml",
677}
678`),
679		checkVersionedAndroidBpContents(`
680// This is auto-generated. DO NOT EDIT.
681
682java_test_import {
683    name: "myexports_myjavatests@current",
684    sdk_member_name: "myjavatests",
685    visibility: ["//visibility:public"],
686    apex_available: ["//apex_available:platform"],
687    device_supported: false,
688    host_supported: true,
689    jars: ["java/myjavatests.jar"],
690    test_config: "java/myjavatests-AndroidTest.xml",
691}
692
693module_exports_snapshot {
694    name: "myexports@current",
695    visibility: ["//visibility:public"],
696    device_supported: false,
697    host_supported: true,
698    java_tests: ["myexports_myjavatests@current"],
699}
700`),
701		checkAllCopyRules(`
702.intermediates/myjavatests/linux_glibc_common/javac/myjavatests.jar -> java/myjavatests.jar
703.intermediates/myjavatests/linux_glibc_common/myjavatests.config -> java/myjavatests-AndroidTest.xml
704`),
705	)
706}
707
708func TestSnapshotWithJavaSystemModules(t *testing.T) {
709	result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
710		sdk {
711			name: "mysdk",
712			java_header_libs: ["exported-system-module"],
713			java_sdk_libs: ["myjavalib"],
714			java_system_modules: ["my-system-modules"],
715		}
716
717		java_sdk_library {
718			name: "myjavalib",
719			apex_available: ["//apex_available:anyapex"],
720			srcs: ["Test.java"],
721			sdk_version: "current",
722			shared_library: false,
723			public: {
724				enabled: true,
725			},
726		}
727
728		java_system_modules {
729			name: "my-system-modules",
730			libs: ["system-module", "exported-system-module", "myjavalib.stubs"],
731		}
732
733		java_library {
734			name: "system-module",
735			srcs: ["Test.java"],
736			sdk_version: "none",
737			system_modules: "none",
738		}
739
740		java_library {
741			name: "exported-system-module",
742			srcs: ["Test.java"],
743			sdk_version: "none",
744			system_modules: "none",
745		}
746	`)
747
748	CheckSnapshot(t, result, "mysdk", "",
749		checkUnversionedAndroidBpContents(`
750// This is auto-generated. DO NOT EDIT.
751
752java_import {
753    name: "exported-system-module",
754    prefer: false,
755    visibility: ["//visibility:public"],
756    apex_available: ["//apex_available:platform"],
757    jars: ["java/exported-system-module.jar"],
758}
759
760java_import {
761    name: "mysdk_system-module",
762    prefer: false,
763    visibility: ["//visibility:private"],
764    apex_available: ["//apex_available:platform"],
765    jars: ["java/system-module.jar"],
766}
767
768java_sdk_library_import {
769    name: "myjavalib",
770    prefer: false,
771    visibility: ["//visibility:public"],
772    apex_available: ["//apex_available:anyapex"],
773    shared_library: false,
774    public: {
775        jars: ["sdk_library/public/myjavalib-stubs.jar"],
776        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
777        current_api: "sdk_library/public/myjavalib.txt",
778        removed_api: "sdk_library/public/myjavalib-removed.txt",
779        sdk_version: "current",
780    },
781}
782
783java_system_modules_import {
784    name: "my-system-modules",
785    prefer: false,
786    visibility: ["//visibility:public"],
787    libs: [
788        "mysdk_system-module",
789        "exported-system-module",
790        "myjavalib.stubs",
791    ],
792}
793`),
794		checkVersionedAndroidBpContents(`
795// This is auto-generated. DO NOT EDIT.
796
797java_import {
798    name: "mysdk_exported-system-module@current",
799    sdk_member_name: "exported-system-module",
800    visibility: ["//visibility:public"],
801    apex_available: ["//apex_available:platform"],
802    jars: ["java/exported-system-module.jar"],
803}
804
805java_import {
806    name: "mysdk_system-module@current",
807    sdk_member_name: "system-module",
808    visibility: ["//visibility:private"],
809    apex_available: ["//apex_available:platform"],
810    jars: ["java/system-module.jar"],
811}
812
813java_sdk_library_import {
814    name: "mysdk_myjavalib@current",
815    sdk_member_name: "myjavalib",
816    visibility: ["//visibility:public"],
817    apex_available: ["//apex_available:anyapex"],
818    shared_library: false,
819    public: {
820        jars: ["sdk_library/public/myjavalib-stubs.jar"],
821        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
822        current_api: "sdk_library/public/myjavalib.txt",
823        removed_api: "sdk_library/public/myjavalib-removed.txt",
824        sdk_version: "current",
825    },
826}
827
828java_system_modules_import {
829    name: "mysdk_my-system-modules@current",
830    sdk_member_name: "my-system-modules",
831    visibility: ["//visibility:public"],
832    libs: [
833        "mysdk_system-module@current",
834        "mysdk_exported-system-module@current",
835        "mysdk_myjavalib.stubs@current",
836    ],
837}
838
839sdk_snapshot {
840    name: "mysdk@current",
841    visibility: ["//visibility:public"],
842    java_header_libs: ["mysdk_exported-system-module@current"],
843    java_sdk_libs: ["mysdk_myjavalib@current"],
844    java_system_modules: ["mysdk_my-system-modules@current"],
845}
846`),
847		checkAllCopyRules(`
848.intermediates/exported-system-module/android_common/turbine-combined/exported-system-module.jar -> java/exported-system-module.jar
849.intermediates/system-module/android_common/turbine-combined/system-module.jar -> java/system-module.jar
850.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
851.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
852.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
853`),
854	)
855}
856
857func TestHostSnapshotWithJavaSystemModules(t *testing.T) {
858	result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, `
859		sdk {
860			name: "mysdk",
861			device_supported: false,
862			host_supported: true,
863			java_system_modules: ["my-system-modules"],
864		}
865
866		java_system_modules {
867			name: "my-system-modules",
868			device_supported: false,
869			host_supported: true,
870			libs: ["system-module"],
871		}
872
873		java_library {
874			name: "system-module",
875			device_supported: false,
876			host_supported: true,
877			srcs: ["Test.java"],
878			sdk_version: "none",
879			system_modules: "none",
880		}
881	`)
882
883	CheckSnapshot(t, result, "mysdk", "",
884		checkUnversionedAndroidBpContents(`
885// This is auto-generated. DO NOT EDIT.
886
887java_import {
888    name: "mysdk_system-module",
889    prefer: false,
890    visibility: ["//visibility:private"],
891    apex_available: ["//apex_available:platform"],
892    device_supported: false,
893    host_supported: true,
894    jars: ["java/system-module.jar"],
895}
896
897java_system_modules_import {
898    name: "my-system-modules",
899    prefer: false,
900    visibility: ["//visibility:public"],
901    device_supported: false,
902    host_supported: true,
903    libs: ["mysdk_system-module"],
904}
905`),
906		checkVersionedAndroidBpContents(`
907// This is auto-generated. DO NOT EDIT.
908
909java_import {
910    name: "mysdk_system-module@current",
911    sdk_member_name: "system-module",
912    visibility: ["//visibility:private"],
913    apex_available: ["//apex_available:platform"],
914    device_supported: false,
915    host_supported: true,
916    jars: ["java/system-module.jar"],
917}
918
919java_system_modules_import {
920    name: "mysdk_my-system-modules@current",
921    sdk_member_name: "my-system-modules",
922    visibility: ["//visibility:public"],
923    device_supported: false,
924    host_supported: true,
925    libs: ["mysdk_system-module@current"],
926}
927
928sdk_snapshot {
929    name: "mysdk@current",
930    visibility: ["//visibility:public"],
931    device_supported: false,
932    host_supported: true,
933    java_system_modules: ["mysdk_my-system-modules@current"],
934}
935`),
936		checkAllCopyRules(".intermediates/system-module/linux_glibc_common/javac/system-module.jar -> java/system-module.jar"),
937	)
938}
939
940func TestDeviceAndHostSnapshotWithOsSpecificMembers(t *testing.T) {
941	result := android.GroupFixturePreparers(prepareForSdkTestWithJava).RunTestWithBp(t, `
942		module_exports {
943			name: "myexports",
944			host_supported: true,
945			java_libs: ["myjavalib"],
946			target: {
947				android: {
948					java_header_libs: ["androidjavalib"],
949				},
950				host: {
951					java_header_libs: ["hostjavalib"],
952				},
953			},
954		}
955
956		java_library {
957			name: "myjavalib",
958			host_supported: true,
959			srcs: ["Test.java"],
960			system_modules: "none",
961			sdk_version: "none",
962		}
963
964		java_library {
965			name: "androidjavalib",
966			srcs: ["Test.java"],
967			system_modules: "none",
968			sdk_version: "none",
969		}
970
971		java_library_host {
972			name: "hostjavalib",
973			srcs: ["Test.java"],
974		}
975	`)
976
977	CheckSnapshot(t, result, "myexports", "",
978		checkUnversionedAndroidBpContents(`
979// This is auto-generated. DO NOT EDIT.
980
981java_import {
982    name: "hostjavalib",
983    prefer: false,
984    visibility: ["//visibility:public"],
985    apex_available: ["//apex_available:platform"],
986    device_supported: false,
987    host_supported: true,
988    jars: ["java/hostjavalib.jar"],
989}
990
991java_import {
992    name: "androidjavalib",
993    prefer: false,
994    visibility: ["//visibility:public"],
995    apex_available: ["//apex_available:platform"],
996    jars: ["java/androidjavalib.jar"],
997}
998
999java_import {
1000    name: "myjavalib",
1001    prefer: false,
1002    visibility: ["//visibility:public"],
1003    apex_available: ["//apex_available:platform"],
1004    host_supported: true,
1005    target: {
1006        android: {
1007            jars: ["java/android/myjavalib.jar"],
1008        },
1009        linux_glibc: {
1010            jars: ["java/linux_glibc/myjavalib.jar"],
1011        },
1012    },
1013}
1014`),
1015		checkVersionedAndroidBpContents(`
1016// This is auto-generated. DO NOT EDIT.
1017
1018java_import {
1019    name: "myexports_hostjavalib@current",
1020    sdk_member_name: "hostjavalib",
1021    visibility: ["//visibility:public"],
1022    apex_available: ["//apex_available:platform"],
1023    device_supported: false,
1024    host_supported: true,
1025    jars: ["java/hostjavalib.jar"],
1026}
1027
1028java_import {
1029    name: "myexports_androidjavalib@current",
1030    sdk_member_name: "androidjavalib",
1031    visibility: ["//visibility:public"],
1032    apex_available: ["//apex_available:platform"],
1033    jars: ["java/androidjavalib.jar"],
1034}
1035
1036java_import {
1037    name: "myexports_myjavalib@current",
1038    sdk_member_name: "myjavalib",
1039    visibility: ["//visibility:public"],
1040    apex_available: ["//apex_available:platform"],
1041    host_supported: true,
1042    target: {
1043        android: {
1044            jars: ["java/android/myjavalib.jar"],
1045        },
1046        linux_glibc: {
1047            jars: ["java/linux_glibc/myjavalib.jar"],
1048        },
1049    },
1050}
1051
1052module_exports_snapshot {
1053    name: "myexports@current",
1054    visibility: ["//visibility:public"],
1055    host_supported: true,
1056    java_libs: ["myexports_myjavalib@current"],
1057    target: {
1058        android: {
1059            java_header_libs: ["myexports_androidjavalib@current"],
1060        },
1061        linux_glibc: {
1062            java_header_libs: ["myexports_hostjavalib@current"],
1063        },
1064    },
1065}
1066`),
1067		checkAllCopyRules(`
1068.intermediates/hostjavalib/linux_glibc_common/javac/hostjavalib.jar -> java/hostjavalib.jar
1069.intermediates/androidjavalib/android_common/turbine-combined/androidjavalib.jar -> java/androidjavalib.jar
1070.intermediates/myjavalib/android_common/javac/myjavalib.jar -> java/android/myjavalib.jar
1071.intermediates/myjavalib/linux_glibc_common/javac/myjavalib.jar -> java/linux_glibc/myjavalib.jar
1072`),
1073	)
1074}
1075
1076func TestSnapshotWithJavaSdkLibrary(t *testing.T) {
1077	result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
1078		sdk {
1079			name: "mysdk",
1080			java_sdk_libs: ["myjavalib"],
1081		}
1082
1083		java_sdk_library {
1084			name: "myjavalib",
1085			apex_available: ["//apex_available:anyapex"],
1086			srcs: ["Test.java"],
1087			sdk_version: "current",
1088			shared_library: false,
1089			stubs_library_visibility: ["//other"],
1090			stubs_source_visibility: ["//another"],
1091			permitted_packages: ["pkg.myjavalib"],
1092		}
1093	`)
1094
1095	CheckSnapshot(t, result, "mysdk", "",
1096		checkUnversionedAndroidBpContents(`
1097// This is auto-generated. DO NOT EDIT.
1098
1099java_sdk_library_import {
1100    name: "myjavalib",
1101    prefer: false,
1102    visibility: ["//visibility:public"],
1103    apex_available: ["//apex_available:anyapex"],
1104    shared_library: false,
1105    permitted_packages: ["pkg.myjavalib"],
1106    public: {
1107        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1108        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1109        current_api: "sdk_library/public/myjavalib.txt",
1110        removed_api: "sdk_library/public/myjavalib-removed.txt",
1111        sdk_version: "current",
1112    },
1113    system: {
1114        jars: ["sdk_library/system/myjavalib-stubs.jar"],
1115        stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
1116        current_api: "sdk_library/system/myjavalib.txt",
1117        removed_api: "sdk_library/system/myjavalib-removed.txt",
1118        sdk_version: "system_current",
1119    },
1120    test: {
1121        jars: ["sdk_library/test/myjavalib-stubs.jar"],
1122        stub_srcs: ["sdk_library/test/myjavalib_stub_sources"],
1123        current_api: "sdk_library/test/myjavalib.txt",
1124        removed_api: "sdk_library/test/myjavalib-removed.txt",
1125        sdk_version: "test_current",
1126    },
1127}
1128`),
1129		checkVersionedAndroidBpContents(`
1130// This is auto-generated. DO NOT EDIT.
1131
1132java_sdk_library_import {
1133    name: "mysdk_myjavalib@current",
1134    sdk_member_name: "myjavalib",
1135    visibility: ["//visibility:public"],
1136    apex_available: ["//apex_available:anyapex"],
1137    shared_library: false,
1138    permitted_packages: ["pkg.myjavalib"],
1139    public: {
1140        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1141        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1142        current_api: "sdk_library/public/myjavalib.txt",
1143        removed_api: "sdk_library/public/myjavalib-removed.txt",
1144        sdk_version: "current",
1145    },
1146    system: {
1147        jars: ["sdk_library/system/myjavalib-stubs.jar"],
1148        stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
1149        current_api: "sdk_library/system/myjavalib.txt",
1150        removed_api: "sdk_library/system/myjavalib-removed.txt",
1151        sdk_version: "system_current",
1152    },
1153    test: {
1154        jars: ["sdk_library/test/myjavalib-stubs.jar"],
1155        stub_srcs: ["sdk_library/test/myjavalib_stub_sources"],
1156        current_api: "sdk_library/test/myjavalib.txt",
1157        removed_api: "sdk_library/test/myjavalib-removed.txt",
1158        sdk_version: "test_current",
1159    },
1160}
1161
1162sdk_snapshot {
1163    name: "mysdk@current",
1164    visibility: ["//visibility:public"],
1165    java_sdk_libs: ["mysdk_myjavalib@current"],
1166}
1167`),
1168		checkAllCopyRules(`
1169.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
1170.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
1171.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
1172.intermediates/myjavalib.stubs.system/android_common/javac/myjavalib.stubs.system.jar -> sdk_library/system/myjavalib-stubs.jar
1173.intermediates/myjavalib.stubs.source.system/android_common/metalava/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib.txt
1174.intermediates/myjavalib.stubs.source.system/android_common/metalava/myjavalib.stubs.source.system_removed.txt -> sdk_library/system/myjavalib-removed.txt
1175.intermediates/myjavalib.stubs.test/android_common/javac/myjavalib.stubs.test.jar -> sdk_library/test/myjavalib-stubs.jar
1176.intermediates/myjavalib.stubs.source.test/android_common/metalava/myjavalib.stubs.source.test_api.txt -> sdk_library/test/myjavalib.txt
1177.intermediates/myjavalib.stubs.source.test/android_common/metalava/myjavalib.stubs.source.test_removed.txt -> sdk_library/test/myjavalib-removed.txt
1178`),
1179		checkMergeZips(
1180			".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
1181			".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip",
1182			".intermediates/mysdk/common_os/tmp/sdk_library/test/myjavalib_stub_sources.zip",
1183		),
1184		snapshotTestChecker(checkSnapshotWithoutSource, func(t *testing.T, result *android.TestResult) {
1185			// Make sure that the name of the child modules created by a versioned java_sdk_library_import
1186			// module is correct, i.e. the suffix is added before the version and not after.
1187			result.Module("mysdk_myjavalib.stubs@current", "android_common")
1188			result.Module("mysdk_myjavalib.stubs.source@current", "android_common")
1189		}),
1190	)
1191}
1192
1193func TestSnapshotWithJavaSdkLibrary_UseSrcJar(t *testing.T) {
1194	result := android.GroupFixturePreparers(
1195		prepareForSdkTestWithJavaSdkLibrary,
1196		android.FixtureMergeEnv(map[string]string{
1197			"SOONG_SDK_SNAPSHOT_USE_SRCJAR": "true",
1198		}),
1199	).RunTestWithBp(t, `
1200		sdk {
1201			name: "mysdk",
1202			java_sdk_libs: ["myjavalib"],
1203		}
1204
1205		java_sdk_library {
1206			name: "myjavalib",
1207			srcs: ["Test.java"],
1208			sdk_version: "current",
1209			shared_library: false,
1210			public: {
1211				enabled: true,
1212			},
1213		}
1214	`)
1215
1216	CheckSnapshot(t, result, "mysdk", "",
1217		checkUnversionedAndroidBpContents(`
1218// This is auto-generated. DO NOT EDIT.
1219
1220java_sdk_library_import {
1221    name: "myjavalib",
1222    prefer: false,
1223    visibility: ["//visibility:public"],
1224    apex_available: ["//apex_available:platform"],
1225    shared_library: false,
1226    public: {
1227        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1228        stub_srcs: ["sdk_library/public/myjavalib.srcjar"],
1229        current_api: "sdk_library/public/myjavalib.txt",
1230        removed_api: "sdk_library/public/myjavalib-removed.txt",
1231        sdk_version: "current",
1232    },
1233}
1234		`),
1235		checkAllCopyRules(`
1236.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
1237.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source-stubs.srcjar -> sdk_library/public/myjavalib.srcjar
1238.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
1239.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
1240		`),
1241	)
1242}
1243
1244func TestSnapshotWithJavaSdkLibrary_AnnotationsZip(t *testing.T) {
1245	result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
1246		sdk {
1247			name: "mysdk",
1248			java_sdk_libs: ["myjavalib"],
1249		}
1250
1251		java_sdk_library {
1252			name: "myjavalib",
1253			srcs: ["Test.java"],
1254			sdk_version: "current",
1255			shared_library: false,
1256			annotations_enabled: true,
1257			public: {
1258				enabled: true,
1259			},
1260		}
1261	`)
1262
1263	CheckSnapshot(t, result, "mysdk", "",
1264		checkUnversionedAndroidBpContents(`
1265// This is auto-generated. DO NOT EDIT.
1266
1267java_sdk_library_import {
1268    name: "myjavalib",
1269    prefer: false,
1270    visibility: ["//visibility:public"],
1271    apex_available: ["//apex_available:platform"],
1272    shared_library: false,
1273    public: {
1274        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1275        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1276        current_api: "sdk_library/public/myjavalib.txt",
1277        removed_api: "sdk_library/public/myjavalib-removed.txt",
1278        annotations: "sdk_library/public/myjavalib_annotations.zip",
1279        sdk_version: "current",
1280    },
1281}
1282		`),
1283		checkAllCopyRules(`
1284.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
1285.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
1286.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
1287.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_annotations.zip -> sdk_library/public/myjavalib_annotations.zip
1288		`),
1289		checkMergeZips(".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip"),
1290	)
1291}
1292
1293func TestSnapshotWithJavaSdkLibrary_AnnotationsZip_PreT(t *testing.T) {
1294	result := android.GroupFixturePreparers(
1295		prepareForSdkTestWithJavaSdkLibrary,
1296		android.FixtureMergeEnv(map[string]string{
1297			"SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE": "S",
1298		}),
1299	).RunTestWithBp(t, `
1300		sdk {
1301			name: "mysdk",
1302			java_sdk_libs: ["myjavalib"],
1303		}
1304
1305		java_sdk_library {
1306			name: "myjavalib",
1307			srcs: ["Test.java"],
1308			sdk_version: "current",
1309			shared_library: false,
1310			annotations_enabled: true,
1311			public: {
1312				enabled: true,
1313			},
1314		}
1315	`)
1316
1317	CheckSnapshot(t, result, "mysdk", "",
1318		checkUnversionedAndroidBpContents(`
1319// This is auto-generated. DO NOT EDIT.
1320
1321java_sdk_library_import {
1322    name: "myjavalib",
1323    prefer: false,
1324    visibility: ["//visibility:public"],
1325    apex_available: ["//apex_available:platform"],
1326    shared_library: false,
1327    public: {
1328        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1329        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1330        current_api: "sdk_library/public/myjavalib.txt",
1331        removed_api: "sdk_library/public/myjavalib-removed.txt",
1332        sdk_version: "current",
1333    },
1334}
1335		`),
1336		checkAllCopyRules(`
1337.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
1338.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
1339.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
1340		`),
1341		checkMergeZips(".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip"),
1342	)
1343}
1344
1345func TestSnapshotWithJavaSdkLibrary_CompileDex(t *testing.T) {
1346	result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
1347		sdk {
1348			name: "mysdk",
1349			java_sdk_libs: ["myjavalib"],
1350		}
1351
1352		java_sdk_library {
1353			name: "myjavalib",
1354			srcs: ["Test.java"],
1355			sdk_version: "current",
1356			shared_library: false,
1357			compile_dex: true,
1358			public: {
1359				enabled: true,
1360			},
1361			system: {
1362				enabled: true,
1363			},
1364		}
1365	`)
1366
1367	CheckSnapshot(t, result, "mysdk", "",
1368		checkUnversionedAndroidBpContents(`
1369// This is auto-generated. DO NOT EDIT.
1370
1371java_sdk_library_import {
1372    name: "myjavalib",
1373    prefer: false,
1374    visibility: ["//visibility:public"],
1375    apex_available: ["//apex_available:platform"],
1376    shared_library: false,
1377    compile_dex: true,
1378    public: {
1379        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1380        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1381        current_api: "sdk_library/public/myjavalib.txt",
1382        removed_api: "sdk_library/public/myjavalib-removed.txt",
1383        sdk_version: "current",
1384    },
1385    system: {
1386        jars: ["sdk_library/system/myjavalib-stubs.jar"],
1387        stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
1388        current_api: "sdk_library/system/myjavalib.txt",
1389        removed_api: "sdk_library/system/myjavalib-removed.txt",
1390        sdk_version: "system_current",
1391    },
1392}
1393`),
1394		snapshotTestChecker(checkSnapshotWithSourcePreferred, func(t *testing.T, result *android.TestResult) {
1395			ctx := android.ModuleInstallPathContextForTesting(result.Config)
1396			dexJarBuildPath := func(name string, kind android.SdkKind) string {
1397				dep := result.Module(name, "android_common").(java.SdkLibraryDependency)
1398				path := dep.SdkApiStubDexJar(ctx, kind).Path()
1399				return path.RelativeToTop().String()
1400			}
1401
1402			dexJarPath := dexJarBuildPath("myjavalib", android.SdkPublic)
1403			android.AssertStringEquals(t, "source dex public stubs jar build path", "out/soong/.intermediates/myjavalib.stubs/android_common/dex/myjavalib.stubs.jar", dexJarPath)
1404
1405			dexJarPath = dexJarBuildPath("myjavalib", android.SdkSystem)
1406			systemDexJar := "out/soong/.intermediates/myjavalib.stubs.system/android_common/dex/myjavalib.stubs.system.jar"
1407			android.AssertStringEquals(t, "source dex system stubs jar build path", systemDexJar, dexJarPath)
1408
1409			// This should fall back to system as module is not available.
1410			dexJarPath = dexJarBuildPath("myjavalib", android.SdkModule)
1411			android.AssertStringEquals(t, "source dex module stubs jar build path", systemDexJar, dexJarPath)
1412
1413			dexJarPath = dexJarBuildPath(android.PrebuiltNameFromSource("myjavalib"), android.SdkPublic)
1414			android.AssertStringEquals(t, "prebuilt dex public stubs jar build path", "out/soong/.intermediates/snapshot/prebuilt_myjavalib.stubs/android_common/dex/myjavalib.stubs.jar", dexJarPath)
1415		}),
1416	)
1417}
1418
1419func TestSnapshotWithJavaSdkLibrary_SdkVersion_None(t *testing.T) {
1420	result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
1421		sdk {
1422			name: "mysdk",
1423			java_sdk_libs: ["myjavalib"],
1424		}
1425
1426		java_sdk_library {
1427			name: "myjavalib",
1428			srcs: ["Test.java"],
1429			sdk_version: "none",
1430			system_modules: "none",
1431		}
1432	`)
1433
1434	CheckSnapshot(t, result, "mysdk", "",
1435		checkUnversionedAndroidBpContents(`
1436// This is auto-generated. DO NOT EDIT.
1437
1438java_sdk_library_import {
1439    name: "myjavalib",
1440    prefer: false,
1441    visibility: ["//visibility:public"],
1442    apex_available: ["//apex_available:platform"],
1443    shared_library: true,
1444    public: {
1445        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1446        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1447        current_api: "sdk_library/public/myjavalib.txt",
1448        removed_api: "sdk_library/public/myjavalib-removed.txt",
1449        sdk_version: "none",
1450    },
1451}
1452`),
1453		checkVersionedAndroidBpContents(`
1454// This is auto-generated. DO NOT EDIT.
1455
1456java_sdk_library_import {
1457    name: "mysdk_myjavalib@current",
1458    sdk_member_name: "myjavalib",
1459    visibility: ["//visibility:public"],
1460    apex_available: ["//apex_available:platform"],
1461    shared_library: true,
1462    public: {
1463        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1464        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1465        current_api: "sdk_library/public/myjavalib.txt",
1466        removed_api: "sdk_library/public/myjavalib-removed.txt",
1467        sdk_version: "none",
1468    },
1469}
1470
1471sdk_snapshot {
1472    name: "mysdk@current",
1473    visibility: ["//visibility:public"],
1474    java_sdk_libs: ["mysdk_myjavalib@current"],
1475}
1476`),
1477		checkAllCopyRules(`
1478.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
1479.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
1480.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
1481`),
1482		checkMergeZips(
1483			".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
1484		),
1485	)
1486}
1487
1488func TestSnapshotWithJavaSdkLibrary_SdkVersion_ForScope(t *testing.T) {
1489	result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
1490		sdk {
1491			name: "mysdk",
1492			java_sdk_libs: ["myjavalib"],
1493		}
1494
1495		java_sdk_library {
1496			name: "myjavalib",
1497			srcs: ["Test.java"],
1498			sdk_version: "module_current",
1499			public: {
1500				enabled: true,
1501				sdk_version: "module_current",
1502			},
1503		}
1504	`)
1505
1506	CheckSnapshot(t, result, "mysdk", "",
1507		checkUnversionedAndroidBpContents(`
1508// This is auto-generated. DO NOT EDIT.
1509
1510java_sdk_library_import {
1511    name: "myjavalib",
1512    prefer: false,
1513    visibility: ["//visibility:public"],
1514    apex_available: ["//apex_available:platform"],
1515    shared_library: true,
1516    public: {
1517        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1518        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1519        current_api: "sdk_library/public/myjavalib.txt",
1520        removed_api: "sdk_library/public/myjavalib-removed.txt",
1521        sdk_version: "module_current",
1522    },
1523}
1524`),
1525		checkVersionedAndroidBpContents(`
1526// This is auto-generated. DO NOT EDIT.
1527
1528java_sdk_library_import {
1529    name: "mysdk_myjavalib@current",
1530    sdk_member_name: "myjavalib",
1531    visibility: ["//visibility:public"],
1532    apex_available: ["//apex_available:platform"],
1533    shared_library: true,
1534    public: {
1535        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1536        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1537        current_api: "sdk_library/public/myjavalib.txt",
1538        removed_api: "sdk_library/public/myjavalib-removed.txt",
1539        sdk_version: "module_current",
1540    },
1541}
1542
1543sdk_snapshot {
1544    name: "mysdk@current",
1545    visibility: ["//visibility:public"],
1546    java_sdk_libs: ["mysdk_myjavalib@current"],
1547}
1548`),
1549		checkAllCopyRules(`
1550.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
1551.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
1552.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
1553`),
1554		checkMergeZips(
1555			".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
1556		),
1557	)
1558}
1559
1560func TestSnapshotWithJavaSdkLibrary_ApiScopes(t *testing.T) {
1561	result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
1562		sdk {
1563			name: "mysdk",
1564			java_sdk_libs: ["myjavalib"],
1565		}
1566
1567		java_sdk_library {
1568			name: "myjavalib",
1569			apex_available: ["//apex_available:anyapex"],
1570			srcs: ["Test.java"],
1571			sdk_version: "current",
1572			public: {
1573				enabled: true,
1574			},
1575			system: {
1576				enabled: true,
1577			},
1578		}
1579	`)
1580
1581	CheckSnapshot(t, result, "mysdk", "",
1582		checkUnversionedAndroidBpContents(`
1583// This is auto-generated. DO NOT EDIT.
1584
1585java_sdk_library_import {
1586    name: "myjavalib",
1587    prefer: false,
1588    visibility: ["//visibility:public"],
1589    apex_available: ["//apex_available:anyapex"],
1590    shared_library: true,
1591    public: {
1592        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1593        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1594        current_api: "sdk_library/public/myjavalib.txt",
1595        removed_api: "sdk_library/public/myjavalib-removed.txt",
1596        sdk_version: "current",
1597    },
1598    system: {
1599        jars: ["sdk_library/system/myjavalib-stubs.jar"],
1600        stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
1601        current_api: "sdk_library/system/myjavalib.txt",
1602        removed_api: "sdk_library/system/myjavalib-removed.txt",
1603        sdk_version: "system_current",
1604    },
1605}
1606`),
1607		checkVersionedAndroidBpContents(`
1608// This is auto-generated. DO NOT EDIT.
1609
1610java_sdk_library_import {
1611    name: "mysdk_myjavalib@current",
1612    sdk_member_name: "myjavalib",
1613    visibility: ["//visibility:public"],
1614    apex_available: ["//apex_available:anyapex"],
1615    shared_library: true,
1616    public: {
1617        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1618        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1619        current_api: "sdk_library/public/myjavalib.txt",
1620        removed_api: "sdk_library/public/myjavalib-removed.txt",
1621        sdk_version: "current",
1622    },
1623    system: {
1624        jars: ["sdk_library/system/myjavalib-stubs.jar"],
1625        stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
1626        current_api: "sdk_library/system/myjavalib.txt",
1627        removed_api: "sdk_library/system/myjavalib-removed.txt",
1628        sdk_version: "system_current",
1629    },
1630}
1631
1632sdk_snapshot {
1633    name: "mysdk@current",
1634    visibility: ["//visibility:public"],
1635    java_sdk_libs: ["mysdk_myjavalib@current"],
1636}
1637`),
1638		checkAllCopyRules(`
1639.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
1640.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
1641.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
1642.intermediates/myjavalib.stubs.system/android_common/javac/myjavalib.stubs.system.jar -> sdk_library/system/myjavalib-stubs.jar
1643.intermediates/myjavalib.stubs.source.system/android_common/metalava/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib.txt
1644.intermediates/myjavalib.stubs.source.system/android_common/metalava/myjavalib.stubs.source.system_removed.txt -> sdk_library/system/myjavalib-removed.txt
1645`),
1646		checkMergeZips(
1647			".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
1648			".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip",
1649		),
1650	)
1651}
1652
1653func TestSnapshotWithJavaSdkLibrary_ModuleLib(t *testing.T) {
1654	result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
1655		sdk {
1656			name: "mysdk",
1657			java_sdk_libs: ["myjavalib"],
1658		}
1659
1660		java_sdk_library {
1661			name: "myjavalib",
1662			apex_available: ["//apex_available:anyapex"],
1663			srcs: ["Test.java"],
1664			sdk_version: "current",
1665			public: {
1666				enabled: true,
1667			},
1668			system: {
1669				enabled: true,
1670			},
1671			module_lib: {
1672				enabled: true,
1673			},
1674		}
1675	`)
1676
1677	CheckSnapshot(t, result, "mysdk", "",
1678		checkUnversionedAndroidBpContents(`
1679// This is auto-generated. DO NOT EDIT.
1680
1681java_sdk_library_import {
1682    name: "myjavalib",
1683    prefer: false,
1684    visibility: ["//visibility:public"],
1685    apex_available: ["//apex_available:anyapex"],
1686    shared_library: true,
1687    public: {
1688        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1689        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1690        current_api: "sdk_library/public/myjavalib.txt",
1691        removed_api: "sdk_library/public/myjavalib-removed.txt",
1692        sdk_version: "current",
1693    },
1694    system: {
1695        jars: ["sdk_library/system/myjavalib-stubs.jar"],
1696        stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
1697        current_api: "sdk_library/system/myjavalib.txt",
1698        removed_api: "sdk_library/system/myjavalib-removed.txt",
1699        sdk_version: "system_current",
1700    },
1701    module_lib: {
1702        jars: ["sdk_library/module-lib/myjavalib-stubs.jar"],
1703        stub_srcs: ["sdk_library/module-lib/myjavalib_stub_sources"],
1704        current_api: "sdk_library/module-lib/myjavalib.txt",
1705        removed_api: "sdk_library/module-lib/myjavalib-removed.txt",
1706        sdk_version: "module_current",
1707    },
1708}
1709`),
1710		checkVersionedAndroidBpContents(`
1711// This is auto-generated. DO NOT EDIT.
1712
1713java_sdk_library_import {
1714    name: "mysdk_myjavalib@current",
1715    sdk_member_name: "myjavalib",
1716    visibility: ["//visibility:public"],
1717    apex_available: ["//apex_available:anyapex"],
1718    shared_library: true,
1719    public: {
1720        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1721        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1722        current_api: "sdk_library/public/myjavalib.txt",
1723        removed_api: "sdk_library/public/myjavalib-removed.txt",
1724        sdk_version: "current",
1725    },
1726    system: {
1727        jars: ["sdk_library/system/myjavalib-stubs.jar"],
1728        stub_srcs: ["sdk_library/system/myjavalib_stub_sources"],
1729        current_api: "sdk_library/system/myjavalib.txt",
1730        removed_api: "sdk_library/system/myjavalib-removed.txt",
1731        sdk_version: "system_current",
1732    },
1733    module_lib: {
1734        jars: ["sdk_library/module-lib/myjavalib-stubs.jar"],
1735        stub_srcs: ["sdk_library/module-lib/myjavalib_stub_sources"],
1736        current_api: "sdk_library/module-lib/myjavalib.txt",
1737        removed_api: "sdk_library/module-lib/myjavalib-removed.txt",
1738        sdk_version: "module_current",
1739    },
1740}
1741
1742sdk_snapshot {
1743    name: "mysdk@current",
1744    visibility: ["//visibility:public"],
1745    java_sdk_libs: ["mysdk_myjavalib@current"],
1746}
1747`),
1748		checkAllCopyRules(`
1749.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
1750.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
1751.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
1752.intermediates/myjavalib.stubs.system/android_common/javac/myjavalib.stubs.system.jar -> sdk_library/system/myjavalib-stubs.jar
1753.intermediates/myjavalib.stubs.source.system/android_common/metalava/myjavalib.stubs.source.system_api.txt -> sdk_library/system/myjavalib.txt
1754.intermediates/myjavalib.stubs.source.system/android_common/metalava/myjavalib.stubs.source.system_removed.txt -> sdk_library/system/myjavalib-removed.txt
1755.intermediates/myjavalib.stubs.module_lib/android_common/javac/myjavalib.stubs.module_lib.jar -> sdk_library/module-lib/myjavalib-stubs.jar
1756.intermediates/myjavalib.stubs.source.module_lib/android_common/metalava/myjavalib.stubs.source.module_lib_api.txt -> sdk_library/module-lib/myjavalib.txt
1757.intermediates/myjavalib.stubs.source.module_lib/android_common/metalava/myjavalib.stubs.source.module_lib_removed.txt -> sdk_library/module-lib/myjavalib-removed.txt
1758`),
1759		checkMergeZips(
1760			".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
1761			".intermediates/mysdk/common_os/tmp/sdk_library/system/myjavalib_stub_sources.zip",
1762			".intermediates/mysdk/common_os/tmp/sdk_library/module-lib/myjavalib_stub_sources.zip",
1763		),
1764	)
1765}
1766
1767func TestSnapshotWithJavaSdkLibrary_SystemServer(t *testing.T) {
1768	result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
1769		sdk {
1770			name: "mysdk",
1771			java_sdk_libs: ["myjavalib"],
1772		}
1773
1774		java_sdk_library {
1775			name: "myjavalib",
1776			apex_available: ["//apex_available:anyapex"],
1777			srcs: ["Test.java"],
1778			sdk_version: "current",
1779			public: {
1780				enabled: true,
1781			},
1782			system_server: {
1783				enabled: true,
1784			},
1785		}
1786	`)
1787
1788	CheckSnapshot(t, result, "mysdk", "",
1789		checkUnversionedAndroidBpContents(`
1790// This is auto-generated. DO NOT EDIT.
1791
1792java_sdk_library_import {
1793    name: "myjavalib",
1794    prefer: false,
1795    visibility: ["//visibility:public"],
1796    apex_available: ["//apex_available:anyapex"],
1797    shared_library: true,
1798    public: {
1799        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1800        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1801        current_api: "sdk_library/public/myjavalib.txt",
1802        removed_api: "sdk_library/public/myjavalib-removed.txt",
1803        sdk_version: "current",
1804    },
1805    system_server: {
1806        jars: ["sdk_library/system-server/myjavalib-stubs.jar"],
1807        stub_srcs: ["sdk_library/system-server/myjavalib_stub_sources"],
1808        current_api: "sdk_library/system-server/myjavalib.txt",
1809        removed_api: "sdk_library/system-server/myjavalib-removed.txt",
1810        sdk_version: "system_server_current",
1811    },
1812}
1813`),
1814		checkVersionedAndroidBpContents(`
1815// This is auto-generated. DO NOT EDIT.
1816
1817java_sdk_library_import {
1818    name: "mysdk_myjavalib@current",
1819    sdk_member_name: "myjavalib",
1820    visibility: ["//visibility:public"],
1821    apex_available: ["//apex_available:anyapex"],
1822    shared_library: true,
1823    public: {
1824        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1825        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1826        current_api: "sdk_library/public/myjavalib.txt",
1827        removed_api: "sdk_library/public/myjavalib-removed.txt",
1828        sdk_version: "current",
1829    },
1830    system_server: {
1831        jars: ["sdk_library/system-server/myjavalib-stubs.jar"],
1832        stub_srcs: ["sdk_library/system-server/myjavalib_stub_sources"],
1833        current_api: "sdk_library/system-server/myjavalib.txt",
1834        removed_api: "sdk_library/system-server/myjavalib-removed.txt",
1835        sdk_version: "system_server_current",
1836    },
1837}
1838
1839sdk_snapshot {
1840    name: "mysdk@current",
1841    visibility: ["//visibility:public"],
1842    java_sdk_libs: ["mysdk_myjavalib@current"],
1843}
1844`),
1845		checkAllCopyRules(`
1846.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
1847.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
1848.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
1849.intermediates/myjavalib.stubs.system_server/android_common/javac/myjavalib.stubs.system_server.jar -> sdk_library/system-server/myjavalib-stubs.jar
1850.intermediates/myjavalib.stubs.source.system_server/android_common/metalava/myjavalib.stubs.source.system_server_api.txt -> sdk_library/system-server/myjavalib.txt
1851.intermediates/myjavalib.stubs.source.system_server/android_common/metalava/myjavalib.stubs.source.system_server_removed.txt -> sdk_library/system-server/myjavalib-removed.txt
1852`),
1853		checkMergeZips(
1854			".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
1855			".intermediates/mysdk/common_os/tmp/sdk_library/system-server/myjavalib_stub_sources.zip",
1856		),
1857	)
1858}
1859
1860func TestSnapshotWithJavaSdkLibrary_NamingScheme(t *testing.T) {
1861	result := android.GroupFixturePreparers(prepareForSdkTestWithJavaSdkLibrary).RunTestWithBp(t, `
1862		sdk {
1863			name: "mysdk",
1864			java_sdk_libs: ["myjavalib"],
1865		}
1866
1867		java_sdk_library {
1868			name: "myjavalib",
1869			apex_available: ["//apex_available:anyapex"],
1870			srcs: ["Test.java"],
1871			sdk_version: "current",
1872			naming_scheme: "default",
1873			public: {
1874				enabled: true,
1875			},
1876		}
1877	`)
1878
1879	CheckSnapshot(t, result, "mysdk", "",
1880		checkUnversionedAndroidBpContents(`
1881// This is auto-generated. DO NOT EDIT.
1882
1883java_sdk_library_import {
1884    name: "myjavalib",
1885    prefer: false,
1886    visibility: ["//visibility:public"],
1887    apex_available: ["//apex_available:anyapex"],
1888    naming_scheme: "default",
1889    shared_library: true,
1890    public: {
1891        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1892        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1893        current_api: "sdk_library/public/myjavalib.txt",
1894        removed_api: "sdk_library/public/myjavalib-removed.txt",
1895        sdk_version: "current",
1896    },
1897}
1898`),
1899		checkVersionedAndroidBpContents(`
1900// This is auto-generated. DO NOT EDIT.
1901
1902java_sdk_library_import {
1903    name: "mysdk_myjavalib@current",
1904    sdk_member_name: "myjavalib",
1905    visibility: ["//visibility:public"],
1906    apex_available: ["//apex_available:anyapex"],
1907    naming_scheme: "default",
1908    shared_library: true,
1909    public: {
1910        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1911        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1912        current_api: "sdk_library/public/myjavalib.txt",
1913        removed_api: "sdk_library/public/myjavalib-removed.txt",
1914        sdk_version: "current",
1915    },
1916}
1917
1918sdk_snapshot {
1919    name: "mysdk@current",
1920    visibility: ["//visibility:public"],
1921    java_sdk_libs: ["mysdk_myjavalib@current"],
1922}
1923`),
1924		checkAllCopyRules(`
1925.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
1926.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
1927.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
1928`),
1929		checkMergeZips(
1930			".intermediates/mysdk/common_os/tmp/sdk_library/public/myjavalib_stub_sources.zip",
1931		),
1932	)
1933}
1934
1935func TestSnapshotWithJavaSdkLibrary_DoctagFiles(t *testing.T) {
1936	result := android.GroupFixturePreparers(
1937		prepareForSdkTestWithJavaSdkLibrary,
1938		android.FixtureAddFile("docs/known_doctags", nil),
1939	).RunTestWithBp(t, `
1940		sdk {
1941			name: "mysdk",
1942			java_sdk_libs: ["myjavalib"],
1943		}
1944
1945		java_sdk_library {
1946			name: "myjavalib",
1947			srcs: ["Test.java"],
1948			sdk_version: "current",
1949			public: {
1950				enabled: true,
1951			},
1952			doctag_files: ["docs/known_doctags"],
1953		}
1954
1955		filegroup {
1956			name: "mygroup",
1957			srcs: [":myjavalib{.doctags}"],
1958		}
1959	`)
1960
1961	CheckSnapshot(t, result, "mysdk", "",
1962		checkUnversionedAndroidBpContents(`
1963// This is auto-generated. DO NOT EDIT.
1964
1965java_sdk_library_import {
1966    name: "myjavalib",
1967    prefer: false,
1968    visibility: ["//visibility:public"],
1969    apex_available: ["//apex_available:platform"],
1970    shared_library: true,
1971    doctag_files: ["doctags/docs/known_doctags"],
1972    public: {
1973        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1974        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1975        current_api: "sdk_library/public/myjavalib.txt",
1976        removed_api: "sdk_library/public/myjavalib-removed.txt",
1977        sdk_version: "current",
1978    },
1979}
1980`),
1981		checkVersionedAndroidBpContents(`
1982// This is auto-generated. DO NOT EDIT.
1983
1984java_sdk_library_import {
1985    name: "mysdk_myjavalib@current",
1986    sdk_member_name: "myjavalib",
1987    visibility: ["//visibility:public"],
1988    apex_available: ["//apex_available:platform"],
1989    shared_library: true,
1990    doctag_files: ["doctags/docs/known_doctags"],
1991    public: {
1992        jars: ["sdk_library/public/myjavalib-stubs.jar"],
1993        stub_srcs: ["sdk_library/public/myjavalib_stub_sources"],
1994        current_api: "sdk_library/public/myjavalib.txt",
1995        removed_api: "sdk_library/public/myjavalib-removed.txt",
1996        sdk_version: "current",
1997    },
1998}
1999
2000sdk_snapshot {
2001    name: "mysdk@current",
2002    visibility: ["//visibility:public"],
2003    java_sdk_libs: ["mysdk_myjavalib@current"],
2004}
2005`),
2006		checkAllCopyRules(`
2007.intermediates/myjavalib.stubs/android_common/javac/myjavalib.stubs.jar -> sdk_library/public/myjavalib-stubs.jar
2008.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_api.txt -> sdk_library/public/myjavalib.txt
2009.intermediates/myjavalib.stubs.source/android_common/metalava/myjavalib.stubs.source_removed.txt -> sdk_library/public/myjavalib-removed.txt
2010docs/known_doctags -> doctags/docs/known_doctags
2011`),
2012	)
2013}
2014