blob: 2dfa546357738a9bf37d47dfec75b8e14c435e5b [file] [log] [blame]
Colin Cross70dd38f2018-04-16 13:52:10 -07001// Copyright 2017 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package main
16
17import (
Colin Crosscf53e602018-06-26 15:27:20 -070018 "archive/zip"
Colin Cross70dd38f2018-04-16 13:52:10 -070019 "bufio"
20 "bytes"
21 "encoding/xml"
22 "flag"
23 "fmt"
24 "io/ioutil"
25 "os"
26 "os/exec"
27 "path/filepath"
28 "regexp"
29 "sort"
30 "strings"
31 "text/template"
32
33 "github.com/google/blueprint/proptools"
34
35 "android/soong/bpfix/bpfix"
36)
37
38type RewriteNames []RewriteName
39type RewriteName struct {
40 regexp *regexp.Regexp
41 repl string
42}
43
44func (r *RewriteNames) String() string {
45 return ""
46}
47
48func (r *RewriteNames) Set(v string) error {
49 split := strings.SplitN(v, "=", 2)
50 if len(split) != 2 {
51 return fmt.Errorf("Must be in the form of <regex>=<replace>")
52 }
53 regex, err := regexp.Compile(split[0])
54 if err != nil {
55 return nil
56 }
57 *r = append(*r, RewriteName{
58 regexp: regex,
59 repl: split[1],
60 })
61 return nil
62}
63
64func (r *RewriteNames) MavenToBp(groupId string, artifactId string) string {
65 for _, r := range *r {
66 if r.regexp.MatchString(groupId + ":" + artifactId) {
67 return r.regexp.ReplaceAllString(groupId+":"+artifactId, r.repl)
68 } else if r.regexp.MatchString(artifactId) {
69 return r.regexp.ReplaceAllString(artifactId, r.repl)
70 }
71 }
72 return artifactId
73}
74
75var rewriteNames = RewriteNames{}
76
77type ExtraDeps map[string][]string
78
79func (d ExtraDeps) String() string {
80 return ""
81}
82
83func (d ExtraDeps) Set(v string) error {
84 split := strings.SplitN(v, "=", 2)
85 if len(split) != 2 {
86 return fmt.Errorf("Must be in the form of <module>=<module>[,<module>]")
87 }
88 d[split[0]] = strings.Split(split[1], ",")
89 return nil
90}
91
Paul Duffinbabaf072019-04-16 11:35:20 +010092var extraStaticLibs = make(ExtraDeps)
93
94var extraLibs = make(ExtraDeps)
Colin Cross70dd38f2018-04-16 13:52:10 -070095
96type Exclude map[string]bool
97
98func (e Exclude) String() string {
99 return ""
100}
101
102func (e Exclude) Set(v string) error {
103 e[v] = true
104 return nil
105}
106
107var excludes = make(Exclude)
108
Jeff Gastond4928532018-08-24 14:30:13 -0400109type HostModuleNames map[string]bool
110
111func (n HostModuleNames) IsHostModule(groupId string, artifactId string) bool {
Colin Cross86bc9d42018-08-29 15:36:33 -0700112 _, found := n[groupId+":"+artifactId]
Jeff Gastond4928532018-08-24 14:30:13 -0400113 return found
114}
115
116func (n HostModuleNames) String() string {
117 return ""
118}
119
120func (n HostModuleNames) Set(v string) error {
121 n[v] = true
122 return nil
123}
124
125var hostModuleNames = HostModuleNames{}
126
Colin Cross70dd38f2018-04-16 13:52:10 -0700127var sdkVersion string
128var useVersion string
Dan Willemsen7fdab6e2019-04-20 21:47:14 -0700129var jetifier bool
Colin Cross70dd38f2018-04-16 13:52:10 -0700130
131func InList(s string, list []string) bool {
132 for _, l := range list {
133 if l == s {
134 return true
135 }
136 }
137
138 return false
139}
140
141type Dependency struct {
142 XMLName xml.Name `xml:"dependency"`
143
144 BpTarget string `xml:"-"`
145
146 GroupId string `xml:"groupId"`
147 ArtifactId string `xml:"artifactId"`
148 Version string `xml:"version"`
149 Type string `xml:"type"`
150 Scope string `xml:"scope"`
151}
152
153func (d Dependency) BpName() string {
154 if d.BpTarget == "" {
155 d.BpTarget = rewriteNames.MavenToBp(d.GroupId, d.ArtifactId)
156 }
157 return d.BpTarget
158}
159
160type Pom struct {
161 XMLName xml.Name `xml:"http://maven.apache.org/POM/4.0.0 project"`
162
Colin Crosscf53e602018-06-26 15:27:20 -0700163 PomFile string `xml:"-"`
164 ArtifactFile string `xml:"-"`
165 BpTarget string `xml:"-"`
166 MinSdkVersion string `xml:"-"`
Colin Cross70dd38f2018-04-16 13:52:10 -0700167
168 GroupId string `xml:"groupId"`
169 ArtifactId string `xml:"artifactId"`
170 Version string `xml:"version"`
171 Packaging string `xml:"packaging"`
172
173 Dependencies []*Dependency `xml:"dependencies>dependency"`
174}
175
176func (p Pom) IsAar() bool {
177 return p.Packaging == "aar"
178}
179
180func (p Pom) IsJar() bool {
181 return p.Packaging == "jar"
182}
183
Jeff Gastond4928532018-08-24 14:30:13 -0400184func (p Pom) IsHostModule() bool {
185 return hostModuleNames.IsHostModule(p.GroupId, p.ArtifactId)
186}
187
188func (p Pom) IsDeviceModule() bool {
189 return !p.IsHostModule()
190}
191
Colin Cross632987a2018-08-29 16:17:55 -0700192func (p Pom) ModuleType() string {
193 if p.IsAar() {
194 return "android_library"
195 } else if p.IsHostModule() {
196 return "java_library_host"
197 } else {
198 return "java_library_static"
199 }
200}
201
202func (p Pom) ImportModuleType() string {
203 if p.IsAar() {
204 return "android_library_import"
205 } else if p.IsHostModule() {
206 return "java_import_host"
207 } else {
208 return "java_import"
209 }
210}
211
212func (p Pom) ImportProperty() string {
213 if p.IsAar() {
214 return "aars"
215 } else {
216 return "jars"
217 }
218}
219
Colin Cross70dd38f2018-04-16 13:52:10 -0700220func (p Pom) BpName() string {
221 if p.BpTarget == "" {
222 p.BpTarget = rewriteNames.MavenToBp(p.GroupId, p.ArtifactId)
223 }
224 return p.BpTarget
225}
226
227func (p Pom) BpJarDeps() []string {
228 return p.BpDeps("jar", []string{"compile", "runtime"})
229}
230
231func (p Pom) BpAarDeps() []string {
232 return p.BpDeps("aar", []string{"compile", "runtime"})
233}
234
Paul Duffinbabaf072019-04-16 11:35:20 +0100235func (p Pom) BpExtraStaticLibs() []string {
236 return extraStaticLibs[p.BpName()]
237}
238
239func (p Pom) BpExtraLibs() []string {
240 return extraLibs[p.BpName()]
Colin Cross70dd38f2018-04-16 13:52:10 -0700241}
242
243// BpDeps obtains dependencies filtered by type and scope. The results of this
244// method are formatted as Android.bp targets, e.g. run through MavenToBp rules.
245func (p Pom) BpDeps(typeExt string, scopes []string) []string {
246 var ret []string
247 for _, d := range p.Dependencies {
248 if d.Type != typeExt || !InList(d.Scope, scopes) {
249 continue
250 }
251 name := rewriteNames.MavenToBp(d.GroupId, d.ArtifactId)
252 ret = append(ret, name)
253 }
254 return ret
255}
256
257func (p Pom) SdkVersion() string {
258 return sdkVersion
259}
260
Dan Willemsen7fdab6e2019-04-20 21:47:14 -0700261func (p Pom) Jetifier() bool {
262 return jetifier
263}
264
Colin Cross70dd38f2018-04-16 13:52:10 -0700265func (p *Pom) FixDeps(modules map[string]*Pom) {
266 for _, d := range p.Dependencies {
267 if d.Type == "" {
268 if depPom, ok := modules[d.BpName()]; ok {
269 // We've seen the POM for this dependency, use its packaging
270 // as the dependency type rather than Maven spec default.
271 d.Type = depPom.Packaging
272 } else {
273 // Dependency type was not specified and we don't have the POM
274 // for this artifact, use the default from Maven spec.
275 d.Type = "jar"
276 }
277 }
278 if d.Scope == "" {
279 // Scope was not specified, use the default from Maven spec.
280 d.Scope = "compile"
281 }
282 }
283}
284
Colin Crosscf53e602018-06-26 15:27:20 -0700285// ExtractMinSdkVersion extracts the minSdkVersion from the AndroidManifest.xml file inside an aar file, or sets it
286// to "current" if it is not present.
287func (p *Pom) ExtractMinSdkVersion() error {
288 aar, err := zip.OpenReader(p.ArtifactFile)
289 if err != nil {
290 return err
291 }
292 defer aar.Close()
293
294 var manifest *zip.File
295 for _, f := range aar.File {
296 if f.Name == "AndroidManifest.xml" {
297 manifest = f
298 break
299 }
300 }
301
302 if manifest == nil {
303 return fmt.Errorf("failed to find AndroidManifest.xml in %s", p.ArtifactFile)
304 }
305
306 r, err := manifest.Open()
307 if err != nil {
308 return err
309 }
310 defer r.Close()
311
312 decoder := xml.NewDecoder(r)
313
314 manifestData := struct {
315 XMLName xml.Name `xml:"manifest"`
316 Uses_sdk struct {
317 MinSdkVersion string `xml:"http://schemas.android.com/apk/res/android minSdkVersion,attr"`
318 } `xml:"uses-sdk"`
319 }{}
320
321 err = decoder.Decode(&manifestData)
322 if err != nil {
323 return err
324 }
325
326 p.MinSdkVersion = manifestData.Uses_sdk.MinSdkVersion
327 if p.MinSdkVersion == "" {
328 p.MinSdkVersion = "current"
329 }
330
331 return nil
332}
333
Colin Cross70dd38f2018-04-16 13:52:10 -0700334var bpTemplate = template.Must(template.New("bp").Parse(`
Colin Cross632987a2018-08-29 16:17:55 -0700335{{.ImportModuleType}} {
Colin Cross70dd38f2018-04-16 13:52:10 -0700336 name: "{{.BpName}}-nodeps",
Colin Cross632987a2018-08-29 16:17:55 -0700337 {{.ImportProperty}}: ["{{.ArtifactFile}}"],
338 sdk_version: "{{.SdkVersion}}",
Dan Willemsen7fdab6e2019-04-20 21:47:14 -0700339 {{- if .Jetifier}}
340 jetifier: true,
341 {{- end}}
Colin Cross632987a2018-08-29 16:17:55 -0700342 {{- if .IsAar}}
Colin Crosscf53e602018-06-26 15:27:20 -0700343 min_sdk_version: "{{.MinSdkVersion}}",
Colin Cross632987a2018-08-29 16:17:55 -0700344 static_libs: [
Colin Cross1aa7f262019-04-10 11:07:15 -0700345 {{- range .BpJarDeps}}
346 "{{.}}",
347 {{- end}}
Colin Cross632987a2018-08-29 16:17:55 -0700348 {{- range .BpAarDeps}}
349 "{{.}}",
350 {{- end}}
Paul Duffinbabaf072019-04-16 11:35:20 +0100351 {{- range .BpExtraStaticLibs}}
Colin Cross632987a2018-08-29 16:17:55 -0700352 "{{.}}",
353 {{- end}}
354 ],
Paul Duffinbabaf072019-04-16 11:35:20 +0100355 {{- if .BpExtraLibs}}
356 libs: [
357 {{- range .BpExtraLibs}}
358 "{{.}}",
359 {{- end}}
360 ],
361 {{- end}}
Colin Cross632987a2018-08-29 16:17:55 -0700362 {{- end}}
Colin Cross70dd38f2018-04-16 13:52:10 -0700363}
364
Colin Cross632987a2018-08-29 16:17:55 -0700365{{.ModuleType}} {
366 name: "{{.BpName}}",
367 {{- if .IsDeviceModule}}
368 sdk_version: "{{.SdkVersion}}",
369 {{- if .IsAar}}
Colin Cross461ba492018-07-10 13:45:30 -0700370 min_sdk_version: "{{.MinSdkVersion}}",
Colin Cross632987a2018-08-29 16:17:55 -0700371 manifest: "manifests/{{.BpName}}/AndroidManifest.xml",
372 {{- end}}
373 {{- end}}
Colin Cross70dd38f2018-04-16 13:52:10 -0700374 static_libs: [
Colin Cross632987a2018-08-29 16:17:55 -0700375 "{{.BpName}}-nodeps",
Colin Cross1aa7f262019-04-10 11:07:15 -0700376 {{- range .BpJarDeps}}
Colin Cross632987a2018-08-29 16:17:55 -0700377 "{{.}}",
378 {{- end}}
379 {{- range .BpAarDeps}}
380 "{{.}}",
381 {{- end}}
Paul Duffinbabaf072019-04-16 11:35:20 +0100382 {{- range .BpExtraStaticLibs}}
Colin Cross632987a2018-08-29 16:17:55 -0700383 "{{.}}",
384 {{- end}}
Colin Cross70dd38f2018-04-16 13:52:10 -0700385 ],
Paul Duffinbabaf072019-04-16 11:35:20 +0100386 {{- if .BpExtraLibs}}
387 libs: [
388 {{- range .BpExtraLibs}}
389 "{{.}}",
390 {{- end}}
391 ],
392 {{- end}}
Colin Cross70dd38f2018-04-16 13:52:10 -0700393 java_version: "1.7",
394}
395`))
396
397func parse(filename string) (*Pom, error) {
398 data, err := ioutil.ReadFile(filename)
399 if err != nil {
400 return nil, err
401 }
402
403 var pom Pom
404 err = xml.Unmarshal(data, &pom)
405 if err != nil {
406 return nil, err
407 }
408
409 if useVersion != "" && pom.Version != useVersion {
410 return nil, nil
411 }
412
413 if pom.Packaging == "" {
414 pom.Packaging = "jar"
415 }
416
417 pom.PomFile = filename
418 pom.ArtifactFile = strings.TrimSuffix(filename, ".pom") + "." + pom.Packaging
419
420 return &pom, nil
421}
422
423func rerunForRegen(filename string) error {
424 buf, err := ioutil.ReadFile(filename)
425 if err != nil {
426 return err
427 }
428
429 scanner := bufio.NewScanner(bytes.NewBuffer(buf))
430
431 // Skip the first line in the file
432 for i := 0; i < 2; i++ {
433 if !scanner.Scan() {
434 if scanner.Err() != nil {
435 return scanner.Err()
436 } else {
437 return fmt.Errorf("unexpected EOF")
438 }
439 }
440 }
441
442 // Extract the old args from the file
443 line := scanner.Text()
444 if strings.HasPrefix(line, "// pom2bp ") {
445 line = strings.TrimPrefix(line, "// pom2bp ")
446 } else if strings.HasPrefix(line, "// pom2mk ") {
447 line = strings.TrimPrefix(line, "// pom2mk ")
448 } else if strings.HasPrefix(line, "# pom2mk ") {
449 line = strings.TrimPrefix(line, "# pom2mk ")
450 } else {
451 return fmt.Errorf("unexpected second line: %q", line)
452 }
453 args := strings.Split(line, " ")
454 lastArg := args[len(args)-1]
455 args = args[:len(args)-1]
456
457 // Append all current command line args except -regen <file> to the ones from the file
458 for i := 1; i < len(os.Args); i++ {
Colin Crosscf53e602018-06-26 15:27:20 -0700459 if os.Args[i] == "-regen" || os.Args[i] == "--regen" {
Colin Cross70dd38f2018-04-16 13:52:10 -0700460 i++
461 } else {
462 args = append(args, os.Args[i])
463 }
464 }
465 args = append(args, lastArg)
466
467 cmd := os.Args[0] + " " + strings.Join(args, " ")
468 // Re-exec pom2bp with the new arguments
469 output, err := exec.Command("/bin/sh", "-c", cmd).Output()
470 if exitErr, _ := err.(*exec.ExitError); exitErr != nil {
471 return fmt.Errorf("failed to run %s\n%s", cmd, string(exitErr.Stderr))
472 } else if err != nil {
473 return err
474 }
475
476 // If the old file was a .mk file, replace it with a .bp file
477 if filepath.Ext(filename) == ".mk" {
478 os.Remove(filename)
479 filename = strings.TrimSuffix(filename, ".mk") + ".bp"
480 }
481
482 return ioutil.WriteFile(filename, output, 0666)
483}
484
485func main() {
486 flag.Usage = func() {
487 fmt.Fprintf(os.Stderr, `pom2bp, a tool to create Android.bp files from maven repos
488
489The tool will extract the necessary information from *.pom files to create an Android.bp whose
490aar libraries can be linked against when using AAPT2.
491
Paul Duffinbabaf072019-04-16 11:35:20 +0100492Usage: %s [--rewrite <regex>=<replace>] [-exclude <module>] [--extra-static-libs <module>=<module>[,<module>]] [--extra-libs <module>=<module>[,<module>]] [<dir>] [-regen <file>]
Colin Cross70dd38f2018-04-16 13:52:10 -0700493
494 -rewrite <regex>=<replace>
495 rewrite can be used to specify mappings between Maven projects and Android.bp modules. The -rewrite
496 option can be specified multiple times. When determining the Android.bp module for a given Maven
497 project, mappings are searched in the order they were specified. The first <regex> matching
498 either the Maven project's <groupId>:<artifactId> or <artifactId> will be used to generate
499 the Android.bp module name using <replace>. If no matches are found, <artifactId> is used.
500 -exclude <module>
501 Don't put the specified module in the Android.bp file.
Paul Duffinbabaf072019-04-16 11:35:20 +0100502 -extra-static-libs <module>=<module>[,<module>]
503 Some Android.bp modules have transitive static dependencies that must be specified when they
504 are depended upon (like android-support-v7-mediarouter requires android-support-v7-appcompat).
505 This may be specified multiple times to declare these dependencies.
506 -extra-libs <module>=<module>[,<module>]
507 Some Android.bp modules have transitive runtime dependencies that must be specified when they
508 are depended upon (like androidx.test.rules requires android.test.base).
Colin Cross70dd38f2018-04-16 13:52:10 -0700509 This may be specified multiple times to declare these dependencies.
510 -sdk-version <version>
Dan Willemsen7fdab6e2019-04-20 21:47:14 -0700511 Sets sdk_version: "<version>" for all modules.
Colin Cross70dd38f2018-04-16 13:52:10 -0700512 -use-version <version>
513 If the maven directory contains multiple versions of artifacts and their pom files,
514 -use-version can be used to only write Android.bp files for a specific version of those artifacts.
Dan Willemsen7fdab6e2019-04-20 21:47:14 -0700515 -jetifier
516 Sets jetifier: true for all modules.
Colin Cross70dd38f2018-04-16 13:52:10 -0700517 <dir>
518 The directory to search for *.pom files under.
519 The contents are written to stdout, to be put in the current directory (often as Android.bp)
520 -regen <file>
521 Read arguments from <file> and overwrite it (if it ends with .bp) or move it to .bp (if it
522 ends with .mk).
523
524`, os.Args[0])
525 }
526
527 var regen string
528
529 flag.Var(&excludes, "exclude", "Exclude module")
Paul Duffinbabaf072019-04-16 11:35:20 +0100530 flag.Var(&extraStaticLibs, "extra-static-libs", "Extra static dependencies needed when depending on a module")
531 flag.Var(&extraLibs, "extra-libs", "Extra runtime dependencies needed when depending on a module")
Colin Cross70dd38f2018-04-16 13:52:10 -0700532 flag.Var(&rewriteNames, "rewrite", "Regex(es) to rewrite artifact names")
Jeff Gastond4928532018-08-24 14:30:13 -0400533 flag.Var(&hostModuleNames, "host", "Specifies that the corresponding module (specified in the form 'module.group:module.artifact') is a host module")
Dan Willemsen7fdab6e2019-04-20 21:47:14 -0700534 flag.StringVar(&sdkVersion, "sdk-version", "", "What to write to sdk_version")
Colin Cross70dd38f2018-04-16 13:52:10 -0700535 flag.StringVar(&useVersion, "use-version", "", "Only read artifacts of a specific version")
Dan Willemsen7fdab6e2019-04-20 21:47:14 -0700536 flag.BoolVar(&jetifier, "jetifier", false, "Sets jetifier: true on all modules")
Colin Cross70dd38f2018-04-16 13:52:10 -0700537 flag.Bool("static-deps", false, "Ignored")
538 flag.StringVar(&regen, "regen", "", "Rewrite specified file")
539 flag.Parse()
540
541 if regen != "" {
542 err := rerunForRegen(regen)
543 if err != nil {
544 fmt.Fprintln(os.Stderr, err)
545 os.Exit(1)
546 }
547 os.Exit(0)
548 }
549
550 if flag.NArg() == 0 {
551 fmt.Fprintln(os.Stderr, "Directory argument is required")
552 os.Exit(1)
553 } else if flag.NArg() > 1 {
554 fmt.Fprintln(os.Stderr, "Multiple directories provided:", strings.Join(flag.Args(), " "))
555 os.Exit(1)
556 }
557
558 dir := flag.Arg(0)
559 absDir, err := filepath.Abs(dir)
560 if err != nil {
561 fmt.Fprintln(os.Stderr, "Failed to get absolute directory:", err)
562 os.Exit(1)
563 }
564
565 var filenames []string
566 err = filepath.Walk(absDir, func(path string, info os.FileInfo, err error) error {
567 if err != nil {
568 return err
569 }
570
571 name := info.Name()
572 if info.IsDir() {
573 if strings.HasPrefix(name, ".") {
574 return filepath.SkipDir
575 }
576 return nil
577 }
578
579 if strings.HasPrefix(name, ".") {
580 return nil
581 }
582
583 if strings.HasSuffix(name, ".pom") {
584 path, err = filepath.Rel(absDir, path)
585 if err != nil {
586 return err
587 }
588 filenames = append(filenames, filepath.Join(dir, path))
589 }
590 return nil
591 })
592 if err != nil {
593 fmt.Fprintln(os.Stderr, "Error walking files:", err)
594 os.Exit(1)
595 }
596
597 if len(filenames) == 0 {
598 fmt.Fprintln(os.Stderr, "Error: no *.pom files found under", dir)
599 os.Exit(1)
600 }
601
602 sort.Strings(filenames)
603
604 poms := []*Pom{}
605 modules := make(map[string]*Pom)
606 duplicate := false
607 for _, filename := range filenames {
608 pom, err := parse(filename)
609 if err != nil {
610 fmt.Fprintln(os.Stderr, "Error converting", filename, err)
611 os.Exit(1)
612 }
613
614 if pom != nil {
615 key := pom.BpName()
616 if excludes[key] {
617 continue
618 }
619
620 if old, ok := modules[key]; ok {
621 fmt.Fprintln(os.Stderr, "Module", key, "defined twice:", old.PomFile, pom.PomFile)
622 duplicate = true
623 }
624
625 poms = append(poms, pom)
626 modules[key] = pom
627 }
628 }
629 if duplicate {
630 os.Exit(1)
631 }
632
633 for _, pom := range poms {
Colin Crosscf53e602018-06-26 15:27:20 -0700634 if pom.IsAar() {
635 err := pom.ExtractMinSdkVersion()
636 if err != nil {
Colin Crossfe5a3b72018-07-13 21:25:15 -0700637 fmt.Fprintf(os.Stderr, "Error reading manifest for %s: %s", pom.ArtifactFile, err)
Colin Crosscf53e602018-06-26 15:27:20 -0700638 os.Exit(1)
639 }
640 }
Colin Cross70dd38f2018-04-16 13:52:10 -0700641 pom.FixDeps(modules)
642 }
643
644 buf := &bytes.Buffer{}
645
646 fmt.Fprintln(buf, "// Automatically generated with:")
Colin Cross0b9f31f2019-02-28 11:00:01 -0800647 fmt.Fprintln(buf, "// pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " "))
Colin Cross70dd38f2018-04-16 13:52:10 -0700648
649 for _, pom := range poms {
650 var err error
651 err = bpTemplate.Execute(buf, pom)
652 if err != nil {
653 fmt.Fprintln(os.Stderr, "Error writing", pom.PomFile, pom.BpName(), err)
654 os.Exit(1)
655 }
656 }
657
658 out, err := bpfix.Reformat(buf.String())
659 if err != nil {
660 fmt.Fprintln(os.Stderr, "Error formatting output", err)
661 os.Exit(1)
662 }
663
664 os.Stdout.WriteString(out)
665}