Add support for pom with packaging=apk to pom2bp.

Bug: 251825866
Test: ./prebuilts/misc/common/androidx-test/update-from-gmaven.py
Change-Id: I7811898d9801bb733f3b43c55308f6741778a378
This commit is contained in:
Brett Chabot 2022-10-12 12:12:02 -07:00
parent 58fecb427f
commit 98fb28670c

View file

@ -207,6 +207,10 @@ func (p Pom) IsJar() bool {
return p.Packaging == "jar"
}
func (p Pom) IsApk() bool {
return p.Packaging == "apk"
}
func (p Pom) IsHostModule() bool {
return hostModuleNames.IsHostModule(p.GroupId, p.ArtifactId)
}
@ -244,6 +248,8 @@ func (p Pom) BazelTargetType() string {
func (p Pom) ImportModuleType() string {
if p.IsAar() {
return "android_library_import"
} else if p.IsApk() {
return "android_app_import"
} else if p.IsHostOnly() {
return "java_import_host"
} else {
@ -254,6 +260,8 @@ func (p Pom) ImportModuleType() string {
func (p Pom) BazelImportTargetType() string {
if p.IsAar() {
return "aar_import"
} else if p.IsApk() {
return "apk_import"
} else {
return "java_import"
}
@ -262,6 +270,8 @@ func (p Pom) BazelImportTargetType() string {
func (p Pom) ImportProperty() string {
if p.IsAar() {
return "aars"
} else if p.IsApk() {
return "apk"
} else {
return "jars"
}
@ -270,6 +280,8 @@ func (p Pom) ImportProperty() string {
func (p Pom) BazelImportProperty() string {
if p.IsAar() {
return "aar"
} else if p.IsApk() {
return "apk"
} else {
return "jars"
}
@ -493,8 +505,12 @@ func (p *Pom) ExtractMinSdkVersion() error {
var bpTemplate = template.Must(template.New("bp").Parse(`
{{.ImportModuleType}} {
name: "{{.BpName}}",
{{- if .IsApk}}
{{.ImportProperty}}: "{{.ArtifactFile}}",
{{- else}}
{{.ImportProperty}}: ["{{.ArtifactFile}}"],
sdk_version: "{{.SdkVersion}}",
{{- end}}
{{- if .Jetifier}}
jetifier: true,
{{- end}}
@ -535,8 +551,14 @@ var bpTemplate = template.Must(template.New("bp").Parse(`
],
{{- end}}
{{- else if not .IsHostOnly}}
{{- if not .IsApk}}
min_sdk_version: "{{.DefaultMinSdkVersion}}",
{{- end}}
{{- end}}
{{- if .IsApk}}
presigned: true
{{- end}}
}
`))
@ -995,7 +1017,7 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib
for _, pom := range poms {
var err error
if staticDeps {
if staticDeps && !pom.IsApk() {
err = depsTemplate.Execute(buf, pom)
} else {
err = template.Execute(buf, pom)