-
Notifications
You must be signed in to change notification settings - Fork 265
/
VersionsHelper.java
432 lines (394 loc) · 16 KB
/
VersionsHelper.java
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
package org.codehaus.mojo.versions.api;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.VersionRange;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Plugin;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.mojo.versions.ordering.VersionComparator;
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator;
/**
* Helper class that provides common functionality required by both the mojos and the reports.
*
* @author Stephen Connolly
* @since 1.0-alpha-3
*/
public interface VersionsHelper
{
/**
* Gets the logger used by this helper.
*
* @return the logger used by this helper.
*/
Log getLog();
/**
* Returns the version comparator to use for the specified artifact.
*
* @param artifact the artifact.
* @return the version comparator to use.
* @since 1.0-alpha-3
*/
VersionComparator getVersionComparator( Artifact artifact );
/**
* Returns the version comparator to use for the specified groupId and artifactId.
*
* @param groupId the groupId.
* @param artifactId the artifactId.
* @return the version comparator to use.
* @since 1.0-alpha-3
*/
VersionComparator getVersionComparator( String groupId, String artifactId );
/**
* Shorthand method for <code>repositorySystem.createPluginArtifact(...)</code>.
*
* @param groupId The group Id.
* @param artifactId The artifact Id.
* @param version The version range.
* @return the corresponding plugin artifact.
* @since 1.0-alpha-3
*/
Artifact createPluginArtifact( String groupId, String artifactId, String version );
/**
* Shorthand method for <code>repositorySystem.createDependencyArtifact(...)</code>.
*
* @param groupId The group id.
* @param artifactId The artifact id.
* @param version The version (possibly a range)
* @param type The type.
* @param classifier The classifier.
* @param scope The scope.
* @param optional If optional or not.
* @return The corresponding dependency artifact.
* @since 1.0-alpha-3
*/
Artifact createDependencyArtifact( String groupId, String artifactId, String version, String type,
String classifier, String scope, boolean optional );
/**
* Shorthand method for <code>getArtifactFactory().createDependencyArtifact(...)</code>.
*
* @param groupId The group id.
* @param artifactId The artifact id.
* @param version The version.
* @param type The type.
* @param classifier The classifier.
* @param scope The scope.
* @return The corresponding dependency artifact.
* @since 1.0-beta-1
*/
Artifact createDependencyArtifact( String groupId, String artifactId, String version, String type,
String classifier, String scope );
/**
* Shorthand method for <code>repositorySystem.createDependencyArtifact(...)</code> which extracts the
* parameters from the Dependency instance.
*
* @param dependency The dependency to create the artifact for.
* @return The corresponding dependency artifact.
* @since 1.0-alpha-3
*/
Artifact createDependencyArtifact( Dependency dependency );
/**
* Takes a {@link List} of {@link org.apache.maven.project.MavenProject} instances and converts it into a
* {@link Set} of {@link Artifact} instances.
*
* @param mavenProjects the {@link List} of {@link org.apache.maven.project.MavenProject} instances.
* @return a {@link Set} of {@link Artifact} instances.
* @since 1.0-alpha-3
*/
Set<Artifact> extractArtifacts( Collection<MavenProject> mavenProjects );
/**
* Creates an {@link ArtifactVersion} instance from a string.
*
* @param version the string representation of the version.
* @return The artifact version.
* @since 1.0-beta-1
*/
ArtifactVersion createArtifactVersion( String version );
/**
* Looks up the versions of the specified artifact that are available in either the local repository, or the
* appropriate remote repositories.
*
* @param artifact The artifact to look for versions of.
* @param usePluginRepositories <code>true</code> will consult the pluginRepositories, while <code>false</code> will
* consult the repositories for normal dependencies.
* @return The details of the available artifact versions.
* @throws VersionRetrievalException thrown if version resolution fails
* @since 1.0-alpha-3
*/
ArtifactVersions lookupArtifactVersions( Artifact artifact, boolean usePluginRepositories )
throws VersionRetrievalException;
/**
* Looks up the versions of the specified artifact that are available in either the local repository, or the
* appropriate remote repositories.
*
* @param artifact The artifact to look for versions of.
* @param versionRange versionRange to restrict the search
* @param usePluginRepositories <code>true</code> will consult the pluginRepositories, while <code>false</code> will
* consult the repositories for normal dependencies.
* @return The details of the available artifact versions.
* @throws VersionRetrievalException thrown if version resolution fails
* @since 1.0-alpha-3
*/
ArtifactVersions lookupArtifactVersions( Artifact artifact, VersionRange versionRange,
boolean usePluginRepositories )
throws VersionRetrievalException;
/**
* Looks up the updates for a set of dependencies.
*
* @param dependencies The set of {@link Dependency} instances to look up.
* @param usePluginRepositories Search the plugin repositories.
* @return A map, keyed by dependency, with values of type {@link org.codehaus.mojo.versions.api.ArtifactVersions}.
* @throws VersionRetrievalException thrown if version resolution fails
* @since 1.0-beta-1
*/
Map<Dependency, ArtifactVersions> lookupDependenciesUpdates( Set<Dependency> dependencies,
boolean usePluginRepositories )
throws VersionRetrievalException;
/**
* Creates an {@link org.codehaus.mojo.versions.api.ArtifactVersions} instance from a dependency.
*
* @param dependency The dependency.
* @param usePluginRepositories Search the plugin repositories.
* @return The details of updates to the dependency.
* @throws VersionRetrievalException thrown if version resolution fails
* @since 1.0-beta-1
*/
ArtifactVersions lookupDependencyUpdates( Dependency dependency, boolean usePluginRepositories )
throws VersionRetrievalException;
/**
* Looks up the updates for a set of plugins.
*
* @param plugins The set of {@link Plugin} instances to look up.
* @param allowSnapshots Include snapshots in the list of updates.
* @return A map, keyed by plugin, with values of type {@link org.codehaus.mojo.versions.api.PluginUpdatesDetails}.
* @throws VersionRetrievalException thrown if version resolution fails
* @since 1.0-beta-1
*/
Map<Plugin, PluginUpdatesDetails> lookupPluginsUpdates( Set<Plugin> plugins, boolean allowSnapshots )
throws VersionRetrievalException;
/**
* Looks up the updates for a plugin.
*
* @param plugin The {@link Plugin} instance to look up.
* @param allowSnapshots Include snapshots in the list of updates.
* @return The plugin update details.
* @since 1.0-beta-1
*/
PluginUpdatesDetails lookupPluginUpdates( Plugin plugin, boolean allowSnapshots ) throws VersionRetrievalException;
/**
* Returns an {@link ExpressionEvaluator} for the specified project.
*
* @param project The project.
* @return an {@link ExpressionEvaluator} for the specified project.
* @since 1.0-beta-1
*/
ExpressionEvaluator getExpressionEvaluator( MavenProject project );
/**
* Returns a map of {@link org.codehaus.mojo.versions.api.PropertyVersions} values keyed by
* {@link Property} instances consisting of the properties defined in the project which
* are associated with version information.
*
* @param request {@link VersionPropertiesMapRequest} instance containing the arguments
* @return a map of {@link org.codehaus.mojo.versions.api.PropertyVersions} values keyed by
* {@link Property} instances.
* @throws MojoExecutionException if something goes wrong.
*/
Map<Property, PropertyVersions> getVersionPropertiesMap( VersionPropertiesMapRequest request )
throws MojoExecutionException;
/**
* Argument builder class for
* {@link VersionsHelper#getVersionPropertiesMap(VersionPropertiesMapRequest)}.
*/
class VersionPropertiesMapRequest
{
private MavenProject mavenProject;
private Property[] propertyDefinitions;
private String includeProperties;
private String excludeProperties;
private boolean includeParent;
private boolean autoLinkItems;
/**
* Returns the {@link MavenProject} object
* @return {@link MavenProject} object
*/
protected MavenProject getMavenProject()
{
return mavenProject;
}
/**
* Returns the {@link Property} array
* @return {@link Property} array
*/
protected Property[] getPropertyDefinitions()
{
return propertyDefinitions;
}
/**
* Returns the value of {@link #includeProperties}
* @return value of {@link #includeProperties}
*/
protected String getIncludeProperties()
{
return includeProperties;
}
/**
* Returns the value of {@link #excludeProperties}
* @return value of {@link #excludeProperties}
*/
protected String getExcludeProperties()
{
return excludeProperties;
}
/**
* Returns the value of {@link #includeParent}.
* If not set, it is assumed to be {@code true}
*
* @return value of {@link #includeParent}
*/
protected boolean isIncludeParent()
{
return includeParent;
}
/**
* Returns the value of {@link #autoLinkItems}
* If not set, it is assumed to be {@code true}
* @return value of {@link #autoLinkItems}
*/
protected boolean isAutoLinkItems()
{
return autoLinkItems;
}
/**
* Returns a new {@link Builder} instance
* @return new {@link Builder} instance
*/
public static Builder builder()
{
return new Builder();
}
/**
* Builder class for {@link VersionPropertiesMapRequest}
*/
public static class Builder
{
private MavenProject mavenProject;
private Property[] propertyDefinitions;
private String includeProperties;
private String excludeProperties;
private Boolean includeParent;
private Boolean autoLinkItems;
private Builder()
{
}
/**
* Supplies the {@link MavenProject} instance
* @param mavenProject {@link MavenProject} instance
* @return {@link Builder} instance
*/
public Builder withMavenProject( MavenProject mavenProject )
{
this.mavenProject = mavenProject;
return this;
}
/**
* Supplies the {@link MavenProject} instance
* @param propertyDefinitions array of property definitions
* @return {@link Builder} instance
*/
public Builder withPropertyDefinitions( Property[] propertyDefinitions )
{
this.propertyDefinitions = propertyDefinitions;
return this;
}
/**
* Supplies the properties to include
* @param includeProperties comma-delimited properties to include
* @return {@link Builder} instance
*/
public Builder withIncludeProperties( String includeProperties )
{
this.includeProperties = includeProperties;
return this;
}
/**
* Supplies the properties to exclude
* @param excludeProperties comma-delimited properties to exclude
* @return {@link Builder} instance
*/
public Builder withExcludeProperties( String excludeProperties )
{
this.excludeProperties = excludeProperties;
return this;
}
/**
* Supplies the includeParent parameter (whether parent POMs should be included)
* @param includeParent whether parent POMs should be included
* @return {@link Builder} instance
*/
public Builder withIncludeParent( boolean includeParent )
{
this.includeParent = includeParent;
return this;
}
/**
* Supplies the information whether to automatically infer associations
* @param autoLinkItems whether to automatically infer associations
* @return {@link Builder} instance
*/
public Builder withAutoLinkItems( boolean autoLinkItems )
{
this.autoLinkItems = autoLinkItems;
return this;
}
/**
* Returns the {@link VersionPropertiesMapRequest} instance
* @return {@link VersionPropertiesMapRequest} instance
*/
public VersionPropertiesMapRequest build()
{
VersionPropertiesMapRequest instance = new VersionPropertiesMapRequest();
instance.mavenProject = this.mavenProject;
instance.propertyDefinitions = propertyDefinitions;
instance.includeProperties = includeProperties;
instance.excludeProperties = excludeProperties;
instance.includeParent = includeParent == null || includeParent;
instance.autoLinkItems = autoLinkItems == null || autoLinkItems;
return instance;
}
}
}
/**
* Attempts to resolve the artifact.
*
* @param artifact The artifact to resolve.
* @param usePluginRepositories whether to resolve from the plugin repositories or the regular repositories.
* @throws ArtifactResolutionException if resolution is unsuccessful
* @since 1.3
*/
void resolveArtifact( Artifact artifact, boolean usePluginRepositories )
throws ArtifactResolutionException;
}