Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ignore version #345

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
public final class RequireSameVersions extends AbstractStandardEnforcerRule {
private boolean uniqueVersions;

private Set<String> ignores = new HashSet<>();

private Set<String> dependencies = new HashSet<>();

private Set<String> plugins = new HashSet<>();
Expand Down Expand Up @@ -105,20 +107,24 @@ private Map<String, List<String>> collectVersionMembers(
Set<Artifact> artifacts, Collection<String> patterns, String source) {
Map<String, List<String>> versionMembers = new LinkedHashMap<>();

List<Pattern> regExs = new ArrayList<>();
for (String pattern : patterns) {
String regex = pattern.replace(".", "\\.")
.replace("*", ".*")
.replace(":", "\\:")
.replace('?', '.');

// pattern is groupId[:artifactId[:type[:classifier]]]
regExs.add(Pattern.compile(regex + "(\\:.+)?"));
}
List<Pattern> regExs = convertToPatterns(patterns);
List<Pattern> ignorePatterns = convertToPatterns(ignores);

for (Artifact artifact : artifacts) {
for (Pattern regEx : regExs) {
if (regEx.matcher(artifact.getDependencyConflictId()).matches()) {
boolean ignored = false;
for (Pattern ignorePattern : ignorePatterns) {
if (ignorePattern
.matcher(artifact.getDependencyConflictId())
.matches()) {
ignored = true;
break;
}
}
if (ignored) {
continue;
}
String version = uniqueVersions ? artifact.getVersion() : artifact.getBaseVersion();
if (!versionMembers.containsKey(version)) {
versionMembers.put(version, new ArrayList<>());
Expand All @@ -130,6 +136,20 @@ private Map<String, List<String>> collectVersionMembers(
return versionMembers;
}

private List<Pattern> convertToPatterns(Collection<String> patterns) {
List<Pattern> regExs = new ArrayList<>();
for (String pattern : patterns) {
String regex = pattern.replace(".", "\\.")
.replace("*", ".*")
.replace(":", "\\:")
.replace('?', '.');

// pattern is groupId[:artifactId[:type[:classifier]]]
regExs.add(Pattern.compile(regex + "(\\:.+)?"));
}
return regExs;
}

@Override
public String toString() {
return String.format(
Expand Down