summaryrefslogtreecommitdiff
path: root/java/java_test.go
diff options
context:
space:
mode:
author Jihoon Kang <jihoonkang@google.com> 2023-01-09 23:42:40 +0000
committer Jihoon Kang <jihoonkang@google.com> 2023-01-10 22:34:31 +0000
commit1c51f50120b9b6a2c2ae6cfd79344f9248e39516 (patch)
tree677cf5a4f5368d090922311f2cc53434cc5e9ed3 /java/java_test.go
parent64b0fbd1512f0c4bc888695d096454b028391607 (diff)
Add java_api_library properties to java_defaults
Context - Some Java API surfaces have subset relationships (i.e. public API surface is a subset of system API surface). Thus, simply listing all API files that contributes to hierarchical API surfaces when defining java_api_library modules can lead to repetition of code in Android.bp files. - Utilizing java_defaults can resolve this problem by grouping java_api_contribution modules by API surfaces, and reduce code repetition and enhance readability. Implementation - Modify java_api_library module to utilize java_defaults modules. Test: m Change-Id: I6adead208ca36c21de72ee39c4f532b84af8a153
Diffstat (limited to 'java/java_test.go')
-rw-r--r--java/java_test.go88
1 files changed, 88 insertions, 0 deletions
diff --git a/java/java_test.go b/java/java_test.go
index 085f6272a..49adefbde 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -1894,6 +1894,94 @@ func TestJavaApiLibraryAndProviderLink(t *testing.T) {
}
}
+func TestJavaApiLibraryAndDefaultsLink(t *testing.T) {
+ provider_bp_a := `java_api_contribution {
+ name: "foo1",
+ api_file: "foo1.txt",
+ }
+ `
+ provider_bp_b := `java_api_contribution {
+ name: "foo2",
+ api_file: "foo2.txt",
+ }
+ `
+ provider_bp_c := `java_api_contribution {
+ name: "foo3",
+ api_file: "foo3.txt",
+ }
+ `
+ provider_bp_d := `java_api_contribution {
+ name: "foo4",
+ api_file: "foo4.txt",
+ }
+ `
+ ctx, _ := testJavaWithFS(t, `
+ java_defaults {
+ name: "baz1",
+ api_surface: "public",
+ api_contributions: ["foo1", "foo2"],
+ }
+
+ java_defaults {
+ name: "baz2",
+ api_surface: "system",
+ api_contributions: ["foo3"],
+ }
+
+ java_api_library {
+ name: "bar1",
+ api_surface: "public",
+ api_contributions: ["foo1"],
+ }
+
+ java_api_library {
+ name: "bar2",
+ api_surface: "public",
+ defaults:["baz1"],
+ }
+
+ java_api_library {
+ name: "bar3",
+ api_surface: "system",
+ defaults:["baz1", "baz2"],
+ api_contributions: ["foo4"],
+ api_files: ["api1/current.txt", "api2/current.txt"]
+ }
+ `,
+ map[string][]byte{
+ "a/Android.bp": []byte(provider_bp_a),
+ "b/Android.bp": []byte(provider_bp_b),
+ "c/Android.bp": []byte(provider_bp_c),
+ "d/Android.bp": []byte(provider_bp_d),
+ })
+
+ testcases := []struct {
+ moduleName string
+ sourceTextFileDirs []string
+ }{
+ {
+ moduleName: "bar1",
+ sourceTextFileDirs: []string{"a/foo1.txt"},
+ },
+ {
+ moduleName: "bar2",
+ sourceTextFileDirs: []string{"a/foo1.txt", "b/foo2.txt"},
+ },
+ {
+ moduleName: "bar3",
+ sourceTextFileDirs: []string{"c/foo3.txt", "a/foo1.txt", "b/foo2.txt", "d/foo4.txt", "api1/current.txt", "api2/current.txt"},
+ },
+ }
+ for _, c := range testcases {
+ m := ctx.ModuleForTests(c.moduleName, "android_common")
+ manifest := m.Output("metalava.sbox.textproto")
+ sboxProto := android.RuleBuilderSboxProtoForTests(t, manifest)
+ manifestCommand := sboxProto.Commands[0].GetCommand()
+ sourceFilesFlag := "--source-files " + strings.Join(c.sourceTextFileDirs, " ")
+ android.AssertStringDoesContain(t, "source text files not present", manifestCommand, sourceFilesFlag)
+ }
+}
+
func TestJavaApiLibraryJarGeneration(t *testing.T) {
provider_bp_a := `
java_api_contribution {