Compare commits
3 commits
07cbbb9bb3
...
9b97390a9c
Author | SHA1 | Date | |
---|---|---|---|
9b97390a9c | |||
6c3c449416 | |||
9cd888299f |
2 changed files with 25 additions and 62 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 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,64 +305,17 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
if (dependency.contains("=")) {
|
|
||||||
// Check for '<' and '>'
|
|
||||||
if (dependency.contains("<") || dependency.contains(">"))
|
|
||||||
throw new IllegalStateException("The dependency listing \"" + dependency + "\" can't require a specific version and have minimum and maximum version specifiers");
|
|
||||||
|
|
||||||
// Check for multiple '='
|
|
||||||
if (dependency.split("\\\\=").length != 1)
|
|
||||||
throw new IllegalStateException("The dependency listing \"" + dependency + "\" can't include multiple equals characters");
|
|
||||||
|
|
||||||
// Get identifier and required version
|
|
||||||
int index = dependency.indexOf("=");
|
|
||||||
String identifier = dependency.substring(0, index);
|
|
||||||
String version = dependency.substring(index + 1);
|
|
||||||
|
|
||||||
DependencyVector dependencyResolved = getMatchingVector(identifier);
|
|
||||||
if (dependencyResolved == null)
|
|
||||||
unmetDependencies.add("Dependency \"" + dependency + "\" is not met: Not found");
|
|
||||||
else {
|
|
||||||
VersioningSystem versioningSystemResolved;
|
|
||||||
VersioningSystem versioningSystemEquals;
|
|
||||||
|
|
||||||
// Create VersioningSystem instances for comparing versions
|
|
||||||
try {
|
|
||||||
versioningSystemResolved = dependencyResolved.getVersioningSystem().getDeclaredConstructor(String.class).newInstance(dependencyResolved.getVersion());
|
|
||||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException |
|
|
||||||
InvocationTargetException exception) {
|
|
||||||
logger.crash("Unable to check version of dependency \"" + dependency + "\": Unable to initialize versioning system " + dependencyResolved.getVersioningSystem().getName(), exception);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
versioningSystemEquals = dependencyResolved.getVersioningSystem().getDeclaredConstructor(String.class).newInstance(version);
|
|
||||||
} catch (NoSuchMethodException | InstantiationException | IllegalAccessException |
|
|
||||||
InvocationTargetException exception) {
|
|
||||||
logger.crash("Unable to initialize versioning system " + vector.getVersioningSystem().getName() + " of vector " + vector.getIdentifier(), exception);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compare versions
|
|
||||||
if (versioningSystemResolved.compare(versioningSystemEquals) != 1)
|
|
||||||
unmetDependencies.add("Dependency \"" + dependency + "\" is not met: Expected version " + version + " does not match found version " + vector.getVersion());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new IllegalStateException("The dependency listing \"" + dependency + "\" does not contain a version identifier");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return unmetDependencies;
|
return unmetDependencies;
|
||||||
|
|
|
@ -94,6 +94,7 @@ class DependencyResolverTest extends TestBase {
|
||||||
// Vector 2
|
// Vector 2
|
||||||
dependencies = new HashSet<>();
|
dependencies = new HashSet<>();
|
||||||
dependencies.add("test0=49");
|
dependencies.add("test0=49");
|
||||||
|
dependencies.add("test1=999");
|
||||||
vectors.add(
|
vectors.add(
|
||||||
new DependencyVector.Builder()
|
new DependencyVector.Builder()
|
||||||
.setIdentifier("test2")
|
.setIdentifier("test2")
|
||||||
|
@ -164,7 +165,7 @@ class DependencyResolverTest extends TestBase {
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
// Vector 5
|
// Vector 5
|
||||||
dependencies.add("test4>998<100");
|
dependencies.add("test4>998<1000");
|
||||||
vectors.add(
|
vectors.add(
|
||||||
new DependencyVector.Builder()
|
new DependencyVector.Builder()
|
||||||
.setIdentifier("test5")
|
.setIdentifier("test5")
|
||||||
|
@ -235,8 +236,8 @@ class DependencyResolverTest extends TestBase {
|
||||||
.setDependencies(dependencies)
|
.setDependencies(dependencies)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
// Vector 6
|
// Vector 6p
|
||||||
dependencies.add("test5>998<100");
|
dependencies.add("test5>998<1000");
|
||||||
vectors.add(
|
vectors.add(
|
||||||
new DependencyVector.Builder()
|
new DependencyVector.Builder()
|
||||||
.setIdentifier("test6")
|
.setIdentifier("test6")
|
||||||
|
@ -266,7 +267,7 @@ class DependencyResolverTest extends TestBase {
|
||||||
try {
|
try {
|
||||||
resolver.resolve();
|
resolver.resolve();
|
||||||
} catch (UnmetDependenciesException exception) {
|
} catch (UnmetDependenciesException exception) {
|
||||||
getLogger().error("Dependency resolution failed: Unmet dependencies found:");
|
getLogger().error("Dependency resolution failed:");
|
||||||
for (DependencyVector vector : exception.getUnmetDependencies().keySet())
|
for (DependencyVector vector : exception.getUnmetDependencies().keySet())
|
||||||
getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector));
|
getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector));
|
||||||
|
|
||||||
|
@ -351,6 +352,7 @@ class DependencyResolverTest extends TestBase {
|
||||||
);
|
);
|
||||||
// Vector 2
|
// Vector 2
|
||||||
dependencies = new HashSet<>();
|
dependencies = new HashSet<>();
|
||||||
|
dependencies.add("testNULL");
|
||||||
dependencies.add("test1>999");
|
dependencies.add("test1>999");
|
||||||
vectors.add(
|
vectors.add(
|
||||||
new DependencyVector.Builder()
|
new DependencyVector.Builder()
|
||||||
|
@ -483,7 +485,7 @@ class DependencyResolverTest extends TestBase {
|
||||||
try {
|
try {
|
||||||
resolver.resolve();
|
resolver.resolve();
|
||||||
} catch (UnmetDependenciesException exception) {
|
} catch (UnmetDependenciesException exception) {
|
||||||
getLogger().error("Dependency resolution failed (great!): Unmet dependencies found:");
|
getLogger().error("Dependency resolution failed (great!):");
|
||||||
for (DependencyVector vector : exception.getUnmetDependencies().keySet())
|
for (DependencyVector vector : exception.getUnmetDependencies().keySet())
|
||||||
getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector));
|
getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue