@@ -18,6 +18,7 @@ type Pom struct {
18
18
Version string `xml:"version"`
19
19
Dependencies Dependencies `xml:"dependencies"`
20
20
DependencyManagement DependencyManagement `xml:"dependencyManagement"`
21
+ Build Build `xml:"build"`
21
22
Properties Properties `xml:"properties"`
22
23
}
23
24
@@ -31,6 +32,19 @@ type Dependencies struct {
31
32
Dependency []Dependency `xml:"dependency"`
32
33
}
33
34
35
+ type Plugins struct {
36
+ Plugin []Dependency `xml:"plugin"`
37
+ }
38
+
39
+ type PluginManagement struct {
40
+ Plugins Plugins `xml:"plugins"`
41
+ }
42
+
43
+ type Build struct {
44
+ PluginManagement PluginManagement `xml:"pluginManagement"`
45
+ Plugins Plugins `xml:"plugins"`
46
+ }
47
+
34
48
// Dependency represents a single dependency block
35
49
type Dependency struct {
36
50
GroupID string `xml:"groupId"`
@@ -59,11 +73,6 @@ func UpdatePomFile(metadata []Metadata, url string, path string) error {
59
73
metadataByGA [depKey (m .GroupID , m .ArtifactID )] = m
60
74
}
61
75
62
- propVariable := regexp .MustCompile ("\\ $\\ {(\\ S+)}" )
63
- propValue := regexp .MustCompile ("([0-9a-z._-]+)" )
64
-
65
- versionRegex := regexp .MustCompile ("([0-9]+)\\ .?([0-9]+)?\\ .?([0-9]+)?" )
66
-
67
76
pomFileStr := string (pomFileBytes )
68
77
69
78
if ! strings .Contains (pomFileStr , url ) {
@@ -92,82 +101,115 @@ func UpdatePomFile(metadata []Metadata, url string, path string) error {
92
101
}
93
102
94
103
for _ , d := range p .DependencyManagement .Dependencies .Dependency {
95
- groupId := d . GroupID
96
- if d . GroupID == "io.quarkus" {
97
- groupId = "com.redhat.quarkus.platform"
104
+ pomFileStr , err = replaceDependency ( metadataByGA , p , d , pomFileStr )
105
+ if err != nil {
106
+ return err
98
107
}
99
- m , ok := metadataByGA [depKey (groupId , d .ArtifactID )]
100
- if ! ok {
101
- continue
108
+ }
109
+ for _ , d := range p .Dependencies .Dependency {
110
+ pomFileStr , err = replaceDependency (metadataByGA , p , d , pomFileStr )
111
+ if err != nil {
112
+ return err
102
113
}
103
- version := d .Version
104
- propNameMatch := propVariable .FindStringSubmatch (d .Version )
105
- if len (propNameMatch ) > 1 {
106
- version , ok = p .Properties .Entries [propNameMatch [1 ]]
107
- if ! ok {
108
- return fmt .Errorf ("failed to replace variable %q from properties %#v" , d .Version , p .Properties .Entries )
109
- }
110
- if match := propValue .FindStringSubmatch (version ); len (match ) > 1 {
111
- version = match [1 ]
112
- }
114
+ }
115
+ for _ , d := range p .Build .PluginManagement .Plugins .Plugin {
116
+ pomFileStr , err = replaceDependency (metadataByGA , p , d , pomFileStr )
117
+ if err != nil {
118
+ return err
119
+ }
120
+ }
121
+ for _ , d := range p .Build .Plugins .Plugin {
122
+ pomFileStr , err = replaceDependency (metadataByGA , p , d , pomFileStr )
123
+ if err != nil {
124
+ return err
113
125
}
126
+ }
127
+
128
+ if err := os .WriteFile (path , []byte (pomFileStr ), 0666 ); err != nil {
129
+ return fmt .Errorf ("failed to update POM file %q: %w" , path , err )
130
+ }
131
+ return nil
132
+ }
114
133
115
- log . Printf ( "Dependency %q:%q:%q \n %#v \n " , d . GroupID , d . ArtifactID , version , m )
134
+ func replaceDependency ( metadataByGA map [ string ] Metadata , p * Pom , d Dependency , pomFileStr string ) ( string , error ) {
116
135
117
- versionPieces := versionRegex .FindStringSubmatch (version )
118
- if len (versionPieces ) < 2 {
119
- log .Printf ("Version %q is not parsable" , version )
120
- continue
136
+ propVariable := regexp .MustCompile ("\\ $\\ {(\\ S+)}" )
137
+ propValue := regexp .MustCompile ("([0-9a-z._-]+)" )
138
+
139
+ versionRegex := regexp .MustCompile ("([0-9]+)\\ .?([0-9]+)?\\ .?([0-9]+)?" )
140
+
141
+ groupId := d .GroupID
142
+ if d .GroupID == "io.quarkus" {
143
+ groupId = "com.redhat.quarkus.platform"
144
+ }
145
+ m , ok := metadataByGA [depKey (groupId , d .ArtifactID )]
146
+ if ! ok {
147
+ return pomFileStr , nil
148
+ }
149
+ version := d .Version
150
+ propNameMatch := propVariable .FindStringSubmatch (d .Version )
151
+ if len (propNameMatch ) > 1 {
152
+ version , ok = p .Properties .Entries [propNameMatch [1 ]]
153
+ if ! ok {
154
+ return pomFileStr , fmt .Errorf ("failed to replace variable %q from properties %#v" , d .Version , p .Properties .Entries )
155
+ }
156
+ if match := propValue .FindStringSubmatch (version ); len (match ) > 1 {
157
+ version = match [1 ]
121
158
}
122
- log . Printf ( "Version %q, pieces %#v" , version , versionPieces )
159
+ }
123
160
124
- versions := make ([]string , len (m .Versioning .Versions .Version ))
125
- copy (versions , m .Versioning .Versions .Version )
126
- slices .Reverse (versions )
161
+ log .Printf ("Dependency %q:%q:%q\n %#v\n " , d .GroupID , d .ArtifactID , version , m )
127
162
128
- for _ , v := range versions {
129
- if v == version {
130
- break
131
- }
163
+ versionPieces := versionRegex .FindStringSubmatch (version )
164
+ if len (versionPieces ) < 2 {
165
+ log .Printf ("Version %q is not parsable" , version )
166
+ return pomFileStr , nil
167
+ }
168
+ log .Printf ("Version %q, pieces %#v" , version , versionPieces )
132
169
133
- vPieces := versionRegex .FindStringSubmatch (v )
134
- if len (vPieces ) < 2 {
135
- log .Printf ("Version %q in metadata is not parsable (%s:%s)" , version , m .GroupID , m .ArtifactID )
136
- continue
137
- }
138
- log .Printf ("Red Hat Version %q, pieces %#v" , v , vPieces )
170
+ versions := make ([]string , len (m .Versioning .Versions .Version ))
171
+ copy (versions , m .Versioning .Versions .Version )
172
+ slices .Reverse (versions )
139
173
140
- if vPieces [1 ] != versionPieces [1 ] {
141
- // major version doesn't match
142
- log .Printf ("Version %q doesn't match major version in %q" , version , v )
143
- continue
144
- }
174
+ for _ , v := range versions {
175
+ if v == version {
176
+ break
177
+ }
145
178
146
- if len (versionPieces ) >= 3 && len (vPieces ) >= 3 && vPieces [2 ] != versionPieces [2 ] {
147
- // minor version doesn't match
148
- log .Printf ("Version %q doesn't match minor version in %q" , version , v )
149
- continue
150
- }
179
+ vPieces := versionRegex .FindStringSubmatch (v )
180
+ if len (vPieces ) < 2 {
181
+ log .Printf ("Version %q in metadata is not parsable (%s:%s)" , version , m .GroupID , m .ArtifactID )
182
+ continue
183
+ }
184
+ log .Printf ("Red Hat Version %q, pieces %#v" , v , vPieces )
185
+
186
+ if vPieces [1 ] != versionPieces [1 ] {
187
+ // major version doesn't match
188
+ log .Printf ("Version %q doesn't match major version in %q" , version , v )
189
+ continue
190
+ }
151
191
152
- rg := fmt .Sprintf ("(.*<groupId>\\ s*)%s(\\ s*</groupId>\\ s*<artifactId>\\ s*)%s(\\ s*</artifactId>\\ s*<version>\\ s*)%s(\\ s*</version>.*)" , regexp .QuoteMeta (d .GroupID ), regexp .QuoteMeta (d .ArtifactID ), regexp .QuoteMeta (d .Version ))
153
- log .Printf ("Replacing %q:%q:%q with %q:%q:%q (regex %q)" , d .GroupID , d .ArtifactID , version , m .GroupID , m .ArtifactID , v , rg )
192
+ if len (versionPieces ) >= 3 && len (vPieces ) >= 3 && vPieces [2 ] != versionPieces [2 ] {
193
+ // minor version doesn't match
194
+ log .Printf ("Version %q doesn't match minor version in %q" , version , v )
195
+ continue
196
+ }
154
197
155
- artifactRegex := regexp .MustCompile (rg )
156
- for _ , match := range artifactRegex .FindAllStringSubmatch (pomFileStr , - 1 ) {
157
- oldM := fmt .Sprintf ("%s%s%s%s%s%s%s" , match [1 ], d .GroupID , match [2 ], d .ArtifactID , match [3 ], d .Version , match [4 ])
158
- newM := fmt .Sprintf ("%s%s%s%s%s%s%s" , match [1 ], m .GroupID , match [2 ], m .ArtifactID , match [3 ], v , match [4 ])
198
+ rg := fmt .Sprintf ("(.*<groupId>\\ s*)%s(\\ s*</groupId>\\ s*<artifactId>\\ s*)%s(\\ s*</artifactId>\\ s*<version>\\ s*)%s(\\ s*</version>.*)" , regexp .QuoteMeta (d .GroupID ), regexp .QuoteMeta (d .ArtifactID ), regexp .QuoteMeta (d .Version ))
199
+ log .Printf ("Replacing %q:%q:%q with %q:%q:%q (regex %q)" , d .GroupID , d .ArtifactID , version , m .GroupID , m .ArtifactID , v , rg )
159
200
160
- log .Printf ("match:\n %s\n %s\n " , oldM , newM )
201
+ artifactRegex := regexp .MustCompile (rg )
202
+ for _ , match := range artifactRegex .FindAllStringSubmatch (pomFileStr , - 1 ) {
203
+ oldM := fmt .Sprintf ("%s%s%s%s%s%s%s" , match [1 ], d .GroupID , match [2 ], d .ArtifactID , match [3 ], d .Version , match [4 ])
204
+ newM := fmt .Sprintf ("%s%s%s%s%s%s%s" , match [1 ], m .GroupID , match [2 ], m .ArtifactID , match [3 ], v , match [4 ])
161
205
162
- pomFileStr = strings .ReplaceAll (pomFileStr , oldM , newM )
163
- }
206
+ log .Printf ("match:\n %s\n %s\n " , oldM , newM )
207
+
208
+ pomFileStr = strings .ReplaceAll (pomFileStr , oldM , newM )
164
209
}
165
210
}
166
211
167
- if err := os .WriteFile (path , []byte (pomFileStr ), 0666 ); err != nil {
168
- return fmt .Errorf ("failed to update POM file %q: %w" , path , err )
169
- }
170
- return nil
212
+ return pomFileStr , nil
171
213
}
172
214
173
215
func depKey (groupId , artifactId string ) string {
0 commit comments