From 8bcfb52714c40065d85db2fda3d67acd717fe4a6 Mon Sep 17 00:00:00 2001 From: William Blake Galbreath Date: Tue, 30 Apr 2019 15:45:42 -0500 Subject: [PATCH] Rebrand Purpur --- .gitignore | 46 ++++++++ .gitmodules | 4 + Paper | 1 + README.md | 1 + current-paper | 1 + patches/api/0001-Rebrand-Purpur.patch | 79 +++++++++++++ patches/server/0001-Rebrand-Purpur.patch | 140 +++++++++++++++++++++++ pom.xml | 18 +++ purpur | 112 ++++++++++++++++++ scripts/apply.sh | 90 +++++++++++++++ scripts/generatesources.sh | 40 +++++++ scripts/importmcdev.sh | 89 ++++++++++++++ scripts/init.sh | 65 +++++++++++ scripts/push.sh | 15 +++ scripts/rebuildpatches.sh | 44 +++++++ scripts/upstream.sh | 62 ++++++++++ 16 files changed, 807 insertions(+) create mode 100644 .gitignore create mode 100644 .gitmodules create mode 160000 Paper create mode 100644 README.md create mode 100644 current-paper create mode 100644 patches/api/0001-Rebrand-Purpur.patch create mode 100644 patches/server/0001-Rebrand-Purpur.patch create mode 100644 pom.xml create mode 100755 purpur create mode 100755 scripts/apply.sh create mode 100755 scripts/generatesources.sh create mode 100755 scripts/importmcdev.sh create mode 100755 scripts/init.sh create mode 100755 scripts/push.sh create mode 100755 scripts/rebuildpatches.sh create mode 100755 scripts/upstream.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..3050f4b31 --- /dev/null +++ b/.gitignore @@ -0,0 +1,46 @@ +# Intellij +.idea/ +*.iml +*.ipr +*.iws +out/ + +# Eclipse +.classpath +.project +.settings/ + +# netbeans +nbproject/ +nbactions.xml + +# we use maven! +build.xml + +# Maven +log/ +target/ +dependency-reduced-pom.xml + +# various other potential build files +build/ +bin/ +dist/ +manifest.mf + +# Mac +.DS_Store/ +.DS_Store + +# vim +.*.sw[a-p] + +# Linux temp files +*~ + +# other stuff +run/ + +Purpur-Server +Purpur-API +mc-dev diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..9cfc2efcd --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "Paper"] + path = Paper + url = https://github.com/PaperMC/Paper.git + branch = master diff --git a/Paper b/Paper new file mode 160000 index 000000000..fb25dc17c --- /dev/null +++ b/Paper @@ -0,0 +1 @@ +Subproject commit fb25dc17c62acce335346d5e96899257ae7230c7 diff --git a/README.md b/README.md new file mode 100644 index 000000000..258cd5725 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +todo diff --git a/current-paper b/current-paper new file mode 100644 index 000000000..7988f6f9a --- /dev/null +++ b/current-paper @@ -0,0 +1 @@ +1.13.2--68781abc035f77c64c2ef6961375df70ae357e83 diff --git a/patches/api/0001-Rebrand-Purpur.patch b/patches/api/0001-Rebrand-Purpur.patch new file mode 100644 index 000000000..cc4b8f157 --- /dev/null +++ b/patches/api/0001-Rebrand-Purpur.patch @@ -0,0 +1,79 @@ +From 975b3da44f75bddc4b25e99fc92fadd3041693ff Mon Sep 17 00:00:00 2001 +From: William Blake Galbreath +Date: Tue, 30 Apr 2019 13:50:41 -0600 +Subject: [PATCH] Rebrand Purpur + +--- + pom.xml | 10 ++++----- + .../command/defaults/VersionCommand.java | 21 +++++++++++-------- + 2 files changed, 17 insertions(+), 14 deletions(-) + +diff --git a/pom.xml b/pom.xml +index 3347be41..c6b3aaec 100644 +--- a/pom.xml ++++ b/pom.xml +@@ -4,17 +4,17 @@ + 4.0.0 + + +- com.destroystokyo.paper +- paper-parent ++ net.pl3x.purpur ++ purpur-parent + dev-SNAPSHOT + + +- paper-api ++ purpur-api + 1.13.2-R0.1-SNAPSHOT + jar + +- Paper-API +- https://github.com/PaperMC/Paper ++ Purpur-API ++ https://github.com/pl3xgaming/Purpur + An enhanced plugin API for Minecraft servers. + + +diff --git a/src/main/java/org/bukkit/command/defaults/VersionCommand.java b/src/main/java/org/bukkit/command/defaults/VersionCommand.java +index 5cebb245..e3efafdc 100644 +--- a/src/main/java/org/bukkit/command/defaults/VersionCommand.java ++++ b/src/main/java/org/bukkit/command/defaults/VersionCommand.java +@@ -207,8 +207,8 @@ public class VersionCommand extends BukkitCommand { + private void obtainVersion() { + String version = Bukkit.getVersion(); + if (version == null) version = "Custom"; +- if (version.startsWith("git-Paper-")) { +- String[] parts = version.substring("git-Paper-".length()).split("[-\\s]"); ++ if (version.startsWith("git-Purpur-")) { // Purpur ++ String[] parts = version.substring("git-Purpur-".length()).split("[-\\s]"); // Purpur + int distance = getDistance(null, parts[0]); + switch (distance) { + case -1: +@@ -259,13 +259,16 @@ public class VersionCommand extends BukkitCommand { + + // Paper start + private static int getDistance(String repo, String verInfo) { +- try { +- int currentVer = Integer.decode(verInfo); +- return getFromJenkins(currentVer); +- } catch (NumberFormatException ex) { +- verInfo = verInfo.replace("\"", ""); +- return getFromRepo("PaperMC/Paper", "master", verInfo); +- } ++ // Purpur start ++ //try { ++ // int currentVer = Integer.decode(verInfo); ++ // return getFromJenkins(currentVer); ++ //} catch (NumberFormatException ex) { ++ // verInfo = verInfo.replace("\"", ""); ++ // return getFromRepo("PaperMC/Paper", "master", verInfo); ++ //} ++ return getFromRepo("pl3xgaming/Purpur", "master", verInfo.replace("\"", "")); ++ // Purpur end + /* + BufferedReader reader = Resources.asCharSource( + new URL("https://hub.spigotmc.org/stash/rest/api/1.0/projects/SPIGOT/repos/" + repo + "/commits?since=" + URLEncoder.encode(hash, "UTF-8") + "&withCounts=true"), +-- +2.20.1 + diff --git a/patches/server/0001-Rebrand-Purpur.patch b/patches/server/0001-Rebrand-Purpur.patch new file mode 100644 index 000000000..d14ab75a1 --- /dev/null +++ b/patches/server/0001-Rebrand-Purpur.patch @@ -0,0 +1,140 @@ +From 3597fc2ef74857fbb88d3ee4b299557566308490 Mon Sep 17 00:00:00 2001 +From: William Blake Galbreath +Date: Tue, 30 Apr 2019 14:08:58 -0600 +Subject: [PATCH] Rebrand Purpur + +--- + pom.xml | 18 +++++++++--------- + .../paper/console/PaperConsole.java | 2 +- + src/main/java/net/minecraft/server/EULA.java | 2 +- + .../net/minecraft/server/MinecraftServer.java | 2 +- + .../org/bukkit/craftbukkit/CraftServer.java | 2 +- + .../bukkit/craftbukkit/util/Versioning.java | 2 +- + 6 files changed, 14 insertions(+), 14 deletions(-) + +diff --git a/pom.xml b/pom.xml +index c3844581..860bd355 100644 +--- a/pom.xml ++++ b/pom.xml +@@ -1,11 +1,11 @@ + + 4.0.0 +- paper ++ purpur + jar + 1.13.2-R0.1-SNAPSHOT +- Paper +- https://papermc.io ++ Purpur ++ http://pl3x.net + + + UTF-8 +@@ -20,16 +20,16 @@ + + + +- com.destroystokyo.paper +- paper-parent ++ net.pl3x.purpur ++ purpur-parent + dev-SNAPSHOT + ../pom.xml + + + + +- com.destroystokyo.paper +- paper-api ++ net.pl3x.purpur ++ purpur-api + ${project.version} + compile + +@@ -135,7 +135,7 @@ + + + +- paper-${minecraft.version} ++ purpur-${minecraft.version} + clean install + + +@@ -143,7 +143,7 @@ + gitdescribe-maven-plugin + 1.3 + +- git-Paper- ++ git-Purpur- + .. + + +diff --git a/src/main/java/com/destroystokyo/paper/console/PaperConsole.java b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java +index 688b4715..e4522e68 100644 +--- a/src/main/java/com/destroystokyo/paper/console/PaperConsole.java ++++ b/src/main/java/com/destroystokyo/paper/console/PaperConsole.java +@@ -17,7 +17,7 @@ public final class PaperConsole extends SimpleTerminalConsole { + @Override + protected LineReader buildReader(LineReaderBuilder builder) { + return super.buildReader(builder +- .appName("Paper") ++ .appName("Purpur") // Purpur + .completer(new ConsoleCommandCompleter(this.server)) + ); + } +diff --git a/src/main/java/net/minecraft/server/EULA.java b/src/main/java/net/minecraft/server/EULA.java +index 526f3af5..b64cac25 100644 +--- a/src/main/java/net/minecraft/server/EULA.java ++++ b/src/main/java/net/minecraft/server/EULA.java +@@ -49,7 +49,7 @@ public class EULA { + Properties properties = new Properties(); + fileoutputstream = new FileOutputStream(this.b); + properties.setProperty("eula", "false"); +- properties.store(fileoutputstream, "By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula).\nYou also agree that tacos are tasty, and the best food in the world."); // Paper - fix lag); ++ properties.store(fileoutputstream, "By changing the setting below to TRUE you are indicating your agreement to our EULA (https://account.mojang.com/documents/minecraft_eula)."); + } catch (Exception exception) { + a.warn("Failed to save {}", this.b, exception); + } finally { +diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java +index 9c8c3304..570360f5 100644 +--- a/src/main/java/net/minecraft/server/MinecraftServer.java ++++ b/src/main/java/net/minecraft/server/MinecraftServer.java +@@ -1347,7 +1347,7 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati + } + + public String getServerModName() { +- return "Paper"; //Paper - Paper > // Spigot - Spigot > // CraftBukkit - cb > vanilla! ++ return "Purpur"; // Purpur // Paper - Paper > // Spigot - Spigot > // CraftBukkit - cb > vanilla! + } + + public CrashReport b(CrashReport crashreport) { +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +index 32bf4e58..fc7084ee 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java +@@ -164,7 +164,7 @@ import javax.annotation.Nonnull; // Paper + + + public final class CraftServer implements Server { +- private final String serverName = "Paper"; // Paper ++ private final String serverName = "Purpur"; // Purpur // Paper + private final String serverVersion; + private final String bukkitVersion = Versioning.getBukkitVersion(); + private final Logger logger = Logger.getLogger("Minecraft"); +diff --git a/src/main/java/org/bukkit/craftbukkit/util/Versioning.java b/src/main/java/org/bukkit/craftbukkit/util/Versioning.java +index 674096ca..e9aee2d8 100644 +--- a/src/main/java/org/bukkit/craftbukkit/util/Versioning.java ++++ b/src/main/java/org/bukkit/craftbukkit/util/Versioning.java +@@ -11,7 +11,7 @@ public final class Versioning { + public static String getBukkitVersion() { + String result = "Unknown-Version"; + +- InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("META-INF/maven/com.destroystokyo.paper/paper-api/pom.properties"); ++ InputStream stream = Bukkit.class.getClassLoader().getResourceAsStream("META-INF/maven/net.pl3x.purpur/purpur-api/pom.properties"); // Purpur + Properties properties = new Properties(); + + if (stream != null) { +-- +2.20.1 + diff --git a/pom.xml b/pom.xml new file mode 100644 index 000000000..253f467e9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,18 @@ + + 4.0.0 + + net.pl3x.purpur + purpur-parent + dev-SNAPSHOT + pom + Purpur (Parent) + + + install + ${project.artifactId} + + + Purpur-API + Purpur-Server + + diff --git a/purpur b/purpur new file mode 100755 index 000000000..cef037f1d --- /dev/null +++ b/purpur @@ -0,0 +1,112 @@ +#!/usr/bin/env bash + +# get base dir regardless of execution location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +SOURCE=$([[ "$SOURCE" = /* ]] && echo "$SOURCE" || echo "$PWD/${SOURCE#./}") +basedir=$(dirname "$SOURCE") +. $basedir/scripts/init.sh + +purpurstash() { + STASHED=$(git stash) +} + +purpurunstash() { + if [[ "$STASHED" != "No local changes to save" ]] ; then + git stash pop + fi +} + +case "$1" in + "rb" | "rbp" | "rebuild") + ( + set -e + cd "$basedir" + scripts/rebuildpatches.sh "$basedir" + ) + ;; + "p" | "patch" | "apply") + ( + set -e + cd "$basedir" + scripts/apply.sh "$basedir" + ) + ;; + "b" | "bu" | "build") + ( + basedir + mvn -N install + cd ${FORK_NAME}-API + mvn clean install && cd ../${FORK_NAME}-Server && mvn clean install + ) + ;; + "d" | "de" | "deploy") + ( + basedir + mvn -N install + cd ${FORK_NAME}-API + mvn clean deploy && cd ../${FORK_NAME}-Server && mvn clean install + ) + ;; + "up" | "upstream") + ( + cd "$basedir" + scripts/upstream.sh "$2" + ) + ;; + "r" | "root") + cd "$basedir" + ;; + "a" | "api") + cd "$basedir/Purpur-API" + ;; + "s" | "server") + cd "$basedir/Purpur-Server" + ;; + "setup") + if [[ -f ~/.bashrc ]] ; then + NAME="purpur" + if [[ ! -z "${2+x}" ]] ; then + NAME="$2" + fi + (grep "alias $NAME=" ~/.bashrc > /dev/null) && (sed -i "s|alias $NAME=.*|alias $NAME='. $SOURCE'|g" ~/.bashrc) || (echo "alias $NAME='. $SOURCE'" >> ~/.bashrc) + alias "$NAME=. $SOURCE" + echo "You can now just type '$NAME' at any time to access the purpur tool." + fi + ;; + *) + echo "Purpur build tool command. This provides a variety of commands to build and manage the Purpur build" + echo "environment. For all of the functionality of this command to be available, you must first run the" + echo "'setup' command. View below for details. For essential building and patching, you do not need to do the setup." + echo "" + echo " Normal commands:" + echo " * rb, rebuild | Rebuild patches, can be called from anywhere." + echo " * p, patch | Apply all patches to top of Paper without building it. Can be run from anywhere." + echo " * up, upstream | Build Paper upstream, pass arg up to update paper. Can be run from anywhere." + echo " * b, build | Build API and Server but no deploy. Can be ran anywhere." + echo " * d, deploy | Build and Deploy API jar and build Server. Can be ran anywhere." + echo "" + echo " These commands require the setup command before use:" + echo " * r, root | Change directory to the root of the project." + echo " * a. api | Move to the Purpur-API directory." + echo " * s, server | Move to the Purpur-Server directory." + echo " * e, edit | Use to edit a specific patch, give it the argument \"server\" or \"api\"" + echo " | respectively to edit the correct project. Use the argument \"continue\" after" + echo " | the changes have been made to finish and rebuild patches. Can be called from anywhere." + echo "" + echo " * setup | Add an alias to .bashrc to allow full functionality of this script. Run as:" + echo " | . ./purpur setup" + echo " | After you run this command you'll be able to just run 'purpur' from anywhere." + echo " | The default name for the resulting alias is 'purpur', you can give an argument to override" + echo " | this default, such as:" + echo " | . ./purpur setup example" + echo " | Which will allow you to run 'example' instead." + ;; +esac + +unset -f purpurstash +unset -f purpurunstash diff --git a/scripts/apply.sh b/scripts/apply.sh new file mode 100755 index 000000000..504da627e --- /dev/null +++ b/scripts/apply.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash +# get base dir regardless of execution location +# resolve shell-specifics +case "$(echo "$SHELL" | sed -E 's|/usr(/local)?||g')" in + "/bin/zsh") + RCPATH="$HOME/.zshrc" + SOURCE="${BASH_SOURCE[0]:-${(%):-%N}}" + ;; + *) + RCPATH="$HOME/.bashrc" + if [[ -f "$HOME/.bash_aliases" ]]; then + RCPATH="$HOME/.bash_aliases" + fi + SOURCE="${BASH_SOURCE[0]}" + ;; +esac + +# get base dir regardless of execution location + +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ "$SOURCE" != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +. $(dirname $SOURCE)/init.sh +PS1="$" + +paperVer=$(cat current-paper) +gpgsign="$(git config commit.gpgsign || echo "false")" +echo "Rebuilding Forked projects.... " +function applyPatch { + what=$1 + what_name=$(basename $what) + target=$2 + branch=$3 + patch_folder=$4 + + cd "$basedir/$what" + git fetch --all + git branch -f upstream "$branch" >/dev/null + + cd "$basedir" + if [ ! -d "$basedir/$target" ]; then + mkdir "$basedir/$target" + cd "$basedir/$target" + git init + git remote add origin $5 + cd "$basedir" + fi + cd "$basedir/$target" + + # Disable GPG signing before AM, slows things down and doesn't play nicely. + # There is also zero rational or logical reason to do so for these sub-repo AMs. + # Calm down kids, it's re-enabled (if needed) immediately after, pass or fail. + git config commit.gpgsign false + + echo "Resetting $target to $what_name..." + git remote rm upstream > /dev/null 2>&1 + git remote add upstream $basedir/$what >/dev/null 2>&1 + git checkout master 2>/dev/null || git checkout -b master + git fetch upstream >/dev/null 2>&1 + git reset --hard upstream/upstream + echo " Applying patches to $target..." + git am --abort >/dev/null 2>&1 + git am --3way --ignore-whitespace "$basedir/patches/$patch_folder/"*.patch + if [ "$?" != "0" ]; then + echo " Something did not apply cleanly to $target." + echo " Please review above details and finish the apply then" + echo " save the changes with rebuildPatches.sh" + exit 1 + else + echo " Patches applied cleanly to $target" + fi +} + +function enableCommitSigningIfNeeded { + if [[ "$gpgsign" == "true" ]]; then + git config commit.gpgsign true + fi +} + +( + (applyPatch Paper/Paper-API ${FORK_NAME}-API HEAD api $API_REPO && + applyPatch Paper/Paper-Server ${FORK_NAME}-Server HEAD server $SERVER_REPO) || exit 1 + enableCommitSigningIfNeeded +) || ( + echo "Failed to apply patches" + enableCommitSigningIfNeeded + exit 1 +) || exit 1 diff --git a/scripts/generatesources.sh b/scripts/generatesources.sh new file mode 100755 index 000000000..30c76718a --- /dev/null +++ b/scripts/generatesources.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +. $(dirname $SOURCE)/init.sh + + +cd $basedir +paperVer=$(cat current-paper) + +minecraftversion=$(cat $basedir/Paper/work/BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4) +decompile="Paper/work/Minecraft/$minecraftversion/forge" + +mkdir -p mc-dev/src/net/minecraft/server + +cd mc-dev +if [ ! -d ".git" ]; then + git init +fi + +rm src/net/minecraft/server/*.java +cp $basedir/$decompile/net/minecraft/server/*.java src/net/minecraft/server + +base="$basedir/Paper/Paper-Server/src/main/java/net/minecraft/server" +cd $basedir/mc-dev/src/net/minecraft/server/ +for file in $(/bin/ls $base) +do + if [ -f "$file" ]; then + rm -f "$file" + fi +done +cd $basedir/mc-dev +git add . -A +git commit . -m "mc-dev" +git tag -a "$paperVer" -m "$paperVer" 2>/dev/null +pushRepo . $MCDEV_REPO $paperVer diff --git a/scripts/importmcdev.sh b/scripts/importmcdev.sh new file mode 100755 index 000000000..5139756e3 --- /dev/null +++ b/scripts/importmcdev.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash + +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +. $(dirname $SOURCE)/init.sh + +workdir=$basedir/Paper/work +minecraftversion=$(cat $basedir/Paper/work/BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4) +decompiledir=$workdir/Minecraft/$minecraftversion/forge + +nms="net/minecraft/server" +export MODLOG="" +cd $basedir + +function containsElement { + local e + for e in "${@:2}"; do + [[ "$e" == "$1" ]] && return 0; + done + return 1 +} + +export importedmcdev="" +function import { + if [ -f "$basedir/Paper/Paper-Server/src/main/java/net/minecraft/server/$1.java" ]; then + echo "ALREADY IMPORTED $1" + return 0 + fi + export importedmcdev="$importedmcdev $1" + file="${1}.java" + target="$basedir/Paper/Paper-Server/src/main/java/$nms/$file" + base="$decompiledir/$nms/$file" + + if [[ ! -f "$target" ]]; then + export MODLOG="$MODLOG Imported $file from mc-dev\n"; + echo "$(bashColor 1 32) Copying $(bashColor 1 34)$base $(bashColor 1 32)to$(bashColor 1 34) $target $(bashColorReset)" + cp "$base" "$target" + else + echo "$(bashColor 1 33) UN-NEEDED IMPORT STATEMENT:$(bashColor 1 34) $file $(bashColorReset)" + fi +} + +( + cd Paper/Paper-Server/ + lastlog=$(git log -1 --oneline) + if [[ "$lastlog" = *"Purpur-Extra mc-dev Imports"* ]]; then + git reset --hard HEAD^ + fi +) + + +files=$(cat patches/server/* | grep "+++ b/src/main/java/net/minecraft/server/" | sort | uniq | sed 's/\+\+\+ b\/src\/main\/java\/net\/minecraft\/server\///g' | sed 's/.java//g') + +nonnms=$(cat patches/server/* | grep "create mode " | grep -Po "src/main/java/net/minecraft/server/(.*?).java" | sort | uniq | sed 's/src\/main\/java\/net\/minecraft\/server\///g' | sed 's/.java//g') + +for f in $files; do + containsElement "$f" ${nonnms[@]} + if [ "$?" == "1" ]; then + if [ ! -f "$basedir/Paper/Paper-Server/src/main/java/net/minecraft/server/$f.java" ]; then + if [ ! -f "$decompiledir/$nms/$f.java" ]; then + echo "$(bashColor 1 31) ERROR!!! Missing NMS$(bashColor 1 34) $f $(bashColorReset)"; + else + import $f + fi + fi + fi +done + +############################################################################################### +############################################################################################### +#################### ADD TEMPORARY ADDITIONS HERE ############################################# +############################################################################################### +############################################################################################### + +# import Foo + +################ +( + cd Paper/Paper-Server/ + rm -rf nms-patches + git add src -A + echo -e "Purpur-Extra mc-dev Imports\n\n$MODLOG" | git commit src -F - +) + + diff --git a/scripts/init.sh b/scripts/init.sh new file mode 100755 index 000000000..25ab21ffd --- /dev/null +++ b/scripts/init.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash +# BEGIN config +FORK_NAME="Purpur" +API_REPO="" +SERVER_REPO="" +PAPER_API_REPO="" +PAPER_SERVER_REPO="" +MCDEV_REPO="" +# END config + +sourceBase=$(dirname $SOURCE)/../ +cd ${basedir:-$sourceBase} + +basedir=$(pwd -P) +cd - + + +function bashColor { +if [ $2 ]; then + echo -e "\e[$1;$2m" +else + echo -e "\e[$1m" +fi +} +function bashColorReset { + echo -e "\e[m" +} + +function cleanupPatches { + cd "$1" + for patch in *.patch; do + gitver=$(tail -n 2 $patch | grep -ve "^$" | tail -n 1) + diffs=$(git diff --staged $patch | grep -E "^(\+|\-)" | grep -Ev "(From [a-z0-9]{32,}|\-\-\- a|\+\+\+ b|.index|Date\: )") + + testver=$(echo "$diffs" | tail -n 2 | grep -ve "^$" | tail -n 1 | grep "$gitver") + if [ "x$testver" != "x" ]; then + diffs=$(echo "$diffs" | tail -n +3) + fi + + if [ "x$diffs" == "x" ] ; then + git reset HEAD $patch >/dev/null + git checkout -- $patch >/dev/null + fi + done +} +function pushRepo { + if [ "$(git config minecraft.push-${FORK_NAME})" == "1" ]; then + echo "Pushing - $1 ($3) to $2" + ( + cd "$1" + git remote rm emc-push > /dev/null 2>&1 + git remote add emc-push $2 >/dev/null 2>&1 + git push emc-push $3 -f + ) + fi +} +function basedir { + cd "$basedir" +} +function gethead { + ( + cd "$1" + git log -1 --oneline + ) +} diff --git a/scripts/push.sh b/scripts/push.sh new file mode 100755 index 000000000..ed4bf9f00 --- /dev/null +++ b/scripts/push.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# get base dir regardless of execution location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +. $(dirname $SOURCE)/init.sh + +minecraftversion=$(cat $basedir/Paper/work/BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4) + +basedir +pushRepo ${FORK_NAME}-API $API_REPO master:$minecraftversion +pushRepo ${FORK_NAME}-Server $SERVER_REPO master:$minecraftversion diff --git a/scripts/rebuildpatches.sh b/scripts/rebuildpatches.sh new file mode 100755 index 000000000..a0d13b969 --- /dev/null +++ b/scripts/rebuildpatches.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env bash +# get base dir regardless of execution location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +. $(dirname $SOURCE)/init.sh + +PS1="$" +echo "Rebuilding patch files from current fork state..." +function savePatches { + what=$1 + cd $basedir/$what/ + + mkdir -p $basedir/patches/$2 + if [ -d ".git/rebase-apply" ]; then + # in middle of a rebase, be smarter + echo "REBASE DETECTED - PARTIAL SAVE" + last=$(cat ".git/rebase-apply/last") + next=$(cat ".git/rebase-apply/next") + declare -a files=("$basedir/patches/$2/"*.patch) + for i in $(seq -f "%04g" 1 1 $last) + do + if [ $i -lt $next ]; then + rm "${files[`expr $i - 1`]}" + fi + done + else + rm $basedir/patches/$2/*.patch + fi + + git format-patch --quiet -N -o $basedir/patches/$2 upstream/upstream + cd $basedir + git add -A $basedir/patches/$2 + cleanupPatches $basedir/patches/$2/ + echo " Patches saved for $what to patches/$2" +} + +savePatches ${FORK_NAME}-API api +savePatches ${FORK_NAME}-Server server + +$basedir/scripts/push.sh diff --git a/scripts/upstream.sh b/scripts/upstream.sh new file mode 100755 index 000000000..25ec4c8d4 --- /dev/null +++ b/scripts/upstream.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash +# get base dir regardless of execution location +SOURCE="${BASH_SOURCE[0]}" +while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located +done +. $(dirname $SOURCE)/init.sh + +if [[ "$1" == up* ]]; then + ( + cd "$basedir/Paper/" + git fetch && git reset --hard origin/master + cd ../ + git add Paper + ) +fi + +paperVer=$(gethead Paper) +cd "$basedir/Paper/" + +./paper patch + +cd "Paper-Server" +mcVer=$(mvn -o org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate -Dexpression=minecraft_version | sed -n -e '/^\[.*\]/ !{ /^[0-9]/ { p; q } }') + +basedir +. $basedir/scripts/importmcdev.sh + +minecraftversion=$(cat $basedir/Paper/work/BuildData/info.json | grep minecraftVersion | cut -d '"' -f 4) +version=$(echo -e "Paper: $paperVer\nmc-dev:$importedmcdev") +tag="${minecraftversion}-${mcVer}-$(echo -e $version | shasum | awk '{print $1}')" +echo "$tag" > $basedir/current-paper + +$basedir/scripts/generatesources.sh + +cd Paper/ + +function tag { +( + cd $1 + if [ "$2" == "1" ]; then + git tag -d "$tag" 2>/dev/null + fi + echo -e "$(date)\n\n$version" | git tag -a "$tag" -F - 2>/dev/null +) +} +echo "Tagging as $tag" +echo -e "$version" + +forcetag=0 +if [ "$(cat $basedir/current-paper)" != "$tag" ]; then + forcetag=1 +fi + +tag Paper-API $forcetag +tag Paper-Server $forcetag + +pushRepo Paper-API $PAPER_API_REPO $tag +pushRepo Paper-Server $PAPER_SERVER_REPO $tag +