From 9b0d4c2314aa4c800d54c8af50e4fc8c3855d00a Mon Sep 17 00:00:00 2001 From: deirn Date: Sun, 22 Sep 2024 03:07:01 +0700 Subject: [PATCH] add tests --- .gitignore | 6 +++- build.gradle.kts | 2 +- .../lol/bai/explosion/gradle/ExplosionExt.kt | 8 ++--- .../gradle/internal/ExplosionExtImpl.kt | 5 ++-- explosion-resolver-forge/build.gradle.kts | 1 + .../lol/bai/explosion/resolver/forge/Main.kt | 7 +++-- explosion-test-fabric/build.gradle | 22 ++++++++++++++ explosion-test-fabric/settings.gradle | 12 ++++++++ explosion-test-forge/build.gradle | 29 +++++++++++++++++++ explosion-test-forge/settings.gradle | 11 +++++++ gradle/wrapper/gradle-wrapper.properties | 2 +- 11 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 explosion-test-fabric/build.gradle create mode 100644 explosion-test-fabric/settings.gradle create mode 100644 explosion-test-forge/build.gradle create mode 100644 explosion-test-forge/settings.gradle diff --git a/.gitignore b/.gitignore index 26cff6e..ef7600d 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,8 @@ bin/ ### Mac OS ### .DS_Store -.localMaven/ \ No newline at end of file +.localMaven/ + +explosion-test-*/** +!explosion-test-*/build.gradle +!explosion-test-*/settings.gradle diff --git a/build.gradle.kts b/build.gradle.kts index 82b8d1a..d08b320 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ plugins { `maven-publish` - kotlin("jvm") version "1.9.0" + kotlin("jvm") version "1.9.22" id("com.github.johnrengelman.shadow") version "8.1.1" } diff --git a/explosion-gradle-plugin/src/main/kotlin/lol/bai/explosion/gradle/ExplosionExt.kt b/explosion-gradle-plugin/src/main/kotlin/lol/bai/explosion/gradle/ExplosionExt.kt index 3a2389a..ef42819 100644 --- a/explosion-gradle-plugin/src/main/kotlin/lol/bai/explosion/gradle/ExplosionExt.kt +++ b/explosion-gradle-plugin/src/main/kotlin/lol/bai/explosion/gradle/ExplosionExt.kt @@ -6,16 +6,16 @@ import org.gradle.api.Action import org.gradle.api.Transformer import org.gradle.api.artifacts.ExternalModuleDependency import org.gradle.api.provider.Provider -import java.io.File import java.nio.file.Path +import kotlin.io.path.name interface ExplosionExt { fun withTransformer(id: String, transformer: Transformer): ExplosionExt - fun withTransformer(id: String, @DelegatesTo(File::class) closure: Closure) = withTransformer(id) r@{ - closure.delegate = this - return@r closure.call(this) + fun withTransformer(id: String, @DelegatesTo(Path::class) closure: Closure) = withTransformer(id) r@{ + closure.delegate = it + return@r closure.call(it) } // --- diff --git a/explosion-gradle-plugin/src/main/kotlin/lol/bai/explosion/gradle/internal/ExplosionExtImpl.kt b/explosion-gradle-plugin/src/main/kotlin/lol/bai/explosion/gradle/internal/ExplosionExtImpl.kt index 188aaf6..e353392 100644 --- a/explosion-gradle-plugin/src/main/kotlin/lol/bai/explosion/gradle/internal/ExplosionExtImpl.kt +++ b/explosion-gradle-plugin/src/main/kotlin/lol/bai/explosion/gradle/internal/ExplosionExtImpl.kt @@ -128,7 +128,7 @@ open class ExplosionExtImpl( hashBuilder.append(Hashing.murmur3_128().hashBytes(it.readBytes())) hashBuilder.append(";") - it.copyTo(inputDir.resolve(it.name).toFile()) + it.copyTo(inputDir.resolve(it.name).toFile(), overwrite = true) } val hash = Hashing.murmur3_128().hashString(hashBuilder.toString(), Charsets.UTF_8).toString() @@ -158,11 +158,12 @@ open class ExplosionExtImpl( val bomDeps = arrayListOf() outputDir.resolve("__meta.txt").forEachLine { line -> + log(line) val trimmed = line.trim() if (trimmed.isNotEmpty()) { val (modFile, modId, modVersion) = trimmed.split("\t") bomDeps.add(createPom(loader, modId, modVersion) { path -> - outputDir.resolve(modFile).copyTo(path) + outputDir.resolve(modFile).copyTo(path, overwrite = true) }) } } diff --git a/explosion-resolver-forge/build.gradle.kts b/explosion-resolver-forge/build.gradle.kts index dc7ae7e..ca8c2f9 100644 --- a/explosion-resolver-forge/build.gradle.kts +++ b/explosion-resolver-forge/build.gradle.kts @@ -12,6 +12,7 @@ dependencies { implementation("com.electronwill.night-config:toml:3.7.3") implementation("org.apache.logging.log4j:log4j-api:2.22.1") implementation("org.apache.logging.log4j:log4j-core:2.22.1") + implementation("org.apache.logging.log4j:log4j-slf4j-impl:2.22.1") implementation("org.slf4j:slf4j-api:2.0.16") implementation("com.google.code.gson:gson:2.11.0") diff --git a/explosion-resolver-forge/src/main/kotlin/lol/bai/explosion/resolver/forge/Main.kt b/explosion-resolver-forge/src/main/kotlin/lol/bai/explosion/resolver/forge/Main.kt index a07ae0b..eb488f6 100644 --- a/explosion-resolver-forge/src/main/kotlin/lol/bai/explosion/resolver/forge/Main.kt +++ b/explosion-resolver-forge/src/main/kotlin/lol/bai/explosion/resolver/forge/Main.kt @@ -5,11 +5,14 @@ import net.minecraftforge.fml.loading.moddiscovery.JarInJarDependencyLocator import net.minecraftforge.fml.loading.moddiscovery.ModFile import net.minecraftforge.fml.loading.moddiscovery.createModsFolderLocator import net.minecraftforge.forgespi.locating.IModFile +import java.nio.file.Files +import java.nio.file.StandardCopyOption import kotlin.io.path.Path -import kotlin.io.path.copyTo +import kotlin.io.path.inputStream import kotlin.io.path.name import kotlin.io.path.writeText +@Suppress("UnstableApiUsage") fun main(args: Array) { val (inputDirStr, outputDirStr) = args val inputDir = Path(inputDirStr) @@ -30,7 +33,7 @@ fun main(args: Array) { for (modFile in uniqueModFiles) { val mod = modFile.modInfos[0] val path = outputDir.resolve("${mod.modId}-${mod.version}") - modFile.filePath.copyTo(path, overwrite = true) + Files.copy(modFile.filePath.inputStream(), path, StandardCopyOption.REPLACE_EXISTING) meta.append(path.name) .append("\t") .append(mod.modId) diff --git a/explosion-test-fabric/build.gradle b/explosion-test-fabric/build.gradle new file mode 100644 index 0000000..5c8772f --- /dev/null +++ b/explosion-test-fabric/build.gradle @@ -0,0 +1,22 @@ +plugins { + id 'fabric-loom' version '1.7-SNAPSHOT' + id 'maven-publish' + id 'lol.bai.explosion' +} + +repositories { + maven { + url "https://cursemaven.com" + content { + includeGroup "curse.maven" + } + } +} + +dependencies { + minecraft "com.mojang:minecraft:1.21.1" + mappings "net.fabricmc:yarn:1.21.1+build.3:v2" + modImplementation "net.fabricmc:fabric-loader:0.16.5" + + modImplementation explosion.fabric("curse.maven:fabric-api-306612:5710210") +} \ No newline at end of file diff --git a/explosion-test-fabric/settings.gradle b/explosion-test-fabric/settings.gradle new file mode 100644 index 0000000..2f06ba1 --- /dev/null +++ b/explosion-test-fabric/settings.gradle @@ -0,0 +1,12 @@ +pluginManagement { + repositories { + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + mavenCentral() + gradlePluginPortal() + } +} + +includeBuild ".." \ No newline at end of file diff --git a/explosion-test-forge/build.gradle b/explosion-test-forge/build.gradle new file mode 100644 index 0000000..6464e09 --- /dev/null +++ b/explosion-test-forge/build.gradle @@ -0,0 +1,29 @@ +plugins { + id 'net.minecraftforge.gradle' version '[6.0,6.2)' + id 'lol.bai.explosion' +} + +minecraft { + mappings channel: "official", version: "1.20.1" +} + +repositories { + maven { + url "https://cursemaven.com" + content { + includeGroup "curse.maven" + } + } +} + + +dependencies { + minecraft "net.minecraftforge:forge:1.20.1-47.3.0" + + def deobfuscator = new net.minecraftforge.gradle.userdev.util.Deobfuscator(project, file("build/explosion_deobf")) + def explosion = project.explosion.withTransformer("forge_official_1.20.1") { + return deobfuscator.deobfBinary(it.toFile(), "official_1.20.1", it.fileName.toString()).toPath() + } + + implementation explosion.forge("curse.maven:create-328085:5689514") +} diff --git a/explosion-test-forge/settings.gradle b/explosion-test-forge/settings.gradle new file mode 100644 index 0000000..184afe0 --- /dev/null +++ b/explosion-test-forge/settings.gradle @@ -0,0 +1,11 @@ +pluginManagement { + repositories { + gradlePluginPortal() + maven { + name = 'MinecraftForge' + url = 'https://maven.minecraftforge.net/' + } + } +} + +includeBuild ".." diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1b298ae..db4c326 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists \ No newline at end of file