-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpomparser.go
352 lines (308 loc) · 11.2 KB
/
pomparser.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
package main
import (
"encoding/xml"
"fmt"
"io"
"io/ioutil"
"os"
)
type Project 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"`
Description string `xml:"description"`
URL string `xml:"url"`
InceptionYear string `xml:"inceptionYear"`
Organization Organization `xml:"organization"`
Licenses []License `xml:"licenses>license"`
Developers []Developer `xml:"developers>developer"`
Contributors []Contributor `xml:"contributors>contributor"`
MailingLists []MailingList `xml:"mailingLists>mailingList"`
Prerequisites Prerequisites `xml:"prerequisites"`
Modules []string `xml:"modules>module"`
SCM Scm `xml:"scm"`
IssueManagement IssueManagement `xml:"issueManagement"`
CIManagement CIManagement `xml:"ciManagement"`
DistributionManagement DistributionManagement `xml:"distributionManagement"`
DependencyManagement DependencyManagement `xml:"dependencyManagement"`
Dependencies []Dependency `xml:"dependencies>dependency"`
Repositories []Repository `xml:"repositories>repository"`
PluginRepositories []PluginRepository `xml:"pluginRepositories>pluginRepository"`
Build Build `xml:"build"`
Reporting Reporting `xml:"reporting"`
Profiles []Profile `xml:"profiles>profile"`
Properties Properties `xml:"properties"`
}
type Properties struct {
Entries map[string]string
}
func (p *Properties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
type entry struct {
XMLName xml.Name
Key string `xml:"name,attr"`
Value string `xml:",chardata"`
}
e := entry{}
p.Entries = map[string]string{}
for err = d.Decode(&e); err == nil; err = d.Decode(&e) {
e.Key = e.XMLName.Local
p.Entries[e.Key] = e.Value
}
if err != nil && err != io.EOF {
return err
}
return nil
}
type Parent struct {
GroupID string `xml:"groupId"`
ArtifactID string `xml:"artifactId"`
Version string `xml:"version"`
RelativePath string `xml:"relativePath"`
}
type Organization struct {
Name string `xml:"name"`
URL string `xml:"url"`
}
type License struct {
Name string `xml:"name"`
URL string `xml:"url"`
Distribution string `xml:"distribution"`
Comments string `xml:"comments"`
}
type Developer struct {
ID string `xml:"id"`
Name string `xml:"name"`
Email string `xml:"email"`
URL string `xml:"url"`
Organization string `xml:"organization"`
OrganizationURL string `xml:"organizationUrl"`
Roles []string `xml:"roles>role"`
Timezone string `xml:"timezone"`
Properties Properties `xml:"properties"`
}
type Contributor struct {
Name string `xml:"name"`
Email string `xml:"email"`
URL string `xml:"url"`
Organization string `xml:"organization"`
OrganizationURL string `xml:"organizationUrl"`
Roles []string `xml:"roles>role"`
Timezone string `xml:"timezone"`
Properties Properties `xml:"properties"`
}
type MailingList struct {
Name string `xml:"name"`
Subscribe string `xml:"subscribe"`
Unsubscribe string `xml:"unsubscribe"`
Post string `xml:"post"`
Archive string `xml:"archive"`
OtherArchives []string `xml:"otherArchives>otherArchive"`
}
type Prerequisites struct {
Maven string `xml:"maven"`
}
type Scm struct {
Connection string `xml:"connection"`
DeveloperConnection string `xml:"developerConnection"`
Tag string `xml:"tag"`
URL string `xml:"url"`
}
type IssueManagement struct {
System string `xml:"system"`
URL string `xml:"url"`
}
type CIManagement struct {
System string `xml:"system"`
URL string `xml:"url"`
Notifiers []Notifier `xml:"notifiers>notifier"`
}
type Notifier struct {
Type string `xml:"type"`
SendOnError bool `xml:"sendOnError"`
SendOnFailure bool `xml:"sendOnFailure"`
SendOnSuccess bool `xml:"sendOnSuccess"`
SendOnWarning bool `xml:"sendOnWarning"`
Address string `xml:"address"`
Configuration Properties `xml:"configuration"`
}
type DistributionManagement struct {
Repository Repository `xml:"repository"`
SnapshotRepository Repository `xml:"snapshotRepository"`
Site Site `xml:"site"`
DownloadURL string `xml:"downloadUrl"`
Relocation Relocation `xml:"relocation"`
Status string `xml:"status"`
}
type Site struct {
ID string `xml:"id"`
Name string `xml:"name"`
URL string `xml:"url"`
}
type Relocation struct {
GroupID string `xml:"groupId"`
ArtifactID string `xml:"artifactId"`
Version string `xml:"version"`
Message string `xml:"message"`
}
type DependencyManagement struct {
Dependencies []Dependency `xml:"dependencies>dependency"`
}
type Dependency struct {
GroupID string `xml:"groupId"`
ArtifactID string `xml:"artifactId"`
Version string `xml:"version"`
Type string `xml:"type"`
Classifier string `xml:"classifier"`
Scope string `xml:"scope"`
SystemPath string `xml:"systemPath"`
Exclusions []Exclusion `xml:"exclusions>exclusion"`
Optional string `xml:"optional"`
}
type Exclusion struct {
ArtifactID string `xml:"artifactId"`
GroupID string `xml:"groupId"`
}
type Repository struct {
UniqueVersion bool `xml:"uniqueVersion"`
Releases RepositoryPolicy `xml:"releases"`
Snapshots RepositoryPolicy `xml:"snapshots"`
ID string `xml:"id"`
Name string `xml:"name"`
URL string `xml:"url"`
Layout string `xml:"layout"`
}
type RepositoryPolicy struct {
Enabled string `xml:"enabled"`
UpdatePolicy string `xml:"updatePolicy"`
ChecksumPolicy string `xml:"checksumPolicy"`
}
type PluginRepository struct {
Releases RepositoryPolicy `xml:"releases"`
Snapshots RepositoryPolicy `xml:"snapshots"`
ID string `xml:"id"`
Name string `xml:"name"`
URL string `xml:"url"`
Layout string `xml:"layout"`
}
type BuildBase struct {
DefaultGoal string `xml:"defaultGoal"`
Resources []Resource `xml:"resources>resource"`
TestResources []Resource `xml:"testResources>testResource"`
Directory string `xml:"directory"`
FinalName string `xml:"finalName"`
Filters []string `xml:"filters>filter"`
PluginManagement PluginManagement `xml:"pluginManagement"`
Plugins []Plugin `xml:"plugins>plugin"`
}
type Build struct {
SourceDirectory string `xml:"sourceDirectory"`
ScriptSourceDirectory string `xml:"scriptSourceDirectory"`
TestSourceDirectory string `xml:"testSourceDirectory"`
OutputDirectory string `xml:"outputDirectory"`
TestOutputDirectory string `xml:"testOutputDirectory"`
Extensions []Extension `xml:"extensions>extension"`
BuildBase
}
type Extension struct {
GroupID string `xml:"groupId"`
ArtifactID string `xml:"artifactId"`
Version string `xml:"version"`
}
type Resource struct {
TargetPath string `xml:"targetPath"`
Filtering string `xml:"filtering"`
Directory string `xml:"directory"`
Includes []string `xml:"includes>include"`
Excludes []string `xml:"excludes>exclude"`
}
type PluginManagement struct {
Plugins []Plugin `xml:"plugins>plugin"`
}
type Plugin struct {
GroupID string `xml:"groupId"`
ArtifactID string `xml:"artifactId"`
Version string `xml:"version"`
Extensions string `xml:"extensions"`
Executions []PluginExecution `xml:"executions>execution"`
Dependencies []Dependency `xml:"dependencies>dependency"`
Inherited string `xml:"inherited"`
Configuration Configuration `xml:"configuration"`
}
type Configuration struct {
Encoding string `xml:"encoding"`
Source string `xml:"source"`
Target string `xml:"target"`
}
type PluginExecution struct {
ID string `xml:"id"`
Phase string `xml:"phase"`
Goals []string `xml:"goals>goal"`
Inherited string `xml:"inherited"`
}
type Reporting struct {
ExcludeDefaults string `xml:"excludeDefaults"`
OutputDirectory string `xml:"outputDirectory"`
Plugins []ReportingPlugin `xml:"plugins>plugin"`
}
type ReportingPlugin struct {
GroupID string `xml:"groupId"`
ArtifactID string `xml:"artifactId"`
Version string `xml:"version"`
Inherited string `xml:"inherited"`
ReportSets []ReportSet `xml:"reportSets>reportSet"`
}
type ReportSet struct {
ID string `xml:"id"`
Reports []string `xml:"reports>report"`
Inherited string `xml:"inherited"`
}
type Profile struct {
ID string `xml:"id"`
Activation Activation `xml:"activation"`
Build BuildBase `xml:"build"`
Modules []string `xml:"modules>module"`
DistributionManagement DistributionManagement `xml:"distributionManagement"`
Properties Properties `xml:"properties"`
DependencyManagement DependencyManagement `xml:"dependencyManagement"`
Dependencies []Dependency `xml:"dependencies>dependency"`
Repositories []Repository `xml:"repositories>repository"`
PluginRepositories []PluginRepository `xml:"pluginRepositories>pluginRepository"`
Reporting Reporting `xml:"reporting"`
}
type Activation struct {
ActiveByDefault bool `xml:"activeByDefault"`
JDK string `xml:"jdk"`
OS ActivationOS `xml:"os"`
Property ActivationProperty `xml:"property"`
File ActivationFile `xml:"file"`
}
type ActivationOS struct {
Name string `xml:"name"`
Family string `xml:"family"`
Arch string `xml:"arch"`
Version string `xml:"version"`
}
type ActivationProperty struct {
Name string `xml:"name"`
Value string `xml:"value"`
}
type ActivationFile struct {
Missing string `xml:"missing"`
Exists string `xml:"exists"`
}
func ParsePom(file string) (Project, error) {
var project Project
xmlFile, err := os.Open(file)
if err != nil {
fmt.Println(err)
}
defer xmlFile.Close()
byteValue, _ := ioutil.ReadAll(xmlFile)
xml.Unmarshal(byteValue, &project)
return project, err
}