From a90c5ac179649ccf115e8dd49390ef78d2ed14aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tofik=20=E2=99=A1?= <62406295+Toffikk@users.noreply.github.com> Date: Mon, 14 Jun 2021 20:29:53 +0200 Subject: [PATCH 1/3] [ci-skip] Replaced buildSrc with a gradle plugin (#504) --- .github/workflows/build.yml | 2 +- Yatoclip/build.gradle.kts | 4 + api | 1 - build.gradle.kts | 16 +- buildSrc/build.gradle.kts | 39 --- buildSrc/license.txt | 21 -- .../yatoclip/gradle/MakePatchesTask.java | 269 ------------------ .../yatoclip/gradle/PatchesMetadata.java | 51 ---- .../yatoclip/gradle/PropertiesUtils.java | 22 -- .../src/main/kotlin/ConfigureSubprojects.kt | 253 ---------------- buildSrc/src/main/kotlin/Constants.kt | 2 - buildSrc/src/main/kotlin/DependencyLoading.kt | 72 ----- buildSrc/src/main/kotlin/InitTasks.kt | 74 ----- buildSrc/src/main/kotlin/MCDevImports.kt | 45 --- buildSrc/src/main/kotlin/PatchParser.kt | 77 ----- buildSrc/src/main/kotlin/PomParsing.kt | 55 ---- buildSrc/src/main/kotlin/Toothpick.kt | 9 - .../src/main/kotlin/ToothpickExtension.kt | 93 ------ .../src/main/kotlin/ToothpickExtensions.kt | 41 --- .../src/main/kotlin/ToothpickSubproject.kt | 20 -- buildSrc/src/main/kotlin/Upstream.kt | 88 ------ buildSrc/src/main/kotlin/Util.kt | 92 ------ .../kotlin/relocation/ToothpickRelocator.kt | 58 ---- buildSrc/src/main/kotlin/task/ApplyPatches.kt | 102 ------- buildSrc/src/main/kotlin/task/FixBranches.kt | 55 ---- buildSrc/src/main/kotlin/task/ImportMCDev.kt | 118 -------- .../src/main/kotlin/task/InitGitSubmodules.kt | 25 -- buildSrc/src/main/kotlin/task/Paperclip.kt | 38 --- buildSrc/src/main/kotlin/task/PatchCredits.kt | 100 ------- .../src/main/kotlin/task/RebuildPatches.kt | 89 ------ buildSrc/src/main/kotlin/task/RepackageNMS.kt | 108 ------- .../src/main/kotlin/task/SetupUpstream.kt | 35 --- .../src/main/kotlin/task/UpdateUpstream.kt | 155 ---------- .../src/main/kotlin/task/UpstreamCommit.kt | 82 ------ ...difiedLog4j2PluginsCacheFileTransformer.kt | 39 --- gradle/wrapper/gradle-wrapper.properties | 4 +- mcdevimports.json | 135 +++++++++ patches/server/0066-Fix-Log4j-Warning.patch | 262 ----------------- server | 1 - settings.gradle.kts | 9 + subprojects/api.gradle.kts | 8 + subprojects/server.gradle.kts | 8 + 42 files changed, 180 insertions(+), 2597 deletions(-) delete mode 100644 api delete mode 100644 buildSrc/build.gradle.kts delete mode 100644 buildSrc/license.txt delete mode 100644 buildSrc/src/main/java/org/yatopiamc/yatoclip/gradle/MakePatchesTask.java delete mode 100644 buildSrc/src/main/java/org/yatopiamc/yatoclip/gradle/PatchesMetadata.java delete mode 100644 buildSrc/src/main/java/org/yatopiamc/yatoclip/gradle/PropertiesUtils.java delete mode 100644 buildSrc/src/main/kotlin/ConfigureSubprojects.kt delete mode 100644 buildSrc/src/main/kotlin/Constants.kt delete mode 100644 buildSrc/src/main/kotlin/DependencyLoading.kt delete mode 100644 buildSrc/src/main/kotlin/InitTasks.kt delete mode 100644 buildSrc/src/main/kotlin/MCDevImports.kt delete mode 100644 buildSrc/src/main/kotlin/PatchParser.kt delete mode 100644 buildSrc/src/main/kotlin/PomParsing.kt delete mode 100644 buildSrc/src/main/kotlin/Toothpick.kt delete mode 100644 buildSrc/src/main/kotlin/ToothpickExtension.kt delete mode 100644 buildSrc/src/main/kotlin/ToothpickExtensions.kt delete mode 100644 buildSrc/src/main/kotlin/ToothpickSubproject.kt delete mode 100644 buildSrc/src/main/kotlin/Upstream.kt delete mode 100644 buildSrc/src/main/kotlin/Util.kt delete mode 100644 buildSrc/src/main/kotlin/relocation/ToothpickRelocator.kt delete mode 100644 buildSrc/src/main/kotlin/task/ApplyPatches.kt delete mode 100644 buildSrc/src/main/kotlin/task/FixBranches.kt delete mode 100644 buildSrc/src/main/kotlin/task/ImportMCDev.kt delete mode 100644 buildSrc/src/main/kotlin/task/InitGitSubmodules.kt delete mode 100644 buildSrc/src/main/kotlin/task/Paperclip.kt delete mode 100644 buildSrc/src/main/kotlin/task/PatchCredits.kt delete mode 100644 buildSrc/src/main/kotlin/task/RebuildPatches.kt delete mode 100644 buildSrc/src/main/kotlin/task/RepackageNMS.kt delete mode 100644 buildSrc/src/main/kotlin/task/SetupUpstream.kt delete mode 100644 buildSrc/src/main/kotlin/task/UpdateUpstream.kt delete mode 100644 buildSrc/src/main/kotlin/task/UpstreamCommit.kt delete mode 100644 buildSrc/src/main/kotlin/transformer/ModifiedLog4j2PluginsCacheFileTransformer.kt create mode 100644 mcdevimports.json delete mode 100644 patches/server/0066-Fix-Log4j-Warning.patch delete mode 100644 server diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 247818a5..0662643c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -77,7 +77,7 @@ jobs: - name: Build Yatopia run: | - ./gradlew clean build paperclip + ./gradlew clean build paperclip --no-build-cache - name: Upload Artifact uses: actions/upload-artifact@v2 diff --git a/Yatoclip/build.gradle.kts b/Yatoclip/build.gradle.kts index 3d1d3e7a..4f6fb0da 100644 --- a/Yatoclip/build.gradle.kts +++ b/Yatoclip/build.gradle.kts @@ -1,3 +1,7 @@ +plugins { + `java-library` +} + repositories { mavenCentral() maven("https://jitpack.io/") diff --git a/api b/api deleted file mode 100644 index 20848e10..00000000 --- a/api +++ /dev/null @@ -1 +0,0 @@ -Yatopia-API/ \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 6de486f1..1c44955c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,9 @@ +import org.yatopiamc.toothpick.* + plugins { `java-library` `maven-publish` - toothpick + id("org.yatopiamc.toothpick") version "1.0.1-SNAPSHOT" } toothpick { @@ -54,16 +56,24 @@ subprojects { maven("https://libraries.minecraft.net") maven("https://repo.codemc.io/repository/maven-public/") maven("https://jitpack.io") + maven("https://mvn.thearcanebrony.net/maven-public/") mavenLocal() maven("${rootProjectDir}/.repository") } java { if(JavaVersion.VERSION_1_8 > JavaVersion.current()){ - error("This build must be run with Java 8 or better") + error("This build must be run with Java 8 or newer") } sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.current() + targetCompatibility = JavaVersion.VERSION_1_8 withSourcesJar() } + +tasks.withType().configureEach { + options.isIncremental = true + options.isFork = true + options.encoding = "UTF-8" + } } + diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts deleted file mode 100644 index 540b3574..00000000 --- a/buildSrc/build.gradle.kts +++ /dev/null @@ -1,39 +0,0 @@ -val kotlinxDomVersion = "0.0.10" -val shadowVersion = "7.0.0" -val mustacheVersion = "0.9.6" -val javaxMailVersion = "1.4.4" - -plugins { - `kotlin-dsl` -} - -repositories { - mavenCentral() - maven("https://plugins.gradle.org/m2/") - maven("https://jitpack.io/") -} - -dependencies { - implementation("org.jetbrains.kotlinx:kotlinx.dom:$kotlinxDomVersion") - implementation("com.github.johnrengelman:shadow:$shadowVersion") - implementation("com.github.spullara.mustache.java:compiler:$mustacheVersion") - implementation("javax.mail:mail:$javaxMailVersion") - implementation("com.github.ishlandbukkit:jbsdiff:deff66b794") - implementation("com.google.code.gson:gson:2.8.6") - implementation("com.google.guava:guava:30.0-jre") - implementation("commons-io:commons-io:2.8.0") -} - -tasks.withType { - options.encoding = "UTF-8" - sourceCompatibility = "1.8" -} - -gradlePlugin { - plugins { - register("Toothpick") { - id = "toothpick" - implementationClass = "Toothpick" - } - } -} diff --git a/buildSrc/license.txt b/buildSrc/license.txt deleted file mode 100644 index ffe469d9..00000000 --- a/buildSrc/license.txt +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020-2021 Jason Penilla & Contributors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/buildSrc/src/main/java/org/yatopiamc/yatoclip/gradle/MakePatchesTask.java b/buildSrc/src/main/java/org/yatopiamc/yatoclip/gradle/MakePatchesTask.java deleted file mode 100644 index ec7223fc..00000000 --- a/buildSrc/src/main/java/org/yatopiamc/yatoclip/gradle/MakePatchesTask.java +++ /dev/null @@ -1,269 +0,0 @@ -package org.yatopiamc.yatoclip.gradle; - -import com.google.common.base.Preconditions; -import com.google.common.base.Throwables; -import com.google.common.collect.Sets; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -import com.google.gson.Gson; -import io.sigpipe.jbsdiff.Diff; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.gradle.api.DefaultTask; -import org.gradle.api.internal.project.ProjectInternal; -import org.gradle.api.tasks.Copy; -import org.gradle.api.tasks.Input; -import org.gradle.api.tasks.InputFile; -import org.gradle.api.tasks.OutputDirectory; -import org.gradle.api.tasks.TaskAction; -import org.gradle.internal.logging.progress.ProgressLogger; -import org.gradle.internal.logging.progress.ProgressLoggerFactory; -import org.gradle.work.Incremental; -import org.gradle.workers.WorkerExecutor; - -import javax.inject.Inject; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -public class MakePatchesTask extends DefaultTask { - - @OutputDirectory - private final File outputDir = ((Copy) getProject().getTasks().getByPath("processResources")).getDestinationDir().toPath().resolve("patches").toFile(); - - @InputFile - @Incremental - public File originalJar = null; - @InputFile - @Incremental - public File targetJar = null; - - public Set getRelocations() { - return relocations; - } - - public void setRelocations(Set relocations) { - this.relocations = relocations; - } - - @Input - public Set relocations; - - public File getOriginalJar() { - return originalJar; - } - - public void setOriginalJar(File originalJar) { - this.originalJar = originalJar; - } - - public File getTargetJar() { - return targetJar; - } - - public void setTargetJar(File targetJar) { - this.targetJar = targetJar; - } - - public File getOutputDir() { - return outputDir; - } - - private ProgressLoggerFactory getProgressLoggerFactory() { - return ((ProjectInternal) getProject()).getServices().get(ProgressLoggerFactory.class); - } - - @Inject - public WorkerExecutor getWorkerExecutor() { - throw new UnsupportedOperationException(); - } - - @TaskAction - public void genPatches() throws IOException, InterruptedException { - Preconditions.checkNotNull(originalJar); - Preconditions.checkNotNull(targetJar); - getLogger().lifecycle("Generating patches for " + originalJar + " -> " + targetJar); - - final ProgressLogger genPatches = getProgressLoggerFactory().newOperation(getClass()).setDescription("Generate patches"); - genPatches.started(); - - genPatches.progress("Cleanup"); - outputDir.mkdirs(); - FileUtils.cleanDirectory(outputDir); - - genPatches.progress("Reading files"); - ThreadLocal originalZip = ThreadLocal.withInitial(() -> { - try { - return new ZipFile(originalJar); - } catch (IOException e) { - throw new RuntimeException(e); - } - }); - ThreadLocal targetZip = ThreadLocal.withInitial(() -> { - try { - return new ZipFile(targetJar); - } catch (IOException e) { - throw new RuntimeException(e); - } - }); - - Set patchMetadata = Sets.newConcurrentHashSet(); - ThreadLocal digestThreadLocal = ThreadLocal.withInitial(() -> { - try { - return MessageDigest.getInstance("SHA-256"); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException(e); - } - }); - ThreadLocal progressLoggerThreadLocal = ThreadLocal.withInitial(() -> { - final ProgressLogger progressLogger = getProgressLoggerFactory().newOperation(this.getClass()); - progressLogger.setDescription("Patch worker"); - progressLogger.started("Idle"); - return progressLogger; - }); - final ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), - new ThreadFactoryBuilder().setNameFormat("MakePatches-%d").setThreadFactory(r -> new Thread(() -> { - boolean isExceptionOccurred = false; - try { - r.run(); - } catch (Throwable t) { - isExceptionOccurred = true; - progressLoggerThreadLocal.get().completed(t.toString(), true); - throw t; - } finally { - digestThreadLocal.remove(); - if (!isExceptionOccurred) - progressLoggerThreadLocal.get().completed(); - progressLoggerThreadLocal.remove(); - try { - originalZip.get().close(); - targetZip.get().close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - })).build()); - AtomicInteger current = new AtomicInteger(0); - final int size = targetZip.get().size(); - ((Iterator) targetZip.get().entries()).forEachRemaining(zipEntryT -> { - genPatches.progress("Submitting tasks (" + current.incrementAndGet() + "/" + size + ")"); - if (zipEntryT.isDirectory()) return; - executorService.execute(() -> { - ZipEntry zipEntry = targetZip.get().getEntry(zipEntryT.getName()); - final String child = zipEntry.getName(); - progressLoggerThreadLocal.get().progress("Reading " + zipEntry.getName()); - File outputFile = new File(outputDir, child + ".patch"); - outputFile.getParentFile().mkdirs(); - final byte[] originalBytes; - final byte[] targetBytes; - final ZipEntry oEntry = originalZip.get().getEntry(applyRelocationsReverse(child)); - try ( - final InputStream oin = oEntry != null ? originalZip.get().getInputStream(oEntry) : null; - final InputStream tin = targetZip.get().getInputStream(zipEntry); - ) { - originalBytes = oin != null ? IOUtils.toByteArray(oin) : new byte[0]; - targetBytes = IOUtils.toByteArray(tin); - } catch (Throwable e) { - Throwables.throwIfUnchecked(e); - throw new RuntimeException(e); - } - if (Arrays.equals(originalBytes, targetBytes)) return; - - progressLoggerThreadLocal.get().progress("GenPatch " + zipEntry.getName()); - try (final OutputStream out = new FileOutputStream(outputFile)) { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - Diff.diff(originalBytes, targetBytes, byteArrayOutputStream); - patchMetadata.add(new PatchesMetadata.PatchMetadata(child, toHex(digestThreadLocal.get().digest(originalBytes)), toHex(digestThreadLocal.get().digest(targetBytes)), toHex(digestThreadLocal.get().digest(byteArrayOutputStream.toByteArray())))); - out.write(byteArrayOutputStream.toByteArray()); - } catch (Throwable t) { - Throwables.throwIfUnchecked(t); - throw new RuntimeException(t); - } - - progressLoggerThreadLocal.get().progress("Idle"); - }); - }); - genPatches.progress("Calculating exclusions"); - Set copyExcludes = new HashSet<>(); - ((Iterator) originalZip.get().entries()).forEachRemaining(zipEntry -> { - if(targetZip.get().getEntry(applyRelocations(zipEntry.getName())) == null) - copyExcludes.add(zipEntry.getName()); - }); - originalZip.get().close(); - targetZip.get().close(); - - genPatches.progress("Waiting for patching to finish"); - executorService.shutdown(); - while (!executorService.awaitTermination(1, TimeUnit.SECONDS)) ; - digestThreadLocal.remove(); - - genPatches.progress("Writing patches metadata"); - try (final OutputStream out = new FileOutputStream(new File(outputDir, "metadata.json")); - final Writer writer = new OutputStreamWriter(out)) { - new Gson().toJson(new PatchesMetadata(patchMetadata, relocations, copyExcludes), writer); - } - - /* - genPatches.progress("Reading jar files into memory"); - byte[] origin = Files.readAllBytes(originalJar.toPath()); - byte[] target = Files.readAllBytes(targetJar.toPath()); - - genPatches.progress("Generating patch"); - try(final OutputStream out = new BufferedOutputStream(new FileOutputStream(output))){ - Diff.diff(origin, target, out); - } - */ - - genPatches.completed(); - - } - - private String applyRelocations(String name) { - if(!name.endsWith(".class")) return name; - if (name.indexOf('/') == -1) - name = "/" + name; - for (PatchesMetadata.Relocation relocation : relocations) { - if (name.startsWith(relocation.from) && (relocation.includeSubPackages || name.split("/").length == name.split("/").length - 1)) { - return relocation.to + name.substring(relocation.from.length()); - } - } - return name; - } - - private String applyRelocationsReverse(String name) { - if(!name.endsWith(".class")) return name; - if (name.indexOf('/') == -1) - name = "/" + name; - for (PatchesMetadata.Relocation relocation : relocations) { - if (name.startsWith(relocation.to) && (relocation.includeSubPackages || name.split("/").length == name.split("/").length - 1)) { - return relocation.from + name.substring(relocation.to.length()); - } - } - return name; - } - - public static String toHex(final byte[] hash) { - final StringBuilder sb = new StringBuilder(hash.length * 2); - for (byte aHash : hash) { - sb.append(String.format("%02X", aHash & 0xFF)); - } - return sb.toString(); - } - -} diff --git a/buildSrc/src/main/java/org/yatopiamc/yatoclip/gradle/PatchesMetadata.java b/buildSrc/src/main/java/org/yatopiamc/yatoclip/gradle/PatchesMetadata.java deleted file mode 100644 index 4c7f0bbb..00000000 --- a/buildSrc/src/main/java/org/yatopiamc/yatoclip/gradle/PatchesMetadata.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.yatopiamc.yatoclip.gradle; - -import java.io.Serializable; -import java.util.Collections; -import java.util.Objects; -import java.util.Set; - -public class PatchesMetadata { - - public final Set patches; - public final Set relocations; - public final Set copyExcludes; - - public PatchesMetadata(Set patches, Set relocations, Set copyExcludes) { - Objects.requireNonNull(copyExcludes); - this.copyExcludes = Collections.unmodifiableSet(copyExcludes); - Objects.requireNonNull(relocations); - this.relocations = Collections.unmodifiableSet(relocations); - Objects.requireNonNull(patches); - this.patches = Collections.unmodifiableSet(patches); - } - - public static class PatchMetadata { - public final String name; - public final String originalHash; - public final String targetHash; - public final String patchHash; - - public PatchMetadata(String name, String originalHash, String targetHash, String patchHash) { - this.name = name; - this.originalHash = originalHash; - this.targetHash = targetHash; - this.patchHash = patchHash; - } - } - - public static class Relocation implements Serializable { - - public final String from; - public final String to; - public final boolean includeSubPackages; - - public Relocation(String from, String to, boolean includeSubPackages) { - Objects.requireNonNull(from); - Objects.requireNonNull(to); - this.from = from.replaceAll("\\.", "/"); - this.to = to.replaceAll("\\.", "/"); - this.includeSubPackages = includeSubPackages; - } - } -} diff --git a/buildSrc/src/main/java/org/yatopiamc/yatoclip/gradle/PropertiesUtils.java b/buildSrc/src/main/java/org/yatopiamc/yatoclip/gradle/PropertiesUtils.java deleted file mode 100644 index 39b35480..00000000 --- a/buildSrc/src/main/java/org/yatopiamc/yatoclip/gradle/PropertiesUtils.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.yatopiamc.yatoclip.gradle; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.file.Path; -import java.util.Properties; - -public class PropertiesUtils { - - public static void saveProperties(Properties prop, Path file, String comments){ - System.out.println("Saving properties file to " + file); - file.toFile().getParentFile().mkdirs(); - file.toFile().delete(); - try(final OutputStream out = new FileOutputStream(file.toFile())) { - prop.store(out, comments); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - -} diff --git a/buildSrc/src/main/kotlin/ConfigureSubprojects.kt b/buildSrc/src/main/kotlin/ConfigureSubprojects.kt deleted file mode 100644 index 869055f3..00000000 --- a/buildSrc/src/main/kotlin/ConfigureSubprojects.kt +++ /dev/null @@ -1,253 +0,0 @@ -import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar -// import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer -import transformer.ModifiedLog4j2PluginsCacheFileTransformer -import relocation.ToothpickRelocator -import kotlinx.dom.elements -import kotlinx.dom.search -import org.gradle.api.Project -import org.gradle.api.Task -import org.gradle.api.UnknownDomainObjectException -import org.gradle.api.plugins.JavaLibraryPlugin -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.api.publish.PublishingExtension -import org.gradle.api.publish.maven.MavenPublication -import org.gradle.api.publish.maven.plugins.MavenPublishPlugin -import org.gradle.api.publish.maven.tasks.GenerateMavenPom -import org.gradle.api.tasks.Copy -import org.gradle.api.tasks.bundling.Jar -import org.gradle.api.tasks.compile.JavaCompile -import org.gradle.api.tasks.javadoc.Javadoc -import org.gradle.api.tasks.testing.Test -import org.gradle.kotlin.dsl.* -import org.yatopiamc.yatoclip.gradle.MakePatchesTask -import org.yatopiamc.yatoclip.gradle.PatchesMetadata -import org.yatopiamc.yatoclip.gradle.PropertiesUtils -import java.nio.charset.StandardCharsets.UTF_8 -import java.text.SimpleDateFormat -import java.util.* -import kotlin.collections.HashSet - -internal fun Project.configureSubprojects() { - subprojects { - apply() - apply() - - tasks.withType { - options.encoding = UTF_8.name() - } - tasks.withType { - options.encoding = UTF_8.name() - } - - extensions.configure { - publications { - create("mavenJava") { - groupId = rootProject.group as String - version = rootProject.version as String - pom { - name.set(project.name) - url.set(toothpick.forkUrl) - } - } - } - } - - when { - project.name.endsWith("server") -> configureServerProject() - project.name.endsWith("api") -> configureApiProject() - } - } - rootProject.project("Yatoclip") { - configureYatoclipProject() - } -} - -private fun Project.configureYatoclipProject() { - try { - rootProject.toothpick.serverProject.project.extensions.getByName("relocations") - } catch (e: UnknownDomainObjectException) { - return - } - - apply() - apply() - - tasks.register("genPatches") { - originalJar = rootProject.toothpick.paperDir.resolve("work").resolve("Minecraft") - .resolve(rootProject.toothpick.minecraftVersion).resolve("${rootProject.toothpick.minecraftVersion}-m.jar") - targetJar = rootProject.toothpick.serverProject.project.tasks.getByName("shadowJar").outputs.files.singleFile - setRelocations(rootProject.toothpick.serverProject.project.extensions.getByName("relocations") as HashSet) - dependsOn(rootProject.toothpick.serverProject.project.tasks.getByName("shadowJar")) - doLast { - val prop = Properties() - prop.setProperty("minecraftVersion", rootProject.toothpick.minecraftVersion) - PropertiesUtils.saveProperties( - prop, - outputDir.toPath().parent.resolve("yatoclip-launch.properties"), - "Yatoclip launch values" - ) - } - } - - val sourceSets = extensions.getByName("sourceSets") as org.gradle.api.tasks.SourceSetContainer - - sourceSets.create("java9") { - java { - srcDir("src/java9") - } - } - - val shadowJar by tasks.getting(ShadowJar::class) { - manifest { - attributes( - "Main-Class" to "org.yatopiamc.yatoclip.Yatoclip", - "Launcher-Agent-Class" to "org.yatopiamc.yatoclip.YatoclipLaunch", - "Premain-Class" to "org.yatopiamc.yatoclip.YatoclipLaunch", - "Multi-Release" to "true" - ) - } - into("META-INF/versions/9") { - from(sourceSets.getByName("java9").output) - } - } - - tasks.register("copyJar") { - val targetName = "yatopia-${rootProject.toothpick.minecraftVersion}-yatoclip.jar" - from(shadowJar.outputs.files.singleFile) { - rename { targetName } - } - - into(rootProject.projectDir) - - doLast { - logger.lifecycle(">>> $targetName saved to root project directory") - } - - dependsOn(shadowJar) - } - - tasks.getByName("processResources").dependsOn(tasks.getByName("genPatches")) - tasks.getByName("assemble").dependsOn(tasks.getByName("copyJar")) - tasks.getByName("jar").enabled = false - val buildTask = tasks.getByName("build") - val buildTaskDependencies = HashSet(buildTask.dependsOn) - buildTask.setDependsOn(HashSet()) - buildTask.onlyIf { false } - tasks.register("yatoclip") { - buildTaskDependencies.forEach { - dependsOn(it) - } - } -} - -private fun Project.configureServerProject() { - apply() - - val generatePomFileForMavenJavaPublication by tasks.getting(GenerateMavenPom::class) { - destination = project.buildDir.resolve("tmp/pom.xml") - } - - tasks.withType { - // didn't bother to look into why these fail. paper excludes them in paperweight as well though - exclude("org/bukkit/craftbukkit/inventory/ItemStack*Test.class") - } - - val shadowJar by tasks.getting(ShadowJar::class) { - archiveClassifier.set("") // ShadowJar is the main server artifact - dependsOn(generatePomFileForMavenJavaPublication) - transform(ModifiedLog4j2PluginsCacheFileTransformer::class.java) - mergeServiceFiles() - manifest { - attributes( - "Main-Class" to "org.bukkit.craftbukkit.Main", - "Implementation-Title" to "CraftBukkit", - "Implementation-Version" to toothpick.forkVersion, - "Implementation-Vendor" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(Date()), - "Specification-Title" to "Bukkit", - "Specification-Version" to "${project.rootProject.toothpick.minecraftVersion}-${project.rootProject.toothpick.nmsRevision}", - "Specification-Vendor" to "Bukkit Team" - ) - } - from(project.buildDir.resolve("tmp/pom.xml")) { - // dirty hack to make "java -Dpaperclip.install=true -jar paperclip.jar" work without forking paperclip - into("META-INF/maven/io.papermc.paper/paper") - } - - val relocationSet = HashSet() - - // Don't like to do this but sadly have to do this for compatibility reasons - relocate("org.bukkit.craftbukkit", "org.bukkit.craftbukkit.v${toothpick.nmsPackage}") { - exclude("org.bukkit.craftbukkit.Main*") - } - relocationSet.add(PatchesMetadata.Relocation("", "net.minecraft.server.v${toothpick.nmsPackage}", false)) - - // Make sure we relocate deps the same as Paper et al. - val dom = project.parsePom() ?: return@getting - val buildSection = dom.search("build").first() - val plugins = buildSection.search("plugins").first() - plugins.elements("plugin").filter { - val artifactId = it.search("artifactId").first().textContent - artifactId == "maven-shade-plugin" - }.forEach { - it.search("executions").first() - .search("execution").first() - .search("configuration").first() - .search("relocations").first() - .elements("relocation").forEach { relocation -> - val pattern = relocation.search("pattern").first().textContent - val shadedPattern = relocation.search("shadedPattern").first().textContent - val rawString = relocation.search("rawString").firstOrNull()?.textContent?.toBoolean() ?: false - if (pattern != "org.bukkit.craftbukkit") { // We handle cb ourselves - val excludes = if (rawString) listOf("net/minecraft/data/Main*") else emptyList() - relocate( - ToothpickRelocator( - pattern, - shadedPattern.replace("\${minecraft_version}", toothpick.nmsPackage), - rawString, - excludes = excludes - ) - ) - relocationSet.add(PatchesMetadata.Relocation(pattern, shadedPattern, true)) - } - } - } - project.extensions.add("relocations", relocationSet) - } - tasks.getByName("build") { - dependsOn(shadowJar) - } - - extensions.configure { - publications { - create("shadow") { - artifact(project.tasks.named("shadowJar")) - } - } - } -} - -@Suppress("UNUSED_VARIABLE") -private fun Project.configureApiProject() { - val jar by this.tasks.getting(Jar::class) { - doFirst { - buildDir.resolve("tmp/pom.properties") - .writeText("version=${project.rootProject.toothpick.minecraftVersion}-${project.rootProject.toothpick.nmsRevision}") - } - from(buildDir.resolve("tmp/pom.properties")) { - into("META-INF/maven/${project.group}/${project.name}") - } - manifest { - attributes("Automatic-Module-Name" to "org.bukkit") - } - } - - extensions.configure { - publications { - getByName("mavenJava") { - artifactId = project.name - from(components["java"]) - } - } - } -} diff --git a/buildSrc/src/main/kotlin/Constants.kt b/buildSrc/src/main/kotlin/Constants.kt deleted file mode 100644 index e579b850..00000000 --- a/buildSrc/src/main/kotlin/Constants.kt +++ /dev/null @@ -1,2 +0,0 @@ -const val taskGroup = "toothpick" -const val internalTaskGroup = "toothpick_internal" diff --git a/buildSrc/src/main/kotlin/DependencyLoading.kt b/buildSrc/src/main/kotlin/DependencyLoading.kt deleted file mode 100644 index 35f1c852..00000000 --- a/buildSrc/src/main/kotlin/DependencyLoading.kt +++ /dev/null @@ -1,72 +0,0 @@ -import kotlinx.dom.elements -import kotlinx.dom.search -import org.gradle.api.Project -import org.gradle.api.artifacts.dsl.RepositoryHandler -import org.gradle.kotlin.dsl.DependencyHandlerScope -import org.gradle.kotlin.dsl.maven -import org.gradle.kotlin.dsl.project -import org.w3c.dom.Element - -fun RepositoryHandler.loadRepositories(project: Project) { - val dom = project.parsePom() ?: return - val repositoriesBlock = dom.search("repositories").firstOrNull() ?: return - - // Load repositories - repositoriesBlock.elements("repository").forEach { repositoryElem -> - val url = repositoryElem.search("url").firstOrNull()?.textContent ?: return@forEach - maven(url) - } -} - -fun DependencyHandlerScope.loadDependencies(project: Project) { - val dom = project.parsePom() ?: return - - // Load dependencies - dom.search("dependencies").forEach { - loadDependencies(project, it) - } -} - -private fun DependencyHandlerScope.loadDependencies(project: Project, dependenciesBlock: Element) { - dependenciesBlock.elements("dependency").forEach { dependencyElem -> - val groupId = dependencyElem.search("groupId").first().textContent - val artifactId = dependencyElem.search("artifactId").first().textContent - val version = dependencyElem.search("version").firstOrNull()?.textContent - val scope = dependencyElem.search("scope").firstOrNull()?.textContent - val classifier = dependencyElem.search("classifier").firstOrNull()?.textContent - - val dependencyString = - "$groupId:$artifactId${processOptionalDependencyElement(version)}${processOptionalDependencyElement(classifier)}" - project.logger.debug("Read $scope scope dependency '$dependencyString' from '${project.name}' pom.xml") - - // Special case API - if (artifactId == project.toothpick.apiProject.project.name - || artifactId == "${project.toothpick.upstreamLowercase}-api" - ) { - if (project == project.toothpick.serverProject.project) { - add("api", project(":${project.toothpick.forkNameLowercase}-api")) - } - return@forEach - } - - when (scope) { - "import" -> add("api", platform(dependencyString)) - "compile", null -> { - add("api", dependencyString) - if (version != null) { - add("annotationProcessor", dependencyString) - } - } - "provided" -> { - add("compileOnly", dependencyString) - add("testImplementation", dependencyString) - add("annotationProcessor", dependencyString) - } - "runtime" -> add("runtimeOnly", dependencyString) - "test" -> add("testImplementation", dependencyString) - } - } -} - -private fun processOptionalDependencyElement(element: String?): String = - element?.run { ":$this" } ?: "" \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/InitTasks.kt b/buildSrc/src/main/kotlin/InitTasks.kt deleted file mode 100644 index ac6074e6..00000000 --- a/buildSrc/src/main/kotlin/InitTasks.kt +++ /dev/null @@ -1,74 +0,0 @@ -import org.gradle.api.Project -import org.gradle.api.tasks.javadoc.Javadoc -import org.gradle.api.tasks.testing.Test -import org.gradle.kotlin.dsl.withType -import task.* - -@Suppress("UNUSED_VARIABLE") -internal fun Project.initToothpickTasks() { - gradle.taskGraph.whenReady { - val fast = project.hasProperty("fast") - tasks.withType { - onlyIf { !fast } - } - tasks.withType { - onlyIf { !fast || gradle.taskGraph.allTasks.any { it.name.contains("publish", ignoreCase = true) } } - } - } - - tasks.getByName("build") { - doFirst { - val readyToBuild = - upstreamDir.resolve(".git").exists() - && toothpick.subprojects.values.all { it.projectDir.exists() && it.baseDir.exists() } - if (!readyToBuild) { - error("Workspace has not been setup. Try running `./gradlew applyPatches` first") - } - } - } - - val initGitSubmodules = createInitGitSubmodulesTask() - - val setupUpstream = createSetupUpstreamTask { - dependsOn(initGitSubmodules) - } - - val importMCDev = createImportMCDevTask { - mustRunAfter(setupUpstream) - } - - val paperclip = createPaperclipTask { - val shadowJar = toothpick.serverProject.project.tasks.getByName("shadowJar") - dependsOn(shadowJar) - inputs.file(shadowJar.outputs.files.singleFile) - } - - val applyPatches = createApplyPatchesTask { - // If Paper has not been setup yet or if we modified the submodule (i.e. upstream update), patch - if (!lastUpstream.exists() - || !upstreamDir.resolve(".git").exists() - || lastUpstream.readText() != gitHash(upstreamDir) - ) { - dependsOn(setupUpstream) - } - mustRunAfter(setupUpstream) - dependsOn(importMCDev) - } - - val patchCredits = createPatchCreditsTask() - - val fixBranch = createFixBranchesTask() - - val rebuildPatches = createRebuildPatchesTask { - dependsOn(fixBranch) - finalizedBy(patchCredits) - } - - val updateUpstream = createUpdateUpstreamTask { - finalizedBy(setupUpstream) - } - - val upstreamCommit = createUpstreamCommitTask() - - val repackageNMS = createRepackageNMSTask() -} diff --git a/buildSrc/src/main/kotlin/MCDevImports.kt b/buildSrc/src/main/kotlin/MCDevImports.kt deleted file mode 100644 index d58be4f5..00000000 --- a/buildSrc/src/main/kotlin/MCDevImports.kt +++ /dev/null @@ -1,45 +0,0 @@ -/** - * This is the set of extra NMS files which will be imported as part of the patch process - * - * See `./Paper/work/Minecraft/$MCVER/spigot/net/minecraft/server` for a list of possible files - * - * The `.java` extension is always assumed and should be excluded - * - * NOTE: Do not commit changes to this set! Instead make changes, rebuild patches, and commit the modified patches. - * Files already modified in existing patches will be imported automatically. - */ -val nmsImports = setOf( - // ex: - //"EntityZombieVillager" -) - -data class LibraryImport(val group: String, val library: String, val prefix: String, val file: String) - -/** - * This is the set of extra files to import into the server workspace from libraries - * - * Changes to this set should be committed to the repo, as these won't be automatically imported. - */ -val libraryImports = setOf( - LibraryImport("com.mojang", "brigadier", "com/mojang/brigadier", "CommandDispatcher"), - LibraryImport("com.mojang", "brigadier", "com/mojang/brigadier/tree", "LiteralCommandNode"), - LibraryImport("com.mojang", "brigadier", "com/mojang/brigadier/suggestion", "SuggestionsBuilder"), - LibraryImport("com.mojang", "brigadier", "com/mojang/brigadier/arguments", "BoolArgumentType"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers", "FieldFinder"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers", "DataFixUtils"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers", "TypeRewriteRule"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers", "Typed"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers", "TypedOptic"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers", "View"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers/functions", "Apply"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers/functions", "Comp"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers/functions", "PointFree"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers/functions", "PointFreeRule"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers/optics", "IdAdapter"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers/optics", "Inj1"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers/optics", "Inj2"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers/optics", "Optics"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers/optics", "Proj1"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers/optics", "Proj2"), - LibraryImport("com.mojang", "datafixerupper", "com/mojang/datafixers/types", "Type") -) \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/PatchParser.kt b/buildSrc/src/main/kotlin/PatchParser.kt deleted file mode 100644 index 9e33de97..00000000 --- a/buildSrc/src/main/kotlin/PatchParser.kt +++ /dev/null @@ -1,77 +0,0 @@ -import java.io.File -import java.io.IOException -import java.io.UnsupportedEncodingException -import java.nio.charset.StandardCharsets -import java.nio.file.Files -import java.util.* -import java.util.function.Function -import javax.mail.internet.MimeUtility - -/** - * Rudimentary parser to get Author, subject and coAuthors of a patch file - * - * @author tr7zw - */ -object PatchParser { - fun parsePatch(file: File): PatchInfo { - val lines: List = Files.readAllLines(file.toPath(), StandardCharsets.UTF_8) - var from: String = "Unknown" - var subject: String = "Unknown" - val coAuthors: MutableList = ArrayList() - for (line: String in lines) { - when { - line.startsWith("From: ") -> { - from = - decodeStringIfNeeded(line.replace("From: ", "").split("<").toTypedArray()[0].trim { it <= ' ' }) - } - line.startsWith("Subject: ") -> { - subject = line.replace("Subject: ", "").replace("[PATCH]", "").trim { it <= ' ' } - } - line.startsWith("Co-authored-by: ") -> { - coAuthors.add( - decodeStringIfNeeded( - line.replace("Co-authored-by: ", "").split("<").toTypedArray()[0].trim { it <= ' ' }) - ) - } - } - } - return PatchInfo(file.parentFile.name, from, subject, coAuthors) - } - - private fun decodeStringIfNeeded(org: String): String { - if (org.contains("=") || org.startsWith("=?UTF-8")) { - try { - return MimeUtility.decodeText(org) - } catch (ex: UnsupportedEncodingException) { - throw IOException(ex) - } - } - return org - } - - class PatchInfo(val parent: String, val from: String, val subject: String, val coAuthors: List) { - val coAuthorString: Function - get() = Function { - java.lang.String.join( - ", ", - coAuthors - ) - } - - override fun toString(): String { - return ("PatchInfo{" - + "parent='" - + parent - + '\'' - + ", from='" - + from - + '\'' - + ", subject='" - + subject - + '\'' - + ", coAuthors=" - + coAuthors - + '}') - } - } -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/PomParsing.kt b/buildSrc/src/main/kotlin/PomParsing.kt deleted file mode 100644 index 933155f0..00000000 --- a/buildSrc/src/main/kotlin/PomParsing.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This file is part of Toothpick, licensed under the MIT License. - * - * Copyright (c) 2020-2021 Jason Penilla & Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -import kotlinx.dom.elements -import kotlinx.dom.parseXml -import kotlinx.dom.search -import org.gradle.api.Project -import org.w3c.dom.Document - -internal fun Project.parsePom(): Document? { - val file = file("pom.xml") - if (!file.exists()) { - return null - } - val contents = file.readText() - val dom = parseXml(contents.byteInputStream()) - val properties = dom.search("properties").firstOrNull()?.elements() ?: emptyList() - val propertiesMap = properties.associateBy({ it.nodeName }, { it.textContent }).toMutableMap() - - propertiesMap["project.version"] = project.version.toString() - propertiesMap["minecraft.version"] = toothpick.minecraftVersion - propertiesMap["minecraft_version"] = toothpick.nmsPackage - - return parseXml(contents.replaceProperties(propertiesMap).byteInputStream()) -} - -private fun String.replaceProperties( - properties: Map -): String { - var result = this - for ((key, value) in properties) { - result = result.replace("\${$key}", value) - } - return result -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/Toothpick.kt b/buildSrc/src/main/kotlin/Toothpick.kt deleted file mode 100644 index c5829962..00000000 --- a/buildSrc/src/main/kotlin/Toothpick.kt +++ /dev/null @@ -1,9 +0,0 @@ -import org.gradle.api.Plugin -import org.gradle.api.Project -import org.gradle.kotlin.dsl.create - -class Toothpick : Plugin { - override fun apply(project: Project) { - project.extensions.create("toothpick", project.objects) - } -} diff --git a/buildSrc/src/main/kotlin/ToothpickExtension.kt b/buildSrc/src/main/kotlin/ToothpickExtension.kt deleted file mode 100644 index 50fbf476..00000000 --- a/buildSrc/src/main/kotlin/ToothpickExtension.kt +++ /dev/null @@ -1,93 +0,0 @@ -import org.gradle.api.Project -import org.gradle.api.model.ObjectFactory -import java.io.File -import java.io.FileInputStream -import java.util.* -import java.util.stream.Collectors -import kotlin.collections.ArrayList - -@Suppress("UNUSED_PARAMETER") -open class ToothpickExtension(objects: ObjectFactory) { - lateinit var project: Project - lateinit var forkName: String - val forkNameLowercase - get() = forkName.toLowerCase(Locale.ENGLISH) - lateinit var forkUrl: String - lateinit var forkVersion: String - lateinit var groupId: String - lateinit var minecraftVersion: String - lateinit var nmsRevision: String - lateinit var nmsPackage: String - - lateinit var upstream: String - val upstreamLowercase - get() = upstream.toLowerCase(Locale.ENGLISH) - var upstreamBranch: String = "origin/master" - - var paperclipName: String? = null - val calcPaperclipName - get() = paperclipName ?: "${forkNameLowercase}-paperclip.jar" - - lateinit var serverProject: ToothpickSubproject - - lateinit var patchCreditsOutput: String - lateinit var patchCreditsTemplate: String - - lateinit var currentBranch : String - val currentBranchDisplayName - get() = currentBranch.replace("/${minecraftVersion}", "") - val calcVersionString - get() = "${minecraftVersion}-${nmsRevision}" - - fun server(receiver: ToothpickSubproject.() -> Unit) { - serverProject = ToothpickSubproject() - receiver(serverProject) - } - - lateinit var apiProject: ToothpickSubproject - fun api(receiver: ToothpickSubproject.() -> Unit) { - apiProject = ToothpickSubproject() - receiver(apiProject) - } - - val subprojects: Map - get() = if (::forkName.isInitialized) mapOf( - "$forkName-API" to apiProject, - "$forkName-Server" to serverProject - ) else emptyMap() - - val paperDir: File by lazy { - if (upstream == "Paper") { - project.upstreamDir - } else { - project.upstreamDir.walk().find { - it.name == "Paper" && it.isDirectory - && it.resolve("work/Minecraft/${minecraftVersion}").exists() - } ?: error("Failed to find Paper directory!") - } - } - - val paperDecompDir: File - get() = paperDir.resolve("work/Minecraft/${minecraftVersion}") - - val paperWorkDir: File - get() = paperDir.resolve("work") - - fun getUpstreams(rootProjectDir: File): MutableList? { - val configDir = rootProjectDir.resolve("$rootProjectDir/upstreamConfig") - val upstreams = configDir.listFiles() - val upstreamArray = ArrayList() - val prop = Properties() - for (upstream in upstreams) { - prop.load(FileInputStream(upstream)) - upstreamArray.add(Upstream(prop.getProperty("name"), - prop.getProperty("useBlackList")!!.toBoolean(), - (prop.getProperty("list")), - rootProjectDir, - prop.getProperty("branch"), - Integer.parseInt(upstream.name.substring(0,4)), - project)) - } - return upstreamArray.stream().sorted { upstream1, upstream2 -> upstream1.id - upstream2.id}.collect(Collectors.toList()) - } -} diff --git a/buildSrc/src/main/kotlin/ToothpickExtensions.kt b/buildSrc/src/main/kotlin/ToothpickExtensions.kt deleted file mode 100644 index 1c524c0c..00000000 --- a/buildSrc/src/main/kotlin/ToothpickExtensions.kt +++ /dev/null @@ -1,41 +0,0 @@ -import org.gradle.api.Project -import org.gradle.kotlin.dsl.findByType -import java.io.File - -val Project.toothpick: ToothpickExtension - get() = rootProject.extensions.findByType(ToothpickExtension::class)!! - -fun Project.toothpick(receiver: ToothpickExtension.() -> Unit) { - toothpick.project = this - receiver(toothpick) - allprojects { - group = toothpick.groupId - version = toothpick.calcVersionString - } - configureSubprojects() - initToothpickTasks() -} - -val Project.lastUpstream: File - get() = rootProject.projectDir.resolve("last-${toothpick.upstreamLowercase}") - -val Project.rootProjectDir: File - get() = rootProject.projectDir - -val Project.upstreamDir: File - get() = rootProject.projectDir.resolve(toothpick.upstream) - -val Project.upstream: String - get() = toothpick.upstream - -val Project.upstreams: MutableList - get() = toothpick.getUpstreams(rootProject.projectDir) as MutableList - -val Project.forkName: String - get() = toothpick.forkName - -val Project.patchCreditsOutput: String - get() = toothpick.patchCreditsOutput - -val Project.patchCreditsTemplate: String - get() = toothpick.patchCreditsTemplate diff --git a/buildSrc/src/main/kotlin/ToothpickSubproject.kt b/buildSrc/src/main/kotlin/ToothpickSubproject.kt deleted file mode 100644 index df34f33e..00000000 --- a/buildSrc/src/main/kotlin/ToothpickSubproject.kt +++ /dev/null @@ -1,20 +0,0 @@ -import org.gradle.api.Project -import java.io.File - -class ToothpickSubproject { - lateinit var project: Project - - val baseDir: File by lazy { - val name = project.name - val upstream = project.toothpick.upstream - val suffix = if (name.endsWith("server")) "Server" else "API" - project.upstreamDir.resolve("$upstream-$suffix") - } - val projectDir: File - get() = project.projectDir - lateinit var patchesDir: File - - operator fun component1(): File = baseDir - operator fun component2(): File = projectDir - operator fun component3(): File = patchesDir -} diff --git a/buildSrc/src/main/kotlin/Upstream.kt b/buildSrc/src/main/kotlin/Upstream.kt deleted file mode 100644 index 532cf499..00000000 --- a/buildSrc/src/main/kotlin/Upstream.kt +++ /dev/null @@ -1,88 +0,0 @@ -import org.gradle.api.Project -import java.io.File -import java.io.FileWriter -import java.nio.file.Files -import java.nio.file.Paths -import java.util.stream.Collectors - -open class Upstream(in_name: String, in_useBlackList: Boolean, in_list: String, in_rootProjectDir: File, in_branch: String, in_id: Int, in_project: Project) { - var name: String = in_name - var useBlackList: Boolean = in_useBlackList - private var list: ArrayList = ArrayList(in_list.split(",".toRegex())) - private var rootProjectDir: File = in_rootProjectDir - var branch = in_branch - var id = in_id - - var serverList = list.stream().filter { patch -> patch.startsWith("server/") } - ?.sorted()?.map { patch -> patch.substring(7, patch.length) }?.collect(Collectors.toList()) - var apiList = list.stream().filter { patch -> patch.startsWith("api/") } - ?.sorted()?.map { patch -> patch.substring(4, patch.length) }?.collect(Collectors.toList()) - - - var patchPath = Paths.get("$rootProjectDir/patches/$name/patches") - var repoPath = Paths.get("$rootProjectDir/upstream/$name") - - var project = in_project - - var upstreamCommit = getUpstreamCommitHash() - - private fun getUpstreamCommitHash(): String { - val commitFileFolder = Paths.get("$rootProjectDir/upstreamCommits") - val commitFilePath = Paths.get("$commitFileFolder/$name") - val commitFile = commitFilePath.toFile() - var commitHash: String - if (commitFile.isFile) { - commitHash = Files.readAllLines(commitFilePath).toString() - commitHash = commitHash.substring(1, commitHash.length - 1) - if (commitHash == "") { - commitHash = updateHashFile(commitFile) - } - } else { - Files.createFile(commitFilePath) - commitHash = updateHashFile(commitFile) - } - return commitHash; - } - - public fun updateUpstreamCommitHash() { - val commitFileFoler = Paths.get("$rootProjectDir/upstreamCommits") - val commitFilePath = Paths.get("$commitFileFoler/$name") - val commitFile = commitFilePath.toFile() - updateHashFile(commitFile) - upstreamCommit = getUpstreamCommitHash() - } - - public fun getCurrentCommitHash(): String { - return project.getCommitHash() - } - - private fun updateHashFile(commitFile: File): String { - var commitHash: String - commitHash = project.getCommitHash() - val fileWriter = FileWriter(commitFile) - fileWriter.use { out -> out.write(commitHash) } - fileWriter.close() - return commitHash - } - - private fun Project.getCommitHash(): String = gitHash(repo = repoPath.toFile()) - - public fun getRepoServerPatches(): MutableList? { - return getRepoPatches(rootProjectDir.resolve("$repoPath/patches/server")).stream() - .sorted().map {patch -> patch.substring(5, patch.length) }.collect(Collectors.toList()) - } - - public fun getRepoAPIPatches(): MutableList? { - return getRepoPatches(rootProjectDir.resolve("$repoPath/patches/api")).stream() - .sorted().map {patch -> patch.substring(5, patch.length) }.collect(Collectors.toList()) - } - - private fun getRepoPatches(path: File): ArrayList { - val files = path.listFiles() - val filesList = ArrayList() - for (patch in files) { - filesList.add(patch.name) - } - return filesList - } -} diff --git a/buildSrc/src/main/kotlin/Util.kt b/buildSrc/src/main/kotlin/Util.kt deleted file mode 100644 index bfc2b1fe..00000000 --- a/buildSrc/src/main/kotlin/Util.kt +++ /dev/null @@ -1,92 +0,0 @@ -import org.gradle.api.Project -import java.io.File -import java.util.* -import kotlin.streams.asSequence - -data class CmdResult(val exitCode: Int, val output: String?) - -fun Project.cmd( - vararg args: String, - dir: File = rootProject.projectDir, - printOut: Boolean = false, - environment: Map = emptyMap() -): CmdResult { - val process = ProcessBuilder().apply { - command(*args) - redirectErrorStream(true) - directory(dir) - environment().putAll(environment) - }.start() - val output = process.inputStream.bufferedReader().use { reader -> - reader.lines().asSequence() - .onEach { - if (printOut) { - logger.lifecycle(it) - } else { - logger.debug(it) - } - } - .toCollection(LinkedList()) - .joinToString(separator = "\n") - } - val exit = process.waitFor() - return CmdResult(exit, output) -} - -fun ensureSuccess( - cmd: CmdResult, - errorHandler: CmdResult.() -> Unit = {} -): String? { - val (exit, output) = cmd - if (exit != 0) { - errorHandler(cmd) - error("Failed to run command, exit code is $exit") - } - return output -} - -fun Project.gitCmd( - vararg args: String, - dir: File = rootProject.projectDir, - printOut: Boolean = false, - environment: Map = emptyMap() -): CmdResult = - cmd("git", *args, dir = dir, printOut = printOut) - -fun Project.bashCmd( - vararg args: String, - dir: File = rootProject.projectDir, - printOut: Boolean = false, - environment: Map = emptyMap() -): CmdResult = - cmd("bash", "-c", *args, dir = dir, printOut = printOut) - -internal fun String.applyReplacements( - vararg replacements: Pair -): String { - var result = this - for ((key, value) in replacements) { - result = result.replace("\${$key}", value) - } - return result -} - -private fun Project.gitSigningEnabled(repo: File): Boolean = - gitCmd("config", "commit.gpgsign", dir = repo).output?.toBoolean() == true - -internal fun Project.temporarilyDisableGitSigning(repo: File): Boolean { - val isCurrentlyEnabled = gitSigningEnabled(repo) - if (isCurrentlyEnabled) { - gitCmd("config", "commit.gpgsign", "false", dir = repo) - } - return isCurrentlyEnabled -} - -internal fun Project.reEnableGitSigning(repo: File) { - gitCmd("config", "commit.gpgsign", "true", dir = repo) -} - -fun Project.gitHash(repo: File): String = - gitCmd("rev-parse", "HEAD", dir = repo).output ?: "" - -val jenkins = System.getenv("JOB_NAME") != null diff --git a/buildSrc/src/main/kotlin/relocation/ToothpickRelocator.kt b/buildSrc/src/main/kotlin/relocation/ToothpickRelocator.kt deleted file mode 100644 index 5e1877cc..00000000 --- a/buildSrc/src/main/kotlin/relocation/ToothpickRelocator.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is part of Toothpick, licensed under the MIT License. - * - * Copyright (c) 2020-2021 Jason Penilla & Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package relocation - -import com.github.jengelman.gradle.plugins.shadow.relocation.Relocator -import com.github.jengelman.gradle.plugins.shadow.relocation.SimpleRelocator -import java.lang.reflect.Method -import java.util.regex.Pattern - -internal class ToothpickRelocator( - pattern: String, - shadedPattern: String, - rawString: Boolean = false, - includes: List = emptyList(), - excludes: List = emptyList(), - private val simpleRelocator: SimpleRelocator = SimpleRelocator(pattern, shadedPattern, includes, excludes, rawString) -) : Relocator by simpleRelocator { - override fun canRelocatePath(path: String): Boolean { - // Respect includes/excludes for rawString too - if (simpleRelocator.rawString) { - return isIncludedMethod(simpleRelocator, path) as Boolean - && !(isExcludedMethod(simpleRelocator, path) as Boolean) - && Pattern.compile(simpleRelocator.pathPattern).matcher(path).find() - } - return simpleRelocator.canRelocatePath(path) - } - - companion object { - private val isExcludedMethod: Method = SimpleRelocator::class.java.getDeclaredMethod("isExcluded", String::class.java) - private val isIncludedMethod: Method = SimpleRelocator::class.java.getDeclaredMethod("isIncluded", String::class.java) - - init { - isExcludedMethod.isAccessible = true - isIncludedMethod.isAccessible = true - } - } -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/task/ApplyPatches.kt b/buildSrc/src/main/kotlin/task/ApplyPatches.kt deleted file mode 100644 index 49758256..00000000 --- a/buildSrc/src/main/kotlin/task/ApplyPatches.kt +++ /dev/null @@ -1,102 +0,0 @@ -package task - -import ensureSuccess -import forkName -import gitCmd -import org.gradle.api.Project -import org.gradle.api.Task -import reEnableGitSigning -import taskGroup -import temporarilyDisableGitSigning -import toothpick -import upstreams -import java.io.File -import java.nio.file.Files -import java.nio.file.Path -import java.nio.file.Paths - -internal fun Project.createApplyPatchesTask( - receiver: Task.() -> Unit = {} -): Task = tasks.create("applyPatches") { - receiver(this) - group = taskGroup - - fun checkCursed(project: Project): Boolean { - return project.properties.getOrDefault("cursed", "false").toString().toBoolean() - } - - fun applyPatches(patchDir: Path, applyName: String, name: String, wasGitSigningEnabled: Boolean, projectDir: File): Boolean { - if (Files.notExists(patchDir)) return true - - val patchPaths = Files.newDirectoryStream(patchDir) - .map { it.toFile() } - .filter { it.name.endsWith(".patch") } - .sorted() - .takeIf { it.isNotEmpty() } ?: return true - val patches = patchPaths.map { it.absolutePath }.toTypedArray() - - logger.lifecycle(">>> Applying $applyName patches to $name") - - gitCmd("am", "--abort") - - //Cursed Apply Mode that makes fixing stuff a lot easier - if (checkCursed(project)) { - for (patch in patches) { - val gitCommand = arrayListOf("am", "--3way", "--ignore-whitespace", - "--rerere-autoupdate", "--whitespace=fix", "--reject", "-C0", patch) - if (gitCmd(*gitCommand.toTypedArray(), dir = projectDir, printOut = true).exitCode != 0) { - gitCmd("add", ".", dir = projectDir, printOut = true) - gitCmd("am", "--continue", dir = projectDir, printOut = true) - } - } - } else { - val gitCommand = arrayListOf("am", "--3way", "--ignore-whitespace", - "--rerere-autoupdate", "--whitespace=fix", *patches) - ensureSuccess(gitCmd(*gitCommand.toTypedArray(), dir = projectDir, printOut = true)) { - if (wasGitSigningEnabled) reEnableGitSigning(projectDir) - } - } - return false; - } - - doLast { - for ((name, subproject) in toothpick.subprojects) { - val (sourceRepo, projectDir, patchesDir) = subproject - - val folder = (if (patchesDir.endsWith("server")) "server" else "api") - - // Reset or initialize subproject - logger.lifecycle(">>> Resetting subproject $name") - if (projectDir.exists()) { - ensureSuccess(gitCmd("fetch", "origin", dir = projectDir)) - ensureSuccess(gitCmd("reset", "--hard", "origin/master", dir = projectDir)) - } else { - ensureSuccess(gitCmd("clone", sourceRepo.absolutePath, projectDir.absolutePath, printOut = true)) - } - logger.lifecycle(">>> Done resetting subproject $name") - - val wasGitSigningEnabled = temporarilyDisableGitSigning(projectDir) - - for (upstream in upstreams) { - if (((folder == "server" && upstream.serverList?.isEmpty() != false) || (folder == "api" && upstream.apiList?.isEmpty() != false)) && !upstream.useBlackList) continue - if (((folder == "server" && upstream.getRepoServerPatches()?.isEmpty() != false) || (folder == "api" && upstream.getRepoAPIPatches()?.isEmpty() != false)) && upstream.useBlackList) continue - project.gitCmd("branch", "-D", "${upstream.name}-$folder", dir = projectDir) - project.gitCmd("checkout", "-b", "${upstream.name}-$folder", dir = projectDir) - // Apply patches - val patchDir = Paths.get("${upstream.patchPath}/$folder") - - if (applyPatches(patchDir, upstream.name, name, wasGitSigningEnabled, projectDir)) continue - } - // project.gitCmd("branch", "-D", "$forkName-$folder", dir = projectDir) - // project.gitCmd("checkout", "-b", "$forkName-$folder", dir = projectDir) - project.gitCmd("branch", "-D", "master", dir = projectDir) - project.gitCmd("checkout", "-b", "master", dir = projectDir) - val patchDir = patchesDir.toPath() - // Apply patches - if (applyPatches(patchDir, forkName, name, wasGitSigningEnabled, projectDir)) continue - - if (wasGitSigningEnabled) reEnableGitSigning(projectDir) - logger.lifecycle(">>> Done applying patches to $name") - } - } -} diff --git a/buildSrc/src/main/kotlin/task/FixBranches.kt b/buildSrc/src/main/kotlin/task/FixBranches.kt deleted file mode 100644 index 4c330793..00000000 --- a/buildSrc/src/main/kotlin/task/FixBranches.kt +++ /dev/null @@ -1,55 +0,0 @@ -package task - -import org.gradle.api.Project -import org.gradle.api.Task -import taskGroup -import upstreams -import gitCmd -import toothpick -import java.nio.file.Paths -import java.util.concurrent.ConcurrentHashMap -import ensureSuccess - -internal fun Project.createFixBranchesTask( - receiver: Task.() -> Unit = {} -): Task = tasks.create("fixBranches") { - receiver(this) - group = taskGroup - val folderArray = arrayListOf("api", "server") - doLast { - for (folder in folderArray) { - val subprojectWorkDir = Paths.get("${toothpick.forkName}-${if (folder == "api") {"API"} else {"Server"}}").toFile() - // val currentBranchCommits = gitCmd("--no-pager", "log", "${toothpick.forkName}-$folder...${toothpick.upstreamBranch}", "--pretty=oneline", - val currentBranchCommits = gitCmd("--no-pager", "log", "master...${toothpick.upstreamBranch}", "--pretty=oneline", - dir = subprojectWorkDir).output.toString() - val nameMap = ConcurrentHashMap() - for (upstream in upstreams) { - val patchPath = Paths.get("${upstream.patchPath}/$folder").toFile() - if (patchPath.listFiles()?.isEmpty() != false) continue - val commitName = gitCmd("--no-pager", "log", "${upstream.name}-$folder", "-1", "--format=\"%s\"", - dir = subprojectWorkDir).output.toString() - val branchName = "${upstream.name}-$folder" - val commitNameFiltered = commitName.substring(1, commitName.length-1) - for (line in currentBranchCommits.split("\\n".toRegex()).stream().parallel()) { - val commitNameIterator = line.substring(41, line.length) - if (commitNameIterator == commitNameFiltered) { - val hash = line.substring(0, 40) - nameMap.put(branchName, hash) - continue - } - } - } - for (upstream in upstreams) { - val patchPath = Paths.get("${upstream.patchPath}/$folder").toFile() - if (patchPath.listFiles()?.isEmpty() != false) continue - val branchName = "${upstream.name}-$folder" - ensureSuccess(gitCmd("checkout", branchName, dir = subprojectWorkDir, printOut = true)) - ensureSuccess(gitCmd("reset", "--hard", nameMap.get(branchName) as String, dir = subprojectWorkDir, - printOut = true)) - } - // ensureSuccess(gitCmd("checkout", "${toothpick.forkName}-$folder", dir = subprojectWorkDir, - ensureSuccess(gitCmd("checkout", "master", dir = subprojectWorkDir, - printOut = true)) - } - } -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/task/ImportMCDev.kt b/buildSrc/src/main/kotlin/task/ImportMCDev.kt deleted file mode 100644 index 139423b0..00000000 --- a/buildSrc/src/main/kotlin/task/ImportMCDev.kt +++ /dev/null @@ -1,118 +0,0 @@ -package task - -import LibraryImport -import ensureSuccess -import gitCmd -import internalTaskGroup -import libraryImports -import nmsImports -import org.gradle.api.Project -import org.gradle.api.Task -import toothpick -import upstreams -import java.io.File -import java.nio.file.Files -import kotlin.streams.toList - -internal fun Project.createImportMCDevTask( - receiver: Task.() -> Unit = {} -): Task = tasks.create("importMCDev") { - receiver(this) - group = internalTaskGroup - val upstreamServer = toothpick.serverProject.baseDir - val importLog = arrayListOf("Extra mc-dev imports") - - fun isDuplicateImport(target: File, className: String): Boolean { - if (!target.exists()) return false - val message = "Skipped import for $className, a class with that name already exists in the source tree. Is there an extra entry in mcdevimports.json?" - project.gradle.taskGraph.allTasks.last().doLast { - logger.warn(message) - } - logger.warn(message) - return true - } - - fun importNMS(className: String) { - logger.lifecycle("Importing $className") - val classPath = "${className.replace(".", "/")}.java" - val source = toothpick.paperDecompDir.resolve("spigot/$classPath") - importLog.add("Importing $className") - if (!source.exists()) error("Missing NMS: $className") - val target = upstreamServer.resolve("src/main/java/$classPath") - if (isDuplicateImport(target, className)) return - target.parentFile.mkdirs() - source.copyTo(target) - } - - fun importLibrary(import: LibraryImport) { - val (group, lib, prefix, file) = import - val className = "${prefix.replace("/", ".")}.$file" - importLog.add("Imported $className from $group.$lib") - logger.lifecycle("Importing $className from $group.$lib") - val source = toothpick.paperDecompDir.resolve("libraries/$group/$lib/$prefix/$file.java") - if (!source.exists()) error("Missing Base: $lib $prefix/$file") - val targetDir = upstreamServer.resolve("src/main/java/$prefix") - val target = targetDir.resolve("$file.java") - if (isDuplicateImport(target, className)) return - targetDir.mkdirs() - source.copyTo(target) - } - - fun findNeededImports(patches: List): Set = patches.asSequence() - .flatMap { it.readLines().asSequence() } - .filter { line -> - line.startsWith("+++ b/src/main/java/net/minecraft/") - || line.startsWith("+++ b/src/main/java/com/mojang/math/") - } - .distinct() - .map { it.substringAfter("+++ b/src/main/java/") } - .filter { !upstreamServer.resolve("src/main/java/$it").exists() } - .filter { - val sourceFile = toothpick.paperDecompDir.resolve("spigot/$it") - val exists = sourceFile.exists() - if (!sourceFile.exists()) logger.lifecycle("$it is either missing, or is a new file added through a patch") - exists - } - .map { it.replace("/", ".").substringBefore(".java") } - .toSet() - - fun getAndApplyNMS(patchesDir: File) { - findNeededImports(patchesDir.listFiles().toList()).toList().forEach(::importNMS) - } - - doLast { - logger.lifecycle(">>> Importing mc-dev") - val lastCommitIsMCDev = gitCmd( - "log", "-1", "--oneline", - dir = upstreamServer - ).output?.contains("Extra mc-dev imports") == true - if (lastCommitIsMCDev) { - ensureSuccess( - gitCmd( - "reset", "--hard", "HEAD~1", - dir = upstreamServer, - printOut = true - ) - ) - } - for (upstream in upstreams) { - val patchesDir = rootProject.projectDir.resolve("${upstream.patchPath}/server") - getAndApplyNMS(patchesDir) - } - - val patchesDir = toothpick.serverProject.patchesDir - getAndApplyNMS(patchesDir) - - - // Imports from MCDevImports.kt - nmsImports.forEach(::importNMS) - libraryImports.forEach(::importLibrary) - - val add = gitCmd("add", ".", "-A", dir = upstreamServer).exitCode == 0 - val commit = gitCmd("commit", "-m", importLog.joinToString("\n"), dir = upstreamServer).exitCode == 0 - if (!add || !commit) { - logger.lifecycle(">>> Didn't import any extra files") - } - logger.lifecycle(">>> Done importing mc-dev") - } -} diff --git a/buildSrc/src/main/kotlin/task/InitGitSubmodules.kt b/buildSrc/src/main/kotlin/task/InitGitSubmodules.kt deleted file mode 100644 index 65345379..00000000 --- a/buildSrc/src/main/kotlin/task/InitGitSubmodules.kt +++ /dev/null @@ -1,25 +0,0 @@ -package task - -import gitCmd -import org.gradle.api.Project -import org.gradle.api.Task -import taskGroup -import upstreamDir -import upstreams - -internal fun Project.createInitGitSubmodulesTask( - receiver: Task.() -> Unit = {} -): Task = tasks.create("initGitSubmodules") { - receiver(this) - group = taskGroup - var upstreamNotInit = false - for (upstream in upstreams) { upstreamNotInit = upstreamNotInit || upstream.repoPath.toFile().resolve(".git").exists() } - onlyIf { !upstreamDir.resolve(".git").exists() || upstreamNotInit } - doLast { - var exit = gitCmd("submodule", "update", "--init", printOut = true).exitCode - exit += gitCmd("submodule", "update", "--init", "--recursive", dir = upstreamDir, printOut = true).exitCode - if (exit != 0) { - error("Failed to checkout git submodules: git exited with code $exit") - } - } -} diff --git a/buildSrc/src/main/kotlin/task/Paperclip.kt b/buildSrc/src/main/kotlin/task/Paperclip.kt deleted file mode 100644 index a9f82332..00000000 --- a/buildSrc/src/main/kotlin/task/Paperclip.kt +++ /dev/null @@ -1,38 +0,0 @@ -package task - -import cmd -import ensureSuccess -import jenkins -import org.gradle.api.Project -import org.gradle.api.Task -import rootProjectDir -import taskGroup -import toothpick - -internal fun Project.createPaperclipTask( - receiver: Task.() -> Unit = {} -): Task = tasks.create("paperclip") { - receiver(this) - group = taskGroup - doLast { - val workDir = toothpick.paperDir.resolve("work") - val paperclipDir = workDir.resolve("Paperclip") - val vanillaJarPath = - workDir.resolve("Minecraft/${toothpick.minecraftVersion}/${toothpick.minecraftVersion}.jar").absolutePath - val patchedJarPath = inputs.files.singleFile.absolutePath - logger.lifecycle(">>> Building paperclip") - val paperclipCmd = arrayListOf( - "mvn", "-T", "2C", "clean", "package", - "-Dmcver=${toothpick.minecraftVersion}", - "-Dpaperjar=$patchedJarPath", - "-Dvanillajar=$vanillaJarPath" - ) - if (System.getProperty("os.name").startsWith("Windows")) paperclipCmd[0] = "mvn.cmd" - if (jenkins) paperclipCmd.add("-Dstyle.color=never") - ensureSuccess(cmd(*paperclipCmd.toTypedArray(), dir = paperclipDir, printOut = true)) - val paperClip = paperclipDir.resolve("assembly/target/paperclip-${toothpick.minecraftVersion}.jar") - val destination = rootProjectDir.resolve(toothpick.calcPaperclipName) - paperClip.copyTo(destination, overwrite = true) - logger.lifecycle(">>> ${toothpick.calcPaperclipName} saved to root project directory") - } -} diff --git a/buildSrc/src/main/kotlin/task/PatchCredits.kt b/buildSrc/src/main/kotlin/task/PatchCredits.kt deleted file mode 100644 index 96c84d7f..00000000 --- a/buildSrc/src/main/kotlin/task/PatchCredits.kt +++ /dev/null @@ -1,100 +0,0 @@ -package task - -import PatchParser -import PatchParser.PatchInfo -import com.github.mustachejava.DefaultMustacheFactory -import com.github.mustachejava.MustacheFactory -import org.gradle.api.Project -import org.gradle.api.Task -import taskGroup -import java.io.* -import java.nio.charset.StandardCharsets -import java.nio.file.Paths -import java.util.* -import patchCreditsOutput -import patchCreditsTemplate - -internal fun Project.createPatchCreditsTask( - receiver: Task.() -> Unit = {} -): Task = tasks.create("patchCredits") { - receiver(this) - group = taskGroup - - val projectDirectory: File = rootDir - val patchDirectory: File? = Paths.get("$rootDir/patches").toFile() - val outputFileName: String = patchCreditsOutput - val srcFileName: String = patchCreditsTemplate - - doLast { - val src = File(projectDirectory, srcFileName) - if (!src.exists()) { - logger.warn("Unable to find src at '" + src.absolutePath + "'! Skipping!") - return@doLast - } - if (!patchDirectory!!.exists()) { - logger - .warn( - "Unable to find patch directory at '" - + patchDirectory.absolutePath - + "'! Skipping!" - ) - return@doLast - } - logger.lifecycle("Scanning '$patchDirectory' for patches!") - val patches: MutableList = ArrayList() - scanFolder(patchDirectory, patches, project) - if (patches.isEmpty()) { - logger.warn("Unable to find any patches! Skipping!") - return@doLast - } - - patches.sortWith { a: PatchInfo, b: PatchInfo -> a.subject.compareTo(b.subject) } - val output = Output() - output.patches = patches - try { - val mf: MustacheFactory = DefaultMustacheFactory() - FileReader(src).use { srcReader -> - val mustache = mf.compile(srcReader, "template") - val outputFile = File(projectDirectory, outputFileName) - if (outputFile.exists()) { - outputFile.delete() - } - OutputStreamWriter(FileOutputStream(outputFile), StandardCharsets.UTF_8).use { writer -> - mustache.execute( - writer, - output - ).flush() - } - } - } catch (ex: IOException) { - error("Error while writing the output file!") - } - } -} - - -fun scanFolder(folder: File?, patches: MutableList, project: Project) { - val files = folder!!.listFiles { dir: File, name: String -> - if (dir.isDirectory) { - return@listFiles !name.equals("removed", ignoreCase = true) - } else { - return@listFiles true - } - } ?: return - for (f: File in files) { - if (f.isDirectory) { - scanFolder(f, patches, project) - } else if (f.name.endsWith(".patch")) { - try { - patches.add(PatchParser.parsePatch(f)) - } catch (ex: IOException) { - project.logger.warn("Exception while parsing '" + f.absolutePath + "'!", ex) - } - } - } -} - -class Output { - var patches: List? = null -} - diff --git a/buildSrc/src/main/kotlin/task/RebuildPatches.kt b/buildSrc/src/main/kotlin/task/RebuildPatches.kt deleted file mode 100644 index fbd637d9..00000000 --- a/buildSrc/src/main/kotlin/task/RebuildPatches.kt +++ /dev/null @@ -1,89 +0,0 @@ -package task - -import ensureSuccess -import forkName -import gitCmd -import org.gradle.api.Project -import org.gradle.api.Task -import taskGroup -import toothpick -import upstreams -import java.io.File -import java.nio.file.Paths -import Upstream - -@Suppress("UNUSED_VARIABLE") -internal fun Project.createRebuildPatchesTask( - receiver: Task.() -> Unit = {} -): Task = tasks.create("rebuildPatches") { - receiver(this) - group = taskGroup - doLast { - for ((name, subproject) in toothpick.subprojects) { - val (sourceRepo, projectDir, patchesDir) = subproject - var previousUpstreamName = "origin/master" - val folder = (if (patchesDir.endsWith("server")) "server" else "api") - - for (upstream in upstreams) { - val patchPath = Paths.get("${upstream.patchPath}/$folder").toFile() - - if (patchPath.listFiles()?.isEmpty() != false) continue - - updatePatches(patchPath, upstream.name, folder, projectDir, previousUpstreamName) - previousUpstreamName = "${upstream.name}-$folder" - } - // ensureSuccess(gitCmd("checkout", "$forkName-$folder", dir = projectDir, - ensureSuccess(gitCmd("checkout", "master", dir = projectDir, - printOut = true)) - - updatePatches(patchesDir, toothpick.forkName, folder, projectDir, previousUpstreamName) - - logger.lifecycle(">>> Done rebuilding patches for $name") - } - } -} - -private fun Project.updatePatches( - patchPath: File, - name: String, - folder: String, - projectDir: File, - previousUpstreamName: String -) { - logger.lifecycle(">>> Rebuilding patches for $name-$folder") - if (!patchPath.exists()) { - patchPath.mkdirs() - } - // Nuke old patches - patchPath.listFiles() - ?.filter { it -> it.name.endsWith(".patch") } - ?.forEach { it -> it.delete() } - - ensureSuccess( - if (name != "Yatopia") { - gitCmd( - "checkout", "$name-$folder", dir = projectDir, - printOut = true - ) - } else { - gitCmd( - "checkout", "master", dir = projectDir, - printOut = true - ) - } - ) - ensureSuccess( - gitCmd( - "format-patch", - "--no-stat", "--zero-commit", "--full-index", "--no-signature", "-N", - "-o", patchPath.absolutePath, previousUpstreamName, - dir = projectDir, - printOut = false - ) - ) - gitCmd( - "add", patchPath.canonicalPath, - dir = patchPath, - printOut = true - ) -} diff --git a/buildSrc/src/main/kotlin/task/RepackageNMS.kt b/buildSrc/src/main/kotlin/task/RepackageNMS.kt deleted file mode 100644 index 0206beeb..00000000 --- a/buildSrc/src/main/kotlin/task/RepackageNMS.kt +++ /dev/null @@ -1,108 +0,0 @@ -/* - * This file is part of Toothpick, licensed under the MIT License. - * - * Copyright (c) 2020-2021 Jason Penilla & Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package task - -import org.gradle.api.tasks.TaskAction -import java.io.File -import org.gradle.api.Project -import org.gradle.api.Task -import taskGroup -import upstreams -import gitCmd -import toothpick -import java.nio.file.Paths -import java.util.concurrent.ConcurrentHashMap -import ensureSuccess -import java.net.URL - -@Suppress("UNUSED_VARIABLE") -internal fun Project.createRepackageNMSTask( - receiver: Task.() -> Unit = {} -): Task = tasks.create("repackageNMS") { - receiver(this) - group = taskGroup - class Mapping(fullyQualifiedClassName: String) { - val className = fullyQualifiedClassName.substringAfterLast(".") - val oldFQName = "net.minecraft.server.$className" - val oldJavaFileName = "net/minecraft/server/$className.java" - val newFQName = fullyQualifiedClassName - val newJavaFileName = "${fullyQualifiedClassName.replace(".", "/")}.java" - } - - class Remapper(private val mappings: Set) { - fun remapFile(file: File): String = - file.readLines().joinToString("\n") { remapLine(it) } + "\n" - - private fun remapLine(line: String): String { - if ( - line.startsWith("diff --git ") - || line.startsWith("+++ ") - || line.startsWith("--- ") - ) { - var text = line - mappings.forEach { text = text.replace(it.oldJavaFileName, it.newJavaFileName) } - return text - } - if (line.startsWith("+")) { - var text = line - mappings.forEach { text = text.replace(it.oldFQName, it.newFQName) } - return text - } - return line - } - } - doLast { - logger.lifecycle("Downloading class mappings from spigot...") - val mappingsFileText = URL("https://hub.spigotmc.org/stash/projects/SPIGOT/repos/builddata/raw/mappings/bukkit-1.16.5-cl.csrg?at=80d35549ec67b87a0cdf0d897abbe826ba34ac27").readText() - logger.lifecycle("Done downloading class mappings.") - - logger.lifecycle(">>> Preparing patches for NMS repackage") - val mappings = mappingsFileText - .split("\n") - .asSequence() - .filter { !it.startsWith("#") && !it.contains("$") && it.trim().isNotEmpty() } - .map { it.split(" ")[1].replace("/", ".") } - .map { Mapping(it) } - .filter { it.newFQName != it.oldFQName } - .toSet() - val remapper = Remapper(mappings) - - toothpick.subprojects.values - .map { it.patchesDir } - .forEach { patchesDir -> - val repackagedPatchesDir = - patchesDir.parentFile.resolve("${patchesDir.name}_repackaged-${System.currentTimeMillis()}") - repackagedPatchesDir.mkdir() - val patchFiles = patchesDir.listFiles()?.toList() ?: error("Could not list patch files") - patchFiles.parallelStream().forEach { patch -> - logger.lifecycle("Processing ${patchesDir.name}/${patch.name}...") - val newPatch = repackagedPatchesDir.resolve(patch.name) - newPatch.writeText(remapper.remapFile(patch)) - } - } - - logger.lifecycle(">>> Done preparing patches") - } -} - diff --git a/buildSrc/src/main/kotlin/task/SetupUpstream.kt b/buildSrc/src/main/kotlin/task/SetupUpstream.kt deleted file mode 100644 index fa969e24..00000000 --- a/buildSrc/src/main/kotlin/task/SetupUpstream.kt +++ /dev/null @@ -1,35 +0,0 @@ -package task - -import bashCmd -import gitHash -import lastUpstream -import org.gradle.api.Project -import org.gradle.api.Task -import taskGroup -import toothpick -import upstreamDir - -internal fun Project.createSetupUpstreamTask( - receiver: Task.() -> Unit = {} -): Task = tasks.create("setupUpstream") { - receiver(this) - group = taskGroup - doLast { - val setupUpstreamCommand = if (upstreamDir.resolve(toothpick.upstreamLowercase).exists()) { - "./${toothpick.upstreamLowercase} patch" - } else if ( - upstreamDir.resolve("build.gradle.kts").exists() - && upstreamDir.resolve("subprojects/server.gradle.kts").exists() - && upstreamDir.resolve("subprojects/api.gradle.kts").exists() - ) { - "./gradlew applyPatches" - } else { - error("Don't know how to setup upstream!") - } - val result = bashCmd(setupUpstreamCommand, dir = upstreamDir, printOut = true) - if (result.exitCode != 0) { - error("Failed to apply upstream patches: script exited with code ${result.exitCode}") - } - lastUpstream.writeText(gitHash(upstreamDir)) - } -} diff --git a/buildSrc/src/main/kotlin/task/UpdateUpstream.kt b/buildSrc/src/main/kotlin/task/UpdateUpstream.kt deleted file mode 100644 index 5b0c612e..00000000 --- a/buildSrc/src/main/kotlin/task/UpdateUpstream.kt +++ /dev/null @@ -1,155 +0,0 @@ -package task - -import Upstream -import ensureSuccess -import gitCmd -import org.apache.tools.ant.util.FileUtils -import org.gradle.api.Project -import org.gradle.api.Task -import rootProjectDir -import taskGroup -import toothpick -import upstreamDir -import upstreams -import java.io.File -import java.nio.charset.StandardCharsets -import java.nio.file.Files -import java.nio.file.Paths -import java.util.stream.Collectors - - -internal fun Project.createUpdateUpstreamTask( - receiver: Task.() -> Unit = {} -): Task = tasks.create("updateUpstream") { - receiver(this) - group = taskGroup - doLast { - ensureSuccess(gitCmd("fetch", dir = upstreamDir, printOut = true)) - ensureSuccess(gitCmd("reset", "--hard", toothpick.upstreamBranch, dir = upstreamDir, printOut = true)) - ensureSuccess(gitCmd("add", toothpick.upstream, dir = rootProjectDir, printOut = true)) - for (upstream in upstreams) { - ensureSuccess(gitCmd("fetch", dir = upstream.repoPath.toFile(), printOut = true)) - ensureSuccess(gitCmd("reset", "--hard", upstream.branch, dir = upstream.repoPath.toFile(), printOut = true)) - ensureSuccess(gitCmd("add", "upstream/${upstream.name}", dir = rootProjectDir, printOut = true)) - } - ensureSuccess(gitCmd("submodule", "update", "--init", "--recursive", dir = upstreamDir, printOut = true)) - val fileUtils = FileUtils.getFileUtils() - for (upstream in upstreams) { - val serverRepoPatches = upstream.getRepoServerPatches() - val apiRepoPatches = upstream.getRepoAPIPatches() - val serverPatches = upstream.serverList - val apiPatches = upstream.apiList - logger.lifecycle(">>> Pulling ${upstream.name} patches") - updatePatches(serverRepoPatches, upstream, fileUtils, serverPatches, "server") - updatePatches(apiRepoPatches, upstream, fileUtils, apiPatches, "api") - upstream.updateUpstreamCommitHash() - } - } -} - -private fun updatePatches( - repoPatches: MutableList?, - upstream: Upstream, - fileUtils: FileUtils, - patches: MutableList?, - folder: String -) { - if (repoPatches != null) { - var i = 0 - val currentPatchList = Paths.get("${upstream.patchPath}/$folder").toFile().listFiles() as Array? - val tmpFolder = Paths.get("${upstream.patchPath}/tmp/$folder").toFile() - tmpFolder.mkdirs() - if (currentPatchList != null) { - for (patch in currentPatchList) { - if (patch.exists()) { - fileUtils.copyFile( - "${upstream.patchPath}/$folder/${patch.name}", - "${upstream.patchPath}/tmp/$folder/${patch.name}" - ) - patch.delete() - } - } - } - val currentPatchListFiltered = currentPatchList?.toList() - ?.stream()?.sorted()?.map { patch -> patch.name.substring(5, patch.name.length) } - ?.collect(Collectors.toList()) - for (patch in repoPatches) { - if (patches != null) { - if ((patches.contains(patch) && upstream.useBlackList) || (!patches.contains(patch) && !upstream.useBlackList)) { - continue - } else { - i++ - updatePatch(fileUtils, upstream, repoPatches, patch, i, folder, currentPatchListFiltered) - } - } - } - val tmpFolderList = tmpFolder.listFiles() - if (tmpFolderList != null) { - for (patch in tmpFolderList) { - patch.delete() - } - } - } -} - -private fun updatePatch( - fileUtils: FileUtils, - upstream: Upstream, - serverRepoPatches: MutableList, - patch: String, - i: Int, - folder: String, - currentPatchListFiltered: MutableList? -) { - if (currentPatchListFiltered == null || patchHasDiff(upstream, serverRepoPatches, patch, folder, currentPatchListFiltered)) { - fileUtils.copyFile("${upstream.repoPath}/patches/$folder/" + - "${String.format("%04d", serverRepoPatches.indexOf(patch) + 1)}-$patch", - "${upstream.patchPath}/$folder/${String.format("%04d", i)}-$patch" - ) - } else { - fileUtils.copyFile("${upstream.patchPath}/tmp/$folder/" + - "${String.format("%04d", currentPatchListFiltered.indexOf(patch) + 1)}-$patch", - "${upstream.patchPath}/$folder/${String.format("%04d", i)}-$patch" - ) - } -} - -fun patchHasDiff( - upstream: Upstream, - serverRepoPatches: MutableList, - patch: String, - folder: String, - currentPatchListFiltered: MutableList -): Boolean { - if (!Paths.get("${upstream.patchPath}/tmp/$folder/${String.format("%04d", currentPatchListFiltered.indexOf(patch) + 1)}-$patch").toFile().isFile) return true - if (!patchChanged(upstream, serverRepoPatches, patch, folder)) return false - val upstreamFile = Files.readAllLines(Paths.get("${upstream.repoPath}/patches/$folder/${String.format("%04d", serverRepoPatches.indexOf(patch) + 1)}-$patch"), StandardCharsets.UTF_8) - val repoFile = Files.readAllLines(Paths.get("${upstream.patchPath}/tmp/$folder/${String.format("%04d", currentPatchListFiltered.indexOf(patch) + 1)}-$patch"), StandardCharsets.UTF_8) - return upstreamFile.stream().filter {line -> line.startsWith("+") || line.startsWith("-")} - .filter {line -> if (line.startsWith("---") || line.startsWith("+++")) { - line.substring(3, line.length).trim().isNotBlank() - } - else if (line.startsWith("--") || line.startsWith("++")) { - line.substring(2, line.length).trim().isNotBlank() - } - else { - line.substring(1, line.length).trim().isNotBlank() - } } - .filter {line -> if (repoFile.contains(line)) { - repoFile.remove(line) - return@filter false - } else { return@filter true } }.collect(Collectors.toList()).isNotEmpty() -} - -fun patchChanged( - upstream: Upstream, - serverRepoPatches: MutableList, - patch: String, - folder: String -): Boolean { - val diffCheckCmdResult = upstream.project.gitCmd("diff", "--name-only", upstream.upstreamCommit, upstream.getCurrentCommitHash(), dir = upstream.repoPath.toFile() ) - val diffCheckResult = diffCheckCmdResult.output.toString() - if (diffCheckResult.isBlank()) return false - val diffCheckChangeFiles = diffCheckResult.split("\\n".toRegex()).toTypedArray().toList() - return diffCheckChangeFiles.contains("patches/$folder/${String.format("%04d", serverRepoPatches.indexOf(patch) + 1)}-$patch") -} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/task/UpstreamCommit.kt b/buildSrc/src/main/kotlin/task/UpstreamCommit.kt deleted file mode 100644 index 0fbadcad..00000000 --- a/buildSrc/src/main/kotlin/task/UpstreamCommit.kt +++ /dev/null @@ -1,82 +0,0 @@ -package task - -import ensureSuccess -import gitCmd -import org.gradle.api.Project -import org.gradle.api.Task -import taskGroup -import toothpick -import upstreamDir -import upstreams -import java.io.File -import Upstream -import java.util.concurrent.CopyOnWriteArrayList - -internal fun Project.createUpstreamCommitTask( - receiver: Task.() -> Unit = {} -): Task = tasks.create("upstreamCommit") { - receiver(this) - group = taskGroup - doLast { - gitChangelog = getUpstreamChanges(project,this, toothpick.upstream, - upstreamDir, toothpick.upstream) - - for (upstream in upstreams) { - gitChangelog = getUpstreamChanges(project,this, upstream.name, - upstream.repoPath.toFile(), "upstream/${upstream.name}") - } - - var changedUpstreamsString = "" - for (upstreamName in changedUpstreams) { - if (changedUpstreamsString.isNotEmpty()) { - changedUpstreamsString += "/" - } - changedUpstreamsString += upstreamName - } - if (changedUpstreamsString.isNotEmpty()) { - val commitMessage = """ - |Updated Upstream and Sidestream(s) ($changedUpstreamsString) - | - |Upstream/An Sidestream has released updates that appears to apply and compile correctly - |This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing. - | - | - |$gitChangelog - """.trimMargin() - ensureSuccess(gitCmd("commit", "-m", commitMessage, printOut = true)) - } - - } -} - -private fun getUpstreamChanges( - project: Project, - task: Task, - name: String, - dir: File, - path: String -): String { - var gitChangelog1 = gitChangelog - val oldRev = ensureSuccess(project.gitCmd("ls-tree", "HEAD", path)) - ?.substringAfter("commit ")?.substringBefore("\t") - val upstreamTmp = ensureSuccess( - project.gitCmd( - "log", - "--oneline", - "$oldRev...HEAD", - printOut = true, - dir = dir - ) - ) { - task.logger.lifecycle("No $name changes to commit.") - } - if (!upstreamTmp.isNullOrBlank()) { - changedUpstreams.add(name) - gitChangelog1 += "$name Changes:\n$upstreamTmp\n\n" - } - return gitChangelog1 -} - -val changedUpstreams = CopyOnWriteArrayList() - -var gitChangelog = "" \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/transformer/ModifiedLog4j2PluginsCacheFileTransformer.kt b/buildSrc/src/main/kotlin/transformer/ModifiedLog4j2PluginsCacheFileTransformer.kt deleted file mode 100644 index a442b35c..00000000 --- a/buildSrc/src/main/kotlin/transformer/ModifiedLog4j2PluginsCacheFileTransformer.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of Toothpick, licensed under the MIT License. - * - * Copyright (c) 2020-2021 Jason Penilla & Contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package transformer - -import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer -import com.github.jengelman.gradle.plugins.shadow.transformers.Transformer -import org.gradle.api.file.FileTreeElement -import shadow.org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor.PLUGIN_CACHE_FILE - -internal class ModifiedLog4j2PluginsCacheFileTransformer : Transformer by Log4j2PluginsCacheFileTransformer() { - /** - * For some reason we have a file with name matching simply 'Log4j2Plugins.dat' and not PLUGIN_CACHE_FILE. - * That file also needs to be merged. - */ - override fun canTransformResource(element: FileTreeElement): Boolean { - return PLUGIN_CACHE_FILE == element.name || element.name == "Log4j2Plugins.dat" - } -} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 25eb2409..63411c25 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip # Check on https://gradle.org/release-checksums/ -distributionSha256Sum=dccda8aa069563c8ba2f6cdfd0777df0e34a5b4d15138ca8b9757e94f4e8a8cb +distributionSha256Sum=0e46229820205440b48a5501122002842b82886e76af35f0f3a069243dca4b3c zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/mcdevimports.json b/mcdevimports.json new file mode 100644 index 00000000..bc65e1cd --- /dev/null +++ b/mcdevimports.json @@ -0,0 +1,135 @@ +{ + "nmsImports": [ + { + "file": "HeightMap" + } + ] + "libraryImports": [ + { + "group": "com.mojang", + "library": "brigadier", + "prefix": "com/mojang/brigadier", + "file": "CommandDispatcher" + }, + { + "group": "com.mojang", + "library": "brigadier", + "prefix": "com/mojang/brigadier/tree", + "file": "LiteralCommandNode" + }, + { + "group": "com.mojang", + "library": "brigadier", + "prefix": "com/mojang/brigadier/suggestion", + "file": "SuggestionsBuilder" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers", + "file": "FieldFinder" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers", + "file": "DataFixUtils" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers", + "file": "TypeRewriteRule" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers", + "file": "Typed" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers", + "file": "TypedOptic" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers", + "file": "View" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers", + "file": "FieldFinder" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers/functions", + "file": "Apply" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers/functions", + "file": "Comp" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers/functions", + "file": "PointFree" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers/functions", + "file": "PointFreeRule" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers/optics", + "file": "IdAdapter" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers/optics", + "file": "Inj1" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers/optics", + "file": "Inj2" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers/optics", + "file": "Optics" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers/optics", + "file": "Proj1" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers/optics", + "file": "Proj2" + }, + { + "group": "com.mojang", + "library": "datafixerupper", + "prefix": "com/mojang/datafixers/types", + "file": "Type" + } + ] +} diff --git a/patches/server/0066-Fix-Log4j-Warning.patch b/patches/server/0066-Fix-Log4j-Warning.patch deleted file mode 100644 index 58635fc0..00000000 --- a/patches/server/0066-Fix-Log4j-Warning.patch +++ /dev/null @@ -1,262 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: snoopdoooggyttv -Date: Wed, 5 May 2021 20:32:22 +0200 -Subject: [PATCH] Fix Log4j Warning - - -diff --git a/src/main/java/org/apache/logging/log4j/util/StackLocator.java b/src/main/java/org/apache/logging/log4j/util/StackLocator.java -new file mode 100644 -index 0000000000000000000000000000000000000000..44161840e64946b4b6ce0483495304809d15ade8 ---- /dev/null -+++ b/src/main/java/org/apache/logging/log4j/util/StackLocator.java -@@ -0,0 +1,250 @@ -+/* -+ * Licensed to the Apache Software Foundation (ASF) under one or more -+ * contributor license agreements. See the NOTICE file distributed with -+ * this work for additional information regarding copyright ownership. -+ * The ASF licenses this file to You under the Apache license, Version 2.0 -+ * (the "License"); you may not use this file except in compliance with -+ * the License. You may obtain a copy of the License at -+ * -+ * http://www.apache.org/licenses/LICENSE-2.0 -+ * -+ * Unless required by applicable law or agreed to in writing, software -+ * distributed under the License is distributed on an "AS IS" BASIS, -+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -+ * See the license for the specific language governing permissions and -+ * limitations under the license. -+ */ -+package org.apache.logging.log4j.util; -+ -+import java.lang.reflect.Method; -+import java.util.Stack; -+ -+/** -+ * Consider this class private. Provides various methods to determine the caller class.

Background

-+ *

-+ * This method, available only in the Oracle/Sun/OpenJDK implementations of the Java Virtual Machine, is a much more -+ * efficient mechanism for determining the {@link Class} of the caller of a particular method. When it is not available, -+ * a {@link SecurityManager} is the second-best option. When this is also not possible, the {@code StackTraceElement[]} -+ * returned by {@link Throwable#getStackTrace()} must be used, and its {@code String} class name converted to a -+ * {@code Class} using the slow {@link Class#forName} (which can add an extra microsecond or more for each invocation -+ * depending on the runtime ClassLoader hierarchy). -+ *

-+ *

-+ * During Java 8 development, the {@code sun.reflect.Reflection.getCallerClass(int)} was removed from OpenJDK, and this -+ * change was back-ported to Java 7 in version 1.7.0_25 which changed the behavior of the call and caused it to be off -+ * by one stack frame. This turned out to be beneficial for the survival of this API as the change broke hundreds of -+ * libraries and frameworks relying on the API which brought much more attention to the intended API removal. -+ *

-+ *

-+ * After much community backlash, the JDK team agreed to restore {@code getCallerClass(int)} and keep its existing -+ * behavior for the rest of Java 7. However, the method is deprecated in Java 8, and current Java 9 development has not -+ * addressed this API. Therefore, the functionality of this class cannot be relied upon for all future versions of Java. -+ * It does, however, work just fine in Sun JDK 1.6, OpenJDK 1.6, Oracle/OpenJDK 1.7, and Oracle/OpenJDK 1.8. Other Java -+ * environments may fall back to using {@link Throwable#getStackTrace()} which is significantly slower due to -+ * examination of every virtual frame of execution. -+ *

-+ */ -+public final class StackLocator { -+ -+ // Checkstyle Suppress: the lower-case 'u' ticks off CheckStyle... -+ // CHECKSTYLE:OFF -+ static final int JDK_7u25_OFFSET; -+ // CHECKSTYLE:OFF -+ -+ private static final Method GET_CALLER_CLASS; -+ -+ private static final StackLocator INSTANCE; -+ -+ static { -+ Method getCallerClass; -+ int java7u25CompensationOffset = 0; -+ try { -+ final Class sunReflectionClass = LoaderUtil.loadClass("sun.reflect.Reflection"); -+ getCallerClass = sunReflectionClass.getDeclaredMethod("getCallerClass", int.class); -+ Object o = getCallerClass.invoke(null, 0); -+ getCallerClass.invoke(null, 0); -+ if (o == null || o != sunReflectionClass) { -+ getCallerClass = null; -+ java7u25CompensationOffset = -1; -+ } else { -+ o = getCallerClass.invoke(null, 1); -+ if (o == sunReflectionClass) { -+ System.out.println("WARNING: Java 1.7.0_25 is in use which has a broken implementation of Reflection.getCallerClass(). " + -+ " Please consider upgrading to Java 1.7.0_40 or later."); -+ java7u25CompensationOffset = 1; -+ } -+ } -+ } catch (final Exception | LinkageError e) { -+ //System.out.println("WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance."); // Yatopia - Fix Error Message -+ getCallerClass = null; -+ java7u25CompensationOffset = -1; -+ } -+ -+ GET_CALLER_CLASS = getCallerClass; -+ JDK_7u25_OFFSET = java7u25CompensationOffset; -+ -+ INSTANCE = new StackLocator(); -+ } -+ -+ public static StackLocator getInstance() { -+ return INSTANCE; -+ } -+ -+ private StackLocator() { -+ } -+ -+ // TODO: return Object.class instead of null (though it will have a null ClassLoader) -+ // (MS) I believe this would work without any modifications elsewhere, but I could be wrong -+ -+ // migrated from ReflectiveCallerClassUtility -+ @PerformanceSensitive -+ public Class getCallerClass(final int depth) { -+ if (depth < 0) { -+ throw new IndexOutOfBoundsException(Integer.toString(depth)); -+ } -+ if (GET_CALLER_CLASS == null) { -+ return null; -+ } -+ // note that we need to add 1 to the depth value to compensate for this method, but not for the Method.invoke -+ // since Reflection.getCallerClass ignores the call to Method.invoke() -+ try { -+ return (Class) GET_CALLER_CLASS.invoke(null, depth + 1 + JDK_7u25_OFFSET); -+ } catch (final Exception e) { -+ // theoretically this could happen if the caller class were native code -+ // TODO: return Object.class -+ return null; -+ } -+ } -+ -+ // migrated from Log4jLoggerFactory -+ @PerformanceSensitive -+ public Class getCallerClass(final String fqcn, final String pkg) { -+ return getCallerClass(fqcn, pkg, 0); -+ } -+ -+ @PerformanceSensitive -+ public Class getCallerClass(final String fqcn, final String pkg, final int skipDepth) { -+ if (skipDepth < 0) { -+ throw new IllegalArgumentException("skipDepth cannot be negative"); -+ } -+ boolean next = false; -+ Class clazz; -+ for (int i = 2; null != (clazz = getCallerClass(i)); i++) { -+ if (fqcn.equals(clazz.getName())) { -+ next = true; -+ continue; -+ } -+ if (next && clazz.getName().startsWith(pkg)) { -+ return skipDepth == 0 -+ ? clazz -+ : getCallerClass(i + skipDepth); -+ } -+ } -+ // TODO: return Object.class -+ return null; -+ } -+ -+ // added for use in LoggerAdapter implementations mainly -+ @PerformanceSensitive -+ public Class getCallerClass(final Class anchor) { -+ boolean next = false; -+ Class clazz; -+ for (int i = 2; null != (clazz = getCallerClass(i)); i++) { -+ if (anchor.equals(clazz)) { -+ next = true; -+ continue; -+ } -+ if (next) { -+ return clazz; -+ } -+ } -+ return Object.class; -+ } -+ -+ // migrated from ThrowableProxy -+ @PerformanceSensitive -+ public Stack> getCurrentStackTrace() { -+ // benchmarks show that using the SecurityManager is much faster than looping through getCallerClass(int) -+ if (PrivateSecurityManagerStackTraceUtil.isEnabled()) { -+ return PrivateSecurityManagerStackTraceUtil.getCurrentStackTrace(); -+ } -+ // slower version using getCallerClass where we cannot use a SecurityManager -+ final Stack> classes = new Stack<>(); -+ Class clazz; -+ for (int i = 1; null != (clazz = getCallerClass(i)); i++) { -+ classes.push(clazz); -+ } -+ return classes; -+ } -+ -+ public StackTraceElement calcLocation(final String fqcnOfLogger) { -+ if (fqcnOfLogger == null) { -+ return null; -+ } -+ // LOG4J2-1029 new Throwable().getStackTrace is faster than Thread.currentThread().getStackTrace(). -+ final StackTraceElement[] stackTrace = new Throwable().getStackTrace(); -+ boolean found = false; -+ for (int i = 0; i < stackTrace.length; i++) { -+ final String className = stackTrace[i].getClassName(); -+ if (fqcnOfLogger.equals(className)) { -+ -+ found = true; -+ continue; -+ } -+ if (found && !fqcnOfLogger.equals(className)) { -+ return stackTrace[i]; -+ } -+ } -+ return null; -+ } -+ -+ public StackTraceElement getStackTraceElement(final int depth) { -+ // (MS) I tested the difference between using Throwable.getStackTrace() and Thread.getStackTrace(), and -+ // the version using Throwable was surprisingly faster! at least on Java 1.8. See ReflectionBenchmark. -+ final StackTraceElement[] elements = new Throwable().getStackTrace(); -+ int i = 0; -+ for (final StackTraceElement element : elements) { -+ if (isValid(element)) { -+ if (i == depth) { -+ return element; -+ } -+ ++i; -+ } -+ } -+ throw new IndexOutOfBoundsException(Integer.toString(depth)); -+ } -+ -+ private boolean isValid(final StackTraceElement element) { -+ // ignore native methods (oftentimes are repeated frames) -+ if (element.isNativeMethod()) { -+ return false; -+ } -+ final String cn = element.getClassName(); -+ // ignore OpenJDK internal classes involved with reflective invocation -+ if (cn.startsWith("sun.reflect.")) { -+ return false; -+ } -+ final String mn = element.getMethodName(); -+ // ignore use of reflection including: -+ // Method.invoke -+ // InvocationHandler.invoke -+ // Constructor.newInstance -+ if (cn.startsWith("java.lang.reflect.") && (mn.equals("invoke") || mn.equals("newInstance"))) { -+ return false; -+ } -+ // ignore use of Java 1.9+ reflection classes -+ if (cn.startsWith("jdk.internal.reflect.")) { -+ return false; -+ } -+ // ignore Class.newInstance -+ if (cn.equals("java.lang.Class") && mn.equals("newInstance")) { -+ return false; -+ } -+ // ignore use of Java 1.7+ MethodHandle.invokeFoo() methods -+ if (cn.equals("java.lang.invoke.MethodHandle") && mn.startsWith("invoke")) { -+ return false; -+ } -+ // any others? -+ return true; -+ } -+} diff --git a/server b/server deleted file mode 100644 index effd814c..00000000 --- a/server +++ /dev/null @@ -1 +0,0 @@ -Yatopia-Server/ \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts index d05e9373..666d45eb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,6 +5,15 @@ val forkNameLowercase = forkName.toLowerCase(Locale.ENGLISH) rootProject.name = forkNameLowercase +pluginManagement { + repositories { + gradlePluginPortal() + maven("https://mvn.thearcanebrony.net/repository/maven-public/") + maven("https://jitpack.io/") + mavenCentral() + } +} + setupSubproject("$forkNameLowercase-api") { projectDir = File("$forkName-API") buildFileName = "../subprojects/api.gradle.kts" diff --git a/subprojects/api.gradle.kts b/subprojects/api.gradle.kts index 7d46a394..96c93d0f 100644 --- a/subprojects/api.gradle.kts +++ b/subprojects/api.gradle.kts @@ -1,3 +1,11 @@ +import org.yatopiamc.toothpick.loadDependencies +import org.yatopiamc.toothpick.loadRepositories + +plugins { + `java-library` + `maven-publish` +} + repositories { loadRepositories(project) } diff --git a/subprojects/server.gradle.kts b/subprojects/server.gradle.kts index 855fb4bd..96a8e378 100644 --- a/subprojects/server.gradle.kts +++ b/subprojects/server.gradle.kts @@ -1,3 +1,11 @@ +import org.yatopiamc.toothpick.loadDependencies +import org.yatopiamc.toothpick.loadRepositories + +plugins { + `java-library` + `maven-publish` +} + repositories { loadRepositories(project) } From 0fe24c575f1d6bb733952560f09bed854fc0d4fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tofik=20=E2=99=A1?= <62406295+Toffikk@users.noreply.github.com> Date: Mon, 14 Jun 2021 21:11:18 +0200 Subject: [PATCH 2/3] Update build.gradle.kts --- build.gradle.kts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 1c44955c..ba43c32c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,8 +24,8 @@ toothpick { forkVersion = "git-$forkName-$currentBranch-$versionTag" forkUrl = "https://github.com/YatopiaMC/Yatopia" - minecraftVersion = "1.16.5" - nmsPackage = "1_16_R3" + minecraftVersion = "1.17" + nmsPackage = "1_17_R1" nmsRevision = "R0.1-SNAPSHOT" upstream = "Paper" @@ -62,11 +62,11 @@ subprojects { } java { - if(JavaVersion.VERSION_1_8 > JavaVersion.current()){ - error("This build must be run with Java 8 or newer") + if(JavaVersion.VERSION_16 > JavaVersion.current()){ + error("This build must be run with Java 16 or newer") } - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_16 + targetCompatibility = JavaVersion.VERSION_16 withSourcesJar() } @@ -74,6 +74,7 @@ tasks.withType().configureEach { options.isIncremental = true options.isFork = true options.encoding = "UTF-8" + options.release.set(16) } } From 1a07bc652136d6b0f16615bfd3a77d37d24a14e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tofik=20=E2=99=A1?= <62406295+Toffikk@users.noreply.github.com> Date: Mon, 14 Jun 2021 21:11:54 +0200 Subject: [PATCH 3/3] build on all branches --- .github/workflows/build.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0662643c..fbea7736 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,10 +5,6 @@ on: paths-ignore: - '*.md' - 'Jenkinsfile' - branches: - - ver/1.16.5 - - dev/* - - staging/1.16.5 pull_request: paths-ignore: - '*.md' @@ -27,7 +23,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - java: [ '8', '11', '15', '16' ] + java: [ '16' ] fail-fast: false steps: - uses: actions/checkout@v2