From 75b95f8a61cd7fbf29da86d6896b4839a0803c35 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Mon, 4 Dec 2017 16:24:07 -0500 Subject: [PATCH] Update pom2mk to allow duplicate module names if rewritten Fixes: 70162730 Test: ./update_current.py -s -t 4482279 Change-Id: I874d7bfb50fd2d2bc488f5458cfe57b2e0d4d4e5 --- cmd/pom2mk/pom2mk.go | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/cmd/pom2mk/pom2mk.go b/cmd/pom2mk/pom2mk.go index 4596db966..33d7ff912 100644 --- a/cmd/pom2mk/pom2mk.go +++ b/cmd/pom2mk/pom2mk.go @@ -55,13 +55,15 @@ func (r *RewriteNames) Set(v string) error { return nil } -func (r *RewriteNames) Rewrite(name string) string { +func (r *RewriteNames) MavenToMk(groupId string, artifactId string) string { for _, r := range *r { - if r.regexp.MatchString(name) { - return r.regexp.ReplaceAllString(name, r.repl) + if r.regexp.MatchString(groupId + ":" + artifactId) { + return r.regexp.ReplaceAllString(groupId+":"+artifactId, r.repl) + } else if r.regexp.MatchString(artifactId) { + return r.regexp.ReplaceAllString(artifactId, r.repl) } } - return name + return artifactId } var rewriteNames = RewriteNames{} @@ -102,6 +104,7 @@ type Pom struct { PomFile string `xml:"-"` ArtifactFile string `xml:"-"` + MakeTarget string `xml:"-"` GroupId string `xml:"groupId"` ArtifactId string `xml:"artifactId"` @@ -112,7 +115,10 @@ type Pom struct { } func (p Pom) MkName() string { - return rewriteNames.Rewrite(p.ArtifactId) + if p.MakeTarget == "" { + p.MakeTarget = rewriteNames.MavenToMk(p.GroupId, p.ArtifactId) + } + return p.MakeTarget } func (p Pom) MkDeps() []string { @@ -121,7 +127,7 @@ func (p Pom) MkDeps() []string { if d.Type != "aar" { continue } - name := rewriteNames.Rewrite(d.ArtifactId) + name := rewriteNames.MavenToMk(d.GroupId, d.ArtifactId) ret = append(ret, name) ret = append(ret, extraDeps[name]...) } @@ -137,7 +143,7 @@ func (p *Pom) FixDepTypes(modules map[string]*Pom) { if d.Type != "" { continue } - if depPom, ok := modules[d.ArtifactId]; ok { + if depPom, ok := modules[p.MkName()]; ok { d.Type = depPom.Packaging } } @@ -195,9 +201,11 @@ aar libraries can be linked against when using AAPT2. Usage: %s [--rewrite =] [--extra-deps =[,]] -rewrite = - rewrite can be used to specify mappings between the artifactId in the pom files and module - names in the Android.mk files. This can be specified multiple times, the first matching - regex will be used. + rewrite can be used to specify mappings between Maven projects and Make modules. The -rewrite + option can be specified multiple times. When determining the Make module for a given Maven + project, mappings are searched in the order they were specified. The first matching + either the Maven project's : or will be used to generate + the Make module name using . If no matches are found, is used. -extra-deps =[,] Some Android.mk modules have transitive dependencies that must be specified when they are depended upon (like android-support-v7-mediarouter requires android-support-v7-appcompat). @@ -282,13 +290,14 @@ The makefile is written to stdout, to be put in the current directory (often as if pom != nil { poms = append(poms, pom) + key := pom.MkName() - if old, ok := modules[pom.ArtifactId]; ok { - fmt.Fprintln(os.Stderr, "Module", pom.ArtifactId, "defined twice:", old.PomFile, pom.PomFile) + if old, ok := modules[key]; ok { + fmt.Fprintln(os.Stderr, "Module", key, "defined twice:", old.PomFile, pom.PomFile) os.Exit(1) } - modules[pom.ArtifactId] = pom + modules[key] = pom } }