Compare commits

...

2 commits

4 changed files with 20 additions and 2 deletions

View file

@ -321,6 +321,8 @@ public final class Engine extends SubsystemClass {
//noinspection DataFlowIssue // the crash call will prevent a NullPointerException
subsystemsMutable.add(new DependencySubsystemVector(initializedClass.getDependencyVector(), initializedClass));
} catch (Exception exception) {
if (exception.getClass() == IllegalStateException.class && exception.getMessage().startsWith("The version string is invalid: "))
logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Invalid version string: " + exception.getMessage().replace("The version string is invalid: ", ""));
logger.crash("Failed to initialize subsystem " + clazz.getName() + ": Method invocation error", exception);
}
}

View file

@ -22,6 +22,7 @@ package de.staropensource.sosengine.base.classes;
import de.staropensource.sosengine.base.Engine;
import de.staropensource.sosengine.base.annotations.EngineSubsystem;
import de.staropensource.sosengine.base.annotations.EventListener;
import de.staropensource.sosengine.base.exceptions.versioning.InvalidVersionStringException;
import de.staropensource.sosengine.base.internal.events.InternalEngineShutdownEvent;
import de.staropensource.sosengine.base.logging.LoggerInstance;
import de.staropensource.sosengine.base.types.DependencyVector;
@ -73,7 +74,7 @@ public abstract class SubsystemClass {
* @see DependencyVector
* @since v1-alpha1
*/
public abstract @NotNull DependencyVector getDependencyVector();
public abstract @NotNull DependencyVector getDependencyVector() throws InvalidVersionStringException;
/**
* Called on engine shutdown.

View file

@ -34,6 +34,7 @@ import java.text.SimpleDateFormat;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.Properties;
/**
@ -379,7 +380,7 @@ public final class EngineInformation {
versioningType = VersionType.valueOf(gradleParser.getString("versioningType").toUpperCase());
versioningTyperelease = gradleParser.getInteger("versioningTyperelease", true);
versioningFork = gradleParser.getString("versioningFork");
versioningString = "v" + versioningVersion + "-" + (versioningType == VersionType.RELEASE_CANDIDATE ? "releasecandidate" : versioningType.name()) + versioningTyperelease + versioningFork;
versioningString = "v" + versioningVersion + "-" + (versioningType == VersionType.RELEASE_CANDIDATE ? "releasecandidate" : versioningType.name().toLowerCase(Locale.ROOT)) + versioningTyperelease + versioningFork;
dependencyJansi = gradleParser.getString("dependencyJansi");
dependencyReflections = gradleParser.getString("dependencyReflections");

View file

@ -20,11 +20,13 @@
package de.staropensource.sosengine.base.types;
import de.staropensource.sosengine.base.classes.VersioningSystem;
import de.staropensource.sosengine.base.exceptions.versioning.InvalidVersionStringException;
import de.staropensource.sosengine.base.utility.DependencyResolver;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.lang.reflect.InvocationTargetException;
import java.util.HashSet;
import java.util.Set;
@ -198,6 +200,18 @@ public class DependencyVector {
throw new IllegalStateException("The versioning system is unset");
if (version == null || version.isBlank())
throw new IllegalStateException("The version is unset");
// Check if version string is valid
try {
versioningSystem.getDeclaredConstructor(String.class).newInstance(version);
} catch (InvocationTargetException exception) {
if (exception.getTargetException().getClass() == InvalidVersionStringException.class)
throw new IllegalStateException("The version string is invalid: " + exception.getTargetException().getMessage());
else
throw new IllegalStateException("Version string validation failed: Constructor threw " + exception.getTargetException().getClass().getName() + ": " + exception.getTargetException().getMessage());
} catch (Exception exception) {
throw new IllegalStateException("Version string validation failed: Threw " + exception.getClass().getName() + ": " + exception.getMessage());
}
}
/**