Correct DependencyResolver behaviour
This commit is contained in:
parent
9cd888299f
commit
6c3c449416
1 changed files with 18 additions and 10 deletions
|
@ -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 UnmetDependenciesException when dependencies are unmet
|
* @throws IllegalStateException when encountering an invalid vector
|
||||||
|
* @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;
|
||||||
}
|
}
|
||||||
|
@ -146,8 +154,8 @@ 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 list of unmet dependencies
|
* @return list of unmet dependencies
|
||||||
* @throws IllegalStateException when encountering an invalid dependency or provider
|
* @throws IllegalStateException when encountering an invalid dependency or provider
|
||||||
* @throws Exception when some unknown error occurs
|
* @throws Exception when some unknown error occurs
|
||||||
* @since v1-alpha4
|
* @since v1-alpha4
|
||||||
*/
|
*/
|
||||||
private @NotNull List<@NotNull String> resolveVector(@NotNull DependencyVector vector) throws IllegalStateException {
|
private @NotNull List<@NotNull String> resolveVector(@NotNull DependencyVector vector) throws IllegalStateException {
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue