mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-12-01 02:04:51 +00:00
Mark development builds in the console
Purple fins, DEV tag, branch and build age
This commit is contained in:
1 parent
df31f1e2e3
commit
8893432b6f
9 files changed
+226
-11
No files matched your search
@@ -33,6 +33,8 @@ public final class GenerationRevisionScope {
|
||||
"core/src/main/java/art/arcane/iris/diagnostics/splash/IrisSplashRenderer.java",
|
||||
"core/src/main/java/art/arcane/iris/diagnostics/splash/IrisSplashComposer.java",
|
||||
"core/src/main/java/art/arcane/iris/diagnostics/splash/IrisSplashPackScanner.java",
|
||||
"core/src/main/java/art/arcane/iris/diagnostics/splash/SplashBuild.java",
|
||||
"core/src/main/java/art/arcane/iris/diagnostics/BuildChannel.java",
|
||||
"adapters/modded-common/src/main/java/art/arcane/iris/modded/ModdedIrisSplash.java",
|
||||
"adapters/bukkit/plugin/src/main/java/art/arcane/iris/command/CommandDebug.java",
|
||||
"adapters/bukkit/plugin/src/main/java/art/arcane/iris/command/CommandDeveloper.java",
|
||||
|
||||
@@ -235,6 +235,18 @@ tasks.named('processResources').configure { Task resources ->
|
||||
}
|
||||
def templateSource = file('src/main/templates')
|
||||
def templateDest = layout.buildDirectory.dir('generated/sources/templates')
|
||||
def sourceHashesProvided = { -> providers.environmentVariable('MULTIPLEXOR_SOURCE_HASHES').isPresent() }
|
||||
def gitOutput = { String... arguments ->
|
||||
try {
|
||||
Process process = new ProcessBuilder(['git', '-C', rootProject.projectDir.absolutePath] + arguments.toList())
|
||||
.redirectError(ProcessBuilder.Redirect.DISCARD)
|
||||
.start()
|
||||
String output = new String(process.inputStream.readAllBytes(), StandardCharsets.UTF_8).trim()
|
||||
return process.waitFor() == 0 ? output : null
|
||||
} catch (Exception ignored) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
def generateTemplates = tasks.register('generateTemplates', Copy) {
|
||||
inputs.properties([
|
||||
environment: providers.provider {
|
||||
@@ -283,6 +295,23 @@ def generateTemplates = tasks.register('generateTemplates', Copy) {
|
||||
logger.error('Git commit hash not found', failure)
|
||||
return 'unknown'
|
||||
},
|
||||
branch: providers.provider {
|
||||
if (sourceHashesProvided()) {
|
||||
return ''
|
||||
}
|
||||
String branch = gitOutput('rev-parse', '--abbrev-ref', 'HEAD')
|
||||
if (branch == null || branch == 'HEAD') {
|
||||
return ''
|
||||
}
|
||||
return branch.replace('\\', '\\\\').replace('"', '\\"')
|
||||
},
|
||||
dirty: providers.provider {
|
||||
if (sourceHashesProvided()) {
|
||||
return false
|
||||
}
|
||||
String status = gitOutput('status', '--porcelain')
|
||||
return status != null && !status.isEmpty()
|
||||
},
|
||||
minecraftVersion: providers.gradleProperty('minecraftVersion'),
|
||||
])
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package art.arcane.iris.diagnostics;
|
||||
|
||||
import art.arcane.iris.BuildConstants;
|
||||
|
||||
public enum BuildChannel {
|
||||
RELEASE,
|
||||
DEVELOPMENT;
|
||||
|
||||
private static final String RELEASE_ENVIRONMENT = "production";
|
||||
private static final BuildChannel CURRENT = of(BuildConstants.ENVIRONMENT);
|
||||
|
||||
public static BuildChannel current() {
|
||||
return CURRENT;
|
||||
}
|
||||
|
||||
static BuildChannel of(String environment) {
|
||||
return RELEASE_ENVIRONMENT.equals(environment) ? RELEASE : DEVELOPMENT;
|
||||
}
|
||||
|
||||
public boolean isDevelopment() {
|
||||
return this == DEVELOPMENT;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package art.arcane.iris.diagnostics.splash;
|
||||
|
||||
import art.arcane.iris.BuildConstants;
|
||||
import art.arcane.iris.localization.ChatReport;
|
||||
import art.arcane.iris.pack.BuiltInPackUpdates;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
@@ -20,6 +20,11 @@ public final class IrisSplashComposer {
|
||||
private static final int SHORT_COMMIT_LENGTH = 7;
|
||||
private static final int LABEL_WIDTH = 14;
|
||||
private static final String FACT_GAP = " ";
|
||||
private static final String DEVELOPMENT_TAG_SUFFIX = " DEV";
|
||||
private static final String DIRTY_MARK = "+dirty";
|
||||
private static final long SECONDS_PER_MINUTE = 60;
|
||||
private static final long SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
|
||||
private static final long SECONDS_PER_DAY = 24 * SECONDS_PER_HOUR;
|
||||
|
||||
private IrisSplashComposer() {
|
||||
}
|
||||
@@ -29,7 +34,12 @@ public final class IrisSplashComposer {
|
||||
}
|
||||
|
||||
public static String[] composeInfo(String version, String serverLine, InfoStyle style, List<List<Detail>> detailRows) {
|
||||
String[] info = composeHeader(version, serverLine, style);
|
||||
return composeInfo(version, serverLine, style, SplashBuild.current(), detailRows);
|
||||
}
|
||||
|
||||
public static String[] composeInfo(String version, String serverLine, InfoStyle style, SplashBuild build,
|
||||
List<List<Detail>> detailRows) {
|
||||
String[] info = composeHeader(version, serverLine, style, build);
|
||||
int rows = Math.min(detailRows.size(), SPARE_INFO_ROWS);
|
||||
for (int row = 0; row < rows; row++) {
|
||||
info[FIRST_SPARE_INFO_ROW + row] = style.linePrefix() + styledRow(detailRows.get(row), style);
|
||||
@@ -70,23 +80,21 @@ public final class IrisSplashComposer {
|
||||
return text + " ".repeat(Math.max(1, width - text.length()));
|
||||
}
|
||||
|
||||
private static String shortCommit() {
|
||||
String commit = BuildConstants.COMMIT;
|
||||
private static String shortCommit(String commit) {
|
||||
return commit.length() > SHORT_COMMIT_LENGTH ? commit.substring(0, SHORT_COMMIT_LENGTH) : commit;
|
||||
}
|
||||
|
||||
private static String[] composeHeader(String version, String serverLine, InfoStyle style) {
|
||||
String releaseTrain = releaseTrain(version);
|
||||
private static String[] composeHeader(String version, String serverLine, InfoStyle style, SplashBuild build) {
|
||||
String prefix = style.linePrefix();
|
||||
String java = javaVersion() < 0 ? "unknown" : String.valueOf(javaVersion());
|
||||
return new String[]{
|
||||
prefix + style.title(" Iris, ") + style.subtitle("Dimension Engine ") + style.tag("[" + releaseTrain + "]"),
|
||||
prefix + style.title(" Iris, ") + style.subtitle("Dimension Engine ") + style.tag("[" + titleTag(version, build) + "]"),
|
||||
prefix + styledRow(List.of(Detail.headline("Version", version)), style),
|
||||
prefix + styledRow(List.of(new Detail("By", "Volmit Software (Arcane Arts)")), style),
|
||||
prefix + styledRow(List.of(new Detail("Web", "volmitsoftware.com")), style),
|
||||
prefix + styledRow(List.of(Detail.headline("Server", serverLine)), style),
|
||||
prefix + styledRow(List.of(new Detail("Java", java), new Detail("Date", startupDate())), style),
|
||||
prefix + styledRow(List.of(new Detail("Commit", shortCommit() + "/" + BuildConstants.ENVIRONMENT)), style),
|
||||
prefix + styledRow(buildFacts(build), style),
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
@@ -94,6 +102,39 @@ public final class IrisSplashComposer {
|
||||
};
|
||||
}
|
||||
|
||||
private static String titleTag(String version, SplashBuild build) {
|
||||
String releaseTrain = releaseTrain(version);
|
||||
return build.channel().isDevelopment() ? releaseTrain + DEVELOPMENT_TAG_SUFFIX : releaseTrain;
|
||||
}
|
||||
|
||||
private static List<Detail> buildFacts(SplashBuild build) {
|
||||
String commit = shortCommit(build.commit());
|
||||
if (!build.channel().isDevelopment()) {
|
||||
return List.of(new Detail("Commit", commit + "/" + build.environment()));
|
||||
}
|
||||
List<Detail> facts = new ArrayList<>();
|
||||
facts.add(new Detail("Commit", build.dirty() ? commit + DIRTY_MARK : commit));
|
||||
if (build.hasBranch()) {
|
||||
facts.add(new Detail("Branch", build.branch()));
|
||||
}
|
||||
build.age().ifPresent(age -> facts.add(new Detail("Built", compactAge(age) + " ago")));
|
||||
return facts;
|
||||
}
|
||||
|
||||
static String compactAge(Duration age) {
|
||||
long seconds = Math.max(0, age.toSeconds());
|
||||
if (seconds < SECONDS_PER_MINUTE) {
|
||||
return seconds + "s";
|
||||
}
|
||||
if (seconds < SECONDS_PER_HOUR) {
|
||||
return seconds / SECONDS_PER_MINUTE + "m";
|
||||
}
|
||||
if (seconds < SECONDS_PER_DAY) {
|
||||
return seconds / SECONDS_PER_HOUR + "h";
|
||||
}
|
||||
return seconds / SECONDS_PER_DAY + "d";
|
||||
}
|
||||
|
||||
public static String compose(String[] splash, String[] info) {
|
||||
StringBuilder builder = new StringBuilder("\n\n");
|
||||
for (int i = 0; i < splash.length; i++) {
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package art.arcane.iris.diagnostics.splash;
|
||||
|
||||
import art.arcane.iris.BuildConstants;
|
||||
import art.arcane.iris.diagnostics.BuildChannel;
|
||||
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.CodeSource;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
/** What the splash says about the build it is running from. */
|
||||
public record SplashBuild(BuildChannel channel, String commit, String environment, String branch, boolean dirty,
|
||||
Optional<Duration> age) {
|
||||
public static SplashBuild current() {
|
||||
return new SplashBuild(BuildChannel.current(), BuildConstants.COMMIT, BuildConstants.ENVIRONMENT,
|
||||
BuildConstants.BRANCH, BuildConstants.DIRTY, jarAge());
|
||||
}
|
||||
|
||||
public boolean hasBranch() {
|
||||
return branch != null && !branch.isBlank();
|
||||
}
|
||||
|
||||
/** The jar's modification time stands in for the build time, so no timestamp has to be compiled in. */
|
||||
private static Optional<Duration> jarAge() {
|
||||
try {
|
||||
CodeSource source = SplashBuild.class.getProtectionDomain().getCodeSource();
|
||||
URL location = source == null ? null : source.getLocation();
|
||||
if (location == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Path jar = Path.of(location.toURI());
|
||||
if (!Files.isRegularFile(jar)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
Instant built = Files.getLastModifiedTime(jar).toInstant();
|
||||
return Optional.of(Duration.between(built, Instant.now()));
|
||||
} catch (Exception unresolvable) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package art.arcane.iris.world.safeguard;
|
||||
|
||||
import art.arcane.iris.diagnostics.BuildChannel;
|
||||
import art.arcane.iris.diagnostics.splash.IrisSplashComposer;
|
||||
import art.arcane.iris.diagnostics.splash.IrisSplashRenderer;
|
||||
import art.arcane.iris.platform.bukkit.BukkitPlatform;
|
||||
@@ -15,6 +16,11 @@ public enum Mode {
|
||||
WARNING(C.GOLD, C.YELLOW),
|
||||
UNSTABLE(C.RED, C.GOLD);
|
||||
|
||||
private static final C RELEASE_FIN_SHADE = C.DARK_GRAY;
|
||||
private static final C RELEASE_FIN_HIGHLIGHT = C.GRAY;
|
||||
private static final C DEVELOPMENT_FIN_SHADE = C.DARK_PURPLE;
|
||||
private static final C DEVELOPMENT_FIN_HIGHLIGHT = C.LIGHT_PURPLE;
|
||||
|
||||
private final C color;
|
||||
private final C glow;
|
||||
private final String id;
|
||||
@@ -94,12 +100,13 @@ public enum Mode {
|
||||
}
|
||||
|
||||
private String splashTone(char glyph) {
|
||||
boolean development = BuildChannel.current().isDevelopment();
|
||||
return switch (glyph) {
|
||||
case '=' -> C.GRAY.toString();
|
||||
case '*' -> glow.toString();
|
||||
case '%', '@' -> color.toString();
|
||||
case '(', ')' -> C.WHITE.toString();
|
||||
default -> C.DARK_GRAY.toString();
|
||||
case '=' -> (development ? DEVELOPMENT_FIN_HIGHLIGHT : RELEASE_FIN_HIGHLIGHT).toString();
|
||||
default -> (development ? DEVELOPMENT_FIN_SHADE : RELEASE_FIN_SHADE).toString();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,5 +4,7 @@ package art.arcane.iris;
|
||||
public interface BuildConstants {
|
||||
String ENVIRONMENT = "${environment}";
|
||||
String COMMIT = "${commit}";
|
||||
String BRANCH = "${branch}";
|
||||
boolean DIRTY = ${dirty};
|
||||
String MINECRAFT_VERSION = "${minecraftVersion}";
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package art.arcane.iris.diagnostics;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class BuildChannelTest {
|
||||
@Test
|
||||
public void onlyProductionBuildsAreReleases() {
|
||||
assertEquals(BuildChannel.RELEASE, BuildChannel.of("production"));
|
||||
assertEquals(BuildChannel.DEVELOPMENT, BuildChannel.of("development"));
|
||||
assertEquals(BuildChannel.DEVELOPMENT, BuildChannel.of("Argghh!"));
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,67 @@
|
||||
package art.arcane.iris.diagnostics.splash;
|
||||
|
||||
import art.arcane.iris.diagnostics.BuildChannel;
|
||||
import art.arcane.iris.pack.BuiltInPackUpdates;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
public class IrisSplashComposerTest {
|
||||
private static final String COMMIT = "df31f1e2e5f1c0a8d4b7e9f6a3c2b1d0e9f8a7b6";
|
||||
private static final int TITLE_ROW = 0;
|
||||
private static final int COMMIT_ROW = 6;
|
||||
|
||||
private static SplashBuild release() {
|
||||
return new SplashBuild(BuildChannel.RELEASE, COMMIT, "production", "master", true, Optional.of(Duration.ofMinutes(3)));
|
||||
}
|
||||
|
||||
private static SplashBuild development(String branch, boolean dirty, Optional<Duration> age) {
|
||||
return new SplashBuild(BuildChannel.DEVELOPMENT, COMMIT, "development", branch, dirty, age);
|
||||
}
|
||||
|
||||
private static String[] plainInfo(SplashBuild build) {
|
||||
return IrisSplashComposer.composeInfo("4.3.0-26.2", "Paper 26.2", IrisSplashComposer.InfoStyle.PLAIN, build, List.of());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void releaseBuildKeepsItsTitleAndCommitRow() {
|
||||
String[] info = plainInfo(release());
|
||||
|
||||
assertEquals(" Iris, Dimension Engine [4.3]", info[TITLE_ROW]);
|
||||
assertEquals(" Commit df31f1e/production", info[COMMIT_ROW]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void developmentBuildShowsTagBranchDirtyFlagAndAge() {
|
||||
String[] info = plainInfo(development("t3/qol-changes", true, Optional.of(Duration.ofSeconds(200))));
|
||||
|
||||
assertEquals(" Iris, Dimension Engine [4.3 DEV]", info[TITLE_ROW]);
|
||||
assertEquals(" Commit df31f1e+dirty Branch t3/qol-changes Built 3m ago", info[COMMIT_ROW]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void developmentBuildOmitsMissingBranchAndAge() {
|
||||
String[] info = plainInfo(development("", false, Optional.empty()));
|
||||
|
||||
assertEquals(" Commit df31f1e", info[COMMIT_ROW]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildAgeUsesTheLargestWholeUnit() {
|
||||
assertEquals("0s", IrisSplashComposer.compactAge(Duration.ofSeconds(-5)));
|
||||
assertEquals("59s", IrisSplashComposer.compactAge(Duration.ofSeconds(59)));
|
||||
assertEquals("1m", IrisSplashComposer.compactAge(Duration.ofSeconds(60)));
|
||||
assertEquals("59m", IrisSplashComposer.compactAge(Duration.ofMinutes(59).plusSeconds(59)));
|
||||
assertEquals("2h", IrisSplashComposer.compactAge(Duration.ofHours(2).plusMinutes(30)));
|
||||
assertEquals("3d", IrisSplashComposer.compactAge(Duration.ofDays(3).plusHours(23)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateLinesNameOnlyOutdatedPacks() {
|
||||
List<IrisSplashPackScanner.SplashPackMetadata> packs = List.of(
|
||||
@@ -41,7 +93,8 @@ public class IrisSplashComposerTest {
|
||||
|
||||
@Test
|
||||
public void composeInfoUsesCurrentVersionWithoutStaleReleaseTag() {
|
||||
String[] info = IrisSplashComposer.composeInfo("4.0.0-26.2", "Paper 26.2", IrisSplashComposer.InfoStyle.PLAIN);
|
||||
String[] info = IrisSplashComposer.composeInfo("4.0.0-26.2", "Paper 26.2", IrisSplashComposer.InfoStyle.PLAIN,
|
||||
release(), List.of());
|
||||
|
||||
assertEquals(" Iris, Dimension Engine [4.0]", info[0]);
|
||||
assertEquals(" Version 4.0.0-26.2", info[1]);
|
||||
|
||||
Reference in new issue
Block a user