clean up buildscripts

This commit is contained in:
dfsek
2021-03-26 08:50:58 -07:00
parent 77d5162e73
commit b1a1001c49
4 changed files with 140 additions and 58 deletions
@@ -30,7 +30,7 @@ fun Project.configureCommon() {
} }
fun Project.getGitHash(): String { fun Project.getGitHash(): String {
val stdout = java.io.ByteArrayOutputStream() val stdout = ByteArrayOutputStream()
exec { exec {
commandLine = mutableListOf("git", "rev-parse", "--short", "HEAD") commandLine = mutableListOf("git", "rev-parse", "--short", "HEAD")
standardOutput = stdout standardOutput = stdout
@@ -14,13 +14,9 @@ fun Project.configureDistribution() {
apply(plugin = "java-library") apply(plugin = "java-library")
apply(plugin = "com.github.johnrengelman.shadow") apply(plugin = "com.github.johnrengelman.shadow")
// configurations.create("shaded")
configurations { configurations {
val shaded = create("shaded") val shaded = create("shaded")
getByName("compile").extendsFrom(shaded) getByName("compile").extendsFrom(shaded)
// shaded.extendsFrom(getByName("compile"))
val shadedApi = create("shadedApi") val shadedApi = create("shadedApi")
shaded.extendsFrom(shadedApi) shaded.extendsFrom(shadedApi)
getByName("api").extendsFrom(shadedApi) getByName("api").extendsFrom(shadedApi)
@@ -29,11 +25,8 @@ fun Project.configureDistribution() {
getByName("implementation").extendsFrom(shadedImplementation) getByName("implementation").extendsFrom(shadedImplementation)
} }
// tasks.withType<JavaCompile> {
// classpath +=
// }
val downloadDefaultPacks = tasks.create("downloadDefaultPacks") { val downloadDefaultPacks = tasks.create("downloadDefaultPacks") {
group = "terra"
doFirst { doFirst {
file("${buildDir}/resources/main/packs/").deleteRecursively() file("${buildDir}/resources/main/packs/").deleteRecursively()
+137 -49
View File
@@ -15,6 +15,13 @@ configureCommon()
group = "com.dfsek.terra.bukkit" 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 { repositories {
mavenCentral() mavenCentral()
maven { url = uri("http://maven.enginehub.org/repo/") } maven { url = uri("http://maven.enginehub.org/repo/") }
@@ -35,73 +42,155 @@ dependencies {
"shadedImplementation"("com.google.guava:guava:30.0-jre") "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") { fun downloadPaperclip(url: String, dir: String) {
dependsOn("shadowJar") val clip = URL(url.replace("%version%", mcVersion))
doFirst { val clipReadableByteChannel = Channels.newChannel(clip.openStream())
// clean val clipFile = file("$testDir/$dir/paperclip.jar")
file("${testDir}/").deleteRecursively() val clipOutputStream = clipFile.outputStream()
file("${testDir}/plugins").mkdirs() val clipFileChannel = clipOutputStream.channel
clipFileChannel.transferFrom(clipReadableByteChannel, 0, Long.MAX_VALUE)
}
// Downloading latest paper jar. fun copyTerra(dir: String) {
val paperUrl = URL("https://papermc.io/api/v1/paper/1.16.4/latest/download") file("$testDir/$dir").walk().forEach {
val paperReadableByteChannel = Channels.newChannel(paperUrl.openStream()) if(it.name.startsWith("Terra-") && it.name.endsWith(".jar")) it.delete() // Delete old Terra jar(s)
val paperFile = file("${testDir}/paper.jar") }
val paperFileOutputStream = paperFile.outputStream() copy {
val paperFileChannel = paperFileOutputStream.channel from("$buildDir/libs/Terra-bukkit-$version-shaded.jar")
paperFileChannel.transferFrom(paperReadableByteChannel, 0, Long.MAX_VALUE) into("$testDir/$dir/plugins/")
// 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()
} }
} }
val testWithPaper = task<JavaExec>(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<JavaExec>(name = "runPaper") {
group = "bukkit"
standardInput = System.`in` standardInput = System.`in`
dependsOn("shadowJar") dependsOn("shadowJar")
// Copy Terra into dir // Copy Terra into dir
doFirst { doFirst {
copy { copyTerra("paper")
from("${buildDir}/libs/Terra-bukkit-${version}-shaded.jar")
into("${testDir}/plugins/")
}
} }
main = "io.papermc.paperclip.Paperclip" main = "io.papermc.paperclip.Paperclip"
jvmArgs = listOf("-XX:+UseG1GC", "-XX:+ParallelRefProcEnabled", "-XX:MaxGCPauseMillis=200", jvmArgs = aikarsFlags
"-XX:+UnlockExperimentalVMOptions", "-XX:+DisableExplicitGC", "-XX:+AlwaysPreTouch", maxHeapSize = testMem
"-XX:G1NewSizePercent=30", "-XX:G1MaxNewSizePercent=40", "-XX:G1HeapRegionSize=8M", minHeapSize = testMem
"-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"
//args = listOf("nogui") //args = listOf("nogui")
workingDir = file("${testDir}/") workingDir = file("$testDir/paper")
classpath = files("${testDir}/paper.jar") classpath = files("$testDir/paper/paperclip.jar")
}
task<JavaExec>(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>("shadowJar") { tasks.named<ShadowJar>("shadowJar") {
relocate("org.bstats.bukkit", "com.dfsek.terra.lib.bstats") relocate("org.bstats.bukkit", "com.dfsek.terra.lib.bstats")
relocate("io.papermc.lib", "com.dfsek.terra.lib.paperlib") relocate("io.papermc.lib", "com.dfsek.terra.lib.paperlib")
} }
publishing { publishing {
publications { publications {
create<MavenPublication>("mavenJava") { create<MavenPublication>("mavenJava") {
@@ -112,7 +201,6 @@ publishing {
repositories { repositories {
val mavenUrl = "https://repo.codemc.io/repository/maven-releases/" val mavenUrl = "https://repo.codemc.io/repository/maven-releases/"
val mavenSnapshotUrl = "https://repo.codemc.io/repository/maven-snapshots/"
maven(mavenUrl) { maven(mavenUrl) {
val mavenUsername: String? by project val mavenUsername: String? by project
+1
View File
@@ -40,6 +40,7 @@ configure<LoomGradleExtension> {
} }
tasks.register<RemapJarTask>("remapShadedJar") { tasks.register<RemapJarTask>("remapShadedJar") {
group = "fabric"
val shadowJar = tasks.getByName<ShadowJar>("shadowJar") val shadowJar = tasks.getByName<ShadowJar>("shadowJar")
dependsOn(shadowJar) dependsOn(shadowJar)
input.set(shadowJar.archiveFile) input.set(shadowJar.archiveFile)