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.
|
||||
*
|
||||
* @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<DependencyVector, String> 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,64 +305,17 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
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;
|
||||
|
|
|
@ -94,6 +94,7 @@ class DependencyResolverTest extends TestBase {
|
|||
// Vector 2
|
||||
dependencies = new HashSet<>();
|
||||
dependencies.add("test0=49");
|
||||
dependencies.add("test1=999");
|
||||
vectors.add(
|
||||
new DependencyVector.Builder()
|
||||
.setIdentifier("test2")
|
||||
|
@ -164,7 +165,7 @@ class DependencyResolverTest extends TestBase {
|
|||
.build()
|
||||
);
|
||||
// Vector 5
|
||||
dependencies.add("test4>998<100");
|
||||
dependencies.add("test4>998<1000");
|
||||
vectors.add(
|
||||
new DependencyVector.Builder()
|
||||
.setIdentifier("test5")
|
||||
|
@ -235,8 +236,8 @@ class DependencyResolverTest extends TestBase {
|
|||
.setDependencies(dependencies)
|
||||
.build()
|
||||
);
|
||||
// Vector 6
|
||||
dependencies.add("test5>998<100");
|
||||
// Vector 6p
|
||||
dependencies.add("test5>998<1000");
|
||||
vectors.add(
|
||||
new DependencyVector.Builder()
|
||||
.setIdentifier("test6")
|
||||
|
@ -266,7 +267,7 @@ class DependencyResolverTest extends TestBase {
|
|||
try {
|
||||
resolver.resolve();
|
||||
} catch (UnmetDependenciesException exception) {
|
||||
getLogger().error("Dependency resolution failed: Unmet dependencies found:");
|
||||
getLogger().error("Dependency resolution failed:");
|
||||
for (DependencyVector vector : exception.getUnmetDependencies().keySet())
|
||||
getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector));
|
||||
|
||||
|
@ -351,6 +352,7 @@ class DependencyResolverTest extends TestBase {
|
|||
);
|
||||
// Vector 2
|
||||
dependencies = new HashSet<>();
|
||||
dependencies.add("testNULL");
|
||||
dependencies.add("test1>999");
|
||||
vectors.add(
|
||||
new DependencyVector.Builder()
|
||||
|
@ -483,7 +485,7 @@ class DependencyResolverTest extends TestBase {
|
|||
try {
|
||||
resolver.resolve();
|
||||
} catch (UnmetDependenciesException exception) {
|
||||
getLogger().error("Dependency resolution failed (great!): Unmet dependencies found:");
|
||||
getLogger().error("Dependency resolution failed (great!):");
|
||||
for (DependencyVector vector : exception.getUnmetDependencies().keySet())
|
||||
getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector));
|
||||
|
||||
|
|
Loading…
Reference in a new issue