Compare commits

..

No commits in common. "9b97390a9c71ad5983a4c82c6933a98dacce1083" and "07cbbb9bb3e8cbd98f9caa08519c2b6259a10083" have entirely different histories.

2 changed files with 62 additions and 25 deletions

View file

@ -124,27 +124,19 @@ public final class DependencyResolver {
* Throws an exception when detecting an unmet dependency or a dependency cycle.
*
* @return itself
* @throws IllegalStateException when encountering an invalid vector
* @throws UnmetDependenciesException when dependencies are unmet
* @since v1-alpha1
*/
public synchronized DependencyResolver resolve() throws IllegalStateException, UnmetDependenciesException {
Map<@NotNull DependencyVector, @NotNull String> unmetDependencies = new HashMap<>();
List<@NotNull String> output;
public synchronized DependencyResolver resolve() throws UnmetDependenciesException {
Map<DependencyVector, String> unmetDependencies = new HashMap<>();
for (DependencyVector vector : vectors) {
if (!vectorsResolved.contains(vector.getIdentifier())) {
output = resolveVector(vector);
for (String item : output)
unmetDependencies.put(vector, item);
resolveVector(vector);
vectorsResolved.add(vector.getIdentifier());
}
}
if (!unmetDependencies.isEmpty())
throw new UnmetDependenciesException(unmetDependencies);
resolved = true;
return this;
}
@ -282,7 +274,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 if (!versionBigger.isEmpty() || !versionSmaller.isEmpty()) {
} else {
VersioningSystem versioningSystemSmaller = null;
VersioningSystem versioningSystemBigger = null;
@ -305,17 +297,64 @@ public final class DependencyResolver {
// Compare versions
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);
} else {
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);
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);
}
}
/*
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;

View file

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