Replace --sdk-extension-root with --android-jar-pattern

Previously, the only way to specify the location of the SDK extension
jars was to specify the `--sdk-extension-root` directory and then rely
on Metalava's hard-coded pattern to find the jar files. However, it is
now possible to specify the SDK extension jar pattern explicitly as an
`--android-jar-pattern` option.

This change makes use of that new capability to specify patterns for
the SDK extension jars appropriate for the API surface being generated
and removes the `--sdk-extension-root` option altogether.

Bug: 259115852
Test: # Before applying this change run:
      tools/metalava/scripts/gather-android-metalava-artifacts.py before
      # After applying this change run:
      tools/metalava/scripts/gather-android-metalava-artifacts.py after
      # Make sure that there are no differences.
      meld before after
Change-Id: I4db9d4aa7b1ca3ef35a0778889f70acba491908d
diff --git a/java/droidstubs.go b/java/droidstubs.go
index 63611d6..958db40 100644
--- a/java/droidstubs.go
+++ b/java/droidstubs.go
@@ -659,6 +659,10 @@
 
 			addPattern(filename)
 		}
+
+		if extensions_dir != "" {
+			cmd.FlagWithArg("--android-jar-pattern ", fmt.Sprintf("%s/{version:extension}/%s/{module}.jar", extensions_dir, sdkDir))
+		}
 	}
 
 	if d.properties.Extensions_info_file != nil {
@@ -667,7 +671,6 @@
 		}
 		info_file := android.PathForModuleSrc(ctx, *d.properties.Extensions_info_file)
 		cmd.Implicit(info_file)
-		cmd.FlagWithArg("--sdk-extensions-root ", extensions_dir)
 		cmd.FlagWithArg("--sdk-extensions-info ", info_file.String())
 	}
 }
diff --git a/java/droidstubs_test.go b/java/droidstubs_test.go
index 37740ae..ad47210 100644
--- a/java/droidstubs_test.go
+++ b/java/droidstubs_test.go
@@ -303,7 +303,7 @@
 	m := ctx.ModuleForTests("baz-stubs", "android_common")
 	manifest := m.Output("metalava.sbox.textproto")
 	cmdline := String(android.RuleBuilderSboxProtoForTests(t, ctx, manifest).Commands[0].Command)
-	android.AssertStringDoesContain(t, "sdk-extensions-root present", cmdline, "--sdk-extensions-root sdk/extensions")
+	android.AssertStringDoesContain(t, "android-jar-pattern present", cmdline, "--android-jar-pattern sdk/extensions/{version:extension}/public/{module}.jar")
 	android.AssertStringDoesContain(t, "sdk-extensions-info present", cmdline, "--sdk-extensions-info sdk/extensions/info.txt")
 }