Allow wildcards in java_resource_dirs

Expand java_resource_dirs using ctx.Glob before globbing inside it
in case it has wildcards in it.  Fixes:
internal error: panic in GenerateBuildActions for module "icu4j" variant "linux_glibc_common"
path "external/icu/icu4j/main/classes/charset/src/META-INF" does not start with "external/icu/icu4j/main/classes/*/src"

Test: java_test.go
Change-Id: Icd28b7a3dd14752642fb0ec8d41bbd6e30f81a68
diff --git a/java/java_test.go b/java/java_test.go
index c790342..64b6bf8 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -143,8 +143,8 @@
 		"b.kt":           nil,
 		"a.jar":          nil,
 		"b.jar":          nil,
-		"java-res/a":     nil,
-		"java-res/b":     nil,
+		"java-res/a/a":   nil,
+		"java-res/b/b":   nil,
 		"java-res2/a":    nil,
 		"java-fg/a.java": nil,
 		"java-fg/b.java": nil,
@@ -606,13 +606,13 @@
 			// Test that a module with java_resource_dirs includes the files
 			name: "resource dirs",
 			prop: `java_resource_dirs: ["java-res"]`,
-			args: "-C java-res -f java-res/a -f java-res/b",
+			args: "-C java-res -f java-res/a/a -f java-res/b/b",
 		},
 		{
 			// Test that a module with java_resources includes the files
 			name: "resource files",
-			prop: `java_resources: ["java-res/a", "java-res/b"]`,
-			args: "-C . -f java-res/a -f java-res/b",
+			prop: `java_resources: ["java-res/a/a", "java-res/b/b"]`,
+			args: "-C . -f java-res/a/a -f java-res/b/b",
 		},
 		{
 			// Test that a module with a filegroup in java_resources includes the files with the
@@ -623,9 +623,9 @@
 				filegroup {
 					name: "foo-res",
 					path: "java-res",
-					srcs: ["java-res/a", "java-res/b"],
+					srcs: ["java-res/a/a", "java-res/b/b"],
 				}`,
-			args: "-C java-res -f java-res/a -f java-res/b",
+			args: "-C java-res -f java-res/a/a -f java-res/b/b",
 		},
 		{
 			// Test that a module with "include_srcs: true" includes its source files in the resources jar
@@ -633,6 +633,18 @@
 			prop: `include_srcs: true`,
 			args: "-C . -f a.java -f b.java -f c.java",
 		},
+		{
+			// Test that a module with wildcards in java_resource_dirs has the correct path prefixes
+			name: "wildcard dirs",
+			prop: `java_resource_dirs: ["java-res/*"]`,
+			args: "-C java-res/a -f java-res/a/a -C java-res/b -f java-res/b/b",
+		},
+		{
+			// Test that a module exclude_java_resource_dirs excludes the files
+			name: "wildcard dirs",
+			prop: `java_resource_dirs: ["java-res/*"], exclude_java_resource_dirs: ["java-res/b"]`,
+			args: "-C java-res/a -f java-res/a/a",
+		},
 	}
 
 	for _, test := range table {
@@ -677,14 +689,14 @@
 		java_library {
 			name: "bar",
 			srcs: ["a.java"],
-			java_resources: ["java-res/*"],
-			exclude_java_resources: ["java-res/b"],
+			java_resources: ["java-res/*/*"],
+			exclude_java_resources: ["java-res/b/*"],
 		}
 	`)
 
 	fooRes := ctx.ModuleForTests("foo", "android_common").Output("res/foo.jar")
 
-	expected := "-C java-res -f java-res/a -f java-res/b"
+	expected := "-C java-res -f java-res/a/a -f java-res/b/b"
 	if fooRes.Args["jarArgs"] != expected {
 		t.Errorf("foo resource jar args %q is not %q",
 			fooRes.Args["jarArgs"], expected)
@@ -693,7 +705,7 @@
 
 	barRes := ctx.ModuleForTests("bar", "android_common").Output("res/bar.jar")
 
-	expected = "-C . -f java-res/a"
+	expected = "-C . -f java-res/a/a"
 	if barRes.Args["jarArgs"] != expected {
 		t.Errorf("bar resource jar args %q is not %q",
 			barRes.Args["jarArgs"], expected)