Merge changes Ieaff757f,I5bdbba8d
* changes: pom2mk: Fix unlisted dependency types pom2mk: Add a flag to specify a specific version of artifacts
This commit is contained in:
commit
4647be4afe
1 changed files with 58 additions and 11 deletions
|
@ -18,7 +18,6 @@ import (
|
|||
"encoding/xml"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -84,6 +83,8 @@ func (d ExtraDeps) Set(v string) error {
|
|||
|
||||
var extraDeps = make(ExtraDeps)
|
||||
|
||||
var useVersion string
|
||||
|
||||
type Dependency struct {
|
||||
XMLName xml.Name `xml:"dependency"`
|
||||
|
||||
|
@ -98,6 +99,7 @@ type Dependency struct {
|
|||
type Pom struct {
|
||||
XMLName xml.Name `xml:"http://maven.apache.org/POM/4.0.0 project"`
|
||||
|
||||
PomFile string `xml:"-"`
|
||||
ArtifactFile string `xml:"-"`
|
||||
|
||||
GroupId string `xml:"groupId"`
|
||||
|
@ -105,7 +107,7 @@ type Pom struct {
|
|||
Version string `xml:"version"`
|
||||
Packaging string `xml:"packaging"`
|
||||
|
||||
Dependencies []Dependency `xml:"dependencies>dependency"`
|
||||
Dependencies []*Dependency `xml:"dependencies>dependency"`
|
||||
}
|
||||
|
||||
func (p Pom) MkName() string {
|
||||
|
@ -125,6 +127,17 @@ func (p Pom) MkDeps() []string {
|
|||
return ret
|
||||
}
|
||||
|
||||
func (p *Pom) FixDepTypes(modules map[string]*Pom) {
|
||||
for _, d := range p.Dependencies {
|
||||
if d.Type != "" {
|
||||
continue
|
||||
}
|
||||
if depPom, ok := modules[d.ArtifactId]; ok {
|
||||
d.Type = depPom.Packaging
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var mkTemplate = template.Must(template.New("mk").Parse(`
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := {{.MkName}}
|
||||
|
@ -140,25 +153,30 @@ LOCAL_STATIC_ANDROID_LIBRARIES := \
|
|||
include $(BUILD_PREBUILT)
|
||||
`))
|
||||
|
||||
func convert(filename string, out io.Writer) error {
|
||||
func parse(filename string) (*Pom, error) {
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var pom Pom
|
||||
err = xml.Unmarshal(data, &pom)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if useVersion != "" && pom.Version != useVersion {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
if pom.Packaging == "" {
|
||||
pom.Packaging = "jar"
|
||||
}
|
||||
|
||||
pom.PomFile = filename
|
||||
pom.ArtifactFile = strings.TrimSuffix(filename, ".pom") + "." + pom.Packaging
|
||||
|
||||
return mkTemplate.Execute(out, pom)
|
||||
return &pom, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -178,6 +196,9 @@ Usage: %s [--rewrite <regex>=<replace>] [--extra-deps <module>=<module>[,<module
|
|||
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).
|
||||
This may be specified multiple times to declare these dependencies.
|
||||
-use-version <version>
|
||||
If the maven directory contains multiple versions of artifacts and their pom files,
|
||||
-use-version can be used to only write makefiles for a specific version of those artifacts.
|
||||
<dir>
|
||||
The directory to search for *.pom files under.
|
||||
|
||||
|
@ -187,6 +208,7 @@ The makefile is written to stdout, to be put in the current directory (often as
|
|||
|
||||
flag.Var(&extraDeps, "extra-deps", "Extra dependencies needed when depending on a module")
|
||||
flag.Var(&rewriteNames, "rewrite", "Regex(es) to rewrite artifact names")
|
||||
flag.StringVar(&useVersion, "use-version", "", "Only read artifacts of a specific version")
|
||||
flag.Parse()
|
||||
|
||||
if flag.NArg() != 1 {
|
||||
|
@ -240,15 +262,40 @@ The makefile is written to stdout, to be put in the current directory (often as
|
|||
|
||||
sort.Strings(filenames)
|
||||
|
||||
fmt.Println("# Automatically generated with:")
|
||||
fmt.Println("# pom2mk", strings.Join(proptools.ShellEscape(os.Args[1:]), " "))
|
||||
fmt.Println("LOCAL_PATH := $(call my-dir)")
|
||||
|
||||
poms := []*Pom{}
|
||||
modules := make(map[string]*Pom)
|
||||
for _, filename := range filenames {
|
||||
err := convert(filename, os.Stdout)
|
||||
pom, err := parse(filename)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error converting", filename, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if pom != nil {
|
||||
poms = append(poms, pom)
|
||||
|
||||
if old, ok := modules[pom.ArtifactId]; ok {
|
||||
fmt.Fprintln(os.Stderr, "Module", pom.ArtifactId, "defined twice:", old.PomFile, pom.PomFile)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
modules[pom.ArtifactId] = pom
|
||||
}
|
||||
}
|
||||
|
||||
for _, pom := range poms {
|
||||
pom.FixDepTypes(modules)
|
||||
}
|
||||
|
||||
fmt.Println("# Automatically generated with:")
|
||||
fmt.Println("# pom2mk", strings.Join(proptools.ShellEscape(os.Args[1:]), " "))
|
||||
fmt.Println("LOCAL_PATH := $(call my-dir)")
|
||||
|
||||
for _, pom := range poms {
|
||||
err := mkTemplate.Execute(os.Stdout, pom)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error writing", pom.PomFile, pom.MkName(), err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue