-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpomutil.go
68 lines (57 loc) · 1.42 KB
/
pomutil.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"bufio"
"encoding/xml"
"io/ioutil"
"os"
"strings"
)
type PomDependency struct {
GroupId string `xml:"groupId"`
ArtifactId string `xml:"artifactId"`
Version string `xml:"version"`
}
type PomXML struct {
Dependencies []PomDependency `xml:"dependencies>dependency"`
}
type PomRequirements struct {
path string
libraryVersions []LibraryVersion
data PomXML
}
func (p PomRequirements) OpenRequirementsFile() (*bufio.Reader, *os.File) {
f, err := os.Open(p.path)
if err != nil {
panic(err)
}
reader := bufio.NewReader(f)
return reader, f
}
func (p PomRequirements) ReadCurrentVersion(reader *bufio.Reader) Requirements {
var dependencies PomXML
data, err := ioutil.ReadAll(reader)
if err != nil {
panic(err)
}
err = xml.Unmarshal(data, &dependencies)
return p.UnpackDependencies(dependencies)
}
func (p PomRequirements) UnpackDependencies (dependencies PomXML) PomRequirements {
for _, dependency := range dependencies.Dependencies {
if strings.Contains(dependency.GroupId, "com.vingd") {
p.libraryVersions = append(p.libraryVersions, LibraryVersion {
Library: dependency.ArtifactId,
Version: dependency.Version,
})
}
}
return p
}
func (p PomRequirements) GetLibraryVersions() []LibraryVersion {
return p.libraryVersions
}
func (p PomRequirements) GetPath() string {
return p.path
}
func (p PomRequirements) UpdateVersion(toUpdate map[string]string) {
}