1// 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) 22 23func TestSnapshotWithPackageDefaultLicense(t *testing.T) { 24 t.Parallel() 25 result := android.GroupFixturePreparers( 26 prepareForSdkTestWithJava, 27 android.PrepareForTestWithLicenses, 28 android.PrepareForTestWithLicenseDefaultModules, 29 android.MockFS{ 30 "NOTICE1": nil, 31 "NOTICE2": nil, 32 }.AddToFixture(), 33 ).RunTestWithBp(t, ` 34 package { 35 default_applicable_licenses: ["mylicense"], 36 } 37 38 license { 39 name: "mylicense", 40 license_kinds: [ 41 "SPDX-license-identifier-Apache-2.0", 42 "legacy_unencumbered", 43 ], 44 license_text: [ 45 "NOTICE1", 46 "NOTICE2", 47 ], 48 } 49 50 sdk { 51 name: "mysdk", 52 java_header_libs: ["myjavalib"], 53 } 54 55 java_library { 56 name: "myjavalib", 57 srcs: ["Test.java"], 58 system_modules: "none", 59 sdk_version: "none", 60 } 61 `) 62 63 CheckSnapshot(t, result, "mysdk", "", 64 checkAndroidBpContents(` 65// This is auto-generated. DO NOT EDIT. 66 67package { 68 // A default list here prevents the license LSC from adding its own list which would 69 // be unnecessary as every module in the sdk already has its own licenses property. 70 default_applicable_licenses: ["Android-Apache-2.0"], 71} 72 73apex_contributions_defaults { 74 name: "mysdk.contributions", 75 contents: ["prebuilt_myjavalib"], 76} 77 78java_import { 79 name: "myjavalib", 80 prefer: false, 81 visibility: ["//visibility:public"], 82 apex_available: ["//apex_available:platform"], 83 licenses: ["mysdk_mylicense"], 84 jars: ["java/myjavalib.jar"], 85} 86 87license { 88 name: "mysdk_mylicense", 89 visibility: ["//visibility:private"], 90 license_kinds: [ 91 "SPDX-license-identifier-Apache-2.0", 92 "legacy_unencumbered", 93 ], 94 license_text: [ 95 "licenses/NOTICE1", 96 "licenses/NOTICE2", 97 ], 98} 99 `), 100 checkAllCopyRules(` 101.intermediates/myjavalib/android_common/turbine-combined/myjavalib.jar -> java/myjavalib.jar 102NOTICE1 -> licenses/NOTICE1 103NOTICE2 -> licenses/NOTICE2 104`), 105 ) 106} 107