diff --git a/base/src/main/java/de/staropensource/sosengine/base/utility/DependencyResolver.java b/base/src/main/java/de/staropensource/sosengine/base/utility/DependencyResolver.java index 463852cc..168a23dd 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/utility/DependencyResolver.java +++ b/base/src/main/java/de/staropensource/sosengine/base/utility/DependencyResolver.java @@ -124,19 +124,27 @@ public final class DependencyResolver { * Throws an exception when detecting an unmet dependency or a dependency cycle. * * @return itself - * @throws UnmetDependenciesException when dependencies are unmet + * @throws IllegalStateException when encountering an invalid vector + * @throws UnmetDependenciesException when dependencies are unmet * @since v1-alpha1 */ - public synchronized DependencyResolver resolve() throws UnmetDependenciesException { - Map unmetDependencies = new HashMap<>(); + public synchronized DependencyResolver resolve() throws IllegalStateException, UnmetDependenciesException { + Map<@NotNull DependencyVector, @NotNull String> unmetDependencies = new HashMap<>(); + List<@NotNull String> output; for (DependencyVector vector : vectors) { if (!vectorsResolved.contains(vector.getIdentifier())) { - resolveVector(vector); + output = resolveVector(vector); + for (String item : output) + unmetDependencies.put(vector, item); + vectorsResolved.add(vector.getIdentifier()); } } + if (!unmetDependencies.isEmpty()) + throw new UnmetDependenciesException(unmetDependencies); + resolved = true; return this; } @@ -146,8 +154,8 @@ public final class DependencyResolver { * Throws an exception when detecting an unmet dependency or a dependency cycle. * * @return list of unmet dependencies - * @throws IllegalStateException when encountering an invalid dependency or provider - * @throws Exception when some unknown error occurs + * @throws IllegalStateException when encountering an invalid dependency or provider + * @throws Exception when some unknown error occurs * @since v1-alpha4 */ private @NotNull List<@NotNull String> resolveVector(@NotNull DependencyVector vector) throws IllegalStateException { @@ -274,7 +282,7 @@ public final class DependencyResolver { // Compare versions if (versioningSystemResolved.compare(versioningSystemEquals) != 1) 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 versioningSystemBigger = null; @@ -297,14 +305,14 @@ public final class DependencyResolver { // Compare versions 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); } else { 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); 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); } }