[PlutoLib] The initial implementation of the Version API
This commit is contained in:
parent
262cba0000
commit
5bba5ceea2
|
@ -14,6 +14,10 @@
|
||||||
* `[PlutoShader]` Added the `HSBA` and `HSB` single precision float color objects
|
* `[PlutoShader]` Added the `HSBA` and `HSB` single precision float color objects
|
||||||
* `[PlutoShader]` Added methods to convert between HSBA, RGBA, HSB and RGB
|
* `[PlutoShader]` Added methods to convert between HSBA, RGBA, HSB and RGB
|
||||||
* `[PlutoShader]` Added the `UniformRGBA` and `UniformRGB` shader uniform types
|
* `[PlutoShader]` Added the `UniformRGBA` and `UniformRGB` shader uniform types
|
||||||
|
* `[PlutoLib]` Created the Version API
|
||||||
|
* Added the `IVersion` interface
|
||||||
|
* Added support for version objects
|
||||||
|
* As a result, all fields except the version string are no longer compile-time constants
|
||||||
|
|
||||||
Awaiting implementation:
|
Awaiting implementation:
|
||||||
* `[PlutoLib]` Moved `cz.tefek.pluto.io.pluto.pp` to `cz.tefek.pluto.io.plutopackage`
|
* `[PlutoLib]` Moved `cz.tefek.pluto.io.pluto.pp` to `cz.tefek.pluto.io.plutopackage`
|
||||||
|
@ -31,7 +35,7 @@ Awaiting implementation:
|
||||||
* Renamed `VertexArray#createArrayAttrib` to `VertexArray#createArrayAttribute`
|
* Renamed `VertexArray#createArrayAttrib` to `VertexArray#createArrayAttribute`
|
||||||
* Renamed `VertexArray#getVertexAttribs` to `VertexArray#getVertexAttributes`
|
* Renamed `VertexArray#getVertexAttribs` to `VertexArray#getVertexAttributes`
|
||||||
* `[PlutoCore]` Made `PlutoApplication.StartupConfig` fields private, options
|
* `[PlutoCore]` Made `PlutoApplication.StartupConfig` fields private, options
|
||||||
can now only be modified only through public setters
|
can now only be modified only through public setters
|
||||||
* `[PlutoLib]` Added the `ThreadSensitive` annotation
|
* `[PlutoLib]` Added the `ThreadSensitive` annotation
|
||||||
* `[PlutoLib]` Renamed `MiniTimeCouldNotBeParsedException` to `MiniTimeParseException`
|
* `[PlutoLib]` Renamed `MiniTimeCouldNotBeParsedException` to `MiniTimeParseException`
|
||||||
* `[PlutoCore]` Refactored `InputBus` and added several convenience methods
|
* `[PlutoCore]` Refactored `InputBus` and added several convenience methods
|
||||||
|
|
|
@ -2,6 +2,35 @@ apply plugin: 'java-library'
|
||||||
|
|
||||||
description = ""
|
description = ""
|
||||||
|
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
config {
|
||||||
|
java {
|
||||||
|
srcDir "src/config/java"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
main {
|
||||||
|
java {
|
||||||
|
compileClasspath += config.output
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task generateConfigs(type: Copy) {
|
||||||
|
def projectVariables = [
|
||||||
|
plutoVersion: project.version,
|
||||||
|
]
|
||||||
|
|
||||||
|
inputs.properties projectVariables
|
||||||
|
from 'src/config/java'
|
||||||
|
into "$buildDir/generated/java"
|
||||||
|
|
||||||
|
expand projectVariables
|
||||||
|
}
|
||||||
|
|
||||||
|
compileJava.dependsOn generateConfigs
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
|
api platform("org.lwjgl:lwjgl-bom:$lwjglVersion")
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
package cz.tefek.pluto;
|
||||||
|
|
||||||
|
class PlutoVersionConfig
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The combined version string.
|
||||||
|
*
|
||||||
|
* @since 20.2.0.0-alpha.3
|
||||||
|
* */
|
||||||
|
protected static final String VERSION = "$plutoVersion";
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package cz.tefek.pluto;
|
||||||
|
|
||||||
|
public interface IVersion<T> extends Comparable<T>
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
boolean equals(Object o);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
int hashCode();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
String toString();
|
||||||
|
}
|
|
@ -7,65 +7,70 @@ package cz.tefek.pluto;
|
||||||
*
|
*
|
||||||
* @author 493msi
|
* @author 493msi
|
||||||
*/
|
*/
|
||||||
public class Pluto
|
public class Pluto extends PlutoVersionConfig
|
||||||
{
|
{
|
||||||
public static final boolean DEBUG_MODE = Boolean.parseBoolean(System.getProperty("cz.tefek.pluto.debug"));
|
public static final boolean DEBUG_MODE = Boolean.parseBoolean(System.getProperty("cz.tefek.pluto.debug"));
|
||||||
|
|
||||||
// TODO: Automate setting the version numbers with gradle
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The year version number, changes with breaking API changes.
|
|
||||||
*
|
|
||||||
* @since pre-alpha
|
|
||||||
* */
|
|
||||||
public static final int VERSION_YEAR = 20;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The major version number, changes with breaking API changes.
|
|
||||||
*
|
|
||||||
* @since pre-alpha
|
|
||||||
* */
|
|
||||||
public static final int VERSION_MAJOR = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The minor version number, changes with backwards-compatible API changes.
|
|
||||||
*
|
|
||||||
* @since pre-alpha
|
|
||||||
* */
|
|
||||||
public static final int VERSION_MINOR = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The patch number, changes with backwards-compatible fixes and patches.
|
|
||||||
*
|
|
||||||
* @since pre-alpha
|
|
||||||
* */
|
|
||||||
public static final int VERSION_PATCH = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Denotes whether this build is a pre-release build.
|
|
||||||
*
|
|
||||||
* @since pre-alpha
|
|
||||||
* */
|
|
||||||
public static final boolean PRERELEASE = true;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The name of this pre-release, e.g. alpha, beta, RC and similar.
|
|
||||||
*
|
|
||||||
* @since pre-alpha
|
|
||||||
* */
|
|
||||||
public static final String PRERELEASE_NAME = "alpha";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The pre-release patch number, incremented by 1 with *any* pre-release update.
|
|
||||||
*
|
|
||||||
* @since pre-alpha
|
|
||||||
* */
|
|
||||||
public static final int PRERELEASE_PATCH = 3;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The combined version string.
|
* The combined version string.
|
||||||
*
|
*
|
||||||
* @since pre-alpha
|
* @since pre-alpha
|
||||||
* */
|
* */
|
||||||
public static final String VERSION = VERSION_YEAR + "." + VERSION_MAJOR + "." + VERSION_MINOR + "." + VERSION_PATCH + (PRERELEASE ? "-" + PRERELEASE_NAME + "." + PRERELEASE_PATCH : "");
|
public static final String VERSION = PlutoVersionConfig.VERSION;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The version object.
|
||||||
|
*
|
||||||
|
* @since 20.2.0.0-alpha.3
|
||||||
|
* */
|
||||||
|
public static final PlutoVersion VERSION_OBJ = PlutoVersion.of(VERSION);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The year version number, changes with breaking API changes.
|
||||||
|
*
|
||||||
|
* @since pre-alpha
|
||||||
|
* */
|
||||||
|
public static final int VERSION_YEAR = VERSION_OBJ.getYear();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The major version number, changes with breaking API changes.
|
||||||
|
*
|
||||||
|
* @since pre-alpha
|
||||||
|
* */
|
||||||
|
public static final int VERSION_MAJOR = VERSION_OBJ.getMajor();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The minor version number, changes with backwards-compatible API changes.
|
||||||
|
*
|
||||||
|
* @since pre-alpha
|
||||||
|
* */
|
||||||
|
public static final int VERSION_MINOR = VERSION_OBJ.getMinor();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The patch number, changes with backwards-compatible fixes and patches.
|
||||||
|
*
|
||||||
|
* @since pre-alpha
|
||||||
|
* */
|
||||||
|
public static final int VERSION_PATCH = VERSION_OBJ.getPatch();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Denotes whether this build is a pre-release build.
|
||||||
|
*
|
||||||
|
* @since pre-alpha
|
||||||
|
* */
|
||||||
|
public static final boolean PRERELEASE = VERSION_OBJ.isPrerelease();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of this pre-release, e.g. alpha, beta, RC and similar.
|
||||||
|
*
|
||||||
|
* @since pre-alpha
|
||||||
|
* */
|
||||||
|
public static final String PRERELEASE_NAME = VERSION_OBJ.getPrereleaseName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The pre-release patch number, incremented by 1 with *any* pre-release update.
|
||||||
|
*
|
||||||
|
* @since pre-alpha
|
||||||
|
* */
|
||||||
|
public static final int PRERELEASE_PATCH = VERSION_OBJ.getPrereleaseNumber();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,216 @@
|
||||||
|
package cz.tefek.pluto;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import cz.tefek.pluto.annotation.ConstantExpression;
|
||||||
|
|
||||||
|
public final class PlutoVersion implements IVersion<PlutoVersion>
|
||||||
|
{
|
||||||
|
private final int year;
|
||||||
|
private final int major;
|
||||||
|
private final int minor;
|
||||||
|
private final int patch;
|
||||||
|
|
||||||
|
private final boolean prerelease;
|
||||||
|
private final String prereleaseName;
|
||||||
|
private final int prereleaseNumber;
|
||||||
|
|
||||||
|
public PlutoVersion(int year, int major, int minor, int patch)
|
||||||
|
{
|
||||||
|
this.year = year;
|
||||||
|
this.major = major;
|
||||||
|
this.minor = minor;
|
||||||
|
this.patch = patch;
|
||||||
|
|
||||||
|
this.prerelease = false;
|
||||||
|
this.prereleaseName = null;
|
||||||
|
this.prereleaseNumber = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlutoVersion(int year, int major, int minor, int patch, String prereleaseName, int prereleaseNumber)
|
||||||
|
{
|
||||||
|
this.year = year;
|
||||||
|
this.major = major;
|
||||||
|
this.minor = minor;
|
||||||
|
this.patch = patch;
|
||||||
|
|
||||||
|
this.prerelease = true;
|
||||||
|
this.prereleaseName = prereleaseName;
|
||||||
|
this.prereleaseNumber = prereleaseNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getYear()
|
||||||
|
{
|
||||||
|
return this.year;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMajor()
|
||||||
|
{
|
||||||
|
return this.major;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMinor()
|
||||||
|
{
|
||||||
|
return this.minor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPatch()
|
||||||
|
{
|
||||||
|
return this.patch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPrerelease()
|
||||||
|
{
|
||||||
|
return this.prerelease;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPrereleaseName()
|
||||||
|
{
|
||||||
|
return this.prereleaseName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPrereleaseNumber()
|
||||||
|
{
|
||||||
|
return this.prereleaseNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ConstantExpression
|
||||||
|
public static PlutoVersion of(@Nonnull String str)
|
||||||
|
{
|
||||||
|
assert !str.isBlank();
|
||||||
|
|
||||||
|
assert str.matches("[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+([+\\-][a-zA-Z0-9]+(\\.[0-9]+)?)?");
|
||||||
|
|
||||||
|
var parts = str.split("[+\\-]");
|
||||||
|
|
||||||
|
assert parts.length == 1 || parts.length == 2;
|
||||||
|
|
||||||
|
var versionParts = parts[0].split("\\.");
|
||||||
|
|
||||||
|
assert versionParts.length == 4;
|
||||||
|
|
||||||
|
if (parts.length == 2)
|
||||||
|
{
|
||||||
|
var prereleaseParts = parts[1].split("\\.");
|
||||||
|
|
||||||
|
assert prereleaseParts.length == 1 || prereleaseParts.length == 2;
|
||||||
|
|
||||||
|
int prereleaseNumber;
|
||||||
|
|
||||||
|
if (prereleaseParts.length == 2)
|
||||||
|
prereleaseNumber = Integer.parseInt(prereleaseParts[1]);
|
||||||
|
else
|
||||||
|
prereleaseNumber = 0;
|
||||||
|
|
||||||
|
String prereleaseName = prereleaseParts[0];
|
||||||
|
|
||||||
|
return new PlutoVersion(
|
||||||
|
Integer.parseInt(versionParts[0]),
|
||||||
|
Integer.parseInt(versionParts[1]),
|
||||||
|
Integer.parseInt(versionParts[2]),
|
||||||
|
Integer.parseInt(versionParts[3]),
|
||||||
|
prereleaseName,
|
||||||
|
prereleaseNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PlutoVersion(
|
||||||
|
Integer.parseInt(versionParts[0]),
|
||||||
|
Integer.parseInt(versionParts[1]),
|
||||||
|
Integer.parseInt(versionParts[2]),
|
||||||
|
Integer.parseInt(versionParts[3]));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
if (prerelease)
|
||||||
|
return String.format("%d.%d.%d.%d-%s.%d",
|
||||||
|
this.year,
|
||||||
|
this.major,
|
||||||
|
this.minor,
|
||||||
|
this.patch,
|
||||||
|
this.prereleaseName,
|
||||||
|
this.prereleaseNumber);
|
||||||
|
else
|
||||||
|
return String.format("%d.%d.%d.%d",
|
||||||
|
this.year,
|
||||||
|
this.major,
|
||||||
|
this.minor,
|
||||||
|
this.patch);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(@Nonnull PlutoVersion o)
|
||||||
|
{
|
||||||
|
int yearDiff = this.year - o.year;
|
||||||
|
if (yearDiff != 0)
|
||||||
|
return yearDiff;
|
||||||
|
|
||||||
|
int majorDiff = this.major - o.major;
|
||||||
|
if (majorDiff != 0)
|
||||||
|
return majorDiff;
|
||||||
|
|
||||||
|
int minorDiff = this.minor - o.minor;
|
||||||
|
if (minorDiff != 0)
|
||||||
|
return minorDiff;
|
||||||
|
|
||||||
|
int patchDiff = this.patch - o.patch;
|
||||||
|
if (patchDiff != 0)
|
||||||
|
return patchDiff;
|
||||||
|
|
||||||
|
if (!this.prerelease && !o.prerelease)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!this.prerelease)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (!o.prerelease)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
assert this.prereleaseName != null;
|
||||||
|
assert o.prereleaseName != null;
|
||||||
|
|
||||||
|
int prereleaseNameDiff = this.prereleaseName.compareTo(o.prereleaseName);
|
||||||
|
|
||||||
|
if (prereleaseNameDiff != 0)
|
||||||
|
return prereleaseNameDiff;
|
||||||
|
|
||||||
|
return this.prereleaseNumber - o.prereleaseNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o)
|
||||||
|
{
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (o == null || getClass() != o.getClass())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
PlutoVersion that = (PlutoVersion) o;
|
||||||
|
|
||||||
|
if (prerelease)
|
||||||
|
return year == that.year &&
|
||||||
|
major == that.major &&
|
||||||
|
minor == that.minor &&
|
||||||
|
patch == that.patch &&
|
||||||
|
prereleaseNumber == that.prereleaseNumber &&
|
||||||
|
Objects.equals(prereleaseName, that.prereleaseName);
|
||||||
|
else
|
||||||
|
return year == that.year &&
|
||||||
|
major == that.major &&
|
||||||
|
minor == that.minor &&
|
||||||
|
patch == that.patch;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
if (prerelease)
|
||||||
|
return Objects.hash(year, major, minor, patch);
|
||||||
|
else
|
||||||
|
return Objects.hash(year, major, minor, patch, prereleaseName, prereleaseNumber);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue