Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Aug 22, 2024
2 parents 2e65971 + c4556d1 commit c05be31
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft
for (project in projects) {
for (sourceSet in project.extensions.findByType(SourceSetContainer::class.java)?.asMap?.values
?: listOf()) {
if (sourceSet.output.files.intersect(sourceSet.runtimeClasspath.files).isNotEmpty()) {
if (sourceSet.output.files.intersect(this.sourceSet.runtimeClasspath.files).isNotEmpty()) {
sourceSets.add(project to sourceSet)
}
}
Expand All @@ -841,10 +841,10 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft

for ((sourceSet, minecraftConfig) in minecraftConfigs.nonNullValues()) {
if (mappings.devNamespace != minecraftConfig.mappings.devNamespace) {
throw IllegalArgumentException("All combined minecraft configs must be on the same mappings, found ${sourceSet} on ${mappings.devNamespace} and $sourceSet on ${minecraftConfig.mappings.devNamespace}")
throw IllegalArgumentException("All combined minecraft configs must be on the same mappings, found ${this.sourceSet} on ${mappings.devNamespace} and $sourceSet on ${minecraftConfig.mappings.devNamespace}")
}
if (version != minecraftConfig.version) {
throw IllegalArgumentException("All combined minecraft configs must be on the same version, found ${sourceSet} on ${version} and $sourceSet on ${minecraftConfig.version}")
throw IllegalArgumentException("All combined minecraft configs must be on the same version, found ${this.sourceSet} on ${this.version} and $sourceSet on ${minecraftConfig.version}")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,55 +345,69 @@ abstract class FabricLikeMinecraftTransformer(

Files.createDirectories(jars)
Files.createDirectories(includeCache)
var errored = false
for (dep in include.dependencies) {
val source = include.getFiles(dep, "jar").singleFile.toPath()
val path = jars.resolve("${dep.name}-${dep.version}.jar")
if (!source.zipContains(modJsonName)) {
val cachePath = includeCache.resolve("${dep.name}-${dep.version}.jar")
if (!cachePath.exists() || project.unimined.forceReload || project.gradle.startParameter.isRefreshDependencies) {
try {
ZipArchiveOutputStream(
cachePath.outputStream(
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING
)
).use { out ->
source.forEntryInZip { entry, stream ->
out.putArchiveEntry(entry)
stream.copyTo(out)
val files = include.getFiles(dep, "jar")
if (files.isEmpty) continue
try {
val source = files.singleFile.toPath()
val path = jars.resolve("${dep.name}-${dep.version}.jar")
if (!source.zipContains(modJsonName)) {
val cachePath = includeCache.resolve("${dep.name}-${dep.version}.jar")
if (!cachePath.exists() || project.unimined.forceReload || project.gradle.startParameter.isRefreshDependencies) {
try {
ZipArchiveOutputStream(
cachePath.outputStream(
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING
)
).use { out ->
source.forEntryInZip { entry, stream ->
out.putArchiveEntry(entry)
stream.copyTo(out)
out.closeArchiveEntry()
}
out.putArchiveEntry(ZipArchiveEntry(modJsonName).also { entry ->
entry.time = CONSTANT_TIME_FOR_ZIP_ENTRIES
})
val innerjson = JsonObject()
innerjson.addProperty("schemaVersion", 1)
var artifactString = ""
if (dep.group != null) {
artifactString += dep.group!!.replace(".", "_") + "_"
}
artifactString += dep.name
innerjson.addProperty("id", artifactString.lowercase())
innerjson.addProperty("version", dep.version)
innerjson.addProperty("name", dep.name)
val custom = JsonObject()
custom.addProperty("fabric-loom:generated", true)
custom.addProperty("unimined:generated", true)
innerjson.add("custom", custom)
out.write(GSON.toJson(innerjson).toByteArray())
out.closeArchiveEntry()
}
out.putArchiveEntry(ZipArchiveEntry(modJsonName).also { entry ->
entry.time = CONSTANT_TIME_FOR_ZIP_ENTRIES
})
val innerjson = JsonObject()
innerjson.addProperty("schemaVersion", 1)
var artifactString = ""
if (dep.group != null) {
artifactString += dep.group!!.replace(".", "_") + "_"
}
artifactString += dep.name
innerjson.addProperty("id", artifactString.lowercase())
innerjson.addProperty("version", dep.version)
innerjson.addProperty("name", dep.name)
val custom = JsonObject()
custom.addProperty("fabric-loom:generated", true)
custom.addProperty("unimined:generated", true)
innerjson.add("custom", custom)
out.write(GSON.toJson(innerjson).toByteArray())
out.closeArchiveEntry()
} catch (e: Exception) {
project.logger.error(
"[Unimined/Fabric] Failed to create $modJsonName stub for ${source.absolutePathString()}.",
e
)
throw e
}
} catch (e: Exception) {
project.logger.error("[Unimined/Fabric] Failed to create $modJsonName stub for ${source.absolutePathString()}.", e)
throw e
}
cachePath.copyTo(path, StandardCopyOption.REPLACE_EXISTING)
} else {
source.copyTo(path, StandardCopyOption.REPLACE_EXISTING)
}
cachePath.copyTo(path, StandardCopyOption.REPLACE_EXISTING)
} else {
source.copyTo(path, StandardCopyOption.REPLACE_EXISTING)
}

addIncludeToModJson(json, dep, path.toString().removePrefix("/"))
addIncludeToModJson(json, dep, path.toString().removePrefix("/"))
} catch (e: Exception) {
project.logger.error("Failed on $dep", e)
errored = true
}
}
if (errored) {
throw IllegalStateException("An error occured resolving includes")
}
Files.write(mod, GSON.toJson(json).toByteArray(), StandardOpenOption.TRUNCATE_EXISTING)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,14 +570,25 @@ open class FG3MinecraftTransformer(project: Project, val parent: ForgeLikeMinecr
val mod = jarDir.resolve("metadata.json")

jarDir.createDirectories()
var errored = false
for (dep in include.dependencies) {
val path = jarDir.resolve("${dep.name}-${dep.version}.jar")
if (!path.exists()) {
include.getFiles(dep) { it.extension == "jar" }.singleFile.toPath()
.copyTo(jarDir.resolve("${dep.name}-${dep.version}.jar"), true)
}
try {
val path = jarDir.resolve("${dep.name}-${dep.version}.jar")
if (!path.exists()) {
val files = include.getFiles(dep) { it.extension == "jar" }
if (files.isEmpty) continue
files.singleFile.toPath()
.copyTo(jarDir.resolve("${dep.name}-${dep.version}.jar"), true)
}

addIncludeToMetadata(json, dep, "META-INF/jarjar/${dep.name}-${dep.version}.jar")
addIncludeToMetadata(json, dep, "META-INF/jarjar/${dep.name}-${dep.version}.jar")
} catch (e: Exception) {
project.logger.error("Failed on $dep", e)
errored = true
}
}
if (errored) {
throw IllegalStateException("An error occured resolving includes")
}

mod.writeBytes(FabricLikeMinecraftTransformer.GSON.toJson(json).toByteArray())
Expand Down

0 comments on commit c05be31

Please sign in to comment.