Allow multiple startsWith, contains and endsWith clauses in bomr

- Add support for startsWith prohibition
pull/33855/head
Moritz Halbritter 2 years ago
parent 3d42ab085a
commit 484d662085

@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
@ -248,8 +249,8 @@ public class BomExtension {
public void prohibit(Action<ProhibitedHandler> action) {
ProhibitedHandler handler = new ProhibitedHandler();
action.execute(handler);
this.prohibitedVersions.add(
new ProhibitedVersion(handler.versionRange, handler.endsWith, handler.contains, handler.reason));
this.prohibitedVersions.add(new ProhibitedVersion(handler.versionRange, handler.startsWith,
handler.endsWith, handler.contains, handler.reason));
}
public void dependencyVersions(Action<DependencyVersionsHandler> action) {
@ -273,9 +274,11 @@ public class BomExtension {
private String reason;
private String endsWith;
private final List<String> startsWith = new ArrayList<>();
private String contains;
private final List<String> endsWith = new ArrayList<>();
private final List<String> contains = new ArrayList<>();
private VersionRange versionRange;
@ -288,12 +291,28 @@ public class BomExtension {
}
}
public void startsWith(String startsWith) {
this.startsWith.add(startsWith);
}
public void startsWith(Collection<String> startsWith) {
this.startsWith.addAll(startsWith);
}
public void endsWith(String endsWith) {
this.endsWith = endsWith;
this.endsWith.add(endsWith);
}
public void endsWith(Collection<String> endsWith) {
this.endsWith.addAll(endsWith);
}
public void contains(String contains) {
this.contains = contains;
this.contains.add(contains);
}
public void contains(List<String> contains) {
this.contains.addAll(contains);
}
public void because(String because) {

@ -104,14 +104,18 @@ public class Library {
private final VersionRange range;
private final String endsWith;
private final List<String> startsWith;
private final String contains;
private final List<String> endsWith;
private final List<String> contains;
private final String reason;
public ProhibitedVersion(VersionRange range, String endsWith, String contains, String reason) {
public ProhibitedVersion(VersionRange range, List<String> startsWith, List<String> endsWith,
List<String> contains, String reason) {
this.range = range;
this.startsWith = startsWith;
this.endsWith = endsWith;
this.contains = contains;
this.reason = reason;
@ -121,11 +125,15 @@ public class Library {
return this.range;
}
public String getEndsWith() {
public List<String> getStartsWith() {
return this.startsWith;
}
public List<String> getEndsWith() {
return this.endsWith;
}
public String getContains() {
public List<String> getContains() {
return this.contains;
}

@ -167,21 +167,26 @@ public final class InteractiveUpgradeResolver implements UpgradeResolver {
}
private boolean isPermitted(DependencyVersion dependencyVersion, List<ProhibitedVersion> prohibitedVersions) {
if (prohibitedVersions.isEmpty()) {
return true;
}
for (ProhibitedVersion prohibitedVersion : prohibitedVersions) {
String dependencyVersionToString = dependencyVersion.toString();
if (prohibitedVersion.getRange() != null && prohibitedVersion.getRange()
.containsVersion(new DefaultArtifactVersion(dependencyVersion.toString()))) {
.containsVersion(new DefaultArtifactVersion(dependencyVersionToString))) {
return false;
}
if (prohibitedVersion.getEndsWith() != null
&& dependencyVersion.toString().endsWith(prohibitedVersion.getEndsWith())) {
return false;
for (String startsWith : prohibitedVersion.getStartsWith()) {
if (dependencyVersionToString.startsWith(startsWith)) {
return false;
}
}
if (prohibitedVersion.getContains() != null
&& dependencyVersion.toString().contains(prohibitedVersion.getContains())) {
return false;
for (String endsWith : prohibitedVersion.getEndsWith()) {
if (dependencyVersionToString.endsWith(endsWith)) {
return false;
}
}
for (String contains : prohibitedVersion.getContains()) {
if (dependencyVersionToString.contains(contains)) {
return false;
}
}
}
return true;

@ -1362,13 +1362,7 @@ bom {
endsWith ".jre8-preview"
}
prohibit {
contains ".jre11"
}
prohibit {
contains ".jre16"
}
prohibit {
contains ".jre17"
contains([".jre11", ".jre16", ".jre17"])
}
group("com.microsoft.sqlserver") {
modules = [

Loading…
Cancel
Save