|
34 | 34 | import javax.inject.Inject;
|
35 | 35 |
|
36 | 36 | import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
| 37 | +import org.apache.maven.artifact.versioning.VersionRange; |
37 | 38 | import org.gradle.api.DefaultTask;
|
38 | 39 | import org.gradle.api.InvalidUserDataException;
|
39 | 40 | import org.gradle.api.internal.tasks.userinput.UserInputHandler;
|
@@ -227,42 +228,37 @@ private List<Upgrade> resolveUpgrades(Milestone milestone) {
|
227 | 228 | }
|
228 | 229 |
|
229 | 230 | protected List<BiPredicate<Library, DependencyVersion>> determineUpdatePredicates(Milestone milestone) {
|
230 |
| - BiPredicate<Library, DependencyVersion> compilesWithUpgradePolicy = (library, |
231 |
| - candidate) -> this.bom.getUpgrade().getPolicy().test(candidate, library.getVersion().getVersion()); |
232 |
| - BiPredicate<Library, DependencyVersion> isAnUpgrade = (library, |
233 |
| - candidate) -> library.getVersion().getVersion().isUpgrade(candidate, this.movingToSnapshots); |
234 |
| - BiPredicate<Library, DependencyVersion> isPermitted = (library, candidate) -> { |
235 |
| - for (ProhibitedVersion prohibitedVersion : library.getProhibitedVersions()) { |
236 |
| - String candidateString = candidate.toString(); |
237 |
| - if (prohibitedVersion.getRange() != null |
238 |
| - && prohibitedVersion.getRange().containsVersion(new DefaultArtifactVersion(candidateString))) { |
239 |
| - return false; |
240 |
| - } |
241 |
| - for (String startsWith : prohibitedVersion.getStartsWith()) { |
242 |
| - if (candidateString.startsWith(startsWith)) { |
243 |
| - return false; |
244 |
| - } |
245 |
| - } |
246 |
| - for (String endsWith : prohibitedVersion.getEndsWith()) { |
247 |
| - if (candidateString.endsWith(endsWith)) { |
248 |
| - return false; |
249 |
| - } |
250 |
| - } |
251 |
| - for (String contains : prohibitedVersion.getContains()) { |
252 |
| - if (candidateString.contains(contains)) { |
253 |
| - return false; |
254 |
| - } |
255 |
| - } |
256 |
| - } |
257 |
| - return true; |
258 |
| - }; |
259 | 231 | List<BiPredicate<Library, DependencyVersion>> updatePredicates = new ArrayList<>();
|
260 |
| - updatePredicates.add(compilesWithUpgradePolicy); |
261 |
| - updatePredicates.add(isAnUpgrade); |
262 |
| - updatePredicates.add(isPermitted); |
| 232 | + updatePredicates.add(this::compilesWithUpgradePolicy); |
| 233 | + updatePredicates.add(this::isAnUpgrade); |
| 234 | + updatePredicates.add(this::isNotProhibited); |
263 | 235 | return updatePredicates;
|
264 | 236 | }
|
265 | 237 |
|
| 238 | + private boolean compilesWithUpgradePolicy(Library library, DependencyVersion candidate) { |
| 239 | + return this.bom.getUpgrade().getPolicy().test(candidate, library.getVersion().getVersion()); |
| 240 | + } |
| 241 | + |
| 242 | + private boolean isAnUpgrade(Library library, DependencyVersion candidate) { |
| 243 | + return library.getVersion().getVersion().isUpgrade(candidate, this.movingToSnapshots); |
| 244 | + } |
| 245 | + |
| 246 | + private boolean isNotProhibited(Library library, DependencyVersion candidate) { |
| 247 | + return !library.getProhibitedVersions() |
| 248 | + .stream() |
| 249 | + .anyMatch((prohibited) -> isProhibited(prohibited, candidate.toString())); |
| 250 | + } |
| 251 | + |
| 252 | + private boolean isProhibited(ProhibitedVersion prohibited, String candidate) { |
| 253 | + boolean result = false; |
| 254 | + VersionRange range = prohibited.getRange(); |
| 255 | + result = result || (range != null && range.containsVersion(new DefaultArtifactVersion(candidate))); |
| 256 | + result = result || prohibited.getStartsWith().stream().anyMatch(candidate::startsWith); |
| 257 | + result = result || prohibited.getStartsWith().stream().anyMatch(candidate::endsWith); |
| 258 | + result = result || prohibited.getStartsWith().stream().anyMatch(candidate::contains); |
| 259 | + return result; |
| 260 | + } |
| 261 | + |
266 | 262 | private List<Library> matchingLibraries() {
|
267 | 263 | List<Library> matchingLibraries = this.bom.getLibraries().stream().filter(this::eligible).toList();
|
268 | 264 | if (matchingLibraries.isEmpty()) {
|
|
0 commit comments