diff --git a/buildSrc/src/main/kotlin/task/ApplyPatches.kt b/buildSrc/src/main/kotlin/task/ApplyPatches.kt index f158c51f..8dca4d41 100644 --- a/buildSrc/src/main/kotlin/task/ApplyPatches.kt +++ b/buildSrc/src/main/kotlin/task/ApplyPatches.kt @@ -102,13 +102,37 @@ internal fun Project.createApplyPatchesTask( } fun initYarn() { // Todo actually port to kotlin - val paperDecompDir = toothpick.paperDecompDir bashCmd("cd mappings/mapper && ./gradlew installDist", printOut = true) bashCmd("rm -fr mappings/work/Base", printOut = true) bashCmd("mkdir -p mappings/work/Base/src/main/java/com/mojang", printOut = true) - bashCmd("cp -r $paperDecompDir/spigot/* mappings/work/Base/src/main/java/", printOut = true, dir = project.getRootDir()) + bashCmd("cp -r ${toothpick.paperDecompDir}/spigot/* mappings/work/Base/src/main/java/", printOut = true) + + // Todo start - make this code better + val patchPaths = Files.newDirectoryStream(Paths.get("${rootProject.projectDir}/patches/server")) + .map { it.toFile() } + .filter { it.name.endsWith(".patch") } + .sorted() + .toList() + + val linesRaw = patchPaths.asSequence() + .flatMap { it.readLines().asSequence() } + + val lines = linesRaw + .filter { line -> line.startsWith("--- a/src/main/java/") && !linesRaw.contains("+++ b/${line.substringAfter("""-- a/""")}") } + .toList().distinct() + + val removedFiles = lines.asSequence() + .filter { line -> line.startsWith("--- a/src/main/java/") } + .distinct() + .map { it.substringAfter("/src/main/java/") } + .toSet() + // Todo end + bashCmd("cp -r $forkName-Server/src/main/java/* mappings/work/Base/src/main/java/", printOut = true) - bashCmd("cp -r $paperDecompDir/libraries/com.mojang/*/* mappings/work/Base/src/main/java/", printOut = true) + bashCmd("cp -r ${toothpick.paperDecompDir}/libraries/com.mojang/*/* mappings/work/Base/src/main/java/", printOut = true) + + removedFiles.forEach{ bashCmd("rm -frv mappings/work/Base/src/main/java/$it", printOut = true) } + bashCmd("rm -fr mappings/work/$forkName-Server_yarn_unpatched && mkdir -p mappings/work/$forkName-Server_yarn_unpatched/src/main/java", printOut = true) bashCmd("cp $forkName-Server/.gitignore $forkName-Server/pom.xml $forkName-Server/checkstyle.xml $forkName-Server/CONTRIBUTING.md $forkName-Server/LGPL.txt $forkName-Server/LICENCE.txt $forkName-Server/README.md mappings/work/$forkName-Server_yarn_unpatched/", printOut = true) bashCmd("JAVA_OPTS='-Xms1G -Xmx2G' mappings/mapper/build/install/mapper/bin/mapper mappings/map.srg mappings/work/Base/src/main/java mappings/work/$forkName-Server_yarn_unpatched/src/main/java", printOut = true) diff --git a/mappings/scripts/install.sh b/mappings/scripts/install.sh index 654d8b30..e1bd8f13 100755 --- a/mappings/scripts/install.sh +++ b/mappings/scripts/install.sh @@ -13,26 +13,29 @@ do_fixes(){ git config init.defaultBranch master cd $basedir/mappings/work -rm -fr Yatopia-Server_remapped -mkdir -p Yatopia-Server_remapped/src/main -cp -r Base/src/main/java Yatopia-Server_remapped/src/main/ -cd Yatopia-Server_remapped +rm -fr "${inputdirprefix}Server_remapped" +mkdir -p "${inputdirprefix}Server_remapped/src/main" +cp -r Base/src/main/java "${inputdirprefix}Server_remapped/src/main/" +cd "${inputdirprefix}Server_remapped" git init git add . git commit --quiet --message=Base rm -fr src/main/java/* cd .. -JAVA_OPTS="-Xms1G -Xmx2G" "${basedir}/mappings/mapper/build/install/mapper/bin/mapper" "${basedir}/mappings/unmap.srg" "${basedir}/Yatopia-Server_yarn/src/main/java" "${basedir}/mappings/work/Yatopia-Server_remapped/src/main/java" +JAVA_OPTS="-Xms1G -Xmx2G" "${basedir}/mappings/mapper/build/install/mapper/bin/mapper" "${basedir}/mappings/unmap.srg" "${basedir}/${inputdirprefix}Server_yarn/src/main/java" "${basedir}/mappings/work/${inputdirprefix}Server_remapped/src/main/java" -cd ${basedir}/mappings/work/Yatopia-Server_remapped/src/main/java +cd "${basedir}/mappings/work/${inputdirprefix}Server_remapped/src/main/java" do_fixes cd "$basedir" -changed="$(cat mappedPatches/*.patch | grep "+++ b/" | sort | uniq | sed 's/\+\+\+ b\///g')" -cd ${basedir}/mappings/work/Yatopia-Server_remapped +changed="$(cat mappedPatches/*.patch | grep "+++ b/\|+++ a/\|--- b/\|--- a/" | sort | uniq | sed 's/\+\+\+ b\///g' | sed 's/\+\+\+ a\///g' | sed 's/\-\-\- b\///g' | sed 's/\-\-\- a\///g')" +cd "${basedir}/mappings/work/${inputdirprefix}Server_remapped" # git add . -git add $changed #only commit the files that were modified +for file in $changed; do + git add $file || true +done +# git add $changed #only commit the files that were modified git diff --cached > a.patch @@ -46,6 +49,6 @@ if [ $(git log --pretty=format:'%s' | grep '' | wc -l) != "0" ]; fi fi -patch -p1 < "$basedir/mappings/work/Yatopia-Server_remapped/a.patch" +patch -p1 < "$basedir/mappings/work/${inputdirprefix}Server_remapped/a.patch" git add . git commit -m ""