diff --git a/patches/api/Add-Git-information-to-version-command-on-startup.patch b/patches/api/Add-Git-information-to-version-command-on-startup.patch new file mode 100644 index 0000000000..0fd1de54ec --- /dev/null +++ b/patches/api/Add-Git-information-to-version-command-on-startup.patch @@ -0,0 +1,157 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Professor Bloodstone +Date: Sun, 20 Jun 2021 01:48:31 +0200 +Subject: [PATCH] Add Git information to version command/on startup + + +diff --git a/src/main/java/io/papermc/paper/util/JarManifests.java b/src/main/java/io/papermc/paper/util/JarManifests.java +new file mode 100644 +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 +--- /dev/null ++++ b/src/main/java/io/papermc/paper/util/JarManifests.java +@@ -0,0 +0,0 @@ ++/* ++Copyright (c) 2012-2017, jcabi.com ++All rights reserved. ++ ++Redistribution and use in source and binary forms, with or without ++modification, are permitted provided that the following conditions ++are met: 1) Redistributions of source code must retain the above ++copyright notice, this list of conditions and the following ++disclaimer. 2) Redistributions in binary form must reproduce the above ++copyright notice, this list of conditions and the following ++disclaimer in the documentation and/or other materials provided ++with the distribution. 3) Neither the name of the jcabi.com nor ++the names of its contributors may be used to endorse or promote ++products derived from this software without specific prior written ++permission. ++ ++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ++"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT ++NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND ++FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ++THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, ++INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES ++(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR ++SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ++HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, ++STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ++ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED ++OF THE POSSIBILITY OF SUCH DAMAGE. ++*/ ++package io.papermc.paper.util; ++ ++import java.io.IOException; ++import java.io.InputStream; ++import java.net.URL; ++import java.util.*; ++import java.util.jar.Manifest; ++import org.jetbrains.annotations.NotNull; ++ ++/** ++ * Modified version of jcabi-manifests ++ * ++ */ ++public final class JarManifests { ++ ++ public static final JarManifests JAR_MANIFESTS = new JarManifests(); ++ public static final Map MANIFEST_MAP; ++ ++ static { ++ try { ++ MANIFEST_MAP = Collections.unmodifiableMap(JAR_MANIFESTS.getManifestMap()); ++ } catch (final IOException ex) { ++ throw new RuntimeException(ex); ++ } ++ } ++ ++ private JarManifests() {} ++ ++ // Based on: ++ // https://github.com/jcabi/jcabi-manifests/blob/c4e1dd22bb6099769b8d279ebe3737e5b638b278/src/main/java/com/jcabi/manifests/ClasspathMfs.java#L49-L58 ++ ++ /** ++ * Get collection containing all META-INF/MANIFEST.MF streams ++ * ++ * @throws IOException if unable to get resources from classloader ++ */ ++ public @NotNull Collection<@NotNull InputStream> getManifestStreams() throws IOException { ++ final Enumeration resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF"); ++ final Collection streams = new ArrayList<>(1); ++ while (resources.hasMoreElements()) { ++ streams.add(resources.nextElement().openStream()); ++ } ++ return streams; ++ } ++ ++ // Based on: ++ // https://github.com/jcabi/jcabi-manifests/blob/c4e1dd22bb6099769b8d279ebe3737e5b638b278/src/main/java/com/jcabi/manifests/Manifests.java#L209-L225 ++ // https://github.com/jcabi/jcabi-manifests/blob/c4e1dd22bb6099769b8d279ebe3737e5b638b278/src/main/java/com/jcabi/manifests/Manifests.java#L381-L388 ++ ++ /** ++ * Get map containing entries from all manifests ++ * ++ * @throws IOException if unable to get manifest streams ++ */ ++ public @NotNull Map<@NotNull String, @NotNull String> getManifestMap() throws IOException { ++ final HashMap attribs = new HashMap<>(); ++ for (final InputStream stream : getManifestStreams()) { ++ for (final Map.Entry attr: new Manifest(stream).getMainAttributes().entrySet()) { ++ attribs.put(attr.getKey().toString(), attr.getValue().toString()); ++ } ++ } ++ return attribs; ++ } ++} +diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/Bukkit.java ++++ b/src/main/java/org/bukkit/Bukkit.java +@@ -0,0 +0,0 @@ import org.bukkit.util.CachedServerIcon; + import org.jetbrains.annotations.Contract; + import org.jetbrains.annotations.NotNull; + import org.jetbrains.annotations.Nullable; ++import io.papermc.paper.util.JarManifests; // Paper + + /** + * Represents the Bukkit core, for version and Server singleton handling +@@ -0,0 +0,0 @@ public final class Bukkit { + } + + Bukkit.server = server; +- server.getLogger().info("This server is running " + getName() + " version " + getVersion() + " (Implementing API version " + getBukkitVersion() + ")"); ++ // Paper start - add git information ++ server.getLogger().info(getVersionMessage()); ++ } ++ /** ++ * Gets message describing the version server is running. ++ * ++ * @return message describing the version server is running ++ */ ++ @NotNull ++ public static String getVersionMessage() { ++ Map attributes = JarManifests.MANIFEST_MAP; ++ @NotNull String gitBranch = attributes.get("Git-Branch"); ++ @NotNull String gitCommit = attributes.get("Git-Commit"); ++ @NotNull String branchMsg = " on " + gitBranch; ++ if ("master".equals(gitBranch) || "main".equals(gitBranch)) { ++ branchMsg = ""; // Don't show branch on main/master ++ } ++ return "This server is running " + getName() + " version " + getVersion() + " (Implementing API version " + getBukkitVersion() + ") (Git: " + gitCommit + branchMsg + ")"; ++ // Paper end + } + + /** +diff --git a/src/main/java/org/bukkit/command/defaults/VersionCommand.java b/src/main/java/org/bukkit/command/defaults/VersionCommand.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/command/defaults/VersionCommand.java ++++ b/src/main/java/org/bukkit/command/defaults/VersionCommand.java +@@ -0,0 +0,0 @@ public class VersionCommand extends BukkitCommand { + private void setVersionMessage(final @NotNull Component msg) { + lastCheck = System.currentTimeMillis(); + final Component message = net.kyori.adventure.text.TextComponent.ofChildren( +- Component.text("This server is running " + Bukkit.getName() + " version " + Bukkit.getVersion() + " (Implementing API version " + Bukkit.getBukkitVersion() + ")", net.kyori.adventure.text.format.NamedTextColor.WHITE), ++ Component.text(Bukkit.getVersionMessage(), net.kyori.adventure.text.format.NamedTextColor.WHITE), + Component.newline(), + msg + ); diff --git a/patches/server/Add-git-branch-and-commit-to-manifest.patch b/patches/server/Add-git-branch-and-commit-to-manifest.patch new file mode 100644 index 0000000000..df03ab84df --- /dev/null +++ b/patches/server/Add-git-branch-and-commit-to-manifest.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Professor Bloodstone +Date: Sun, 20 Jun 2021 01:14:41 +0200 +Subject: [PATCH] Add git branch and commit to manifest + + +diff --git a/build.gradle.kts b/build.gradle.kts +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/build.gradle.kts ++++ b/build.gradle.kts +@@ -0,0 +0,0 @@ tasks.jar { + val git = Git(rootProject.layout.projectDirectory.path) + val gitHash = git("rev-parse", "HEAD").getText().substring(0, 7) + val implementationVersion = System.getenv("BUILD_NUMBER") ?: "\"$gitHash\"" ++ val gitBranch = git("rev-parse", "--abbrev-ref", "HEAD").getText().trim() // Paper + attributes( + "Main-Class" to "org.bukkit.craftbukkit.Main", + "Implementation-Title" to "CraftBukkit", +@@ -0,0 +0,0 @@ tasks.jar { + "Specification-Version" to project.version, + "Specification-Vendor" to "Bukkit Team", + "Multi-Release" to "true", // Paper ++ "Git-Branch" to gitBranch, // Paper ++ "Git-Commit" to gitHash, // Paper + ) + for (tld in setOf("net", "com", "org")) { + attributes("$tld/bukkit", "Sealed" to true) diff --git a/patches/server/Setup-Gradle-project.patch b/patches/server/Setup-Gradle-project.patch index 385a1e3c45..929c9996cd 100644 --- a/patches/server/Setup-Gradle-project.patch +++ b/patches/server/Setup-Gradle-project.patch @@ -71,10 +71,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + manifest { + val git = Git(rootProject.layout.projectDirectory.path) + val gitHash = git("rev-parse", "HEAD").getText().substring(0, 7) ++ val implementationVersion = System.getenv("BUILD_NUMBER") ?: "\"$gitHash\"" + attributes( + "Main-Class" to "org.bukkit.craftbukkit.Main", + "Implementation-Title" to "CraftBukkit", -+ "Implementation-Version" to "git-Paper-\"$gitHash\"", ++ "Implementation-Version" to "git-Paper-$implementationVersion", + "Implementation-Vendor" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(Date()), // Paper + "Specification-Title" to "Bukkit", + "Specification-Version" to project.version,