Skip to content

Commit

Permalink
fix resolving file collection dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Jun 19, 2024
1 parent 901baac commit a6cf040
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
55 changes: 39 additions & 16 deletions src/api/kotlin/xyz/wagyourtail/unimined/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import org.apache.commons.compress.archivers.zip.ZipFile
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.FileCollectionDependency
import org.gradle.api.artifacts.ModuleDependency
import org.gradle.api.artifacts.component.ComponentArtifactIdentifier
import org.gradle.api.artifacts.component.ComponentIdentifier
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.file.FileCollection
import org.gradle.api.tasks.SourceSet
Expand Down Expand Up @@ -43,29 +47,48 @@ inline fun <T, U> consumerApply(crossinline action: T.() -> U): (T) -> U {
fun Configuration.getFiles(dep: Dependency, filter: (File) -> Boolean): FileCollection {
resolve()
return incoming.artifactView { view ->
view.componentFilter {
when (it) {
is ModuleComponentIdentifier -> {
it.group == dep.group && it.module == dep.name
when (dep) {
is ModuleDependency -> {
view.componentFilter {
when (it) {
is ModuleComponentIdentifier -> {
it.group == dep.group && it.module == dep.name
}
is ComponentArtifactIdentifier -> {
false
}
else -> {
println("Unknown component type: ${it.javaClass}")
false
}
}
}
else -> false
}
is FileCollectionDependency -> {
view.componentFilter { comp ->
when (comp) {
is ModuleComponentIdentifier -> {
false
}
is ComponentIdentifier -> {
dep.files.any { it.name == comp.displayName }
}
else -> {
println("Unknown component type: ${comp.javaClass}")
false
}
}
}
}
else -> {
throw IllegalArgumentException("Unknown dependency type: ${dep.javaClass}")
}
}
}.files.filter(filter)
}

fun Configuration.getFiles(dep: Dependency, extension: String = "jar"): FileCollection {
resolve()
return incoming.artifactView { view ->
view.componentFilter {
when (it) {
is ModuleComponentIdentifier -> {
it.group == dep.group && it.module == dep.name
}
else -> false
}
}
}.files.filter { it.extension == extension }
return getFiles(dep) { it.extension == extension }
}

fun URI.stream(): InputStream {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ package xyz.wagyourtail.unimined.internal.mapping
import com.google.gson.JsonParser
import net.fabricmc.mappingio.MappingVisitor
import net.fabricmc.mappingio.adapter.MappingSourceNsSwitch
import net.fabricmc.mappingio.format.*
import net.fabricmc.mappingio.format.MappingTreeBuilder
import net.fabricmc.mappingio.format.ProGuardReader
import net.fabricmc.mappingio.format.Tiny2Reader2
import net.fabricmc.mappingio.format.Tiny2Writer2
import net.fabricmc.mappingio.tree.MappingTreeView
import net.fabricmc.mappingio.tree.MemoryMappingTree
import net.fabricmc.tinyremapper.IMappingProvider
import org.gradle.api.Project
import org.gradle.api.artifacts.FileCollectionDependency
import xyz.wagyourtail.unimined.api.mapping.MappingDepConfig
import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree
import xyz.wagyourtail.unimined.api.mapping.MappingsConfig
import xyz.wagyourtail.unimined.api.mapping.MemoryMapping
import xyz.wagyourtail.unimined.api.minecraft.EnvType
Expand Down Expand Up @@ -593,12 +595,12 @@ class MappingsProvider(project: Project, minecraft: MinecraftConfig, val mapping
// parse each dep
for (dep in mappingsDeps.values) {
dep as MappingDepConfigImpl
project.logger.info("[Unimined/MappingsProvider] Loading mappings from ${dep.dep.name}")
project.logger.lifecycle("[Unimined/MappingsProvider] Loading mappings from ${dep.dep}")
// resolve dep to files, no pom
val files = configuration.getFiles(dep.dep) { it.extension != "pom" }

// load each file
project.logger.info("[Unimined/MappingsProvider] Loading mappings files ${files.joinToString(", ")}")
project.logger.lifecycle("[Unimined/MappingsProvider] Loading mappings files ${files.joinToString(", ")}")

for (file in files) {
if (minecraft.isMinecraftJar(file.toPath())) {
Expand Down

0 comments on commit a6cf040

Please sign in to comment.