From b1a1001c494600633783f1ac9867891caf98baf1 Mon Sep 17 00:00:00 2001 From: dfsek Date: Fri, 26 Mar 2021 08:50:58 -0700 Subject: [PATCH] clean up buildscripts --- .../kotlin/com/dfsek/terra/CommonConfig.kt | 2 +- .../com/dfsek/terra/DistributionConfig.kt | 9 +- platforms/bukkit/build.gradle.kts | 186 +++++++++++++----- platforms/fabric/build.gradle.kts | 1 + 4 files changed, 140 insertions(+), 58 deletions(-) diff --git a/buildSrc/src/main/kotlin/com/dfsek/terra/CommonConfig.kt b/buildSrc/src/main/kotlin/com/dfsek/terra/CommonConfig.kt index 2405568cd..c06a71b2d 100644 --- a/buildSrc/src/main/kotlin/com/dfsek/terra/CommonConfig.kt +++ b/buildSrc/src/main/kotlin/com/dfsek/terra/CommonConfig.kt @@ -30,7 +30,7 @@ fun Project.configureCommon() { } fun Project.getGitHash(): String { - val stdout = java.io.ByteArrayOutputStream() + val stdout = ByteArrayOutputStream() exec { commandLine = mutableListOf("git", "rev-parse", "--short", "HEAD") standardOutput = stdout diff --git a/buildSrc/src/main/kotlin/com/dfsek/terra/DistributionConfig.kt b/buildSrc/src/main/kotlin/com/dfsek/terra/DistributionConfig.kt index 855d50c95..aeb306888 100644 --- a/buildSrc/src/main/kotlin/com/dfsek/terra/DistributionConfig.kt +++ b/buildSrc/src/main/kotlin/com/dfsek/terra/DistributionConfig.kt @@ -14,13 +14,9 @@ fun Project.configureDistribution() { apply(plugin = "java-library") apply(plugin = "com.github.johnrengelman.shadow") - -// configurations.create("shaded") - configurations { val shaded = create("shaded") getByName("compile").extendsFrom(shaded) -// shaded.extendsFrom(getByName("compile")) val shadedApi = create("shadedApi") shaded.extendsFrom(shadedApi) getByName("api").extendsFrom(shadedApi) @@ -29,11 +25,8 @@ fun Project.configureDistribution() { getByName("implementation").extendsFrom(shadedImplementation) } -// tasks.withType { -// classpath += -// } - val downloadDefaultPacks = tasks.create("downloadDefaultPacks") { + group = "terra" doFirst { file("${buildDir}/resources/main/packs/").deleteRecursively() diff --git a/platforms/bukkit/build.gradle.kts b/platforms/bukkit/build.gradle.kts index dbf066f36..e9dac10e5 100644 --- a/platforms/bukkit/build.gradle.kts +++ b/platforms/bukkit/build.gradle.kts @@ -15,6 +15,13 @@ configureCommon() group = "com.dfsek.terra.bukkit" +val mcVersion = "1.16.5" +val testDir = "target/server/" +val testMem = "3G" + +val paperURL = "https://papermc.io/api/v1/paper/%version%/latest/download/" +val purpurURL = "https://ci.pl3x.net/job/Purpur/lastSuccessfulBuild/artifact/final/purpurclip.jar" + repositories { mavenCentral() maven { url = uri("http://maven.enginehub.org/repo/") } @@ -35,73 +42,155 @@ dependencies { "shadedImplementation"("com.google.guava:guava:30.0-jre") } -val testDir = "target/server/" +val aikarsFlags = listOf("-XX:+UseG1GC", "-XX:+ParallelRefProcEnabled", "-XX:MaxGCPauseMillis=200", + "-XX:+UnlockExperimentalVMOptions", "-XX:+DisableExplicitGC", "-XX:+AlwaysPreTouch", + "-XX:G1NewSizePercent=30", "-XX:G1MaxNewSizePercent=40", "-XX:G1HeapRegionSize=8M", + "-XX:G1ReservePercent=20", "-XX:G1HeapWastePercent=5", "-XX:G1MixedGCCountTarget=4", + "-XX:InitiatingHeapOccupancyPercent=15", "-XX:G1MixedGCLiveThresholdPercent=90", + "-XX:G1RSetUpdatingPauseTimePercent=5", "-XX:SurvivorRatio=32", "-XX:+PerfDisableSharedMem", + "-XX:MaxTenuringThreshold=1", "-Dusing.aikars.flags=https://mcflags.emc.gs", + "-Daikars.new.flags=true", "-DIReallyKnowWhatIAmDoingISwear") -val setupServer = tasks.create("setupServer") { - dependsOn("shadowJar") - doFirst { - // clean - file("${testDir}/").deleteRecursively() - file("${testDir}/plugins").mkdirs() +fun downloadPaperclip(url: String, dir: String) { + val clip = URL(url.replace("%version%", mcVersion)) + val clipReadableByteChannel = Channels.newChannel(clip.openStream()) + val clipFile = file("$testDir/$dir/paperclip.jar") + val clipOutputStream = clipFile.outputStream() + val clipFileChannel = clipOutputStream.channel + clipFileChannel.transferFrom(clipReadableByteChannel, 0, Long.MAX_VALUE) +} - // Downloading latest paper jar. - val paperUrl = URL("https://papermc.io/api/v1/paper/1.16.4/latest/download") - val paperReadableByteChannel = Channels.newChannel(paperUrl.openStream()) - val paperFile = file("${testDir}/paper.jar") - val paperFileOutputStream = paperFile.outputStream() - val paperFileChannel = paperFileOutputStream.channel - paperFileChannel.transferFrom(paperReadableByteChannel, 0, Long.MAX_VALUE) - - // Cloning test setup. - gitClone("https://github.com/PolyhedralDev/WorldGenTestServer") - // Copying plugins - Files.move(Paths.get("WorldGenTestServer/plugins"), - Paths.get("$testDir/plugins"), - StandardCopyOption.REPLACE_EXISTING) - // Copying config - val serverText = URL("https://raw.githubusercontent.com/PolyhedralDev/WorldGenTestServer/master/server.properties").readText() - file("${testDir}/server.properties").writeText(serverText) - val bukkitText = URL("https://raw.githubusercontent.com/PolyhedralDev/WorldGenTestServer/master/bukkit.yml").readText() - file("${testDir}/bukkit.yml").writeText(bukkitText.replace("\${world}", "world").replace("\${gen}", "Terra:DEFAULT")) - - File("${testDir}/eula.txt").writeText("eula=true") - - // clean up - file("WorldGenTestServer").deleteRecursively() +fun copyTerra(dir: String) { + file("$testDir/$dir").walk().forEach { + if(it.name.startsWith("Terra-") && it.name.endsWith(".jar")) it.delete() // Delete old Terra jar(s) + } + copy { + from("$buildDir/libs/Terra-bukkit-$version-shaded.jar") + into("$testDir/$dir/plugins/") } } -val testWithPaper = task(name = "testWithPaper") { +fun installServer(dir: String) { + // clean + file("$testDir/$dir").deleteRecursively() + file("$testDir/$dir/plugins").mkdirs() + // Cloning test setup. + gitClone("https://github.com/PolyhedralDev/WorldGenTestServer") + // Copying plugins + Files.move(Paths.get("WorldGenTestServer/plugins"), + Paths.get("$testDir/$dir/plugins"), + StandardCopyOption.REPLACE_EXISTING) + // Copying config + val serverText = URL("https://raw.githubusercontent.com/PolyhedralDev/WorldGenTestServer/master/server.properties").readText() + file("$testDir/$dir/server.properties").writeText(serverText) + val bukkitText = URL("https://raw.githubusercontent.com/PolyhedralDev/WorldGenTestServer/master/bukkit.yml").readText() + file("$testDir/$dir/bukkit.yml").writeText(bukkitText.replace("\${world}", "world").replace("\${gen}", "Terra:DEFAULT")) + + println("By proceeding, you are agreeing to the Minecraft EULA: https://account.mojang.com/documents/minecraft_eula") + file("$testDir/$dir/eula.txt").writeText("eula=true") + + // clean up + file("WorldGenTestServer").deleteRecursively() +} + +fun deleteFolder(folder: File) { + if(folder.exists()) folder.deleteRecursively() +} + +fun deleteFile(file: File) { + if(file.exists()) file.delete() +} + +tasks.create("cleanWorlds") { + group = "bukkit" + doFirst { + deleteFolder(file("$testDir/paper/world")) + deleteFolder(file("$testDir/paper/world_nether")) + deleteFolder(file("$testDir/paper/world_the_end")) + + deleteFolder(file("$testDir/purpur/world")) + deleteFolder(file("$testDir/purpur/world_nether")) + deleteFolder(file("$testDir/purpur/world_the_end")) + } +} + +tasks.create("updatePaper") { + group = "bukkit" + doFirst { + deleteFile(file("$testDir/paper/paperclip.jar")) + downloadPaperclip(paperURL, "paper") + } +} + +tasks.create("updatePurpur") { + group = "bukkit" + doFirst { + deleteFile(file("$testDir/paper/paperclip.jar")) + downloadPaperclip(purpurURL, "purpur") + } +} + +tasks.create("installPaper") { + group = "bukkit" + dependsOn("shadowJar") + doFirst { + installServer("paper") + // Downloading latest paper jar. + downloadPaperclip(paperURL, "paper") + } +} + +tasks.create("installPurpur") { + group = "bukkit" + dependsOn("shadowJar") + doFirst { + installServer("purpur") + // Downloading latest paper jar. + downloadPaperclip(purpurURL, "purpur") + } +} + +task(name = "runPaper") { + group = "bukkit" standardInput = System.`in` dependsOn("shadowJar") // Copy Terra into dir doFirst { - copy { - from("${buildDir}/libs/Terra-bukkit-${version}-shaded.jar") - into("${testDir}/plugins/") - } + copyTerra("paper") } main = "io.papermc.paperclip.Paperclip" - jvmArgs = listOf("-XX:+UseG1GC", "-XX:+ParallelRefProcEnabled", "-XX:MaxGCPauseMillis=200", - "-XX:+UnlockExperimentalVMOptions", "-XX:+DisableExplicitGC", "-XX:+AlwaysPreTouch", - "-XX:G1NewSizePercent=30", "-XX:G1MaxNewSizePercent=40", "-XX:G1HeapRegionSize=8M", - "-XX:G1ReservePercent=20", "-XX:G1HeapWastePercent=5", "-XX:G1MixedGCCountTarget=4", - "-XX:InitiatingHeapOccupancyPercent=15", "-XX:G1MixedGCLiveThresholdPercent=90", - "-XX:G1RSetUpdatingPauseTimePercent=5", "-XX:SurvivorRatio=32", "-XX:+PerfDisableSharedMem", - "-XX:MaxTenuringThreshold=1", "-Dusing.aikars.flags=https://mcflags.emc.gs", - "-Daikars.new.flags=true", "-DIReallyKnowWhatIAmDoingISwear") - maxHeapSize = "4G" - minHeapSize = "4G" + jvmArgs = aikarsFlags + maxHeapSize = testMem + minHeapSize = testMem //args = listOf("nogui") - workingDir = file("${testDir}/") - classpath = files("${testDir}/paper.jar") + workingDir = file("$testDir/paper") + classpath = files("$testDir/paper/paperclip.jar") +} + +task(name = "runPurpur") { + group = "bukkit" + standardInput = System.`in` + dependsOn("shadowJar") + // Copy Terra into dir + doFirst { + copyTerra("purpur") + } + + main = "io.papermc.paperclip.Paperclip" + jvmArgs = aikarsFlags + maxHeapSize = testMem + minHeapSize = testMem + //args = listOf("nogui") + workingDir = file("$testDir/purpur") + classpath = files("$testDir/purpur/paperclip.jar") } tasks.named("shadowJar") { relocate("org.bstats.bukkit", "com.dfsek.terra.lib.bstats") relocate("io.papermc.lib", "com.dfsek.terra.lib.paperlib") } + publishing { publications { create("mavenJava") { @@ -112,7 +201,6 @@ publishing { repositories { val mavenUrl = "https://repo.codemc.io/repository/maven-releases/" - val mavenSnapshotUrl = "https://repo.codemc.io/repository/maven-snapshots/" maven(mavenUrl) { val mavenUsername: String? by project diff --git a/platforms/fabric/build.gradle.kts b/platforms/fabric/build.gradle.kts index 2e085d24d..900d17698 100644 --- a/platforms/fabric/build.gradle.kts +++ b/platforms/fabric/build.gradle.kts @@ -40,6 +40,7 @@ configure { } tasks.register("remapShadedJar") { + group = "fabric" val shadowJar = tasks.getByName("shadowJar") dependsOn(shadowJar) input.set(shadowJar.archiveFile)