1// Copyright 2018 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 "fmt" 19 "testing" 20 21 "android/soong/android" 22) 23 24func AssertJarJarRename(t *testing.T, result *android.TestResult, libName, original, expectedRename string) { 25 module := result.ModuleForTests(libName, "android_common") 26 27 provider, found := android.OtherModuleProvider(result.OtherModuleProviderAdaptor(), module.Module(), JarJarProvider) 28 android.AssertBoolEquals(t, fmt.Sprintf("found provider (%s)", libName), true, found) 29 30 renamed, found := provider.Rename[original] 31 android.AssertBoolEquals(t, fmt.Sprintf("found rename (%s)", libName), true, found) 32 android.AssertStringEquals(t, fmt.Sprintf("renamed (%s)", libName), expectedRename, renamed) 33} 34 35func TestJarJarRenameDifferentModules(t *testing.T) { 36 t.Parallel() 37 result := android.GroupFixturePreparers( 38 prepareForJavaTest, 39 ).RunTestWithBp(t, ` 40 java_library { 41 name: "their_lib", 42 jarjar_rename: ["com.example.a"], 43 } 44 45 java_library { 46 name: "boundary_lib", 47 jarjar_prefix: "RENAME", 48 static_libs: ["their_lib"], 49 } 50 51 java_library { 52 name: "my_lib", 53 static_libs: ["boundary_lib"], 54 } 55 `) 56 57 original := "com.example.a" 58 renamed := "RENAME.com.example.a" 59 AssertJarJarRename(t, result, "their_lib", original, "") 60 AssertJarJarRename(t, result, "boundary_lib", original, renamed) 61 AssertJarJarRename(t, result, "my_lib", original, renamed) 62} 63 64func TestJarJarRenameSameModule(t *testing.T) { 65 t.Parallel() 66 result := android.GroupFixturePreparers( 67 prepareForJavaTest, 68 ).RunTestWithBp(t, ` 69 java_library { 70 name: "their_lib", 71 jarjar_rename: ["com.example.a"], 72 jarjar_prefix: "RENAME", 73 } 74 75 java_library { 76 name: "my_lib", 77 static_libs: ["their_lib"], 78 } 79 `) 80 81 original := "com.example.a" 82 renamed := "RENAME.com.example.a" 83 AssertJarJarRename(t, result, "their_lib", original, renamed) 84 AssertJarJarRename(t, result, "my_lib", original, renamed) 85} 86