Compare commits
No commits in common. "390a5cd227e528081ddbf2c26e2acc984ccc6c94" and "ede254c7f4bd23a1f19544d98e1ccb043e8e93b6" have entirely different histories.
390a5cd227
...
ede254c7f4
5 changed files with 36 additions and 35 deletions
|
@ -413,17 +413,16 @@ public final class Engine extends SubsystemClass {
|
||||||
order.add((DependencySubsystemVector) vector);
|
order.add((DependencySubsystemVector) vector);
|
||||||
} catch (Throwable throwable) {
|
} catch (Throwable throwable) {
|
||||||
if (throwable instanceof UnmetDependenciesException exception) {
|
if (throwable instanceof UnmetDependenciesException exception) {
|
||||||
List<@NotNull String> unmetDependencies = exception.getUnmetDependencies();
|
Map<@NotNull DependencyVector, @NotNull String> unmetDependencies = exception.getUnmetDependencies();
|
||||||
StringBuilder list = new StringBuilder();
|
StringBuilder list = new StringBuilder();
|
||||||
|
|
||||||
for (String error : unmetDependencies)
|
for (DependencyVector vector : unmetDependencies.keySet())
|
||||||
list
|
list.append("- ")
|
||||||
.append("\n")
|
.append(vector.getIdentifier())
|
||||||
.append("- ")
|
.append(": ")
|
||||||
.append(error);
|
.append(unmetDependencies.get(vector));
|
||||||
|
|
||||||
logger.crash("Found unresolved dependencies:" + list, throwable);
|
logger.crash("Found unresolved dependencies:" + list, throwable);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
logger.crash("An error occurred trying to resolve subsystem dependencies: " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
|
logger.crash("An error occurred trying to resolve subsystem dependencies: " + throwable.getClass().getName() + (throwable.getMessage() == null ? "" : ": " + throwable.getMessage()));
|
||||||
throw throwable;
|
throw throwable;
|
||||||
|
|
|
@ -24,7 +24,7 @@ import de.staropensource.sosengine.base.utility.DependencyResolver;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when the {@link DependencyResolver} cannot resolve one
|
* Thrown when the {@link DependencyResolver} cannot resolve one
|
||||||
|
@ -37,24 +37,30 @@ import java.util.List;
|
||||||
public class UnmetDependenciesException extends Exception {
|
public class UnmetDependenciesException extends Exception {
|
||||||
/**
|
/**
|
||||||
* Contains the unmet dependencies list supplied to the constructor.
|
* Contains the unmet dependencies list supplied to the constructor.
|
||||||
|
* <p>
|
||||||
|
* The key contains the {@link DependencyVector} that
|
||||||
|
* has unmet dependencies, while the value contains the error.
|
||||||
*
|
*
|
||||||
* @since v1-alpha4
|
* @since v1-alpha1
|
||||||
* -- GETTER --
|
* -- GETTER --
|
||||||
* Returns the unmet dependencies list supplied to the constructor.
|
* Returns the unmet dependencies list supplied to the constructor.
|
||||||
|
* <p>
|
||||||
|
* The key contains the {@link DependencyVector} that
|
||||||
|
* has unmet dependencies, while the value contains the error.
|
||||||
*
|
*
|
||||||
* @return unmet dependencies list
|
* @return unmet dependencies list
|
||||||
* @since v1-alpha4
|
* @since v1-alpha1
|
||||||
*/
|
*/
|
||||||
private final @NotNull List<@NotNull String> unmetDependencies;
|
private final @NotNull Map<@NotNull DependencyVector, @NotNull String> unmetDependencies;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs this exception.
|
* Constructs this exception.
|
||||||
*
|
*
|
||||||
* @param unmetDependencies map of all unmet dependencies
|
* @param unmetDependencies map of all unmet dependencies
|
||||||
* @see #unmetDependencies
|
* @see #unmetDependencies
|
||||||
* @since v1-alpha4
|
* @since v1-alpha1
|
||||||
*/
|
*/
|
||||||
public UnmetDependenciesException(@NotNull List<@NotNull String> unmetDependencies) {
|
public UnmetDependenciesException(@NotNull Map<@NotNull DependencyVector, @NotNull String> unmetDependencies) {
|
||||||
this.unmetDependencies = unmetDependencies;
|
this.unmetDependencies = unmetDependencies;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,6 @@ Dear developer: FIX YOUR GODDAMN SHIT! Please check if your code or 3rd party su
|
||||||
|
|
||||||
// Escape message
|
// Escape message
|
||||||
message = message
|
message = message
|
||||||
.replace("\n", "\n ")
|
|
||||||
.replace("\\", "\\\\")
|
.replace("\\", "\\\\")
|
||||||
.replace("<", "\\<");
|
.replace("<", "\\<");
|
||||||
|
|
||||||
|
|
|
@ -79,13 +79,9 @@ public final class DependencyResolver {
|
||||||
*
|
*
|
||||||
* @param vector {@link DependencyVector} to add
|
* @param vector {@link DependencyVector} to add
|
||||||
* @return itself
|
* @return itself
|
||||||
* @throws IllegalArgumentException if the specified vector has been added already
|
|
||||||
* @since v1-alpha1
|
* @since v1-alpha1
|
||||||
*/
|
*/
|
||||||
public synchronized @NotNull DependencyResolver addVector(@NotNull DependencyVector vector) throws IllegalArgumentException {
|
public synchronized @NotNull DependencyResolver addVector(@NotNull DependencyVector vector) {
|
||||||
if (vectors.contains(vector))
|
|
||||||
throw new IllegalArgumentException("The specified vector has been added already");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
vectors.add(vector);
|
vectors.add(vector);
|
||||||
} catch (IllegalArgumentException ignored) {}
|
} catch (IllegalArgumentException ignored) {}
|
||||||
|
@ -122,17 +118,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 IllegalStateException when encountering an invalid vector
|
||||||
* @throws UnmetDependenciesException when dependencies are unmet
|
* @throws UnmetDependenciesException when dependencies are unmet
|
||||||
* @throws DependencyCycleException when a circular dependency is found
|
* @since v1-alpha1
|
||||||
* @since v1-alpha4
|
|
||||||
*/
|
*/
|
||||||
public synchronized @NotNull DependencyResolver resolve() throws IllegalStateException, UnmetDependenciesException {
|
public synchronized @NotNull DependencyResolver resolve() throws IllegalStateException, UnmetDependenciesException {
|
||||||
List<@NotNull String> unmetDependencies = new ArrayList<>();
|
Map<@NotNull DependencyVector, @NotNull String> unmetDependencies = new HashMap<>();
|
||||||
List<@NotNull String> output;
|
List<@NotNull String> output;
|
||||||
|
|
||||||
for (DependencyVector vector : vectors)
|
for (DependencyVector vector : vectors) {
|
||||||
unmetDependencies.addAll(resolveVector(vector, new LinkedHashSet<>()));
|
output = resolveVector(vector, new LinkedHashSet<>());
|
||||||
|
for (String item : output)
|
||||||
|
unmetDependencies.put(vector, item);
|
||||||
|
}
|
||||||
|
|
||||||
if (!unmetDependencies.isEmpty())
|
if (!unmetDependencies.isEmpty())
|
||||||
throw new UnmetDependenciesException(unmetDependencies);
|
throw new UnmetDependenciesException(unmetDependencies);
|
||||||
|
@ -146,12 +144,11 @@ 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 DependencyCycleException when a circular dependency is found
|
* @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, @NotNull LinkedHashSet<@NotNull String> vectorsDependencyStack) throws IllegalStateException, DependencyCycleException {
|
private @NotNull List<@NotNull String> resolveVector(@NotNull DependencyVector vector, @NotNull LinkedHashSet<@NotNull String> vectorsDependencyStack) throws IllegalStateException {
|
||||||
List<@NotNull String> unmetDependencies = new ArrayList<>();
|
List<@NotNull String> unmetDependencies = new ArrayList<>();
|
||||||
|
|
||||||
vectorsDependencyStack.add(vector.getIdentifier());
|
vectorsDependencyStack.add(vector.getIdentifier());
|
||||||
|
|
|
@ -273,8 +273,8 @@ class DependencyResolverTest extends TestBase {
|
||||||
resolver.resolve();
|
resolver.resolve();
|
||||||
} catch (UnmetDependenciesException exception) {
|
} catch (UnmetDependenciesException exception) {
|
||||||
getLogger().error("Dependency resolution failed in testResolve(layers=" + layers + "):");
|
getLogger().error("Dependency resolution failed in testResolve(layers=" + layers + "):");
|
||||||
for (String error : exception.getUnmetDependencies())
|
for (DependencyVector vector : exception.getUnmetDependencies().keySet())
|
||||||
getLogger().error("-> " + error);
|
getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector));
|
||||||
|
|
||||||
assertEquals("Please ignore this, this just exists to trigger an error", "", "Dependency resolution failed in testResolve(layers=" + layers + "): See logs");
|
assertEquals("Please ignore this, this just exists to trigger an error", "", "Dependency resolution failed in testResolve(layers=" + layers + "): See logs");
|
||||||
} catch (DependencyCycleException exception) {
|
} catch (DependencyCycleException exception) {
|
||||||
|
@ -497,8 +497,8 @@ class DependencyResolverTest extends TestBase {
|
||||||
resolver.resolve();
|
resolver.resolve();
|
||||||
} catch (UnmetDependenciesException exception) {
|
} catch (UnmetDependenciesException exception) {
|
||||||
getLogger().error("Dependency resolution failed in testResolve(layers=" + layers + ") (great!):");
|
getLogger().error("Dependency resolution failed in testResolve(layers=" + layers + ") (great!):");
|
||||||
for (String error : exception.getUnmetDependencies())
|
for (DependencyVector vector : exception.getUnmetDependencies().keySet())
|
||||||
getLogger().error("-> " + error);
|
getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} catch (DependencyCycleException exception) {
|
} catch (DependencyCycleException exception) {
|
||||||
|
@ -613,8 +613,8 @@ class DependencyResolverTest extends TestBase {
|
||||||
resolver.resolve();
|
resolver.resolve();
|
||||||
} catch (UnmetDependenciesException exception) {
|
} catch (UnmetDependenciesException exception) {
|
||||||
getLogger().error("Dependency resolution failed in testResolveDependencyCycle():");
|
getLogger().error("Dependency resolution failed in testResolveDependencyCycle():");
|
||||||
for (String error : exception.getUnmetDependencies())
|
for (DependencyVector vector : exception.getUnmetDependencies().keySet())
|
||||||
getLogger().error("-> " + error);
|
getLogger().error("-> " + vector.getIdentifier() + "=" + vector.getVersion() + ": " + exception.getUnmetDependencies().get(vector));
|
||||||
|
|
||||||
assertEquals("Please ignore this, this just exists to trigger an error", "", "Dependency resolution failed in testResolveDependencyCycle(): See logs");
|
assertEquals("Please ignore this, this just exists to trigger an error", "", "Dependency resolution failed in testResolveDependencyCycle(): See logs");
|
||||||
} catch (DependencyCycleException exception) {
|
} catch (DependencyCycleException exception) {
|
||||||
|
|
Loading…
Reference in a new issue