-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathparser.go
137 lines (123 loc) · 4.24 KB
/
parser.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// MIT License
//
// Copyright (c) 2019 Aloïs Micard
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
package mvnparser
import (
"encoding/xml"
"io"
)
// Represent a POM file
type MavenProject struct {
XMLName xml.Name `xml:"project"`
ModelVersion string `xml:"modelVersion"`
Parent Parent `xml:"parent"`
GroupId string `xml:"groupId"`
ArtifactId string `xml:"artifactId"`
Version string `xml:"version"`
Packaging string `xml:"packaging"`
Name string `xml:"name"`
Repositories []Repository `xml:"repositories>repository"`
Properties Properties `xml:"properties"`
DependencyManagement DependencyManagement `xml:"dependencyManagement"`
Dependencies []Dependency `xml:"dependencies>dependency"`
Profiles []Profile `xml:"profiles"`
Build Build `xml:"build"`
PluginRepositories []PluginRepository `xml:"pluginRepositories>pluginRepository"`
Modules []string `xml:"modules>module"`
}
// Represent the parent of the project
type Parent struct {
GroupId string `xml:"groupId"`
ArtifactId string `xml:"artifactId"`
Version string `xml:"version"`
RelativePath string `xml:"relativePath"`
}
// Represent a dependency of the project
type Dependency struct {
XMLName xml.Name `xml:"dependency"`
GroupId string `xml:"groupId"`
ArtifactId string `xml:"artifactId"`
Version string `xml:"version"`
Classifier string `xml:"classifier"`
Type string `xml:"type"`
Scope string `xml:"scope"`
Exclusions []Exclusion `xml:"exclusions>exclusion"`
}
// Represent an exclusion
type Exclusion struct {
XMLName xml.Name `xml:"exclusion"`
GroupId string `xml:"groupId"`
ArtifactId string `xml:"artifactId"`
}
type DependencyManagement struct {
Dependencies []Dependency `xml:"dependencies>dependency"`
}
// Represent a repository
type Repository struct {
Id string `xml:"id"`
Name string `xml:"name"`
Url string `xml:"url"`
}
type Profile struct {
Id string `xml:"id"`
Build Build `xml:"build"`
}
type Build struct {
// todo: final name ?
Plugins []Plugin `xml:"plugins>plugin"`
}
type Plugin struct {
XMLName xml.Name `xml:"plugin"`
GroupId string `xml:"groupId"`
ArtifactId string `xml:"artifactId"`
Version string `xml:"version"`
//todo something like: Configuration map[string]string `xml:"configuration"`
// todo executions
}
// Represent a pluginRepository
type PluginRepository struct {
Id string `xml:"id"`
Name string `xml:"name"`
Url string `xml:"url"`
}
// Represent Properties
type Properties map[string]string
func (p *Properties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
*p = map[string]string{}
for {
key := ""
value := ""
token, err := d.Token()
if err == io.EOF {
break
}
switch tokenType := token.(type) {
case xml.StartElement:
key = tokenType.Name.Local
err := d.DecodeElement(&value, &start)
if err != nil {
return err
}
(*p)[key] = value
}
}
return nil
}