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