Migrate common library to Kotlin (not working)
This commit is contained in:
parent
151afaad40
commit
1e5e0cc47c
6 changed files with 119 additions and 422 deletions
common/src/main
java
kotlin/de/jeremystartm/pickshadow
|
@ -1,368 +0,0 @@
|
|||
/*
|
||||
* PICKSHADOW SERVER KIT SOURCE FILE
|
||||
* Copyright (c) 2024 The PickShadow Server Kit authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.jeremystartm.pickshadow.common;
|
||||
|
||||
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.VersionType;
|
||||
import de.staropensource.engine.base.utility.PropertiesReader;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Provides build information about the engine.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class PSSKInformation {
|
||||
/**
|
||||
* Contains the extensions's version codename.
|
||||
*
|
||||
* @since v1-alpha2
|
||||
* -- GETTER --
|
||||
* Returns the extensions's version codename.
|
||||
*
|
||||
* @return extensions version codename
|
||||
* @since v1-alpha2
|
||||
*/
|
||||
@Getter
|
||||
private static String versioningCodename;
|
||||
|
||||
/**
|
||||
* Contains the extensions's version.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Returns the extensions's version.
|
||||
*
|
||||
* @return extensions version
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
private static int versioningVersion;
|
||||
|
||||
/**
|
||||
* Contains the extensions's version type.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Returns the extensions's version type.
|
||||
*
|
||||
* @return extensions version type
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
private static VersionType versioningType;
|
||||
|
||||
/**
|
||||
* Contains the extensions's typerelease.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Returns the extensions's typerelease.
|
||||
*
|
||||
* @return extensions typerelease
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
private static int versioningTyperelease;
|
||||
|
||||
/**
|
||||
* Contains the extensions's fork identifier.
|
||||
* <p>
|
||||
* Likely empty. If not, prefixed with a dash.
|
||||
*
|
||||
* @since v1-alpha0
|
||||
* -- GETTER --
|
||||
* Returns the extensions's fork identifier.
|
||||
* <p>
|
||||
* Likely empty. If not, prefixed with a dash.
|
||||
*
|
||||
* @return extensions fork identifier
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@Getter
|
||||
private static String versioningFork;
|
||||
|
||||
/**
|
||||
* Contains the extensions's full version string.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* -- GETTER --
|
||||
* Returns the extensions's full version string.
|
||||
*
|
||||
* @return extensions version string
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
private static String versioningString;
|
||||
|
||||
|
||||
/**
|
||||
* Contains the Java version of the extensions source.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* -- GETTER --
|
||||
* Returns the Java version of the extensions source.
|
||||
*
|
||||
* @return java version of extensions source
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
@Getter
|
||||
private static short javaSource;
|
||||
|
||||
/**
|
||||
* Contains the Java version the extensions was compiled against.
|
||||
*
|
||||
* @since v1-alpha4
|
||||
* -- GETTER --
|
||||
* Returns the Java version the extensions was compiled against.
|
||||
*
|
||||
* @return Java version compiled against
|
||||
* @since v1-alpha4
|
||||
*/
|
||||
@Getter
|
||||
private static short javaTarget;
|
||||
|
||||
|
||||
/**
|
||||
* Contains the {@code dirty} value (i.e. if the source tree has been modified).
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* -- GETTER --
|
||||
* Returns the {@code dirty} value (i.e. if the source tree has been modified).
|
||||
*
|
||||
* @return git dirty value
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
private static boolean gitDirty;
|
||||
|
||||
/**
|
||||
* Contains the branch the extensions was built on.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* -- GETTER --
|
||||
* Returns the branch the extensions was built on.
|
||||
*
|
||||
* @return git branch
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
private static String gitBranch;
|
||||
|
||||
/**
|
||||
* Contains the commit count.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* -- GETTER --
|
||||
* Returns the commit count.
|
||||
*
|
||||
* @return git commit count
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
private static int gitCommitCount;
|
||||
|
||||
/**
|
||||
* Contains the commit identifier (short form).
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* -- GETTER --
|
||||
* Returns the commit identifier (short form).
|
||||
*
|
||||
* @return git long commit id
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
private static String gitCommitIdentifierShort;
|
||||
|
||||
/**
|
||||
* Contains the commit identifier (long form).
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* -- GETTER --
|
||||
* Returns the commit identifier (long form).
|
||||
*
|
||||
* @return git long commit id
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
private static String gitCommitIdentifierLong;
|
||||
|
||||
/**
|
||||
* Contains the commit header.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* -- GETTER --
|
||||
* Returns the commit header.
|
||||
*
|
||||
* @return git commit header
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
private static String gitCommitHeader;
|
||||
|
||||
/**
|
||||
* Contains the commit time.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* -- GETTER --
|
||||
* Returns the commit time.
|
||||
*
|
||||
* @return git commit time
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
private static ZonedDateTime gitCommitTime;
|
||||
|
||||
/**
|
||||
* Contains the commiter's name.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* -- GETTER --
|
||||
* Returns the commiter's name.
|
||||
*
|
||||
* @return git committer name
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
private static String gitCommitterName;
|
||||
|
||||
/**
|
||||
* Contains the commiter's email.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
* -- GETTER --
|
||||
* Returns the commiter's email.
|
||||
*
|
||||
* @return git committer email
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
@Getter
|
||||
private static String gitCommitterEmail;
|
||||
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @since v1-alpha6
|
||||
*/
|
||||
private PSSKInformation() {}
|
||||
|
||||
/**
|
||||
* Updates all variables.
|
||||
* <p>
|
||||
* This method does not need to be invoked manually, as the information provided by
|
||||
* this class is static (does not change) and is already populated at engine startup.
|
||||
*
|
||||
* @since v1-alpha1
|
||||
*/
|
||||
public static synchronized void update() {
|
||||
Logger.diag("Updating extension information");
|
||||
|
||||
// Load properties from bundled gradle.properties
|
||||
Properties gradleProperties = new Properties();
|
||||
InputStream gradleStream = PSSKInformation.class.getClassLoader().getResourceAsStream("psse-gradle.properties");
|
||||
|
||||
if (gradleStream == null) {
|
||||
Logger.crash("Unable to load build information: The bundled gradle.properties file could not be found.");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
gradleProperties.load(gradleStream);
|
||||
gradleStream.close();
|
||||
} catch (IOException exception) {
|
||||
Logger.crash("Unable to load build information: InputStream 'gradleStream' failed", exception);
|
||||
return;
|
||||
}
|
||||
|
||||
// Load properties from bundled git.properties
|
||||
// or fill in blank information if file missing
|
||||
Properties gitProperties = new Properties();
|
||||
InputStream gitStream = PSSKInformation.class.getClassLoader().getResourceAsStream("psse-git.properties");
|
||||
if (gitStream == null) {
|
||||
Logger.error("Unable to load build information: The bundled git.properties file could not be found. Did you download a tarball?");
|
||||
|
||||
// Fake information
|
||||
gitProperties.setProperty("git.total.commit.count", "0");
|
||||
gitProperties.setProperty("git.dirty", "true");
|
||||
gitProperties.setProperty("git.branch", "/git.properties is missing/");
|
||||
gitProperties.setProperty("git.commit.id", "########################################");
|
||||
gitProperties.setProperty("git.commit.id.abbrev", "#######");
|
||||
gitProperties.setProperty("git.commit.message.short", "git.properties file is missing :/");
|
||||
gitProperties.setProperty("git.commit.time", "1970-01-01T00:00+0000");
|
||||
gitProperties.setProperty("git.commit.user.name", "git.properties file is missing :/");
|
||||
gitProperties.setProperty("git.commit.user.email", "git.properties-is-missing@example.com");
|
||||
} else {
|
||||
// Load real information from git.properties file
|
||||
try {
|
||||
gitProperties.load(gitStream);
|
||||
gitStream.close();
|
||||
} catch (IOException exception) {
|
||||
Logger.crash("Unable to load build information: InputStream 'gitStream' failed", exception);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Create new PropertyParsers
|
||||
PropertiesReader gradleParser = new PropertiesReader(gradleProperties);
|
||||
PropertiesReader gitParser = new PropertiesReader(gitProperties);
|
||||
|
||||
// Apply properties to fields
|
||||
versioningCodename = gradleParser.getString("versioningCodename");
|
||||
versioningVersion = gradleParser.getInteger("versioningVersion", true);
|
||||
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().toLowerCase(Locale.ROOT)) + versioningTyperelease + versioningFork;
|
||||
|
||||
javaSource = gradleParser.getShort("javaSource");
|
||||
javaTarget = gradleParser.getShort("javaTarget");
|
||||
|
||||
gitDirty = gitParser.getBoolean("git.dirty");
|
||||
gitBranch = gitParser.getString("git.branch");
|
||||
gitCommitCount = gitParser.getInteger("git.total.commit.count", true);
|
||||
gitCommitIdentifierShort = gitParser.getString("git.commit.id.abbrev");
|
||||
gitCommitIdentifierLong = gitParser.getString("git.commit.id");
|
||||
gitCommitHeader = gitParser.getString("git.commit.message.short");
|
||||
try {
|
||||
Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mmZ").parse(gitParser.getString("git.commit.time"));
|
||||
GregorianCalendar calendar = new GregorianCalendar();
|
||||
calendar.setTime(date);
|
||||
gitCommitTime = calendar.toZonedDateTime();
|
||||
} catch (ParseException exception) {
|
||||
Logger.crash("Unable to load build information: Can't parse \"" + gitParser.getString("git.commit.time") + "\" using format \"yyyy-MM-dd'T'HH:mmZ\"", exception);
|
||||
}
|
||||
gitCommitterName = gitParser.getString("git.commit.user.name");
|
||||
gitCommitterEmail = gitParser.getString("git.commit.user.email");
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
/**
|
||||
* Code commonly used across PSSK's codebase.
|
||||
*
|
||||
* @since v1-release0
|
||||
*/
|
||||
module pickshadow.common {
|
||||
// Libraries
|
||||
requires sosengine.base;
|
||||
|
||||
// API access
|
||||
exports de.jeremystartm.pickshadow.common;
|
||||
|
||||
// Reflection access
|
||||
opens de.jeremystartm.pickshadow.common;
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* PICKSHADOW SERVER KIT SOURCE FILE
|
||||
* Copyright (c) 2024 The PickShadow Server Kit authors
|
||||
* Licensed under the GNU Affero General Public License v3
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package de.jeremystartm.pickshadow.common
|
||||
|
||||
import de.staropensource.engine.base.EngineConfiguration
|
||||
import de.staropensource.engine.base.logging.Logger
|
||||
import de.staropensource.engine.base.type.logging.ChannelSettings
|
||||
import de.staropensource.engine.base.utility.dnihbd.BuildInformation
|
||||
import lombok.Getter
|
||||
|
||||
/**
|
||||
* Initializes and manages the PickShadow Common Library.
|
||||
*
|
||||
* @since v1-release0
|
||||
*/
|
||||
class CommonLibrary private constructor() {
|
||||
companion object {
|
||||
/**
|
||||
* Contains the [Logger] instance
|
||||
* of the common library.
|
||||
*
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
internal val logger: Logger = Logger(channel = "pickshadow-common")
|
||||
|
||||
/**
|
||||
* Contains a [BuildInformation] instance
|
||||
* providing information about the running
|
||||
* engine build.
|
||||
*
|
||||
* @see BuildInformation
|
||||
* @since v1-alpha10
|
||||
*/
|
||||
@JvmStatic
|
||||
var info: BuildInformation? = null
|
||||
|
||||
/**
|
||||
* Contains whether the common
|
||||
* library has initialized.
|
||||
*
|
||||
* @since v1-release0
|
||||
* -- GETTER --
|
||||
* Returns whether the common
|
||||
* library has initialized.
|
||||
*
|
||||
* @return initialized?
|
||||
* @since v1-release0
|
||||
*/
|
||||
@Getter
|
||||
@JvmStatic
|
||||
private var initialized: Boolean = false
|
||||
|
||||
/**
|
||||
* Initializes the common library,
|
||||
* if it isn't already.
|
||||
*
|
||||
* @since v1-release0
|
||||
*/
|
||||
@JvmStatic
|
||||
fun initialize() {
|
||||
if (initialized)
|
||||
return
|
||||
|
||||
// Bootstrap
|
||||
// -> Add logging channel
|
||||
EngineConfiguration.logChannelSettings.put(
|
||||
"pickshadow-common",
|
||||
ChannelSettings()
|
||||
)
|
||||
|
||||
// -> Initialize 'info'
|
||||
info = PSSKInformation()
|
||||
|
||||
|
||||
// Initialize
|
||||
logger.verb("Initializing the PickShadow Common Library")
|
||||
|
||||
|
||||
// Finish
|
||||
logger.verb("Initialized the PickShadow Common Library")
|
||||
initialized = true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,48 +19,27 @@
|
|||
|
||||
package de.jeremystartm.pickshadow.common;
|
||||
|
||||
|
||||
import de.staropensource.engine.base.logging.Logger;
|
||||
import de.staropensource.engine.base.type.versioning.VersionType.V2;
|
||||
import de.staropensource.engine.base.utility.dnihbd.BuildInformation;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Initializes and manages the PickShadow Common Library.
|
||||
* Provides build information about the common library.
|
||||
*
|
||||
* @since v1-release0
|
||||
* @since v1-alpha0
|
||||
*/
|
||||
@SuppressWarnings({ "JavadocDeclaration" })
|
||||
public final class CommonLibrary {
|
||||
/**
|
||||
* Contains the global instance of this class.
|
||||
*
|
||||
* @since v1-release0
|
||||
* -- GETTER --
|
||||
* Returns the global instance of this class.
|
||||
*
|
||||
* @return global instance
|
||||
* @since v1-release0
|
||||
*/
|
||||
@Getter
|
||||
private static CommonLibrary instance = null;
|
||||
|
||||
/**
|
||||
* Creates and initializes an instance of this class.
|
||||
*
|
||||
* @since v1-release0
|
||||
*/
|
||||
private CommonLibrary() {
|
||||
Logger.verb("Initializing the PickShadow Common Library");
|
||||
|
||||
PSSKInformation.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the common library,
|
||||
* if it isn't already.
|
||||
*
|
||||
* @since v1-release0
|
||||
*/
|
||||
public static void initialize() {
|
||||
if (instance == null)
|
||||
instance = new CommonLibrary();
|
||||
}
|
||||
}
|
||||
class PSSKInformation : BuildInformation(
|
||||
loadPrefix = "pickshadow-common"
|
||||
)
|
Loading…
Add table
Reference in a new issue