Correct DependencyResolver behaviour

This commit is contained in:
JeremyStar™ 2024-09-04 17:04:12 +02:00
parent 9cd888299f
commit 6c3c449416
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -124,19 +124,27 @@ public final class DependencyResolver {
* Throws an exception when detecting an unmet dependency or a dependency cycle. * Throws an exception when detecting an unmet dependency or a dependency cycle.
* *
* @return itself * @return itself
* @throws IllegalStateException when encountering an invalid vector
* @throws UnmetDependenciesException when dependencies are unmet * @throws UnmetDependenciesException when dependencies are unmet
* @since v1-alpha1 * @since v1-alpha1
*/ */
public synchronized DependencyResolver resolve() throws UnmetDependenciesException { public synchronized DependencyResolver resolve() throws IllegalStateException, UnmetDependenciesException {
Map<DependencyVector, String> unmetDependencies = new HashMap<>(); Map<@NotNull DependencyVector, @NotNull String> unmetDependencies = new HashMap<>();
List<@NotNull String> output;
for (DependencyVector vector : vectors) { for (DependencyVector vector : vectors) {
if (!vectorsResolved.contains(vector.getIdentifier())) { if (!vectorsResolved.contains(vector.getIdentifier())) {
resolveVector(vector); output = resolveVector(vector);
for (String item : output)
unmetDependencies.put(vector, item);
vectorsResolved.add(vector.getIdentifier()); vectorsResolved.add(vector.getIdentifier());
} }
} }
if (!unmetDependencies.isEmpty())
throw new UnmetDependenciesException(unmetDependencies);
resolved = true; resolved = true;
return this; return this;
} }
@ -274,7 +282,7 @@ public final class DependencyResolver {
// Compare versions // Compare versions
if (versioningSystemResolved.compare(versioningSystemEquals) != 1) if (versioningSystemResolved.compare(versioningSystemEquals) != 1)
unmetDependencies.add("Dependency \"" + dependency + "\" is not met: Expected version " + versionEqual + " does not match found version " + vector.getVersion()); unmetDependencies.add("Dependency \"" + dependency + "\" is not met: Expected version " + versionEqual + " does not match found version " + vector.getVersion());
} else { } else if (!versionBigger.isEmpty() || !versionSmaller.isEmpty()) {
VersioningSystem versioningSystemSmaller = null; VersioningSystem versioningSystemSmaller = null;
VersioningSystem versioningSystemBigger = null; VersioningSystem versioningSystemBigger = null;
@ -297,14 +305,14 @@ public final class DependencyResolver {
// Compare versions // Compare versions
if (versioningSystemSmaller != null && versioningSystemBigger != null) { if (versioningSystemSmaller != null && versioningSystemBigger != null) {
if (versioningSystemResolved.compare(versioningSystemSmaller) != 0 && versioningSystemResolved.compare(versioningSystemBigger) != 2) if (versioningSystemResolved.compare(versioningSystemSmaller) != 2 || versioningSystemResolved.compare(versioningSystemBigger) != 0)
unmetDependencies.add("Dependency \"" + dependency + "\" is not met: Version " + vector.getVersion() + " is not in range " + versionSmaller + " to " + versionBigger); unmetDependencies.add("Dependency \"" + dependency + "\" is not met: Version " + vector.getVersion() + " is not in range " + versionSmaller + " to " + versionBigger);
} else { } else {
if (versioningSystemSmaller != null) if (versioningSystemSmaller != null)
if (versioningSystemResolved.compare(versioningSystemSmaller) != 0) if (versioningSystemResolved.compare(versioningSystemSmaller) != 2)
unmetDependencies.add("Dependency \"" + dependency + "\" is not met: Version " + vector.getVersion() + " is bigger than " + versionSmaller); unmetDependencies.add("Dependency \"" + dependency + "\" is not met: Version " + vector.getVersion() + " is bigger than " + versionSmaller);
if (versioningSystemBigger != null) if (versioningSystemBigger != null)
if (versioningSystemResolved.compare(versioningSystemBigger) != 2) if (versioningSystemResolved.compare(versioningSystemBigger) != 0)
unmetDependencies.add("Dependency \"" + dependency + "\" is not met: Version " + vector.getVersion() + " is smaller than " + versionBigger); unmetDependencies.add("Dependency \"" + dependency + "\" is not met: Version " + vector.getVersion() + " is smaller than " + versionBigger);
} }
} }