blob: 01692a35bdd5f6388da21bb218d254503d3db5e3 [file] [log] [blame]
Jiakai Zhanga8d86602021-09-26 09:02:17 +00001// Copyright (C) 2021 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 "testing"
19
20 "android/soong/android"
21 "android/soong/dexpreopt"
22 "android/soong/java"
23)
24
25func TestSnapshotWithSystemServerClasspathFragment(t *testing.T) {
26 result := android.GroupFixturePreparers(
27 prepareForSdkTestWithJava,
28 java.PrepareForTestWithJavaDefaultModules,
29 java.PrepareForTestWithJavaSdkLibraryFiles,
30 java.FixtureWithLastReleaseApis("mysdklibrary"),
31 dexpreopt.FixtureSetApexSystemServerJars("myapex:mylib", "myapex:mysdklibrary"),
32 prepareForSdkTestWithApex,
33
34 android.FixtureWithRootAndroidBp(`
35 sdk {
36 name: "mysdk",
37 systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
38 java_sdk_libs: [
39 // This is not strictly needed as it should be automatically added to the sdk_snapshot as
40 // a java_sdk_libs module because it is used in the mysystemserverclasspathfragment's
41 // contents property. However, it is specified here to ensure that duplicates are
42 // correctly deduped.
43 "mysdklibrary",
44 ],
45 }
46
47 apex {
48 name: "myapex",
49 key: "myapex.key",
50 min_sdk_version: "2",
51 systemserverclasspath_fragments: ["mysystemserverclasspathfragment"],
52 }
53
54 systemserverclasspath_fragment {
55 name: "mysystemserverclasspathfragment",
56 apex_available: ["myapex"],
57 contents: [
58 "mylib",
59 "mysdklibrary",
60 ],
61 }
62
63 java_library {
64 name: "mylib",
65 apex_available: ["myapex"],
66 srcs: ["Test.java"],
67 system_modules: "none",
68 sdk_version: "none",
69 min_sdk_version: "2",
70 compile_dex: true,
71 permitted_packages: ["mylib"],
72 }
73
74 java_sdk_library {
75 name: "mysdklibrary",
76 apex_available: ["myapex"],
77 srcs: ["Test.java"],
78 shared_library: false,
79 public: {enabled: true},
80 min_sdk_version: "2",
81 }
82 `),
83 ).RunTest(t)
84
85 CheckSnapshot(t, result, "mysdk", "",
Paul Duffinb01ac4b2022-05-24 20:10:05 +000086 checkAndroidBpContents(`
Jiakai Zhanga8d86602021-09-26 09:02:17 +000087// This is auto-generated. DO NOT EDIT.
88
89java_sdk_library_import {
90 name: "mysdklibrary",
91 prefer: false,
92 visibility: ["//visibility:public"],
93 apex_available: ["myapex"],
94 shared_library: false,
95 public: {
96 jars: ["sdk_library/public/mysdklibrary-stubs.jar"],
97 stub_srcs: ["sdk_library/public/mysdklibrary_stub_sources"],
98 current_api: "sdk_library/public/mysdklibrary.txt",
99 removed_api: "sdk_library/public/mysdklibrary-removed.txt",
100 sdk_version: "current",
101 },
102}
103
104java_import {
105 name: "mylib",
106 prefer: false,
107 visibility: ["//visibility:public"],
108 apex_available: ["myapex"],
109 jars: ["java_systemserver_libs/snapshot/jars/are/invalid/mylib.jar"],
110 permitted_packages: ["mylib"],
111}
112
113prebuilt_systemserverclasspath_fragment {
114 name: "mysystemserverclasspathfragment",
115 prefer: false,
116 visibility: ["//visibility:public"],
117 apex_available: ["myapex"],
118 contents: [
119 "mylib",
120 "mysdklibrary",
121 ],
122}
123`),
Jiakai Zhanga8d86602021-09-26 09:02:17 +0000124 )
125}