Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Sep 21, 2024
1 parent c0e5ba9 commit 9b0d4c2
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 11 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ bin/
### Mac OS ###
.DS_Store

.localMaven/
.localMaven/

explosion-test-*/**
!explosion-test-*/build.gradle
!explosion-test-*/settings.gradle
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path, Path>): ExplosionExt

fun withTransformer(id: String, @DelegatesTo(File::class) closure: Closure<Path>) = withTransformer(id) r@{
closure.delegate = this
return@r closure.call(this)
fun withTransformer(id: String, @DelegatesTo(Path::class) closure: Closure<Path>) = withTransformer(id) r@{
closure.delegate = it
return@r closure.call(it)
}

// ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -158,11 +158,12 @@ open class ExplosionExtImpl(

val bomDeps = arrayListOf<BomDependency>()
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)
})
}
}
Expand Down
1 change: 1 addition & 0 deletions explosion-resolver-forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
val (inputDirStr, outputDirStr) = args
val inputDir = Path(inputDirStr)
Expand All @@ -30,7 +33,7 @@ fun main(args: Array<String>) {
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)
Expand Down
22 changes: 22 additions & 0 deletions explosion-test-fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -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")
}
12 changes: 12 additions & 0 deletions explosion-test-fabric/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pluginManagement {
repositories {
maven {
name = 'Fabric'
url = 'https://maven.fabricmc.net/'
}
mavenCentral()
gradlePluginPortal()
}
}

includeBuild ".."
29 changes: 29 additions & 0 deletions explosion-test-forge/build.gradle
Original file line number Diff line number Diff line change
@@ -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")
}
11 changes: 11 additions & 0 deletions explosion-test-forge/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pluginManagement {
repositories {
gradlePluginPortal()
maven {
name = 'MinecraftForge'
url = 'https://maven.minecraftforge.net/'
}
}
}

includeBuild ".."
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9b0d4c2

Please sign in to comment.