This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#16] Fail build if new versions of specified packages are found
- Loading branch information
1 parent
5c8f1b3
commit b0150a6
Showing
15 changed files
with
287 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.ofg.uptodate | ||
|
||
class FiltersHolder { | ||
final IncludedExcludedPatternsHolder patternsHolder = new IncludedExcludedPatternsHolder() | ||
|
||
/** | ||
* String names of configurations to include for checking | ||
* @param configurations | ||
*/ | ||
void include(String... configurations) { | ||
this.patternsHolder.included.addAll(configurations) | ||
} | ||
|
||
void exclude(String... configurations) { | ||
this.patternsHolder.excluded.addAll(configurations) | ||
} | ||
|
||
static class IncludedExcludedPatternsHolder { | ||
final Set<String> included = [] | ||
final Set<String> excluded = [] | ||
} | ||
|
||
Set<String> getIncluded() { | ||
return patternsHolder.included | ||
} | ||
|
||
Set<String> getExcluded() { | ||
return patternsHolder.excluded | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/groovy/com/ofg/uptodate/reporting/BuildBreaker.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.ofg.uptodate.reporting | ||
|
||
import com.ofg.uptodate.UptodatePluginExtension | ||
import com.ofg.uptodate.dependency.Dependency | ||
import groovy.util.logging.Slf4j | ||
|
||
@Slf4j | ||
class BuildBreaker { | ||
|
||
private static final Set<String> INCLUDE_ALL = ['.*'] as Set<String> | ||
|
||
private final UptodatePluginExtension.BuildBreakerConfiguration buildBreakerConfiguration | ||
|
||
BuildBreaker(UptodatePluginExtension.BuildBreakerConfiguration buildBreakerConfiguration) { | ||
this.buildBreakerConfiguration = buildBreakerConfiguration | ||
} | ||
|
||
void breakTheBuildIfNecessary(List<Dependency> sortedUpdates) { | ||
if (!buildBreakerConfiguration.enabled) { | ||
log.debug('Build breaking is disabled') | ||
return | ||
} | ||
log.debug("Build breaking is enabled") | ||
List<Dependency> matchingDependencies = findAllDependenciesMatchingPatterns(sortedUpdates) | ||
log.debug("Found the following matching dependencies $matchingDependencies") | ||
breakTheBuildIfMatchingDepsWereFound(matchingDependencies) | ||
} | ||
|
||
private List<Dependency> findAllDependenciesMatchingPatterns(List<Dependency> sortedUpdates) { | ||
return sortedUpdates.findAll { Dependency dependency -> | ||
getPatternsForInclusionOrAllAsDefault().any { nameOrGroupMatchesRegex(dependency, it) } && | ||
!buildBreakerConfiguration.filters.excluded.any { nameOrGroupMatchesRegex(dependency, it) } | ||
} | ||
} | ||
|
||
private Set<String> getPatternsForInclusionOrAllAsDefault() { | ||
Set<String> patternsForInclusion = buildBreakerConfiguration.filters.included | ||
return patternsForInclusion.empty ? INCLUDE_ALL : patternsForInclusion | ||
} | ||
|
||
private void breakTheBuildIfMatchingDepsWereFound(List<Dependency> matchingDependencies) { | ||
if (!matchingDependencies.empty) { | ||
throw new NewDependencyVersionsFoundException("For the following dependencies $matchingDependencies new versions have been found. Breaking the build") | ||
} | ||
} | ||
|
||
private static boolean nameOrGroupMatchesRegex(Dependency dependency, String regex) { | ||
return dependency.group.matches(regex) || dependency.name.matches(regex) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/groovy/com/ofg/uptodate/reporting/NewDependencyVersionsFoundException.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.ofg.uptodate.reporting | ||
|
||
import groovy.transform.InheritConstructors | ||
|
||
@InheritConstructors | ||
class NewDependencyVersionsFoundException extends RuntimeException { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.