Update DependencyVector

This commit introduces a "Builder" nested class, adds a way to specify which other vector a vector provides and includes a few smaller changes to DependencyVectors.
This commit does not work at the moment as I'm in the process of rewriting the DependencyResolver to work correctly, as it should.
This commit is contained in:
JeremyStar™ 2024-08-17 13:26:12 +02:00
parent 468e206fab
commit 58b9b268a1
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
10 changed files with 353 additions and 46 deletions

View file

@ -77,6 +77,10 @@ public final class AnsiSubsystem extends SubsystemClass {
/** {@inheritDoc} */
@Override
public @NotNull DependencyVector getDependencyVector() {
return new DependencyVector("ansi", StarOpenSourceVersioningSystem.class, EngineInformation.getVersioningString());
return new DependencyVector.Builder()
.setIdentifier("ansi")
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
.setVersion(EngineInformation.getVersioningString())
.build();
}
}

View file

@ -435,7 +435,11 @@ public final class Engine extends SubsystemClass {
/** {@inheritDoc} */
@Override
public @NotNull DependencyVector getDependencyVector() {
return new DependencyVector("engine", StarOpenSourceVersioningSystem.class, EngineInformation.getVersioningString());
return new DependencyVector.Builder()
.setIdentifier("engine")
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
.setVersion(EngineInformation.getVersioningString())
.build();
}
/**

View file

@ -24,8 +24,9 @@ import de.staropensource.sosengine.base.classes.VersioningSystem;
import de.staropensource.sosengine.base.types.DependencyVector;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Set;
/**
* Represents a dependency vector with an additional {@code mainClass} field.
@ -50,41 +51,83 @@ public final class DependencySubsystemVector extends DependencyVector {
private final SubsystemClass mainClass;
/**
* Reuses a {@link DependencyVector} instance.
* Reuses an existing {@link DependencyVector} to create a new {@link DependencySubsystemVector}.
*
* @param vector existing dependency vector to use
* @param vector existing dependency vector to reuse
* @param mainClass {@link SubsystemClass} to associate
* @since v1-alpha1
*/
public DependencySubsystemVector(@NotNull DependencyVector vector, @NotNull SubsystemClass mainClass) {
super(mainClass.getName(), vector.getVersioningSystem(), vector.getVersion(), vector.getDependencies());
super(mainClass.getName(), vector.getVersioningSystem(), vector.getVersion(), vector.getDependencies(), vector.getProvides());
this.mainClass = mainClass;
}
/**
* Creates a new dependency vector.
* Creates a new {@link DependencySubsystemVector}.
*
* @param versioningSystem versioning system to use
* @param version version
* @param dependencies dependencies in the usual format ({@code dependencyA}, {@code dependencyB=5.1}, {@code dependencyC>3.1}, {@code dependencyD<6.1})
* @param dependencies dependencies in the usual format ({@code dependencyA}, {@code dependencyB=5.1}, {@code dependencyC>3.1}, {@code dependencyD<6.1}, {@code dependencyE>5.3<5.4})
* @param provides vectors this vector provides, in the usual format ({@code identifier=version})
* @param mainClass {@link SubsystemClass} to associate
* @since v1-alpha1
*/
public DependencySubsystemVector(@NotNull Class<? extends VersioningSystem> versioningSystem, @NotNull String version, @NotNull List<@NotNull String> dependencies, @NotNull SubsystemClass mainClass) {
super(mainClass.getName(), versioningSystem, version, dependencies);
public DependencySubsystemVector(@NotNull Class<? extends VersioningSystem> versioningSystem, @NotNull String version, @NotNull Set<@NotNull String> dependencies, @NotNull Set<@NotNull String> provides, @NotNull SubsystemClass mainClass) {
super(mainClass.getName(), versioningSystem, version, dependencies, provides);
this.mainClass = mainClass;
}
/**
* Creates a new dependency vector.
* Provides an API for building {@link DependencySubsystemVector}s more easily.
*
* @param versioningSystem versioning system to use
* @param version version
* @param mainClass {@link SubsystemClass} to associate
* @since v1-alpha1
* @since v1-alpha4
*/
public DependencySubsystemVector(@NotNull Class<? extends VersioningSystem> versioningSystem, @NotNull String version, @NotNull SubsystemClass mainClass) {
super(mainClass.getName(), versioningSystem, version);
this.mainClass = mainClass;
public static final class Builder extends DependencyVector.Builder {
/**
* Contains the {@link SubsystemClass} to associate.
*
* @see DependencySubsystemVector#mainClass
* @since v1-alpha4
*/
private @Nullable SubsystemClass mainClass;
/**
* {@inheritDoc}
* @deprecated Use {@link #buildCustom()} instead
*/
@Deprecated
@Override
public @NotNull DependencyVector build() {
return super.build();
}
/**
* Builds a new {@link DependencySubsystemVector} instance.
*
* @return new {@link DependencySubsystemVector}
* @throws IllegalStateException if the identifier, versioning system, version or main class is unset
* @since v1-alpha4
*/
public DependencySubsystemVector buildCustom() {
setIdentifier("this does not need to be set");
// Check for required fields
checkRequiredFields();
// Set defaults
setDefaults();
//noinspection DataFlowIssue // IDE is dumb
return new DependencySubsystemVector(getVersioningSystem(), getVersion(), getDependencies(), getProvides(), mainClass);
}
/** {@inheritDoc} */
@Override
protected void checkRequiredFields() throws IllegalStateException {
super.checkRequiredFields();
if (mainClass == null)
throw new IllegalStateException("The main class is unset");
}
}
}

View file

@ -245,12 +245,12 @@ public final class LoggerInstance {
public LoggerInstance build() throws IllegalStateException {
// Check for required fields
if (clazz == null)
throw new IllegalStateException("The class is unset.");
throw new IllegalStateException("The class is unset");
// Set defaults
if (origin == null || origin.isEmpty())
if (origin == null || origin.isBlank())
origin = "APPLICATION";
if (metadata == null || metadata.isEmpty())
if (metadata == null || metadata.isBlank())
metadata = null;
return new LoggerInstance(clazz, origin, metadata);

View file

@ -23,9 +23,10 @@ import de.staropensource.sosengine.base.classes.VersioningSystem;
import de.staropensource.sosengine.base.utility.DependencyResolver;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.HashSet;
import java.util.Set;
/**
* Represents a dependency vector, used by {@link DependencyResolver}.
@ -72,16 +73,28 @@ public class DependencyVector {
protected @NotNull String version;
/**
* Contains all vectors this vector hard-depends on.
* Contains a set of all identifiers and their versions this vector depends on.
*
* @since v1-alpha1
* @since v1-alpha4
* -- GETTER --
* Returns all vectors this vector hard-depends on.
* Contains a set of all identifiers and their versions this vector depends on.
*
* @return hard dependencies
* @return dependencies
* @since v1-alpha1
*/
protected @NotNull List<@NotNull String> dependencies;
protected @NotNull Set<@NotNull String> dependencies;
/**
* Contains a set of all identifiers and their versions this vector provides.
*
* @since v1-alpha4
* -- GETTER --
* Contains a set of all identifiers and their versions this vector provides.
*
* @return provided vectors
* @since v1-alpha4
*/
protected @NotNull Set<@NotNull String> provides;
/**
* Creates a new dependency vector.
@ -89,26 +102,229 @@ public class DependencyVector {
* @param identifier identifier (name for example)
* @param versioningSystem versioning system to use
* @param version version
* @param dependencies dependencies in the usual format ({@code dependencyA}, {@code dependencyB=5.1}, {@code dependencyC>3.1}, {@code dependencyD<6.1})
* @param dependencies dependencies in the usual format ({@code dependencyA}, {@code dependencyB=5.1}, {@code dependencyC>3.1}, {@code dependencyD<6.1}, {@code dependencyE>5.3<5.4})
* @param provides vectors this vector provides, in the usual format ({@code identifier=version})
* @since v1-alpha4
*/
public DependencyVector(@NotNull String identifier, @NotNull Class<? extends VersioningSystem> versioningSystem, @NotNull String version, @NotNull List<@NotNull String> dependencies) {
protected DependencyVector(@NotNull String identifier, @NotNull Class<? extends VersioningSystem> versioningSystem, @NotNull String version, @NotNull Set<@NotNull String> dependencies, @NotNull Set<@NotNull String> provides) {
this.identifier = identifier;
this.versioningSystem = versioningSystem;
this.version = version;
this.dependencies = dependencies;
this.provides = provides;
}
/**
* Creates a new dependency vector.
* Provides an API for building {@link DependencyVector}s more easily.
*
* @param identifier identifier (name for example)
* @param versioningSystem versioning system to use
* @param version version
* @since v1-alpha4
*/
public DependencyVector(@NotNull String identifier, @NotNull Class<? extends VersioningSystem> versioningSystem, @NotNull String version) {
this.identifier = identifier;
this.versioningSystem = versioningSystem;
this.version = version;
this.dependencies = new ArrayList<>();
@SuppressWarnings({ "unused" })
public static class Builder {
/**
* Contains the identifier of the new vector.
*
* @see DependencyVector#identifier
* @since v1-alpha4
*/
private @Nullable String identifier;
/**
* Contains which versioning system the new vector should use.
*
* @see DependencyVector#versioningSystem
* @since v1-alpha4
*/
private @Nullable Class<? extends VersioningSystem> versioningSystem;
/**
* Contains the version of the new vector.
*
* @see DependencyVector#version
* @since v1-alpha4
*/
private @Nullable String version;
/**
* Contains a set of all identifiers and their versions the new vector should depend on.
*
* @see DependencyVector#dependencies
* @since v1-alpha4
*/
private @Nullable Set<@NotNull String> dependencies;
/**
* Contains a set of all identifiers and their versions the new vector should provide.
*
* @see DependencyVector#provides
* @since v1-alpha4
*/
private @Nullable Set<@NotNull String> provides;
/**
* Constructs this class.
*
* @since v1-alpha4
*/
public Builder() {}
/**
* Builds a new {@link DependencyVector} instance.
*
* @return new {@link DependencyVector}
* @throws IllegalStateException if the identifier, versioning system or version is unset
* @since v1-alpha4
*/
public @NotNull DependencyVector build() throws IllegalStateException {
// Check for required fields
checkRequiredFields();
// Set defaults
setDefaults();
//noinspection DataFlowIssue // IDE is dumb
return new DependencyVector(identifier, versioningSystem, version, dependencies, provides);
}
/**
* Checks for required fields.
*
* @since v1-alpha4
*/
protected void checkRequiredFields() throws IllegalStateException {
if (identifier == null || identifier.isBlank())
throw new IllegalStateException("The identifier is unset");
if (versioningSystem == null)
throw new IllegalStateException("The versioning system is unset");
if (version == null || version.isBlank())
throw new IllegalStateException("The version is unset");
}
/**
* Allows extenders to set defaults.
*
* @since v1-alpha4
*/
protected void setDefaults() {
if (dependencies == null)
dependencies = new HashSet<>();
if (provides == null)
provides = new HashSet<>();
}
/**
* Returns the identifier of the new vector.
*
* @return identifier
* @see DependencyVector#identifier
* @since v1-alpha4
*/
public final @Nullable String getIdentifier() {
return identifier;
}
/**
* Returns the versioning system the new vector should use.
*
* @return versioning system to use
* @see DependencyVector#versioningSystem
* @since v1-alpha4
*/
public final @Nullable Class<? extends VersioningSystem> getVersioningSystem() {
return versioningSystem;
}
/**
* Returns the version of the new vector.
*
* @return vector version
* @see DependencyVector#version
* @since v1-alpha4
*/
public final @Nullable String getVersion() {
return version;
}
/**
* Contains a set of all identifiers and their versions the new vector should depend on.
*
* @return dependencies
* @see DependencyVector#dependencies
* @since v1-alpha4
*/
public final @Nullable Set<@NotNull String> getDependencies() {
return dependencies;
}
/**
* Contains a set of all identifiers and their versions the new vector should provide.
*
* @return provided vectors
* @see DependencyVector#provides
* @since v1-alpha4
*/
public final @Nullable Set<@NotNull String> getProvides() {
return provides;
}
/**
* Sets the identifier of the new vector.
*
* @param identifier new identifier
* @see DependencyVector#identifier
* @since v1-alpha4
*/
public final @NotNull DependencyVector.Builder setIdentifier(@Nullable String identifier) {
this.identifier = identifier;
return this;
}
/**
* Sets the versioning system the new vector should use.
*
* @param versioningSystem versioning system to use
* @see DependencyVector#versioningSystem
* @since v1-alpha4
*/
public final @NotNull DependencyVector.Builder setVersioningSystem(@Nullable Class<? extends VersioningSystem> versioningSystem) {
this.versioningSystem = versioningSystem;
return this;
}
/**
* Sets the version of the new vector.
*
* @param version vector version
* @see DependencyVector#version
* @since v1-alpha4
*/
public final @NotNull DependencyVector.Builder setVersion(@Nullable String version) {
this.version = version;
return this;
}
/**
* Sets a set of all identifiers and their versions the new vector should depend on.
*
* @param dependencies dependencies
* @see DependencyVector#dependencies
* @since v1-alpha4
*/
public final @NotNull DependencyVector.Builder setDependencies(@Nullable Set<@NotNull String> dependencies) {
this.dependencies = dependencies;
return this;
}
/**
* Sets a set of all identifiers and their versions the new vector should provide.
*
* @param provides provided vectors
* @see DependencyVector#provides
* @since v1-alpha4
*/
public final @NotNull DependencyVector.Builder setProvides(@Nullable Set<@NotNull String> provides) {
this.provides = provides;
return this;
}
}
}

View file

@ -27,14 +27,15 @@ import de.staropensource.sosengine.base.logging.LoggerInstance;
import de.staropensource.sosengine.base.types.DependencyVector;
import de.staropensource.sosengine.base.utility.Miscellaneous;
import de.staropensource.sosengine.graphics.events.GraphicsErrorEvent;
import de.staropensource.sosengine.graphics.glfw.exceptions.GlfwInitializationException;
import de.staropensource.sosengine.graphics.exceptions.NotOnMainThreadException;
import de.staropensource.sosengine.graphics.glfw.exceptions.GlfwInitializationException;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWErrorCallbackI;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import static org.lwjgl.glfw.GLFW.*;
@ -111,7 +112,15 @@ public final class GlfwSubsystem extends SubsystemClass {
/** {@inheritDoc} */
@Override
public @NotNull DependencyVector getDependencyVector() {
return new DependencyVector(getName(), StarOpenSourceVersioningSystem.class, EngineInformation.getVersioningString(), Arrays.stream(new String[]{ "graphics" }).toList());
Set<@NotNull String> dependencies = new HashSet<>();
dependencies.add("graphics");
return new DependencyVector.Builder()
.setIdentifier(getName())
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
.setVersion(EngineInformation.getVersioningString())
.setDependencies(dependencies)
.build();
}
/**

View file

@ -37,7 +37,9 @@ import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.lwjgl.system.MemoryUtil;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import static org.lwjgl.glfw.GLFW.*;
@ -138,7 +140,16 @@ public final class OpenGlSubsystem extends ApiClass {
/** {@inheritDoc} */
@Override
public @NotNull DependencyVector getDependencyVector() {
return new DependencyVector("opengl", StarOpenSourceVersioningSystem.class, EngineInformation.getVersioningString());
Set<@NotNull String> dependencies = new HashSet<>();
dependencies.add("graphics");
dependencies.add("glfw");
return new DependencyVector.Builder()
.setIdentifier(getName())
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
.setVersion(EngineInformation.getVersioningString())
.setDependencies(dependencies)
.build();
}
/** {@inheritDoc} */

View file

@ -141,7 +141,11 @@ public final class GraphicsSubsystem extends SubsystemClass {
/** {@inheritDoc} */
@Override
public @NotNull DependencyVector getDependencyVector() {
return new DependencyVector("graphics", StarOpenSourceVersioningSystem.class, EngineInformation.getVersioningString());
return new DependencyVector.Builder()
.setIdentifier("graphics")
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
.setVersion(EngineInformation.getVersioningString())
.build();
}
/**

View file

@ -29,6 +29,9 @@ import de.staropensource.sosengine.base.utility.Miscellaneous;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.Set;
import static org.lwjgl.glfw.GLFW.glfwSetErrorCallback;
import static org.lwjgl.glfw.GLFW.glfwTerminate;
@ -110,6 +113,15 @@ public final class VulkanSubsystem extends SubsystemClass {
/** {@inheritDoc} */
@Override
public @NotNull DependencyVector getDependencyVector() {
return new DependencyVector("vulkan", StarOpenSourceVersioningSystem.class, EngineInformation.getVersioningString());
Set<@NotNull String> dependencies = new HashSet<>();
dependencies.add("graphics");
dependencies.add("glfw");
return new DependencyVector.Builder()
.setIdentifier(getName())
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
.setVersion(EngineInformation.getVersioningString())
.setDependencies(dependencies)
.build();
}
}

View file

@ -98,6 +98,10 @@ public class Slf4jCompatSubsystem extends SubsystemClass {
/** {@inheritDoc} */
@Override
public @NotNull DependencyVector getDependencyVector() {
return new DependencyVector("slf4j-compat", StarOpenSourceVersioningSystem.class, EngineInformation.getVersioningString());
return new DependencyVector.Builder()
.setIdentifier("slf4j-compat")
.setVersioningSystem(StarOpenSourceVersioningSystem.class)
.setVersion(EngineInformation.getVersioningString())
.build();
}
}