Merge "Disallow missing api source files for java_api_library module" am: 0393174fe7 am: 8faf87a3a7 am: 3a9100940e am: 707c3a4ba7 am: 4dd2bc48d9

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2593068

Change-Id: I82ca2ba6a4b33c5972e38fe78fb884961169b409
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/java/java.go b/java/java.go
index 65bfce0..bb8fe62 100644
--- a/java/java.go
+++ b/java/java.go
@@ -1650,7 +1650,7 @@
 	// list of api.txt files relative to this directory that contribute to the
 	// API surface.
 	// This is a list of relative paths
-	Api_files []string
+	Api_files []string `android:"path"`
 
 	// List of flags to be passed to the javac compiler to generate jar file
 	Javacflags []string
@@ -1832,9 +1832,7 @@
 
 	// Add the api_files inputs
 	for _, api := range al.properties.Api_files {
-		// Use MaybeExistentPathForSource since the api file might not exist during analysis.
-		// This will be provided by the orchestrator in the combined execution.
-		srcFiles = append(srcFiles, android.MaybeExistentPathForSource(ctx, ctx.ModuleDir(), api))
+		srcFiles = append(srcFiles, android.PathForModuleSrc(ctx, api))
 	}
 
 	if srcFiles == nil {
diff --git a/java/java_test.go b/java/java_test.go
index 2a4913e..ea89e6e 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -2252,6 +2252,29 @@
 	android.AssertStringDoesContain(t, "Command expected to contain output files list text file flag", manifestCommand, "--out __SBOX_SANDBOX_DIR__/out/sources.txt")
 }
 
+func TestJavaApiLibraryFilegroupInput(t *testing.T) {
+	ctx, _ := testJavaWithFS(t, `
+	    filegroup {
+			name: "default_current.txt",
+			srcs: ["current.txt"],
+		}
+
+		java_api_library {
+			name: "foo",
+			api_files: [":default_current.txt"],
+		}
+		`,
+		map[string][]byte{
+			"current.txt": nil,
+		})
+
+	m := ctx.ModuleForTests("foo", "android_common")
+	outputs := fmt.Sprint(m.AllOutputs())
+	if !strings.Contains(outputs, "foo/foo.jar") {
+		t.Errorf("Module output does not contain expected jar %s", "foo/foo.jar")
+	}
+}
+
 func TestTradefedOptions(t *testing.T) {
 	result := PrepareForTestWithJavaBuildComponents.RunTestWithBp(t, `
 java_test_host {
diff --git a/java/testing.go b/java/testing.go
index 6671bf0..ffc3a08 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -71,7 +71,12 @@
 		// Needed for framework
 		defaultJavaDir + "/framework/aidl": nil,
 		// Needed for various deps defined in GatherRequiredDepsForTest()
-		defaultJavaDir + "/a.java": nil,
+		defaultJavaDir + "/a.java":                        nil,
+		defaultJavaDir + "/api/current.txt":               nil,
+		defaultJavaDir + "/api/system-current.txt":        nil,
+		defaultJavaDir + "/api/test-current.txt":          nil,
+		defaultJavaDir + "/api/module-lib-current.txt":    nil,
+		defaultJavaDir + "/api/system-server-current.txt": nil,
 
 		// Needed for R8 rules on apps
 		"build/make/core/proguard.flags":             nil,