diff --git a/base/.gitignore b/base/.gitignore new file mode 100644 index 0000000..33fe2c9 --- /dev/null +++ b/base/.gitignore @@ -0,0 +1 @@ +src/main/resources/git.properties diff --git a/base/build.gradle b/base/build.gradle index 75df343..b610054 100644 --- a/base/build.gradle +++ b/base/build.gradle @@ -20,6 +20,7 @@ plugins { id 'java' id 'io.freefair.lombok' version "${pluginLombok}" + id "com.gorylenko.gradle-git-properties" version "${pluginGitProperties}" id 'maven-publish' } @@ -51,6 +52,29 @@ dependencies { testImplementation 'org.jooq:joor:' + project.dependencyJoor } +gitProperties { + dotGitDirectory = file("${rootProject.rootDir}/.git") + failOnNoGitDirectory = false + extProperty = 'gitProps' + + dateFormat = "yyyy-MM-dd'T'HH:mmZ" + dateFormatTimeZone = "UTC" +} + +tasks.register("writeGitProperties") { + doLast { + File target = file("${project.projectDir}/src/main/resources/git.properties") + File source = file("${project.projectDir}/build/resources/main/git.properties") + + target.delete() + source.renameTo(target) + } + + outputs.upToDateWhen { false } +} +generateGitProperties.outputs.upToDateWhen { false } +processResources.dependsOn 'writeGitProperties' + javadoc.options { setMemberLevel(JavadocMemberLevel.PUBLIC) setOverview("src/main/javadoc/overview.html") diff --git a/base/src/main/java/de/staropensource/sosengine/base/Engine.java b/base/src/main/java/de/staropensource/sosengine/base/Engine.java index fbff927..33ed081 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/Engine.java +++ b/base/src/main/java/de/staropensource/sosengine/base/Engine.java @@ -21,6 +21,7 @@ package de.staropensource.sosengine.base; import de.staropensource.sosengine.base.classes.SubsystemMainClass; import de.staropensource.sosengine.base.classes.helpers.EventHelper; +import de.staropensource.sosengine.base.classes.logging.LogIssuer; import de.staropensource.sosengine.base.data.info.EngineInformation; import de.staropensource.sosengine.base.events.EngineCrashEvent; import de.staropensource.sosengine.base.events.EngineShutdownEvent; @@ -30,8 +31,9 @@ import de.staropensource.sosengine.base.logging.CrashHandler; import de.staropensource.sosengine.base.logging.Logger; import de.staropensource.sosengine.base.logging.LoggerInstance; import de.staropensource.sosengine.base.types.CodePart; -import de.staropensource.sosengine.base.classes.logging.LogIssuer; -import de.staropensource.sosengine.base.utility.*; +import de.staropensource.sosengine.base.utility.Miscellaneous; +import de.staropensource.sosengine.base.utility.PlaceholderEngine; +import de.staropensource.sosengine.base.utility.ShortcodeConverter; import lombok.Getter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Range; @@ -123,7 +125,7 @@ public final class Engine implements SubsystemMainClass { logger = new LoggerInstance(new LogIssuer(getClass(), CodePart.ENGINE)); }); - logger.info("Initialized sos!engine v%engine_version% in " + initTime + "ms"); + logger.info("Initialized sos!engine v%engine_version% (commit %engine_git_commit_id_long%-%engine_git_branch%, dirty %engine_git_dirty%) in " + initTime + "ms"); } /** diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/info/EngineInformation.java b/base/src/main/java/de/staropensource/sosengine/base/data/info/EngineInformation.java index 0ae7b92..742e9e6 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/data/info/EngineInformation.java +++ b/base/src/main/java/de/staropensource/sosengine/base/data/info/EngineInformation.java @@ -19,15 +19,22 @@ package de.staropensource.sosengine.base.data.info; +import de.staropensource.sosengine.base.Engine; +import de.staropensource.sosengine.base.classes.logging.LogIssuer; +import de.staropensource.sosengine.base.logging.Logger; import de.staropensource.sosengine.base.logging.LoggerInstance; import de.staropensource.sosengine.base.types.CodePart; -import de.staropensource.sosengine.base.classes.logging.LogIssuer; import de.staropensource.sosengine.base.types.VersionType; import de.staropensource.sosengine.base.utility.PropertyParser; 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.Properties; /** @@ -105,6 +112,124 @@ public final class EngineInformation { private String versioningFork; + /** + * Provides the {@code dirty} value (i.e. if the source tree has been modified). + * + * @since 1-alpha1 + * + * -- GETTER -- + * Provides the {@code dirty} value (i.e. if the source tree has been modified). + * + * @return git dirty value + * @since 1-alpha1 + */ + private Boolean gitDirty; + + /** + * Provides the branch the engine was built on. + * + * @since 1-alpha1 + * + * -- GETTER -- + * Provides the branch the engine was built on. + * + * @return git branch + * @since 1-alpha1 + */ + private String gitBranch; + + /** + * Provides the commit count. + * + * @since 1-alpha1 + * + * -- GETTER -- + * Provides the commit count. + * + * @return git commit count + * @since 1-alpha1 + */ + private int gitCommitCount; + + /** + * Provides the commit identifier (short form). + * + * @since 1-alpha1 + * + * -- GETTER -- + * Provides the commit identifier (short form). + * + * @return git long commit id + * @since 1-alpha1 + */ + private String gitCommitIdentifierShort; + + /** + * Provides the commit identifier (long form). + * + * @since 1-alpha1 + * + * -- GETTER -- + * Provides the commit identifier (long form). + * + * @return git long commit id + * @since 1-alpha1 + */ + private String gitCommitIdentifierLong; + + /** + * Provides the commit header. + * + * @since 1-alpha1 + * + * -- GETTER -- + * Provides the commit header. + * + * @return git commit header + * @since 1-alpha1 + */ + private String gitCommitHeader; + + /** + * Provides the commit time. + * + * @since 1-alpha1 + * + * -- GETTER -- + * Provides the commit time. + * + * @return git commit time + * @since 1-alpha1 + */ + private ZonedDateTime gitCommitTime; + + /** + * Provides the commiter's name. + * + * @since 1-alpha1 + * + * -- GETTER -- + * Provides the commiter's name. + * + * @return git committer name + * @since 1-alpha1 + */ + private String gitCommitterName; + + /** + * Provides the commiter's email. + * + * @since 1-alpha1 + * + * -- GETTER -- + * Provides the commiter's email. + * + * @return git committer email + * @since 1-alpha1 + */ + private String gitCommitterEmail; + + /** * Provides the version of the dependency {@code Lombok}. * @@ -215,19 +340,25 @@ public final class EngineInformation { * @since 1-alpha0 */ public EngineInformation() { - LoggerInstance logger = new LoggerInstance(new LogIssuer(getClass(), CodePart.ENGINE)); - // Only allow one instance if (instance == null) instance = this; else { - logger.crash("Tried reinitializing " + getClass().getName() + " twice"); - return; + Logger.crash(new LogIssuer(getClass(), CodePart.ENGINE), "Tried reinitializing " + getClass().getName() + " twice"); } + } + + /** + * Updates all variables. + * + * @since 1-alpha1 + */ + public void load() { + LoggerInstance logger = new LoggerInstance(new LogIssuer(getClass(), CodePart.ENGINE)); // Load properties from bundled gradle.properties - Properties properties = new Properties(); - InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("gradle.properties"); + Properties gradleProperties = new Properties(); + InputStream gradleStream = this.getClass().getClassLoader().getResourceAsStream("gradle.properties"); if (inputStream == null) { logger.crash("Unable to load build information: The bundled gradle.properties file could not be found. Do symlinks work on the system that built this JAR?"); @@ -235,30 +366,76 @@ public final class EngineInformation { } try { - properties.load(inputStream); - inputStream.close(); + gradleProperties.load(gradleStream); + gradleStream.close(); } catch (IOException exception) { logger.crash("Unable to load build information: InputStream failed", exception); return; } - // Create new PropertyParser - PropertyParser parser = new PropertyParser(properties); + // Load properties from bundled git.properties + // or fill in blank information if file missing + Properties gitProperties = new Properties(); + InputStream gitStream = this.getClass().getClassLoader().getResourceAsStream("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", "/unknown/"); + 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: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 + PropertyParser gradleParser = new PropertyParser(gradleProperties); + PropertyParser gitParser = new PropertyParser(gitProperties); // Apply properties to fields - versioningVersion = parser.getInteger("versioningVersion", true); - versioningType = VersionType.valueOf(parser.getString("versioningType").toUpperCase()); - versioningTyperelease = parser.getInteger("versioningTyperelease", true); - versioningFork = parser.getString("versioningFork"); + versioningVersion = gradleParser.getInteger("versioningVersion", true); + versioningType = VersionType.valueOf(gradleParser.getString("versioningType").toUpperCase()); + versioningTyperelease = gradleParser.getInteger("versioningTyperelease", true); + versioningFork = gradleParser.getString("versioningFork"); - dependencyLombok = parser.getString("dependencyLombok"); - dependencyJetbrainsAnnotations = parser.getString("dependencyJetbrainsAnnotations"); - dependencyJansi = parser.getString("dependencyJansi"); - dependencyReflections = parser.getString("dependencyReflections"); - dependencySlf4j = parser.getString("dependencySlf4j"); - dependencyLwjgl = parser.getString("dependencyLwjgl"); + dependencyLombok = gradleParser.getString("dependencyLombok"); + dependencyJetbrainsAnnotations = gradleParser.getString("dependencyJetbrainsAnnotations"); + dependencyJansi = gradleParser.getString("dependencyJansi"); + dependencyReflections = gradleParser.getString("dependencyReflections"); + dependencySlf4j = gradleParser.getString("dependencySlf4j"); + dependencyLwjgl = gradleParser.getString("dependencyLwjgl"); - pluginShadow = parser.getString("pluginShadow"); - pluginLombok = parser.getString("pluginLombok"); + 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 e) { + logger.crash("Unable to load build information: Can't parse \"" + gitParser.getString("git.commit.time") + "\" using format \"yyyy-MM-dd'T'HH:mmZ\""); + } + gitCommitterName = gitParser.getString("git.commit.user.name"); + gitCommitterEmail = gitParser.getString("git.commit.user.email"); + + pluginShadow = gradleParser.getString("pluginShadow"); + pluginLombok = gradleParser.getString("pluginLombok"); } } diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitBranch.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitBranch.java new file mode 100644 index 0000000..63f87c3 --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitBranch.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_branch} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitBranch implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitBranch() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_branch"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", EngineInformation.getInstance().getGitBranch()); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitHeader.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitHeader.java new file mode 100644 index 0000000..6be4944 --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitHeader.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_commit_header} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitCommitHeader implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitCommitHeader() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_commit_header"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", EngineInformation.getInstance().getGitCommitHeader()); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitIdLong.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitIdLong.java new file mode 100644 index 0000000..780764f --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitIdLong.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_commit_id_long} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitCommitIdLong implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitCommitIdLong() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_commit_id_long"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", EngineInformation.getInstance().getGitCommitIdentifierLong()); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitIdShort.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitIdShort.java new file mode 100644 index 0000000..e9eeeb3 --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitIdShort.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_commit_id_short} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitCommitIdShort implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitCommitIdShort() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_commit_id_short"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", EngineInformation.getInstance().getGitCommitIdentifierShort()); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeDay.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeDay.java new file mode 100644 index 0000000..305115f --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeDay.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_commit_time_day} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitCommitTimeDay implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitCommitTimeDay() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_commit_time_day"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", String.valueOf(EngineInformation.getInstance().getGitCommitTime().getDayOfMonth())); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeHour.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeHour.java new file mode 100644 index 0000000..35fd101 --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeHour.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_commit_time_hour} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitCommitTimeHour implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitCommitTimeHour() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_commit_time_hour"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", String.valueOf(EngineInformation.getInstance().getGitCommitTime().getHour())); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeMinute.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeMinute.java new file mode 100644 index 0000000..e6e9f71 --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeMinute.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_commit_time_minute} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitCommitTimeMinute implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitCommitTimeMinute() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_commit_time_minute"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", String.valueOf(EngineInformation.getInstance().getGitCommitTime().getMinute())); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeMonth.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeMonth.java new file mode 100644 index 0000000..5644e37 --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeMonth.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_commit_time_month} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitCommitTimeMonth implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitCommitTimeMonth() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_commit_time_month"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", String.valueOf(EngineInformation.getInstance().getGitCommitTime().getMonth())); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeSecond.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeSecond.java new file mode 100644 index 0000000..5802671 --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeSecond.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_commit_time_second} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitCommitTimeSecond implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitCommitTimeSecond() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_commit_time_second"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", String.valueOf(EngineInformation.getInstance().getGitCommitTime().getSecond())); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeYear.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeYear.java new file mode 100644 index 0000000..495f58a --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitTimeYear.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_commit_time_year} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitCommitTimeYear implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitCommitTimeYear() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_commit_time_year"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", String.valueOf(EngineInformation.getInstance().getGitCommitTime().getYear())); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommits.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommits.java new file mode 100644 index 0000000..15a0365 --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommits.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_commits} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitCommits implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitCommits() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_commits"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", String.valueOf(EngineInformation.getInstance().getGitCommitCount())); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitterEmail.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitterEmail.java new file mode 100644 index 0000000..a0850e5 --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitterEmail.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_committer_email} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitCommitterEmail implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitCommitterEmail() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_committer_email"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", EngineInformation.getInstance().getGitCommitterEmail()); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitterName.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitterName.java new file mode 100644 index 0000000..016294b --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitCommitterName.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_committer_name} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitCommitterName implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitCommitterName() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_committer_name"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", EngineInformation.getInstance().getGitCommitterName()); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitDirty.java b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitDirty.java new file mode 100644 index 0000000..f010d00 --- /dev/null +++ b/base/src/main/java/de/staropensource/sosengine/base/data/placeholders/EngineGitDirty.java @@ -0,0 +1,53 @@ +/* + * STAROPENSOURCE ENGINE SOURCE FILE + * Copyright (c) 2024 The StarOpenSource Engine Contributors + * 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 . + */ + +package de.staropensource.sosengine.base.data.placeholders; + +import de.staropensource.sosengine.base.classes.Placeholder; +import de.staropensource.sosengine.base.data.info.EngineInformation; +import org.jetbrains.annotations.NotNull; + +/** + * Implements the {@code engine_git_dirty} placeholder. + * + * @see Placeholder + * @since 1-alpha0 + */ +@SuppressWarnings({ "unused" }) +public final class EngineGitDirty implements Placeholder { + /** + * Constructor. + * + * @since 1-alpha0 + */ + public EngineGitDirty() {} + + /** {@inheritDoc} */ + @NotNull + public String getName() { + return "engine_git_dirty"; + } + + /** {@inheritDoc} */ + @NotNull + @Override + public String replace(@NotNull String text) { + return text.replace("%" + getName() + "%", String.valueOf(EngineInformation.getInstance().getGitDirty())); + } +} diff --git a/base/src/main/java/de/staropensource/sosengine/base/utility/PlaceholderEngine.java b/base/src/main/java/de/staropensource/sosengine/base/utility/PlaceholderEngine.java index 72d71e2..17876bf 100644 --- a/base/src/main/java/de/staropensource/sosengine/base/utility/PlaceholderEngine.java +++ b/base/src/main/java/de/staropensource/sosengine/base/utility/PlaceholderEngine.java @@ -94,6 +94,21 @@ public final class PlaceholderEngine { placeholders.add(new EngineDependencyLwjgl()); placeholders.add(new EngineDependencyReflections()); placeholders.add(new EngineDependencySlf4j()); + // engine_git_* + placeholders.add(new EngineGitBranch()); + placeholders.add(new EngineGitCommitHeader()); + placeholders.add(new EngineGitCommitIdLong()); + placeholders.add(new EngineGitCommitIdShort()); + placeholders.add(new EngineGitCommits()); + placeholders.add(new EngineGitCommitterEmail()); + placeholders.add(new EngineGitCommitterName()); + placeholders.add(new EngineGitCommitTimeDay()); + placeholders.add(new EngineGitCommitTimeHour()); + placeholders.add(new EngineGitCommitTimeMinute()); + placeholders.add(new EngineGitCommitTimeMonth()); + placeholders.add(new EngineGitCommitTimeSecond()); + placeholders.add(new EngineGitCommitTimeYear()); + placeholders.add(new EngineGitDirty()); // engine_plugin_* placeholders.add(new EnginePluginLombok()); placeholders.add(new EnginePluginShadow()); diff --git a/gradle.properties b/gradle.properties index 65096b1..8307a73 100644 --- a/gradle.properties +++ b/gradle.properties @@ -41,6 +41,7 @@ dependencyJoor=0.9.14 # Plugins pluginShadow=8.1.1 pluginLombok=8.6 +pluginGitProperties=2.4.2 # etc group = de.staropensource.sosengine