Compare commits
No commits in common. "9b97390a9c71ad5983a4c82c6933a98dacce1083" and "07cbbb9bb3e8cbd98f9caa08519c2b6259a10083" have entirely different histories.
9b97390a9c
...
07cbbb9bb3
2 changed files with 62 additions and 25 deletions
|
@ -124,27 +124,19 @@ 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 IllegalStateException, UnmetDependenciesException {
|
public synchronized DependencyResolver resolve() throws UnmetDependenciesException {
|
||||||
Map<@NotNull DependencyVector, @NotNull String> unmetDependencies = new HashMap<>();
|
Map<DependencyVector, 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())) {
|
||||||
output = resolveVector(vector);
|
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;
|
||||||
}
|
}
|
||||||
|
@ -154,8 +146,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 {
|
||||||
|
@ -282,7 +274,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 if (!versionBigger.isEmpty() || !versionSmaller.isEmpty()) {
|
} else {
|
||||||
VersioningSystem versioningSystemSmaller = null;
|
VersioningSystem versioningSystemSmaller = null;
|
||||||
VersioningSystem versioningSystemBigger = null;
|
VersioningSystem versioningSystemBigger = null;
|
||||||
|
|
||||||
|
@ -305,17 +297,64 @@ public final class DependencyResolver {
|
||||||
|
|
||||||
// Compare versions
|
// Compare versions
|
||||||
if (versioningSystemSmaller != null && versioningSystemBigger != null) {
|
if (versioningSystemSmaller != null && versioningSystemBigger != null) {
|
||||||
if (versioningSystemResolved.compare(versioningSystemSmaller) != 2 || versioningSystemResolved.compare(versioningSystemBigger) != 0)
|
if (versioningSystemResolved.compare(versioningSystemSmaller) != 0 && versioningSystemResolved.compare(versioningSystemBigger) != 2)
|
||||||
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) != 2)
|
if (versioningSystemResolved.compare(versioningSystemSmaller) != 0)
|
||||||
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) != 0)
|
if (versioningSystemResolved.compare(versioningSystemBigger) != 2)
|
||||||
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,7 +94,6 @@ 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")
|
||||||
|
@ -165,7 +164,7 @@ class DependencyResolverTest extends TestBase {
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
// Vector 5
|
// Vector 5
|
||||||
dependencies.add("test4>998<1000");
|
dependencies.add("test4>998<100");
|
||||||
vectors.add(
|
vectors.add(
|
||||||
new DependencyVector.Builder()
|
new DependencyVector.Builder()
|
||||||
.setIdentifier("test5")
|
.setIdentifier("test5")
|
||||||
|
@ -236,8 +235,8 @@ class DependencyResolverTest extends TestBase {
|
||||||
.setDependencies(dependencies)
|
.setDependencies(dependencies)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
// Vector 6p
|
// Vector 6
|
||||||
dependencies.add("test5>998<1000");
|
dependencies.add("test5>998<100");
|
||||||
vectors.add(
|
vectors.add(
|
||||||
new DependencyVector.Builder()
|
new DependencyVector.Builder()
|
||||||
.setIdentifier("test6")
|
.setIdentifier("test6")
|
||||||
|
@ -267,7 +266,7 @@ class DependencyResolverTest extends TestBase {
|
||||||
try {
|
try {
|
||||||
resolver.resolve();
|
resolver.resolve();
|
||||||
} catch (UnmetDependenciesException exception) {
|
} catch (UnmetDependenciesException exception) {
|
||||||
getLogger().error("Dependency resolution failed:");
|
getLogger().error("Dependency resolution failed: Unmet dependencies found:");
|
||||||
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));
|
||||||
|
|
||||||
|
@ -352,7 +351,6 @@ 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()
|
||||||
|
@ -485,7 +483,7 @@ class DependencyResolverTest extends TestBase {
|
||||||
try {
|
try {
|
||||||
resolver.resolve();
|
resolver.resolve();
|
||||||
} catch (UnmetDependenciesException exception) {
|
} catch (UnmetDependenciesException exception) {
|
||||||
getLogger().error("Dependency resolution failed (great!):");
|
getLogger().error("Dependency resolution failed (great!): Unmet dependencies found:");
|
||||||
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