Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve testmods file format and resolution #789

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 52 additions & 26 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,28 @@ import net.minecraftforge.gradle.common.util.MavenArtifactDownloader
import net.minecraftforge.gradle.common.util.RunConfig
import net.minecraftforge.gradle.userdev.tasks.JarJar
import net.minecraftforge.gradle.userdev.util.MavenPomUtils
import net.minecraftforge.jarjar.metadata.*
import net.minecraftforge.jarjar.metadata.ContainedJarIdentifier
import net.minecraftforge.jarjar.metadata.ContainedJarMetadata
import net.minecraftforge.jarjar.metadata.ContainedVersion
import net.minecraftforge.jarjar.metadata.MetadataIOHandler
import org.apache.maven.artifact.versioning.DefaultArtifactVersion
import org.apache.maven.artifact.versioning.VersionRange
import org.yaml.snakeyaml.Yaml
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.StandardOpenOption
import java.time.LocalDateTime
import kotlin.io.path.inputStream

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath(group = "org.yaml", name = "snakeyaml", version = "2.2")
}
}

plugins {
java
`maven-publish`
Expand All @@ -23,7 +36,6 @@ plugins {
id("me.modmuss50.mod-publish-plugin") version "0.3.+"
id("net.neoforged.gradleutils") version "2.0.+"
id("org.parchmentmc.librarian.forgegradle") version "1.+"
id ("de.undercouch.download") version "5.5.0"
}

val versionConnector: String by project
Expand Down Expand Up @@ -116,7 +128,7 @@ val modJar: JarJar by tasks.creating(JarJar::class) {
false
)
Files.deleteIfExists(metadataPath)
Files.write(metadataPath, MetadataIOHandler.toLines(metadata), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)
Files.write(metadataPath, MetadataIOHandler.toLines(metadata), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)
}
}
manifest.attributes(
Expand Down Expand Up @@ -284,6 +296,13 @@ repositories {
name = "Su5eD"
url = uri("https://maven.su5ed.dev/releases")
}
exclusiveRepo("https://api.modrinth.com/maven/", "maven.modrinth")
maven {
url = uri("https://www.cursemaven.com")
content {
includeGroup("curse.maven")
}
}
mavenLocal()
}

Expand Down Expand Up @@ -343,9 +362,20 @@ tasks {
dependsOn("reobfModJar", fullJar)
}

val modDownload = register("downloadMods") {
doLast {
downloadMods()
val modDownload = register("resolveTestMods") {
doFirst {
val configFile = rootProject.file("testmods.yaml")
val data: List<Map<String, String>> = configFile.reader().use(Yaml()::load)
val deps = data.map { project.dependencies.create(it["maven"] as String) }

val config = configurations.detachedConfiguration(*deps.toTypedArray())
val files = config.resolve()

val dir = project.file("run/test/mods").apply {
if (exists()) deleteRecursively()
mkdirs()
}
files.forEach { it.copyTo(dir.resolve(it.name)) }
}
}

Expand All @@ -369,26 +399,6 @@ tasks {
}
}

fun downloadMods() {
val dir = project.file("run/test/mods")
if (dir.exists()) {
dir.deleteRecursively()
}
dir.mkdirs()

file("testmods.txt").forEachLine {
if (it.isBlank() || it.startsWith("#")) return@forEachLine

val split = it.split(" ")
if (split.isEmpty()) return@forEachLine

download.run {
dest(dir)
src(split[0])
}
}
}

publishMods {
file.set(fullJar.archiveFile)
changelog.set(providers.environmentVariable("CHANGELOG").orElse("# $version"))
Expand Down Expand Up @@ -452,3 +462,19 @@ publishing {
}
}
}

// Adapted from https://gist.github.com/pupnewfster/6c21401789ca6d74f9892be8c1c505c9
fun RepositoryHandler.exclusiveRepo(location: String, vararg groups: String) {
exclusiveRepo(location) {
for (group in groups) {
includeGroup(group)
}
}
}

fun RepositoryHandler.exclusiveRepo(location: String, config: Action<InclusiveRepositoryContentDescriptor>) {
exclusiveContent {
forRepositories(maven(location), fg.repository)
filter(config)
}
}
4 changes: 0 additions & 4 deletions testmods.txt

This file was deleted.

8 changes: 8 additions & 0 deletions testmods.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- id: fastback
homepage: https://modrinth.com/mod/fastback
maven: maven.modrinth:fastback:0.15.6+1.20.1-fabric

# Requiring connector extras:
- id: beaconoverhaul
homepage: https://www.curseforge.com/minecraft/mc-mods/beaconoverhaul
maven: curse.maven:beaconoverhaul-430382:4715716
Loading