#159 - Polishing.
Add sanity check to verify dependency upgrade count to prevent accidental dependency upgrades.
This commit is contained in:
@@ -54,4 +54,9 @@ public class Dependency implements Comparable<Dependency> {
|
||||
public int compareTo(Dependency o) {
|
||||
return name.compareTo(o.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getGroupId() + ":" + getArtifactId();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,6 +108,11 @@ public class DependencyUpgradeProposals {
|
||||
|
||||
builder.append("dependency.train=").append(iteration.getTrain().getName()).append(System.lineSeparator());
|
||||
builder.append("dependency.iteration=").append(iteration.getIteration().getName()).append(System.lineSeparator());
|
||||
builder.append(System.lineSeparator());
|
||||
|
||||
builder.append("# Specify the number of desired dependency upgrades as sanity check")
|
||||
.append(System.lineSeparator());
|
||||
builder.append("dependency.upgrade.count=").append(System.lineSeparator());
|
||||
|
||||
proposals.forEach((dependency, proposal) -> {
|
||||
|
||||
@@ -140,6 +145,12 @@ public class DependencyUpgradeProposals {
|
||||
|
||||
String verificationTrain = properties.getProperty("dependency.train", "");
|
||||
String verificationIteration = properties.getProperty("dependency.iteration", "");
|
||||
int expectedUpgradeCount;
|
||||
try {
|
||||
expectedUpgradeCount = Integer.parseInt(properties.getProperty("dependency.upgrade.count", "0"));
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("Please specify a valid dependency.upgrade.count");
|
||||
}
|
||||
|
||||
if (!verificationTrain.equals(iteration.getTrain().getName())
|
||||
|| !verificationIteration.equals(iteration.getIteration().getName())) {
|
||||
@@ -152,7 +163,7 @@ public class DependencyUpgradeProposals {
|
||||
|
||||
properties.forEach((k, v) -> {
|
||||
|
||||
if ("dependency.train".equals(k) || "dependency.iteration".equals(k)) {
|
||||
if ("dependency.train".equals(k) || "dependency.iteration".equals(k) || "dependency.upgrade.count".equals(k)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -167,10 +178,17 @@ public class DependencyUpgradeProposals {
|
||||
Dependency dependency = Dependencies.getRequiredDepependency(groupId, artifactId);
|
||||
|
||||
result.put(dependency, DependencyVersion.of(v.toString()));
|
||||
|
||||
});
|
||||
|
||||
return new DependencyVersions(result);
|
||||
DependencyVersions dependencyVersions = new DependencyVersions(result);
|
||||
|
||||
if (expectedUpgradeCount != result.size()) {
|
||||
throw new IllegalStateException(String.format(
|
||||
"The number of expected upgrades (%s) does not match the number of actual upgrades (%s): %n%n%s",
|
||||
expectedUpgradeCount, result.size(), dependencyVersions.toString(1)));
|
||||
}
|
||||
|
||||
return dependencyVersions;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.apache.maven.shared.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* Value upgrade capturing {@link DependencyVersion} for a {@link Dependency}.
|
||||
*
|
||||
@@ -90,4 +92,21 @@ class DependencyVersions {
|
||||
return versions.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(0);
|
||||
}
|
||||
|
||||
public String toString(int indentation) {
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
for (Map.Entry<Dependency, DependencyVersion> entry : versions.entrySet()) {
|
||||
|
||||
result.append(StringUtils.repeat("\t", indentation)).append(StringUtils.rightPad(entry.getKey().toString(), 40))
|
||||
.append(" = ").append(entry.getValue()).append(System.lineSeparator());
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user