-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanifest.go
41 lines (37 loc) · 1002 Bytes
/
manifest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
)
type Manifest struct {
Applications []Application `yaml:"applications"`
}
type Application struct {
Name string `yaml:"name"`
MavenConfig MavenConfig `yaml:"maven"`
}
func ExtractMavenConfigFromManifest(f string) (MavenConfig, error) {
var config MavenConfig
err := ValidateManifest(f)
if err != nil {
return config, err
}
raw, err := ioutil.ReadFile(f)
if err != nil {
return config, fmt.Errorf("failed to read manifest file %s, %+v", f, err)
}
var manifest Manifest
err = yaml.Unmarshal(raw, &manifest)
if err != nil {
return config, fmt.Errorf("failed to umarshall manifest file %s, %+v", f, err)
}
if numApplications := len(manifest.Applications); numApplications != 1 {
return config, fmt.Errorf("single application manifest required, %d found", numApplications)
}
config = manifest.Applications[0].MavenConfig
if config.Extension == "" {
config.Extension = "jar"
}
return config, nil
}