From 43b1e05bbd66c46fe06e8dbacce13e574161ffd1 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sun, 1 Sep 2024 15:44:45 -0500 Subject: [PATCH 01/13] speed up asset cache checking --- gradle.properties | 2 +- .../xyz/wagyourtail/unimined/util/Utils.kt | 25 +++++++++++++++---- .../minecraft/resolver/AssetsDownloader.kt | 3 +++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index d58db0df..3384fd71 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,5 +5,5 @@ org.gradle.parallel=true maven_group=xyz.wagyourtail.unimined archives_base_name=unimined -version=1.3.9 +version=1.3.10 diff --git a/src/api/kotlin/xyz/wagyourtail/unimined/util/Utils.kt b/src/api/kotlin/xyz/wagyourtail/unimined/util/Utils.kt index 9f451dd0..b15a4779 100644 --- a/src/api/kotlin/xyz/wagyourtail/unimined/util/Utils.kt +++ b/src/api/kotlin/xyz/wagyourtail/unimined/util/Utils.kt @@ -145,14 +145,15 @@ fun Project.cachingDownload(url: String): Path { fun Project.cachingDownload( url: URI, size: Long = -1L, - sha1: String = "", + sha1: String? = null, cachePath: Path = unimined.getGlobalCache().resolve(url.path.substring(1)), + ignoreShaOnCache: Boolean = false, expireTime: Duration = 1.days, retryCount: Int = 3, backoff: (Int) -> Int = { 1000 * 3.0.pow(it.toDouble()).toInt() }, // first backoff -> 1s, second -> 3s, third -> 9s ): Path { if (gradle.startParameter.isOffline) { - if (testSha1(size, sha1, cachePath, Long.MAX_VALUE.milliseconds)) { + if (testSha1(size, if (ignoreShaOnCache) null else sha1, cachePath, Duration.INFINITE)) { return cachePath } if (cachePath.exists()) { @@ -161,10 +162,21 @@ fun Project.cachingDownload( throw IllegalStateException("cached $url at $cachePath doesn't exist and offline mode is enabled") } } - if (testSha1(size, sha1, cachePath, if (gradle.startParameter.isRefreshDependencies || project.unimined.forceReload) 0.seconds else expireTime)) { + + val cacheTime = if (gradle.startParameter.isRefreshDependencies || project.unimined.forceReload) 0.seconds + else if (ignoreShaOnCache) Duration.INFINITE + else expireTime + + if (testSha1( + size, + if (ignoreShaOnCache) null else sha1, + cachePath, + cacheTime + )) { logger.info("[Unimined/Cache] Using cached $url at $cachePath") return cachePath } + var exception: Exception? = null cachePath.parent?.createDirectories() logger.info("[Unimined/Cache] Downloading $url to $cachePath") @@ -188,17 +200,20 @@ fun Project.cachingDownload( logger.warn("[Unimined/Cache] Failed to download $url, retrying in ${backoff(i)}ms...") Thread.sleep(backoff(i).toLong()) } + + // should only happen if ignoreShaOnCache is false if (testSha1(size, sha1, cachePath, Long.MAX_VALUE.milliseconds)) { logger.warn("[Unimined/Cache] Falling back on expired cache $cachePath for $url") return cachePath } + throw IllegalStateException("Failed to download $url", exception) } -fun testSha1(size: Long, sha1: String, path: Path, expireTime: Duration = 1.days): Boolean { +fun testSha1(size: Long, sha1: String?, path: Path, expireTime: Duration = 1.days): Boolean { if (path.exists()) { if (path.fileSize() == size || size == -1L) { - if (sha1.isEmpty()) { + if (sha1.isNullOrEmpty()) { // fallback: expire if older than a day return path.getLastModifiedTime().toMillis() > System.currentTimeMillis() - expireTime.inWholeMilliseconds } diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/resolver/AssetsDownloader.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/resolver/AssetsDownloader.kt index 90bf7a44..47eb25a4 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/resolver/AssetsDownloader.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/resolver/AssetsDownloader.kt @@ -13,6 +13,7 @@ import java.nio.file.StandardCopyOption import java.util.concurrent.atomic.AtomicInteger import kotlin.io.path.createDirectories import kotlin.io.path.inputStream +import kotlin.time.Duration object AssetsDownloader { @@ -68,6 +69,8 @@ object AssetsDownloader { size, hash, assetPath, + ignoreShaOnCache = true, + expireTime = Duration.INFINITE ) if (copyToResources) { From 791a9dde8c33fe954fdef4c044b684cba8efea09 Mon Sep 17 00:00:00 2001 From: Rhys <98863820+rhysdh540@users.noreply.github.com> Date: Wed, 2 Oct 2024 20:46:20 -0400 Subject: [PATCH 02/13] initial sources jar remapping seems to work, not sure if automatically configuring it is good though --- .../wagyourtail/unimined/UniminedPlugin.kt | 8 ++ .../minecraft/task/RemapJarTaskImpl.kt | 3 +- .../minecraft/task/RemapSourcesJarTaskImpl.kt | 100 ++++++++++++++++++ testing/1.21-NeoForged-Fabric/build.gradle | 2 + .../gradle/wrapper/gradle-wrapper.properties | 2 +- 5 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt diff --git a/src/main/kotlin/xyz/wagyourtail/unimined/UniminedPlugin.kt b/src/main/kotlin/xyz/wagyourtail/unimined/UniminedPlugin.kt index a379e0f5..df2dbe16 100644 --- a/src/main/kotlin/xyz/wagyourtail/unimined/UniminedPlugin.kt +++ b/src/main/kotlin/xyz/wagyourtail/unimined/UniminedPlugin.kt @@ -2,6 +2,8 @@ package xyz.wagyourtail.unimined import org.gradle.api.Plugin import org.gradle.api.Project +import xyz.wagyourtail.unimined.internal.minecraft.task.RemapSourcesJarTaskImpl +import xyz.wagyourtail.unimined.util.sourceSets class UniminedPlugin: Plugin { @@ -41,6 +43,12 @@ class UniminedPlugin: Plugin { ) project.extensions.create("unimined", UniminedExtensionImpl::class.java, project) + + project.afterEvaluate { + it.sourceSets.forEach { s -> + RemapSourcesJarTaskImpl.setup(s, it) + } + } } } \ No newline at end of file diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt index 37f31387..0ca3dbce 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt @@ -20,6 +20,7 @@ import java.nio.file.StandardOpenOption import javax.inject.Inject import kotlin.io.path.* +@Suppress("UNCHECKED_CAST") abstract class RemapJarTaskImpl @Inject constructor(@get:Internal val provider: MinecraftConfig): RemapJarTask() { private var mixinRemapOptions: MixinRemapOptions.() -> Unit by FinalizeOnRead {} @@ -129,7 +130,7 @@ abstract class RemapJarTaskImpl @Inject constructor(@get:Internal val provider: } @Suppress("UNNECESSARY_NOT_NULL_ASSERTION") - protected fun remapToInternal( + protected open fun remapToInternal( from: Path, target: Path, fromNs: MappingNamespaceTree.Namespace, diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt new file mode 100644 index 00000000..6fcd0068 --- /dev/null +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt @@ -0,0 +1,100 @@ +package xyz.wagyourtail.unimined.internal.minecraft.task + +import org.gradle.api.Project +import org.gradle.api.tasks.SourceSet +import org.gradle.jvm.tasks.Jar +import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree +import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig +import xyz.wagyourtail.unimined.api.unimined +import xyz.wagyourtail.unimined.util.capitalized +import java.nio.file.Path +import java.util.jar.JarEntry +import java.util.jar.JarOutputStream +import javax.inject.Inject +import kotlin.io.path.* + +abstract class RemapSourcesJarTaskImpl @Inject constructor(provider: MinecraftConfig): RemapJarTaskImpl(provider) { + @OptIn(ExperimentalPathApi::class) + override fun remapToInternal( + from: Path, + target: Path, + fromNs: MappingNamespaceTree.Namespace, + toNs: MappingNamespaceTree.Namespace, + classpathList: Array + ) { + val inputDir = temporaryDir.toPath().resolve("input").apply { + project.copy { + it.from(project.zipTree(inputFile.get().asFile)) + it.into(this) + } + } + + val outputDir = temporaryDir.toPath().resolve("output") + + val remapper = provider.sourceProvider.sourceRemapper + + fun Path.isSourceFile() = isRegularFile() && (name.endsWith(".java") || name.endsWith(".kt")) + + remapper.remap( + inputDir.walk().filter { it.isSourceFile() }.associateWith { + outputDir.resolve(inputDir.relativize(it)) + }, + project.files(classpathList), + fromNs, + fromNs, + toNs, + toNs + ) + + // copy non-java/kotlin files directly + inputDir.walk().filter { it.isRegularFile() && !it.isSourceFile() }.forEach { + val relative = inputDir.relativize(it) + val output = outputDir.resolve(relative) + if (!output.exists()) { + it.copyTo(output.apply { parent.createDirectories() }) + } + } + + JarOutputStream(target.toFile().outputStream()).use { o -> + outputDir.walk().forEach { + val relative = outputDir.relativize(it) + o.putNextEntry(JarEntry(relative.toString().replace('\\', '/'))) + it.inputStream().copyTo(o) + } + } + } + + init { + project.unimined.wagYourMaven("snapshots") + } + + companion object { + fun setup(sourceSet: SourceSet, project: Project) { + val sourcesJarTaskName = sourceSet.sourcesJarTaskName + val sourcesJarTask = project.tasks.findByName(sourcesJarTaskName) + if (sourcesJarTask == null) { + project.logger.warn("[Unimined/RemapSourcesJar] $sourcesJarTaskName task not found, not remapping sources") + return + } + + if (sourcesJarTask !is Jar) { + project.logger.warn("[Unimined/RemapSourcesJar] $sourcesJarTaskName task is not a Jar task, not remapping it") + return + } + + val remapTaskName = "remap${sourcesJarTaskName.capitalized()}" + val remapTask = project.tasks.register(remapTaskName, RemapSourcesJarTaskImpl::class.java, project.unimined.minecrafts[sourceSet]) + remapTask.configure { + it.inputFile.set(sourcesJarTask.archiveFile) + it.dependsOn(sourcesJarTask) + + it.description = "Remaps the sources jar for ${sourceSet.name}" + it.group = "unimined" + + val oldClassifier = sourcesJarTask.archiveClassifier.get() + it.archiveClassifier.set(oldClassifier) + sourcesJarTask.archiveClassifier.set("dev-$oldClassifier") + } + } + } +} \ No newline at end of file diff --git a/testing/1.21-NeoForged-Fabric/build.gradle b/testing/1.21-NeoForged-Fabric/build.gradle index 3beeb1d6..40b28d50 100644 --- a/testing/1.21-NeoForged-Fabric/build.gradle +++ b/testing/1.21-NeoForged-Fabric/build.gradle @@ -14,6 +14,8 @@ java { toolchain { languageVersion = JavaLanguageVersion.of(21) } + + withSourcesJar() } // this is just here so we can test the outputs easier and clean between tests diff --git a/testing/1.21-NeoForged-Fabric/gradle/wrapper/gradle-wrapper.properties b/testing/1.21-NeoForged-Fabric/gradle/wrapper/gradle-wrapper.properties index 20db9ad5..5c40527d 100644 --- a/testing/1.21-NeoForged-Fabric/gradle/wrapper/gradle-wrapper.properties +++ b/testing/1.21-NeoForged-Fabric/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 039fa4eceb41db69d2997f42fcdf8d5a529820fe Mon Sep 17 00:00:00 2001 From: Rhys <98863820+rhysdh540@users.noreply.github.com> Date: Wed, 2 Oct 2024 21:18:58 -0400 Subject: [PATCH 03/13] remove some redundancy, stop log spam from source remap in RemapSourcesJarTaskImpl --- .../api/source/remapper/SourceRemapper.kt | 4 ++- .../api/source/task/MigrateMappingsTask.kt | 3 -- .../minecraft/task/RemapSourcesJarTaskImpl.kt | 7 ++-- .../source/remapper/SourceRemapperImpl.kt | 25 ++++++++++++-- .../gradle/wrapper/gradle-wrapper.properties | 3 +- testing/1.21-NeoForged-Fabric/gradlew | 34 ++++++++++++------- testing/1.21-NeoForged-Fabric/gradlew.bat | 22 ++++++------ 7 files changed, 62 insertions(+), 36 deletions(-) diff --git a/src/api/kotlin/xyz/wagyourtail/unimined/api/source/remapper/SourceRemapper.kt b/src/api/kotlin/xyz/wagyourtail/unimined/api/source/remapper/SourceRemapper.kt index 06eb8283..0729459e 100644 --- a/src/api/kotlin/xyz/wagyourtail/unimined/api/source/remapper/SourceRemapper.kt +++ b/src/api/kotlin/xyz/wagyourtail/unimined/api/source/remapper/SourceRemapper.kt @@ -4,6 +4,7 @@ import groovy.lang.Closure import groovy.lang.DelegatesTo import org.gradle.api.artifacts.Dependency import org.gradle.api.file.FileCollection +import org.gradle.process.JavaExecSpec import org.jetbrains.annotations.ApiStatus import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree import java.nio.file.Path @@ -46,6 +47,7 @@ interface SourceRemapper { source: MappingNamespaceTree.Namespace, sourceFallback: MappingNamespaceTree.Namespace, targetFallback: MappingNamespaceTree.Namespace, - target: MappingNamespaceTree.Namespace + target: MappingNamespaceTree.Namespace, + specConfig: JavaExecSpec.() -> Unit = {} ) } \ No newline at end of file diff --git a/src/api/kotlin/xyz/wagyourtail/unimined/api/source/task/MigrateMappingsTask.kt b/src/api/kotlin/xyz/wagyourtail/unimined/api/source/task/MigrateMappingsTask.kt index 29234e5c..2e961741 100644 --- a/src/api/kotlin/xyz/wagyourtail/unimined/api/source/task/MigrateMappingsTask.kt +++ b/src/api/kotlin/xyz/wagyourtail/unimined/api/source/task/MigrateMappingsTask.kt @@ -24,9 +24,6 @@ abstract class MigrateMappingsTask : ConventionTask() { @get:Input abstract val commonNamespace: Property - init { - project.unimined.wagYourMaven("snapshots") - } /** * set the target version/mappings to migrate to. diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt index 6fcd0068..532378e7 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt @@ -43,7 +43,8 @@ abstract class RemapSourcesJarTaskImpl @Inject constructor(provider: MinecraftCo fromNs, fromNs, toNs, - toNs + toNs, + specConfig = { standardOutput = temporaryDir.resolve("remap.log").outputStream() } ) // copy non-java/kotlin files directly @@ -64,10 +65,6 @@ abstract class RemapSourcesJarTaskImpl @Inject constructor(provider: MinecraftCo } } - init { - project.unimined.wagYourMaven("snapshots") - } - companion object { fun setup(sourceSet: SourceSet, project: Project) { val sourcesJarTaskName = sourceSet.sourcesJarTaskName diff --git a/src/source/kotlin/xyz/wagyourtail/unimined/internal/source/remapper/SourceRemapperImpl.kt b/src/source/kotlin/xyz/wagyourtail/unimined/internal/source/remapper/SourceRemapperImpl.kt index 966054fb..534f3a5c 100644 --- a/src/source/kotlin/xyz/wagyourtail/unimined/internal/source/remapper/SourceRemapperImpl.kt +++ b/src/source/kotlin/xyz/wagyourtail/unimined/internal/source/remapper/SourceRemapperImpl.kt @@ -3,6 +3,7 @@ package xyz.wagyourtail.unimined.internal.source.remapper import org.gradle.api.Project import org.gradle.api.artifacts.Dependency import org.gradle.api.file.FileCollection +import org.gradle.process.JavaExecSpec import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree import xyz.wagyourtail.unimined.api.mapping.task.ExportMappingsTask import xyz.wagyourtail.unimined.api.source.remapper.SourceRemapper @@ -26,6 +27,7 @@ class SourceRemapperImpl(val project: Project, val provider: SourceProvider) : S sourceRemapper.dependencies.add( project.dependencies.create( if (dep is String && !dep.contains(":")) { + project.unimined.wagYourMaven("snapshots") "xyz.wagyourtail.unimined:source-remap:$dep" } else { dep @@ -40,7 +42,15 @@ class SourceRemapperImpl(val project: Project, val provider: SourceProvider) : S val tempDir = project.unimined.getLocalCache().resolve("source-remap-cache") - override fun remap(inputOutput: Map, classpath: FileCollection, source: MappingNamespaceTree.Namespace, sourceFallback: MappingNamespaceTree.Namespace, targetFallback: MappingNamespaceTree.Namespace, target: MappingNamespaceTree.Namespace) { + override fun remap( + inputOutput: Map, + classpath: FileCollection, + source: MappingNamespaceTree.Namespace, + sourceFallback: MappingNamespaceTree.Namespace, + targetFallback: MappingNamespaceTree.Namespace, + target: MappingNamespaceTree.Namespace, + specConfig: JavaExecSpec.() -> Unit + ) { val path = provider.minecraft.mappings.getRemapPath( source, sourceFallback, @@ -83,7 +93,8 @@ class SourceRemapperImpl(val project: Project, val provider: SourceProvider) : S classpath, mc, prevNamespace, - step + step, + specConfig ) prevOutputs = targets @@ -92,7 +103,14 @@ class SourceRemapperImpl(val project: Project, val provider: SourceProvider) : S } } - private fun remapIntl(inputOutput: Map, classpath: FileCollection, minecraft: Path, source: MappingNamespaceTree.Namespace, target: MappingNamespaceTree.Namespace) { + private fun remapIntl( + inputOutput: Map, + classpath: FileCollection, + minecraft: Path, + source: MappingNamespaceTree.Namespace, + target: MappingNamespaceTree.Namespace, + specConfig: JavaExecSpec.() -> Unit + ) { if (sourceRemapper.dependencies.isEmpty()) { remapper("1.0.3-SNAPSHOT") } @@ -127,6 +145,7 @@ class SourceRemapperImpl(val project: Project, val provider: SourceProvider) : S "-m", mappingFile.toFile().absolutePath ) + specConfig(spec) project.logger.info("[Unimined/SourceRemapper] ${spec.args!!.joinToString(" ")}") }.rethrowFailure().assertNormalExitValue() diff --git a/testing/1.21-NeoForged-Fabric/gradle/wrapper/gradle-wrapper.properties b/testing/1.21-NeoForged-Fabric/gradle/wrapper/gradle-wrapper.properties index 5c40527d..09523c0e 100644 --- a/testing/1.21-NeoForged-Fabric/gradle/wrapper/gradle-wrapper.properties +++ b/testing/1.21-NeoForged-Fabric/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/testing/1.21-NeoForged-Fabric/gradlew b/testing/1.21-NeoForged-Fabric/gradlew index 79a61d42..f5feea6d 100755 --- a/testing/1.21-NeoForged-Fabric/gradlew +++ b/testing/1.21-NeoForged-Fabric/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -83,10 +85,9 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,10 +134,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. @@ -144,7 +148,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -152,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -197,11 +201,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/testing/1.21-NeoForged-Fabric/gradlew.bat b/testing/1.21-NeoForged-Fabric/gradlew.bat index 6689b85b..9b42019c 100644 --- a/testing/1.21-NeoForged-Fabric/gradlew.bat +++ b/testing/1.21-NeoForged-Fabric/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -43,11 +45,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail From 4a7469589f80b262b66219687d8a7adce6634386 Mon Sep 17 00:00:00 2001 From: Rhys <98863820+rhysdh540@users.noreply.github.com> Date: Thu, 3 Oct 2024 15:06:09 -0400 Subject: [PATCH 04/13] simplify everything --- .../unimined/api/minecraft/MinecraftConfig.kt | 47 +++++- .../api/source/remapper/SourceRemapper.kt | 6 +- .../wagyourtail/unimined/UniminedPlugin.kt | 8 - .../internal/minecraft/MinecraftProvider.kt | 153 ++++++++++++------ .../minecraft/task/RemapJarTaskImpl.kt | 1 + .../minecraft/task/RemapSourcesJarTaskImpl.kt | 91 ++++------- .../source/remapper/SourceRemapperImpl.kt | 7 +- 7 files changed, 187 insertions(+), 126 deletions(-) diff --git a/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/MinecraftConfig.kt b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/MinecraftConfig.kt index f34de7d4..cc9ee717 100644 --- a/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/MinecraftConfig.kt +++ b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/MinecraftConfig.kt @@ -9,7 +9,6 @@ import org.gradle.api.Task import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.ModuleDependency import org.gradle.api.tasks.SourceSet -import org.gradle.configurationcache.extensions.capitalized import org.intellij.lang.annotations.Language import org.jetbrains.annotations.ApiStatus import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree @@ -23,10 +22,7 @@ import xyz.wagyourtail.unimined.api.runs.RunsConfig import xyz.wagyourtail.unimined.api.source.SourceConfig import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask import xyz.wagyourtail.unimined.api.unimined -import xyz.wagyourtail.unimined.util.FinalizeOnRead -import xyz.wagyourtail.unimined.util.LazyMutable -import xyz.wagyourtail.unimined.util.MustSet -import xyz.wagyourtail.unimined.util.sourceSets +import xyz.wagyourtail.unimined.util.* import java.io.File import java.nio.file.Path @@ -186,7 +182,7 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) : val proj = this.project.project(path) combineWith(proj, proj.sourceSets.getByName(name)) } - }; + } /** * the minecraft version to use @@ -263,6 +259,45 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) : } } + fun remapSources(task: Task) { + remapSources(task) {} + } + + fun remapSources(task: Task, action: RemapJarTask.() -> Unit) { + remapSources(task, "remap${task.name.capitalized()}", action) + } + + fun remapSources( + task: Task, + @DelegatesTo(value = RemapJarTask::class, strategy = Closure.DELEGATE_FIRST) + action: Closure<*> + ) { + remapSources(task) { + action.delegate = this + action.resolveStrategy = Closure.DELEGATE_FIRST + action.call() + } + } + + fun remapSources(task: Task, name: String) { + remapSources(task, name) {} + } + + abstract fun remapSources(task: Task, name: String, action: RemapJarTask.() -> Unit) + + fun remapSources( + task: Task, + name: String, + @DelegatesTo(value = RemapJarTask::class, strategy = Closure.DELEGATE_FIRST) + action: Closure<*> + ) { + remapSources(task, name) { + action.delegate = this + action.resolveStrategy = Closure.DELEGATE_FIRST + action.call() + } + } + fun mods(action: ModsConfig.() -> Unit) { mods.action() } diff --git a/src/api/kotlin/xyz/wagyourtail/unimined/api/source/remapper/SourceRemapper.kt b/src/api/kotlin/xyz/wagyourtail/unimined/api/source/remapper/SourceRemapper.kt index 0729459e..d2b5a298 100644 --- a/src/api/kotlin/xyz/wagyourtail/unimined/api/source/remapper/SourceRemapper.kt +++ b/src/api/kotlin/xyz/wagyourtail/unimined/api/source/remapper/SourceRemapper.kt @@ -2,7 +2,7 @@ package xyz.wagyourtail.unimined.api.source.remapper import groovy.lang.Closure import groovy.lang.DelegatesTo -import org.gradle.api.artifacts.Dependency +import org.gradle.api.artifacts.ExternalModuleDependency import org.gradle.api.file.FileCollection import org.gradle.process.JavaExecSpec import org.jetbrains.annotations.ApiStatus @@ -26,11 +26,11 @@ interface SourceRemapper { * set the remapper to use (defaults to https://github.com/unimined/source-remap) * @since 1.2.0 */ - fun remapper(dep: Any, action: Dependency.() -> Unit) + fun remapper(dep: Any, action: ExternalModuleDependency.() -> Unit) fun remapper( dep: Any, - @DelegatesTo(value = Dependency::class, strategy = Closure.DELEGATE_FIRST) + @DelegatesTo(value = ExternalModuleDependency::class, strategy = Closure.DELEGATE_FIRST) action: Closure<*> ) { remapper(dep) { diff --git a/src/main/kotlin/xyz/wagyourtail/unimined/UniminedPlugin.kt b/src/main/kotlin/xyz/wagyourtail/unimined/UniminedPlugin.kt index df2dbe16..a379e0f5 100644 --- a/src/main/kotlin/xyz/wagyourtail/unimined/UniminedPlugin.kt +++ b/src/main/kotlin/xyz/wagyourtail/unimined/UniminedPlugin.kt @@ -2,8 +2,6 @@ package xyz.wagyourtail.unimined import org.gradle.api.Plugin import org.gradle.api.Project -import xyz.wagyourtail.unimined.internal.minecraft.task.RemapSourcesJarTaskImpl -import xyz.wagyourtail.unimined.util.sourceSets class UniminedPlugin: Plugin { @@ -43,12 +41,6 @@ class UniminedPlugin: Plugin { ) project.extensions.create("unimined", UniminedExtensionImpl::class.java, project) - - project.afterEvaluate { - it.sourceSets.forEach { s -> - RemapSourcesJarTaskImpl.setup(s, it) - } - } } } \ No newline at end of file diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/MinecraftProvider.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/MinecraftProvider.kt index 0138c5f3..66e31da5 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/MinecraftProvider.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/MinecraftProvider.kt @@ -53,6 +53,7 @@ import xyz.wagyourtail.unimined.internal.minecraft.resolver.Library import xyz.wagyourtail.unimined.internal.minecraft.resolver.MinecraftDownloader import xyz.wagyourtail.unimined.internal.minecraft.task.GenSourcesTaskImpl import xyz.wagyourtail.unimined.internal.minecraft.task.RemapJarTaskImpl +import xyz.wagyourtail.unimined.internal.minecraft.task.RemapSourcesJarTaskImpl import xyz.wagyourtail.unimined.internal.mods.ModsProvider import xyz.wagyourtail.unimined.internal.runs.RunsProvider import xyz.wagyourtail.unimined.internal.source.SourceProvider @@ -147,6 +148,18 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft } } + override fun remapSources(task: Task, name: String, action: RemapJarTask.() -> Unit) { + val remapTask = project.tasks.register(name, RemapSourcesJarTaskImpl::class.java, this) + remapTask.configure { + it.dependsOn(task) + if (task is Jar) { + it.inputFile.set(task.archiveFile) + } + it.action() + mcPatcher.configureRemapJar(it) + } + } + override val mergedOfficialMinecraftFile: File? by lazy { val client = minecraftData.minecraftClient if (!client.path.exists()) throw IOException("minecraft path $client does not exist") @@ -436,6 +449,100 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft } } + fun applyDefaultRemapJar() { + var task = project.tasks.findByName("jar".withSourceSet(sourceSet)) + if (task == null && createJarTask) { + project.logger.info("[Unimined/Minecraft ${project.path}:${sourceSet.name}] Creating default jar task for $sourceSet") + task = project.tasks.create("jar".withSourceSet(sourceSet), Jar::class.java) { + it.group = "build" + it.from(sourceSet.output) + it.archiveClassifier.set(sourceSet.name) + for ((_, sourceSet) in combinedWithList) { + it.from(sourceSet.output) + } + } + } else if (task != null) { + if (task is Jar) { + task.also { + it.from(sourceSet.output) + for ((_, sourceSet) in combinedWithList) { + it.from(sourceSet.output) + } + } + } else { + project.logger.warn("[Unimined/Minecraft ${project.path}:${sourceSet.name}] jar task for $sourceSet is not a Jar task") + } + } + + if (task != null && task is Jar) { + val classifier: String = task.archiveClassifier.getOrElse("") + task.apply { + if (classifier.isNotEmpty()) { + archiveClassifier.set("$classifier-dev") + } else { + archiveClassifier.set("dev") + } + } + remap(task) { + group = "unimined" + description = "Remaps $task's output jar" + archiveClassifier.set(classifier) + } + project.tasks.getByName("build").dependsOn("remap" + "jar".withSourceSet(sourceSet).capitalized()) + } else { + project.logger.warn( + "[Unimined/Minecraft ${project.path}:${sourceSet.name}] Could not find default jar task for $sourceSet. named: ${"jar".withSourceSet(sourceSet)}." + ) + project.logger.warn("[Unimined/Minecraft ${project.path}:${sourceSet.name}] add manually with `remap(task)` in the minecraft block for $sourceSet") + } + + var sourcesTask = project.tasks.findByName("sourcesJar".withSourceSet(sourceSet)) + if (sourcesTask == null && createJarTask) { + project.logger.info("[Unimined/Minecraft ${project.path}:${sourceSet.name}] Creating default sources jar task for $sourceSet") + sourcesTask = project.tasks.create("sourcesJar".withSourceSet(sourceSet), Jar::class.java) { + it.group = "build" + it.from(sourceSet.allSource) + it.archiveClassifier.set("${sourceSet.name}-sources") + for ((_, sourceSet) in combinedWithList) { + it.from(sourceSet.allSource) + } + } + } else if (sourcesTask != null) { + if (sourcesTask is Jar) { + sourcesTask.also { + it.from(sourceSet.allSource) + for ((_, sourceSet) in combinedWithList) { + it.from(sourceSet.allSource) + } + } + } else { + project.logger.warn("[Unimined/Minecraft ${project.path}:${sourceSet.name}] sourcesJar task for $sourceSet is not a Jar task") + } + } + + if (sourcesTask != null && sourcesTask is Jar) { + val classifier: String = sourcesTask.archiveClassifier.getOrElse("") + sourcesTask.apply { + if (classifier.isNotEmpty()) { + archiveClassifier.set("$classifier-dev") + } else { + archiveClassifier.set("dev") + } + } + remapSources(sourcesTask) { + group = "unimined" + description = "Remaps $sourcesTask's output jar" + archiveClassifier.set(classifier) + } + project.tasks.getByName("build").dependsOn("remap" + "sourcesJar".withSourceSet(sourceSet).capitalized()) + } else { + project.logger.warn( + "[Unimined/Minecraft ${project.path}:${sourceSet.name}] Could not find default sources jar task for $sourceSet. named: ${"sourcesJar".withSourceSet(sourceSet)}." + ) + project.logger.warn("[Unimined/Minecraft ${project.path}:${sourceSet.name}] add manually with `remapSources(task)` in the minecraft block for $sourceSet") + } + } + fun applyRunConfigs() { project.logger.lifecycle("[Unimined/Minecraft ${project.path}:${sourceSet.name}] Applying run configs") when (side) { @@ -532,52 +639,8 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft // add minecraft libraries if (mcPatcher.addVanillaLibraries) addLibraries(minecraftData.metadata.libraries) - // create remapjar task if (defaultRemapJar) { - var task = project.tasks.findByName("jar".withSourceSet(sourceSet)) - if (task == null && createJarTask) { - project.logger.info("[Unimined/Minecraft ${project.path}:${sourceSet.name}] Creating default jar task for $sourceSet") - task = project.tasks.create("jar".withSourceSet(sourceSet), Jar::class.java) { - it.group = "build" - it.from(sourceSet.output) - it.archiveClassifier.set(sourceSet.name) - for ((_, sourceSet) in combinedWithList) { - it.from(sourceSet.output) - } - } - } else if (task != null) { - (task as Jar).also { - it.from(sourceSet.output) - for ((_, sourceSet) in combinedWithList) { - it.from(sourceSet.output) - } - } - } - if (task != null && task is Jar) { - val classifier: String= task.archiveClassifier.getOrElse("") - task.apply { - if (classifier.isNotEmpty()) { - archiveClassifier.set("$classifier-dev") - } else { - archiveClassifier.set("dev") - } - } - remap(task) { - group = "unimined" - description = "Remaps $task's output jar" - archiveClassifier.set(classifier) - } - project.tasks.getByName("build").dependsOn("remap" + "jar".withSourceSet(sourceSet).capitalized()) - } else { - project.logger.warn( - "[Unimined/Minecraft ${project.path}:${sourceSet.name}] Could not find default jar task for $sourceSet. named: ${ - "jar".withSourceSet( - sourceSet - ) - }." - ) - project.logger.warn("[Unimined/Minecraft ${project.path}:${sourceSet.name}] add manually with `remap(task)` in the minecraft block for $sourceSet") - } + applyDefaultRemapJar() } // apply minecraft patcher changes diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt index 0ca3dbce..3142bc3f 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt @@ -76,6 +76,7 @@ abstract class RemapJarTaskImpl @Inject constructor(@get:Internal val provider: project.logger.lifecycle("[Unimined/RemapJar ${this.path}] remapping output ${inputFile.name} from $devNs/$devFNs to $prodNs") project.logger.info("[Unimined/RemapJar ${this.path}] $devNs -> ${path.joinToString(" -> ") { it.name }}") + var prevTarget = inputFile var prevNamespace = devNs var prevPrevNamespace = devFNs diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt index 532378e7..c16433a0 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt @@ -1,12 +1,8 @@ package xyz.wagyourtail.unimined.internal.minecraft.task -import org.gradle.api.Project -import org.gradle.api.tasks.SourceSet -import org.gradle.jvm.tasks.Jar import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig -import xyz.wagyourtail.unimined.api.unimined -import xyz.wagyourtail.unimined.util.capitalized +import xyz.wagyourtail.unimined.util.deleteRecursively import java.nio.file.Path import java.util.jar.JarEntry import java.util.jar.JarOutputStream @@ -22,75 +18,48 @@ abstract class RemapSourcesJarTaskImpl @Inject constructor(provider: MinecraftCo toNs: MappingNamespaceTree.Namespace, classpathList: Array ) { - val inputDir = temporaryDir.toPath().resolve("input").apply { + // source-remap seems to be broken when reading/writing from a jar, so copy them to/from temp dirs + val output = temporaryDir.resolve(toNs.name).toPath().apply { + if(this.exists()) deleteRecursively() + createDirectories() + } + + val input = temporaryDir.resolve(fromNs.name).toPath().apply { + if(this.exists()) deleteRecursively() + createDirectories() + project.copy { - it.from(project.zipTree(inputFile.get().asFile)) + it.from(project.zipTree(from)) it.into(this) } } - val outputDir = temporaryDir.toPath().resolve("output") - - val remapper = provider.sourceProvider.sourceRemapper - - fun Path.isSourceFile() = isRegularFile() && (name.endsWith(".java") || name.endsWith(".kt")) - - remapper.remap( - inputDir.walk().filter { it.isSourceFile() }.associateWith { - outputDir.resolve(inputDir.relativize(it)) - }, - project.files(classpathList), + provider.sourceProvider.sourceRemapper.remap( + mapOf(input to output), + project.files(*classpathList), fromNs, fromNs, toNs, toNs, - specConfig = { standardOutput = temporaryDir.resolve("remap.log").outputStream() } - ) - - // copy non-java/kotlin files directly - inputDir.walk().filter { it.isRegularFile() && !it.isSourceFile() }.forEach { - val relative = inputDir.relativize(it) - val output = outputDir.resolve(relative) - if (!output.exists()) { - it.copyTo(output.apply { parent.createDirectories() }) + specConfig = { + standardOutput = temporaryDir.resolve("remap-${fromNs}-to-${toNs}.log").outputStream() } - } + ) - JarOutputStream(target.toFile().outputStream()).use { o -> - outputDir.walk().forEach { - val relative = outputDir.relativize(it) - o.putNextEntry(JarEntry(relative.toString().replace('\\', '/'))) - it.inputStream().copyTo(o) - } + // copy non-source files directly + input.walk().filter { it.extension != "java" && it.extension != "kt" }.forEach { file -> + val name = input.relativize(file).toString().replace('\\', '/') + val targetFile = output.resolve(name) + targetFile.parent.createDirectories() + file.copyTo(targetFile, overwrite = true) } - } - - companion object { - fun setup(sourceSet: SourceSet, project: Project) { - val sourcesJarTaskName = sourceSet.sourcesJarTaskName - val sourcesJarTask = project.tasks.findByName(sourcesJarTaskName) - if (sourcesJarTask == null) { - project.logger.warn("[Unimined/RemapSourcesJar] $sourcesJarTaskName task not found, not remapping sources") - return - } - - if (sourcesJarTask !is Jar) { - project.logger.warn("[Unimined/RemapSourcesJar] $sourcesJarTaskName task is not a Jar task, not remapping it") - return - } - - val remapTaskName = "remap${sourcesJarTaskName.capitalized()}" - val remapTask = project.tasks.register(remapTaskName, RemapSourcesJarTaskImpl::class.java, project.unimined.minecrafts[sourceSet]) - remapTask.configure { - it.inputFile.set(sourcesJarTask.archiveFile) - it.dependsOn(sourcesJarTask) - - it.description = "Remaps the sources jar for ${sourceSet.name}" - it.group = "unimined" - val oldClassifier = sourcesJarTask.archiveClassifier.get() - it.archiveClassifier.set(oldClassifier) - sourcesJarTask.archiveClassifier.set("dev-$oldClassifier") + JarOutputStream(target.toFile().outputStream()).use { zos -> + output.walk().forEach { file -> + val name = output.relativize(file).toString().replace('\\', '/') + zos.putNextEntry(JarEntry(name)) + file.inputStream().use { it.copyTo(zos) } + zos.closeEntry() } } } diff --git a/src/source/kotlin/xyz/wagyourtail/unimined/internal/source/remapper/SourceRemapperImpl.kt b/src/source/kotlin/xyz/wagyourtail/unimined/internal/source/remapper/SourceRemapperImpl.kt index 534f3a5c..bb52b91a 100644 --- a/src/source/kotlin/xyz/wagyourtail/unimined/internal/source/remapper/SourceRemapperImpl.kt +++ b/src/source/kotlin/xyz/wagyourtail/unimined/internal/source/remapper/SourceRemapperImpl.kt @@ -1,7 +1,7 @@ package xyz.wagyourtail.unimined.internal.source.remapper import org.gradle.api.Project -import org.gradle.api.artifacts.Dependency +import org.gradle.api.artifacts.ExternalModuleDependency import org.gradle.api.file.FileCollection import org.gradle.process.JavaExecSpec import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree @@ -23,18 +23,19 @@ class SourceRemapperImpl(val project: Project, val provider: SourceProvider) : S val sourceRemapper = project.configurations.maybeCreate("sourceRemapper".withSourceSet(provider.minecraft.sourceSet)) - override fun remapper(dep: Any, action: Dependency.() -> Unit) { + override fun remapper(dep: Any, action: ExternalModuleDependency.() -> Unit) { sourceRemapper.dependencies.add( project.dependencies.create( if (dep is String && !dep.contains(":")) { project.unimined.wagYourMaven("snapshots") + project.repositories.mavenLocal() "xyz.wagyourtail.unimined:source-remap:$dep" } else { dep } ) .also { - action(it) + action(it as ExternalModuleDependency) } ) } From 89ffc6fe48486dd88a3093d759cbd57fcea1b24f Mon Sep 17 00:00:00 2001 From: Rhys <98863820+rhysdh540@users.noreply.github.com> Date: Mon, 7 Oct 2024 08:33:34 -0400 Subject: [PATCH 05/13] bump source-remap --- .../unimined/internal/source/remapper/SourceRemapperImpl.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/source/kotlin/xyz/wagyourtail/unimined/internal/source/remapper/SourceRemapperImpl.kt b/src/source/kotlin/xyz/wagyourtail/unimined/internal/source/remapper/SourceRemapperImpl.kt index bb52b91a..1085022c 100644 --- a/src/source/kotlin/xyz/wagyourtail/unimined/internal/source/remapper/SourceRemapperImpl.kt +++ b/src/source/kotlin/xyz/wagyourtail/unimined/internal/source/remapper/SourceRemapperImpl.kt @@ -28,7 +28,6 @@ class SourceRemapperImpl(val project: Project, val provider: SourceProvider) : S project.dependencies.create( if (dep is String && !dep.contains(":")) { project.unimined.wagYourMaven("snapshots") - project.repositories.mavenLocal() "xyz.wagyourtail.unimined:source-remap:$dep" } else { dep @@ -113,7 +112,7 @@ class SourceRemapperImpl(val project: Project, val provider: SourceProvider) : S specConfig: JavaExecSpec.() -> Unit ) { if (sourceRemapper.dependencies.isEmpty()) { - remapper("1.0.3-SNAPSHOT") + remapper("1.0.5-SNAPSHOT") } val mappingFile = tempDir.createDirectories().resolve("${provider.minecraft.sourceSet.name}-${source.name}-${target.name}.srg") From 135c9675d4c8e598316622a0140d8e258c97f1b2 Mon Sep 17 00:00:00 2001 From: Rhys <98863820+rhysdh540@users.noreply.github.com> Date: Mon, 7 Oct 2024 10:27:32 -0400 Subject: [PATCH 06/13] deduplicate task configuration in MinecraftProvider --- .../internal/minecraft/MinecraftProvider.kt | 100 ++++++------------ 1 file changed, 34 insertions(+), 66 deletions(-) diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/MinecraftProvider.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/MinecraftProvider.kt index 66e31da5..2dd507c4 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/MinecraftProvider.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/MinecraftProvider.kt @@ -7,7 +7,6 @@ import org.gradle.api.artifacts.Dependency import org.gradle.api.artifacts.ModuleDependency import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.SourceSetContainer -import org.gradle.configurationcache.extensions.capitalized import org.gradle.jvm.tasks.Jar import org.intellij.lang.annotations.Language import org.jetbrains.annotations.ApiStatus @@ -408,7 +407,7 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft protected val extractDependencies: MutableMap = mutableMapOf() - fun filterLibrary(lib: Library): Library? { + private fun filterLibrary(lib: Library): Library? { val lib2 = (mcPatcher as AbstractMinecraftTransformer).libraryFilter(lib) if (lib2 != null) { for (filter in libraryReplaceMap) { @@ -449,95 +448,64 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft } } - fun applyDefaultRemapJar() { - var task = project.tasks.findByName("jar".withSourceSet(sourceSet)) - if (task == null && createJarTask) { - project.logger.info("[Unimined/Minecraft ${project.path}:${sourceSet.name}] Creating default jar task for $sourceSet") - task = project.tasks.create("jar".withSourceSet(sourceSet), Jar::class.java) { - it.group = "build" - it.from(sourceSet.output) - it.archiveClassifier.set(sourceSet.name) - for ((_, sourceSet) in combinedWithList) { - it.from(sourceSet.output) - } - } - } else if (task != null) { - if (task is Jar) { - task.also { - it.from(sourceSet.output) - for ((_, sourceSet) in combinedWithList) { - it.from(sourceSet.output) - } - } - } else { - project.logger.warn("[Unimined/Minecraft ${project.path}:${sourceSet.name}] jar task for $sourceSet is not a Jar task") - } + private fun applyDefaultRemapJars() { + applyDefaultRemapJar("jar", ::remap) { + from(sourceSet.output) + archiveClassifier.set(sourceSet.name) + from(combinedWithList.map { it.second.output }) } - if (task != null && task is Jar) { - val classifier: String = task.archiveClassifier.getOrElse("") - task.apply { - if (classifier.isNotEmpty()) { - archiveClassifier.set("$classifier-dev") - } else { - archiveClassifier.set("dev") - } - } - remap(task) { - group = "unimined" - description = "Remaps $task's output jar" - archiveClassifier.set(classifier) - } - project.tasks.getByName("build").dependsOn("remap" + "jar".withSourceSet(sourceSet).capitalized()) - } else { - project.logger.warn( - "[Unimined/Minecraft ${project.path}:${sourceSet.name}] Could not find default jar task for $sourceSet. named: ${"jar".withSourceSet(sourceSet)}." - ) - project.logger.warn("[Unimined/Minecraft ${project.path}:${sourceSet.name}] add manually with `remap(task)` in the minecraft block for $sourceSet") + applyDefaultRemapJar("sourcesJar", ::remapSources) { + from(sourceSet.allSource) + archiveClassifier.set("${sourceSet.name}-sources") + from(combinedWithList.map { it.second.allSource }) } + } - var sourcesTask = project.tasks.findByName("sourcesJar".withSourceSet(sourceSet)) - if (sourcesTask == null && createJarTask) { - project.logger.info("[Unimined/Minecraft ${project.path}:${sourceSet.name}] Creating default sources jar task for $sourceSet") - sourcesTask = project.tasks.create("sourcesJar".withSourceSet(sourceSet), Jar::class.java) { + private inline fun applyDefaultRemapJar( + inputTaskName: String, + remappingFunction: (Task, RemapJarTask.() -> Unit) -> Unit, + crossinline defaultTaskConfiguration: Jar.() -> Unit + ) { + var inputTask = project.tasks.findByName(inputTaskName.withSourceSet(sourceSet)) + if (inputTask == null && createJarTask) { + project.logger.info("[Unimined/Minecraft ${project.path}:${sourceSet.name}] Creating default $inputTaskName for $sourceSet") + inputTask = project.tasks.create(inputTaskName.withSourceSet(sourceSet), Jar::class.java) { it.group = "build" - it.from(sourceSet.allSource) - it.archiveClassifier.set("${sourceSet.name}-sources") - for ((_, sourceSet) in combinedWithList) { - it.from(sourceSet.allSource) - } + defaultTaskConfiguration(it) } - } else if (sourcesTask != null) { - if (sourcesTask is Jar) { - sourcesTask.also { + } else if (inputTask != null) { + if (inputTask is Jar) { + inputTask.also { it.from(sourceSet.allSource) for ((_, sourceSet) in combinedWithList) { it.from(sourceSet.allSource) } } } else { - project.logger.warn("[Unimined/Minecraft ${project.path}:${sourceSet.name}] sourcesJar task for $sourceSet is not a Jar task") + project.logger.warn("[Unimined/Minecraft ${project.path}:${sourceSet.name}] task $inputTaskName for $sourceSet is not an instance of ${Jar::class.qualifiedName}") + return } } - if (sourcesTask != null && sourcesTask is Jar) { - val classifier: String = sourcesTask.archiveClassifier.getOrElse("") - sourcesTask.apply { + if (inputTask != null && inputTask is Jar) { + val classifier: String = inputTask.archiveClassifier.getOrElse("") + inputTask.apply { if (classifier.isNotEmpty()) { archiveClassifier.set("$classifier-dev") } else { archiveClassifier.set("dev") } } - remapSources(sourcesTask) { + remappingFunction(inputTask) { group = "unimined" - description = "Remaps $sourcesTask's output jar" + description = "Remaps $inputTask's output jar" archiveClassifier.set(classifier) } - project.tasks.getByName("build").dependsOn("remap" + "sourcesJar".withSourceSet(sourceSet).capitalized()) + project.tasks.getByName("build").dependsOn("remap" + inputTask.name.capitalized()) } else { project.logger.warn( - "[Unimined/Minecraft ${project.path}:${sourceSet.name}] Could not find default sources jar task for $sourceSet. named: ${"sourcesJar".withSourceSet(sourceSet)}." + "[Unimined/Minecraft ${project.path}:${sourceSet.name}] Could not find default task '${inputTaskName.withSourceSet(sourceSet)} for $sourceSet." ) project.logger.warn("[Unimined/Minecraft ${project.path}:${sourceSet.name}] add manually with `remapSources(task)` in the minecraft block for $sourceSet") } @@ -640,7 +608,7 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft if (mcPatcher.addVanillaLibraries) addLibraries(minecraftData.metadata.libraries) if (defaultRemapJar) { - applyDefaultRemapJar() + applyDefaultRemapJars() } // apply minecraft patcher changes From 6616e35b1894cb7f8d59cac650f1a306cde2998b Mon Sep 17 00:00:00 2001 From: Rhys <98863820+rhysdh540@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:19:34 -0400 Subject: [PATCH 07/13] don't compress intermediate remapping jars --- .../unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt index c16433a0..bbe3bf6b 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt @@ -6,6 +6,7 @@ import xyz.wagyourtail.unimined.util.deleteRecursively import java.nio.file.Path import java.util.jar.JarEntry import java.util.jar.JarOutputStream +import java.util.zip.Deflater import javax.inject.Inject import kotlin.io.path.* @@ -55,6 +56,7 @@ abstract class RemapSourcesJarTaskImpl @Inject constructor(provider: MinecraftCo } JarOutputStream(target.toFile().outputStream()).use { zos -> + zos.setLevel(Deflater.NO_COMPRESSION) output.walk().forEach { file -> val name = output.relativize(file).toString().replace('\\', '/') zos.putNextEntry(JarEntry(name)) From ab98a3c663b5c42fe896a8d20466423c73cd0192 Mon Sep 17 00:00:00 2001 From: Rhys <98863820+rhysdh540@users.noreply.github.com> Date: Mon, 7 Oct 2024 15:21:52 -0400 Subject: [PATCH 08/13] add @ since annotations --- .../unimined/api/minecraft/MinecraftConfig.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/MinecraftConfig.kt b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/MinecraftConfig.kt index cc9ee717..09770488 100644 --- a/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/MinecraftConfig.kt +++ b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/MinecraftConfig.kt @@ -259,14 +259,23 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) : } } + /** + * @since 1.3.10 + */ fun remapSources(task: Task) { remapSources(task) {} } + /** + * @since 1.3.10 + */ fun remapSources(task: Task, action: RemapJarTask.() -> Unit) { remapSources(task, "remap${task.name.capitalized()}", action) } + /** + * @since 1.3.10 + */ fun remapSources( task: Task, @DelegatesTo(value = RemapJarTask::class, strategy = Closure.DELEGATE_FIRST) @@ -279,12 +288,21 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) : } } + /** + * @since 1.3.10 + */ fun remapSources(task: Task, name: String) { remapSources(task, name) {} } + /** + * @since 1.3.10 + */ abstract fun remapSources(task: Task, name: String, action: RemapJarTask.() -> Unit) + /** + * @since 1.3.10 + */ fun remapSources( task: Task, name: String, From 1c075de52345743f3854c7b3a0f1e45e73fb515d Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Wed, 9 Oct 2024 01:59:54 -0500 Subject: [PATCH 09/13] clarify docs --- docs/MULTIPLE.md | 32 ++++++++++++++++++++++++++++++++ docs/USAGE.md | 9 ++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/docs/MULTIPLE.md b/docs/MULTIPLE.md index 0b1031e2..bd1c984f 100644 --- a/docs/MULTIPLE.md +++ b/docs/MULTIPLE.md @@ -35,6 +35,22 @@ unimined.minecraft { accessWidener { accessWidener "src/main/resources/accessWidenerName.aw" } + + // you may want to set this if you want to include architectury mods in common + mods.modImplementation { + namespace("intermediary") + } + + // if you don't want to build/remap a "common" jar + if (sourceSet == sourceSets.main) { + defaultRemapJar = false + } +} + +// if not disabling remapJar above, +// you may want to set this so the "common" jar is in intermediary to match architectury +tasks.named("remapJar") { + prodNamespace("intermediary") } // forge @@ -82,6 +98,22 @@ unimined.minecraft { accessWidener { accessWidener "src/main/resources/accessWidenerName.aw" } + + // you may want to set this if you want to include arch mods in common + mods.modImplementation { + namespace("intermediary") + } + + // if you don't want to build/remap a "common" jar + if (sourceSet == sourceSets.main) { + defaultRemapJar = false + } +} + +// if not disabling remapJar above, +// you may want to set this so the "common" jar is in intermediary to match architectury +tasks.named("remapJar") { + prodNamespace("intermediary") } ``` diff --git a/docs/USAGE.md b/docs/USAGE.md index b3cb679a..21fa1844 100644 --- a/docs/USAGE.md +++ b/docs/USAGE.md @@ -99,7 +99,14 @@ configurations { unimined.minecraft { ... mods { - remap(configurations.modCompileOnly) + remap(configurations.modCompileOnly) { + } + + // this is basically just a shortcut for `remap(configurations.modImplementation)` + modImplementation { + // you can do this is mods have the wrong access widener mapping, but it may break runs + catchAWNamespaceAssertion() + } } } From ce7bf85dec9ab35a658f8efd8074e91a9f27e0ef Mon Sep 17 00:00:00 2001 From: Rhys <98863820+rhysdh540@users.noreply.github.com> Date: Wed, 9 Oct 2024 07:21:00 -0400 Subject: [PATCH 10/13] make common superclass for remap jar tasks --- .../minecraft/task/AbstractRemapJarTask.kt | 136 ++++++++++++++++++ .../minecraft/task/RemapJarTaskImpl.kt | 122 +--------------- .../minecraft/task/RemapSourcesJarTaskImpl.kt | 4 +- 3 files changed, 143 insertions(+), 119 deletions(-) create mode 100644 src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/AbstractRemapJarTask.kt diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/AbstractRemapJarTask.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/AbstractRemapJarTask.kt new file mode 100644 index 00000000..07afdc28 --- /dev/null +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/AbstractRemapJarTask.kt @@ -0,0 +1,136 @@ +package xyz.wagyourtail.unimined.internal.minecraft.task + +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.TaskAction +import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree +import xyz.wagyourtail.unimined.api.mapping.mixin.MixinRemapOptions +import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig +import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.util.FinalizeOnRead +import xyz.wagyourtail.unimined.util.LazyMutable +import xyz.wagyourtail.unimined.util.getField +import xyz.wagyourtail.unimined.util.readZipInputStreamFor +import java.nio.file.Path +import java.nio.file.StandardOpenOption +import javax.inject.Inject +import kotlin.io.path.* + +@Suppress("UNCHECKED_CAST") +abstract class AbstractRemapJarTask @Inject constructor(@get:Internal val provider: MinecraftConfig): RemapJarTask() { + + @get:Internal + protected var mixinRemapOptions: MixinRemapOptions.() -> Unit by FinalizeOnRead {} + + override fun devNamespace(namespace: String) { + val delegate: FinalizeOnRead = RemapJarTask::class.getField("devNamespace")!!.getDelegate(this) as FinalizeOnRead + delegate.setValueIntl(LazyMutable { provider.mappings.getNamespace(namespace) }) + } + + override fun devFallbackNamespace(namespace: String) { + val delegate: FinalizeOnRead = RemapJarTask::class.getField("devFallbackNamespace")!!.getDelegate(this) as FinalizeOnRead + delegate.setValueIntl(LazyMutable { provider.mappings.getNamespace(namespace) }) + } + + override fun prodNamespace(namespace: String) { + val delegate: FinalizeOnRead = RemapJarTask::class.getField("prodNamespace")!!.getDelegate(this) as FinalizeOnRead + delegate.setValueIntl(LazyMutable { provider.mappings.getNamespace(namespace) }) + } + + override fun mixinRemap(action: MixinRemapOptions.() -> Unit) { + val delegate: FinalizeOnRead Unit> = AbstractRemapJarTask::class.getField("mixinRemapOptions")!!.getDelegate(this) as FinalizeOnRead Unit> + val old = delegate.value as MixinRemapOptions.() -> Unit + mixinRemapOptions = { + old() + action() + } + } + + override var allowImplicitWildcards by FinalizeOnRead(false) + + @TaskAction + @Suppress("UNNECESSARY_NOT_NULL_ASSERTION") + fun run() { + val prodNs = prodNamespace ?: provider.mcPatcher.prodNamespace!! + val devNs = devNamespace ?: provider.mappings.devNamespace!! + val devFNs = devFallbackNamespace ?: provider.mappings.devFallbackNamespace!! + + val path = provider.mappings.getRemapPath( + devNs, + devFNs, + prodNs, + prodNs + ) + + val inputFile = provider.mcPatcher.beforeRemapJarTask(this, inputFile.get().asFile.toPath()) + + if (path.isEmpty()) { + project.logger.lifecycle("[Unimined/RemapJar ${this.path}] detected empty remap path, jumping to after remap tasks") + provider.mcPatcher.afterRemapJarTask(this, inputFile) + afterRemap(inputFile) + return + } + + project.logger.lifecycle("[Unimined/RemapJar ${this.path}] remapping output ${inputFile.name} from $devNs/$devFNs to $prodNs") + project.logger.info("[Unimined/RemapJar ${this.path}] $devNs -> ${path.joinToString(" -> ") { it.name }}") + + var prevTarget = inputFile + var prevNamespace = devNs + var prevPrevNamespace = devFNs + for (i in path.indices) { + val step = path[i] + project.logger.info("[Unimined/RemapJar ${this.path}] $step") + val nextTarget = temporaryDir.toPath().resolve("${inputFile.nameWithoutExtension}-temp-${step.name}.jar") + nextTarget.deleteIfExists() + + val mc = provider.getMinecraft( + prevNamespace, + prevPrevNamespace + ) + val classpath = provider.mods.getClasspathAs( + prevNamespace, + prevPrevNamespace, + provider.sourceSet.compileClasspath.files + ).map { it.toPath() }.filter { it.exists() && !provider.isMinecraftJar(it) } + + project.logger.debug("[Unimined/RemapJar ${path}] classpath: ") + classpath.forEach { + project.logger.debug("[Unimined/RemapJar ${path}] $it") + } + + doRemap(prevTarget, nextTarget, prevNamespace, step, (classpath + listOf(mc)).toTypedArray()) + + prevTarget = nextTarget + prevPrevNamespace = prevNamespace + prevNamespace = step + } + project.logger.info("[Unimined/RemapJar ${path}] after remap tasks started ${System.currentTimeMillis()}") + provider.mcPatcher.afterRemapJarTask(this, prevTarget) + afterRemap(prevTarget) + project.logger.info("[Unimined/RemapJar ${path}] after remap tasks finished ${System.currentTimeMillis()}") + } + + private fun afterRemap(afterRemapJar: Path) { + // merge in manifest from input jar + afterRemapJar.readZipInputStreamFor("META-INF/MANIFEST.MF", false) { inp -> + // write to temp file + val inpTmp = temporaryDir.toPath().resolve("input-manifest.MF") + inpTmp.outputStream(StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING).use { out -> + inp.copyTo(out) + } + this.manifest { + it.from(inpTmp) + } + } + // copy into output + from(project.zipTree(afterRemapJar)) + copy() + } + + protected abstract fun doRemap( + from: Path, + target: Path, + fromNs: MappingNamespaceTree.Namespace, + toNs: MappingNamespaceTree.Namespace, + classpathList: Array + ) +} \ No newline at end of file diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt index 3142bc3f..6d7df484 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt @@ -4,134 +4,22 @@ import net.fabricmc.loom.util.kotlin.KotlinClasspathService import net.fabricmc.loom.util.kotlin.KotlinRemapperClassloader import net.fabricmc.tinyremapper.OutputConsumerPath import net.fabricmc.tinyremapper.TinyRemapper -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.TaskAction import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree -import xyz.wagyourtail.unimined.api.mapping.mixin.MixinRemapOptions import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig import xyz.wagyourtail.unimined.api.minecraft.patch.forge.ForgeLikePatcher -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask import xyz.wagyourtail.unimined.internal.mapping.at.AccessTransformerApplier import xyz.wagyourtail.unimined.internal.mapping.aw.AccessWidenerApplier import xyz.wagyourtail.unimined.internal.mapping.extension.MixinRemapExtension -import xyz.wagyourtail.unimined.util.* +import xyz.wagyourtail.unimined.util.openZipFileSystem import java.nio.file.Path -import java.nio.file.StandardOpenOption import javax.inject.Inject -import kotlin.io.path.* +import kotlin.io.path.createDirectories +import kotlin.io.path.deleteIfExists -@Suppress("UNCHECKED_CAST") -abstract class RemapJarTaskImpl @Inject constructor(@get:Internal val provider: MinecraftConfig): RemapJarTask() { - - private var mixinRemapOptions: MixinRemapOptions.() -> Unit by FinalizeOnRead {} - - override fun devNamespace(namespace: String) { - val delegate: FinalizeOnRead = RemapJarTask::class.getField("devNamespace")!!.getDelegate(this) as FinalizeOnRead - delegate.setValueIntl(LazyMutable { provider.mappings.getNamespace(namespace) }) - } - - override fun devFallbackNamespace(namespace: String) { - val delegate: FinalizeOnRead = RemapJarTask::class.getField("devFallbackNamespace")!!.getDelegate(this) as FinalizeOnRead - delegate.setValueIntl(LazyMutable { provider.mappings.getNamespace(namespace) }) - } - - override fun prodNamespace(namespace: String) { - val delegate: FinalizeOnRead = RemapJarTask::class.getField("prodNamespace")!!.getDelegate(this) as FinalizeOnRead - delegate.setValueIntl(LazyMutable { provider.mappings.getNamespace(namespace) }) - } - - override fun mixinRemap(action: MixinRemapOptions.() -> Unit) { - val delegate: FinalizeOnRead Unit> = RemapJarTaskImpl::class.getField("mixinRemapOptions")!!.getDelegate(this) as FinalizeOnRead Unit> - val old = delegate.value as MixinRemapOptions.() -> Unit - mixinRemapOptions = { - old() - action() - } - } - - override var allowImplicitWildcards by FinalizeOnRead(false) - - @TaskAction - @Suppress("UNNECESSARY_NOT_NULL_ASSERTION") - fun run() { - val prodNs = prodNamespace ?: provider.mcPatcher.prodNamespace!! - val devNs = devNamespace ?: provider.mappings.devNamespace!! - val devFNs = devFallbackNamespace ?: provider.mappings.devFallbackNamespace!! - - val path = provider.mappings.getRemapPath( - devNs, - devFNs, - prodNs, - prodNs - ) - - val inputFile = provider.mcPatcher.beforeRemapJarTask(this, inputFile.get().asFile.toPath()) - - if (path.isEmpty()) { - project.logger.lifecycle("[Unimined/RemapJar ${this.path}] detected empty remap path, jumping to after remap tasks") - provider.mcPatcher.afterRemapJarTask(this, inputFile) - afterRemap(inputFile) - return - } - - project.logger.lifecycle("[Unimined/RemapJar ${this.path}] remapping output ${inputFile.name} from $devNs/$devFNs to $prodNs") - project.logger.info("[Unimined/RemapJar ${this.path}] $devNs -> ${path.joinToString(" -> ") { it.name }}") - - var prevTarget = inputFile - var prevNamespace = devNs - var prevPrevNamespace = devFNs - for (i in path.indices) { - val step = path[i] - project.logger.info("[Unimined/RemapJar ${this.path}] $step") - val nextTarget = temporaryDir.toPath().resolve("${inputFile.nameWithoutExtension}-temp-${step.name}.jar") - nextTarget.deleteIfExists() - - val mc = provider.getMinecraft( - prevNamespace, - prevPrevNamespace - ) - val classpath = provider.mods.getClasspathAs( - prevNamespace, - prevPrevNamespace, - provider.sourceSet.compileClasspath.files - ).map { it.toPath() }.filter { it.exists() && !provider.isMinecraftJar(it) } - - project.logger.debug("[Unimined/RemapJar ${path}] classpath: ") - classpath.forEach { - project.logger.debug("[Unimined/RemapJar ${path}] $it") - } - - remapToInternal(prevTarget, nextTarget, prevNamespace, step, (classpath + listOf(mc)).toTypedArray()) - - prevTarget = nextTarget - prevPrevNamespace = prevNamespace - prevNamespace = step - } - project.logger.info("[Unimined/RemapJar ${path}] after remap tasks started ${System.currentTimeMillis()}") - provider.mcPatcher.afterRemapJarTask(this, prevTarget) - afterRemap(prevTarget) - project.logger.info("[Unimined/RemapJar ${path}] after remap tasks finished ${System.currentTimeMillis()}") - } - - private fun afterRemap(afterRemapJar: Path) { - // merge in manifest from input jar - afterRemapJar.readZipInputStreamFor("META-INF/MANIFEST.MF", false) { inp -> - // write to temp file - val inpTmp = temporaryDir.toPath().resolve("input-manifest.MF") - inpTmp.outputStream(StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING).use { out -> - inp.copyTo(out) - } - this.manifest { - it.from(inpTmp) - } - } - // copy into output - from(project.zipTree(afterRemapJar)) - copy() - } +abstract class RemapJarTaskImpl @Inject constructor(provider: MinecraftConfig): AbstractRemapJarTask(provider) { @Suppress("UNNECESSARY_NOT_NULL_ASSERTION") - protected open fun remapToInternal( + override fun doRemap( from: Path, target: Path, fromNs: MappingNamespaceTree.Namespace, diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt index bbe3bf6b..3768fac6 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt @@ -10,9 +10,9 @@ import java.util.zip.Deflater import javax.inject.Inject import kotlin.io.path.* -abstract class RemapSourcesJarTaskImpl @Inject constructor(provider: MinecraftConfig): RemapJarTaskImpl(provider) { +abstract class RemapSourcesJarTaskImpl @Inject constructor(provider: MinecraftConfig): AbstractRemapJarTask(provider) { @OptIn(ExperimentalPathApi::class) - override fun remapToInternal( + override fun doRemap( from: Path, target: Path, fromNs: MappingNamespaceTree.Namespace, From 7ef982c2d879dfdbd4a8639b1a16f2143d0f4a5a Mon Sep 17 00:00:00 2001 From: Rhys <98863820+rhysdh540@users.noreply.github.com> Date: Fri, 11 Oct 2024 23:39:53 -0400 Subject: [PATCH 11/13] last commit but with slightly more brain cells put into it --- .../unimined/api/minecraft/MinecraftConfig.kt | 10 ++- .../api/minecraft/patch/MinecraftPatcher.kt | 9 +-- .../minecraft/task/AbstractRemapJarTask.kt | 74 ++++++++++++++++++ .../api/minecraft/task/RemapJarTask.kt | 75 +------------------ .../api/minecraft/task/RemapSourcesJarTask.kt | 5 ++ .../wagyourtail/unimined/util/JarInterface.kt | 29 +++++++ .../internal/minecraft/MinecraftProvider.kt | 13 ++-- .../patch/AbstractMinecraftTransformer.kt | 8 +- .../fabric/FabricLikeMinecraftTransformer.kt | 9 +-- .../patch/fabric/FlintMinecraftTransformer.kt | 4 +- .../LegacyFabricMinecraftTransformer.kt | 4 +- .../OfficialFabricMinecraftTransformer.kt | 5 +- .../forge/ForgeLikeMinecraftTransformer.kt | 9 +-- .../forge/NeoForgedMinecraftTransformer.kt | 4 +- .../forge/fg3/FG3MinecraftTransformer.kt | 7 +- .../jarmod/JarModAgentMinecraftTransformer.kt | 4 +- .../merged/MergedMinecraftTransformer.kt | 8 +- ...JarTask.kt => AbstractRemapJarTaskImpl.kt} | 12 +-- .../minecraft/task/RemapJarTaskImpl.kt | 4 +- .../minecraft/task/RemapSourcesJarTaskImpl.kt | 4 +- 20 files changed, 166 insertions(+), 131 deletions(-) create mode 100644 src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/task/AbstractRemapJarTask.kt create mode 100644 src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/task/RemapSourcesJarTask.kt create mode 100644 src/api/kotlin/xyz/wagyourtail/unimined/util/JarInterface.kt rename src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/{AbstractRemapJarTask.kt => AbstractRemapJarTaskImpl.kt} (88%) diff --git a/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/MinecraftConfig.kt b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/MinecraftConfig.kt index 09770488..5e7d5d83 100644 --- a/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/MinecraftConfig.kt +++ b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/MinecraftConfig.kt @@ -20,7 +20,9 @@ import xyz.wagyourtail.unimined.api.minecraft.resolver.MinecraftData import xyz.wagyourtail.unimined.api.mod.ModsConfig import xyz.wagyourtail.unimined.api.runs.RunsConfig import xyz.wagyourtail.unimined.api.source.SourceConfig +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.RemapSourcesJarTask import xyz.wagyourtail.unimined.api.unimined import xyz.wagyourtail.unimined.util.* import java.io.File @@ -269,7 +271,7 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) : /** * @since 1.3.10 */ - fun remapSources(task: Task, action: RemapJarTask.() -> Unit) { + fun remapSources(task: Task, action: RemapSourcesJarTask.() -> Unit) { remapSources(task, "remap${task.name.capitalized()}", action) } @@ -278,7 +280,7 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) : */ fun remapSources( task: Task, - @DelegatesTo(value = RemapJarTask::class, strategy = Closure.DELEGATE_FIRST) + @DelegatesTo(value = RemapSourcesJarTask::class, strategy = Closure.DELEGATE_FIRST) action: Closure<*> ) { remapSources(task) { @@ -298,7 +300,7 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) : /** * @since 1.3.10 */ - abstract fun remapSources(task: Task, name: String, action: RemapJarTask.() -> Unit) + abstract fun remapSources(task: Task, name: String, action: RemapSourcesJarTask.() -> Unit) /** * @since 1.3.10 @@ -306,7 +308,7 @@ abstract class MinecraftConfig(val project: Project, val sourceSet: SourceSet) : fun remapSources( task: Task, name: String, - @DelegatesTo(value = RemapJarTask::class, strategy = Closure.DELEGATE_FIRST) + @DelegatesTo(value = RemapSourcesJarTask::class, strategy = Closure.DELEGATE_FIRST) action: Closure<*> ) { remapSources(task, name) { diff --git a/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/patch/MinecraftPatcher.kt b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/patch/MinecraftPatcher.kt index 4a395f60..068a4ec3 100644 --- a/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/patch/MinecraftPatcher.kt +++ b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/patch/MinecraftPatcher.kt @@ -6,8 +6,7 @@ import org.gradle.api.file.FileCollection import org.jetbrains.annotations.ApiStatus import org.objectweb.asm.tree.ClassNode import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask -import java.nio.file.FileSystem +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import java.nio.file.Path /** @@ -47,10 +46,10 @@ interface MinecraftPatcher { } @ApiStatus.Internal - fun beforeRemapJarTask(remapJarTask: RemapJarTask, input: Path): Path + fun beforeRemapJarTask(remapJarTask: AbstractRemapJarTask, input: Path): Path @ApiStatus.Internal - fun afterRemapJarTask(remapJarTask: RemapJarTask, output: Path) + fun afterRemapJarTask(remapJarTask: AbstractRemapJarTask, output: Path) @get:ApiStatus.Internal @set:ApiStatus.Experimental @@ -61,7 +60,7 @@ interface MinecraftPatcher { var unprotectRuntime: Boolean @ApiStatus.Internal - fun configureRemapJar(task: RemapJarTask) + fun configureRemapJar(task: AbstractRemapJarTask) @ApiStatus.Internal fun createSourcesJar(classpath: FileCollection, patchedJar: Path, outputPath: Path, linemappedPath: Path?) diff --git a/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/task/AbstractRemapJarTask.kt b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/task/AbstractRemapJarTask.kt new file mode 100644 index 00000000..107d6f51 --- /dev/null +++ b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/task/AbstractRemapJarTask.kt @@ -0,0 +1,74 @@ +package xyz.wagyourtail.unimined.api.minecraft.task + +import groovy.lang.Closure +import groovy.lang.DelegatesTo +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.bundling.Jar +import org.jetbrains.annotations.ApiStatus +import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree +import xyz.wagyourtail.unimined.api.mapping.mixin.MixinRemapOptions +import xyz.wagyourtail.unimined.util.FinalizeOnRead + +/** + * task responsible for transforming your built jar to production. + * @since 0.1.0 + */ +@Suppress("LeakingThis") +abstract class AbstractRemapJarTask : Jar() { + + @get:InputFile + abstract val inputFile: RegularFileProperty + + @get:Internal + @set:Internal + var devNamespace: MappingNamespaceTree.Namespace? by FinalizeOnRead(null) + + @get:Internal + @set:Internal + var devFallbackNamespace: MappingNamespaceTree.Namespace? by FinalizeOnRead(null) + + @get:Internal + @set:Internal + var prodNamespace: MappingNamespaceTree.Namespace? by FinalizeOnRead(null) + + /** + * whether to remap AccessTransformers to the legacy format (<=1.7.10) + */ + @get:Input + @get:Optional + abstract val remapATToLegacy: Property + + @get:Internal + @set:Internal + @set:ApiStatus.Experimental + abstract var allowImplicitWildcards: Boolean + + abstract fun devNamespace(namespace: String) + + abstract fun devFallbackNamespace(namespace: String) + + abstract fun prodNamespace(namespace: String) + + abstract fun mixinRemap(action: MixinRemapOptions.() -> Unit) + + fun mixinRemap( + @DelegatesTo(value = MixinRemapOptions::class, strategy = Closure.DELEGATE_FIRST) + action: Closure<*> + ) { + mixinRemap { + action.delegate = this + action.resolveStrategy = Closure.DELEGATE_FIRST + action.call() + } + } + + init { + remapATToLegacy.convention(null as Boolean?).finalizeValueOnRead() + } + +} \ No newline at end of file diff --git a/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/task/RemapJarTask.kt b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/task/RemapJarTask.kt index bb9245e6..75798f70 100644 --- a/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/task/RemapJarTask.kt +++ b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/task/RemapJarTask.kt @@ -1,76 +1,5 @@ package xyz.wagyourtail.unimined.api.minecraft.task -import groovy.lang.Closure -import groovy.lang.DelegatesTo -import groovy.transform.stc.ClosureParams -import groovy.transform.stc.SimpleType -import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.Property -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.InputFile -import org.gradle.api.tasks.Internal -import org.gradle.api.tasks.Optional -import org.gradle.jvm.tasks.Jar -import org.jetbrains.annotations.ApiStatus -import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree -import xyz.wagyourtail.unimined.api.mapping.mixin.MixinRemapOptions -import xyz.wagyourtail.unimined.util.FinalizeOnRead +import xyz.wagyourtail.unimined.util.JarInterface -/** - * task responsible for transforming your built jar to production. - * @since 0.1.0 - */ -@Suppress("LeakingThis") -abstract class RemapJarTask : Jar() { - - @get:InputFile - abstract val inputFile: RegularFileProperty - - @get:Internal - @set:Internal - var devNamespace: MappingNamespaceTree.Namespace? by FinalizeOnRead(null) - - @get:Internal - @set:Internal - var devFallbackNamespace: MappingNamespaceTree.Namespace? by FinalizeOnRead(null) - - @get:Internal - @set:Internal - var prodNamespace: MappingNamespaceTree.Namespace? by FinalizeOnRead(null) - - /** - * whether to remap AccessTransformers to the legacy format (<=1.7.10) - */ - @get:Input - @get:Optional - abstract val remapATToLegacy: Property - - @get:Internal - @set:Internal - @set:ApiStatus.Experimental - abstract var allowImplicitWildcards: Boolean - - abstract fun devNamespace(namespace: String) - - abstract fun devFallbackNamespace(namespace: String) - - abstract fun prodNamespace(namespace: String) - - abstract fun mixinRemap(action: MixinRemapOptions.() -> Unit) - - fun mixinRemap( - @DelegatesTo(value = MixinRemapOptions::class, strategy = Closure.DELEGATE_FIRST) - action: Closure<*> - ) { - mixinRemap { - action.delegate = this - action.resolveStrategy = Closure.DELEGATE_FIRST - action.call() - } - } - - init { - remapATToLegacy.convention(null as Boolean?).finalizeValueOnRead() - } - -} \ No newline at end of file +interface RemapJarTask : JarInterface \ No newline at end of file diff --git a/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/task/RemapSourcesJarTask.kt b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/task/RemapSourcesJarTask.kt new file mode 100644 index 00000000..3b99e15f --- /dev/null +++ b/src/api/kotlin/xyz/wagyourtail/unimined/api/minecraft/task/RemapSourcesJarTask.kt @@ -0,0 +1,5 @@ +package xyz.wagyourtail.unimined.api.minecraft.task + +import xyz.wagyourtail.unimined.util.JarInterface + +interface RemapSourcesJarTask : JarInterface \ No newline at end of file diff --git a/src/api/kotlin/xyz/wagyourtail/unimined/util/JarInterface.kt b/src/api/kotlin/xyz/wagyourtail/unimined/util/JarInterface.kt new file mode 100644 index 00000000..03f973d5 --- /dev/null +++ b/src/api/kotlin/xyz/wagyourtail/unimined/util/JarInterface.kt @@ -0,0 +1,29 @@ +package xyz.wagyourtail.unimined.util + +import groovy.lang.Closure +import groovy.lang.DelegatesTo +import org.gradle.api.Task +import org.gradle.api.tasks.Internal +import org.gradle.api.tasks.bundling.Jar + +interface JarInterface : Task { + + @Suppress("UNCHECKED_CAST") + val asJar: T + @Internal + get() = this as T + + fun asJar(action: T.() -> Unit) { + asJar.action() + } + + fun asJar( + @DelegatesTo(Jar::class, strategy = Closure.DELEGATE_FIRST) + closure: Closure<*> + ) { + asJar { + closure.delegate = this + closure.call() + } + } +} \ No newline at end of file diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/MinecraftProvider.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/MinecraftProvider.kt index 2dd507c4..eed2a6a8 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/MinecraftProvider.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/MinecraftProvider.kt @@ -28,7 +28,9 @@ import xyz.wagyourtail.unimined.api.minecraft.patch.forge.MinecraftForgePatcher import xyz.wagyourtail.unimined.api.minecraft.patch.forge.NeoForgedPatcher import xyz.wagyourtail.unimined.api.minecraft.patch.jarmod.JarModAgentPatcher import xyz.wagyourtail.unimined.api.minecraft.patch.rift.RiftPatcher +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.RemapSourcesJarTask import xyz.wagyourtail.unimined.api.unimined import xyz.wagyourtail.unimined.api.uniminedMaybe import xyz.wagyourtail.unimined.internal.mapping.MappingsProvider @@ -147,7 +149,7 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft } } - override fun remapSources(task: Task, name: String, action: RemapJarTask.() -> Unit) { + override fun remapSources(task: Task, name: String, action: RemapSourcesJarTask.() -> Unit) { val remapTask = project.tasks.register(name, RemapSourcesJarTaskImpl::class.java, this) remapTask.configure { it.dependsOn(task) @@ -462,11 +464,12 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft } } - private inline fun applyDefaultRemapJar( + private inline fun applyDefaultRemapJar( inputTaskName: String, - remappingFunction: (Task, RemapJarTask.() -> Unit) -> Unit, + remappingFunction: (Task, JarInterface.() -> Unit) -> Unit, crossinline defaultTaskConfiguration: Jar.() -> Unit - ) { + ) where T : AbstractRemapJarTask, T : JarInterface { + var inputTask = project.tasks.findByName(inputTaskName.withSourceSet(sourceSet)) if (inputTask == null && createJarTask) { project.logger.info("[Unimined/Minecraft ${project.path}:${sourceSet.name}] Creating default $inputTaskName for $sourceSet") @@ -500,7 +503,7 @@ open class MinecraftProvider(project: Project, sourceSet: SourceSet) : Minecraft remappingFunction(inputTask) { group = "unimined" description = "Remaps $inputTask's output jar" - archiveClassifier.set(classifier) + asJar.archiveClassifier.set(classifier) } project.tasks.getByName("build").dependsOn("remap" + inputTask.name.capitalized()) } else { diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/AbstractMinecraftTransformer.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/AbstractMinecraftTransformer.kt index 5bd10f9c..d229348a 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/AbstractMinecraftTransformer.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/AbstractMinecraftTransformer.kt @@ -15,7 +15,7 @@ import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig import xyz.wagyourtail.unimined.api.minecraft.MinecraftJar import xyz.wagyourtail.unimined.api.minecraft.patch.MinecraftPatcher import xyz.wagyourtail.unimined.api.runs.RunConfig -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.api.unimined import xyz.wagyourtail.unimined.api.uniminedMaybe import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider @@ -212,12 +212,12 @@ abstract class AbstractMinecraftTransformer protected constructor( return baseMinecraft } - override fun beforeRemapJarTask(remapJarTask: RemapJarTask, input: Path): Path { + override fun beforeRemapJarTask(remapJarTask: AbstractRemapJarTask, input: Path): Path { return input } @ApiStatus.Internal - override fun afterRemapJarTask(remapJarTask: RemapJarTask, output: Path) { + override fun afterRemapJarTask(remapJarTask: AbstractRemapJarTask, output: Path) { // do nothing } @@ -292,7 +292,7 @@ abstract class AbstractMinecraftTransformer protected constructor( output[sourceSet] = out } - override fun configureRemapJar(task: RemapJarTask) {} + override fun configureRemapJar(task: AbstractRemapJarTask) {} override fun createSourcesJar(classpath: FileCollection, patchedJar: Path, outputPath: Path, linemappedPath: Path?) { provider.sourceProvider.sourceGenerator.generate(provider.sourceSet.compileClasspath, patchedJar, outputPath, linemappedPath) diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/FabricLikeMinecraftTransformer.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/FabricLikeMinecraftTransformer.kt index 64344a55..b8202c9d 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/FabricLikeMinecraftTransformer.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/FabricLikeMinecraftTransformer.kt @@ -14,7 +14,7 @@ import xyz.wagyourtail.unimined.api.minecraft.patch.ataw.AccessWidenerPatcher import xyz.wagyourtail.unimined.api.minecraft.patch.fabric.FabricLikePatcher import xyz.wagyourtail.unimined.api.runs.RunConfig import xyz.wagyourtail.unimined.api.mapping.task.ExportMappingsTask -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.api.unimined import xyz.wagyourtail.unimined.api.uniminedMaybe import xyz.wagyourtail.unimined.internal.mapping.ii.InterfaceInjectionMinecraftTransformer @@ -23,7 +23,6 @@ import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider import xyz.wagyourtail.unimined.internal.minecraft.patch.AbstractMinecraftTransformer import xyz.wagyourtail.unimined.api.minecraft.MinecraftJar import xyz.wagyourtail.unimined.internal.minecraft.patch.access.widener.AccessWidenerMinecraftTransformer -import xyz.wagyourtail.unimined.internal.minecraft.patch.reindev.ReIndevProvider import xyz.wagyourtail.unimined.internal.minecraft.resolver.Library import xyz.wagyourtail.unimined.internal.minecraft.resolver.parseLibrary import xyz.wagyourtail.unimined.internal.minecraft.transform.merge.ClassMerger @@ -34,10 +33,6 @@ import java.nio.file.Files import java.nio.file.Path import java.nio.file.StandardCopyOption import java.nio.file.StandardOpenOption -import java.nio.file.attribute.FileTime -import java.util.concurrent.TimeUnit -import java.util.zip.ZipEntry -import java.util.zip.ZipOutputStream import kotlin.io.path.* abstract class FabricLikeMinecraftTransformer( @@ -321,7 +316,7 @@ abstract class FabricLikeMinecraftTransformer( icp } - override fun afterRemapJarTask(remapJarTask: RemapJarTask, output: Path) { + override fun afterRemapJarTask(remapJarTask: AbstractRemapJarTask, output: Path) { insertIncludes(output) insertAW(output) } diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/FlintMinecraftTransformer.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/FlintMinecraftTransformer.kt index 48afab37..75db7e36 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/FlintMinecraftTransformer.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/FlintMinecraftTransformer.kt @@ -6,7 +6,7 @@ import org.gradle.api.Project import org.gradle.api.artifacts.Dependency import xyz.wagyourtail.unimined.api.minecraft.EnvType import xyz.wagyourtail.unimined.api.minecraft.MinecraftJar -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.api.runs.RunConfig import xyz.wagyourtail.unimined.api.unimined import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider @@ -101,7 +101,7 @@ open class FlintMinecraftTransformer( throw UnsupportedOperationException("Merging is not supported on flint") } - override fun afterRemapJarTask(remapJarTask: RemapJarTask, output: Path) { + override fun afterRemapJarTask(remapJarTask: AbstractRemapJarTask, output: Path) { this.insertAccessWidener(output) } diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/LegacyFabricMinecraftTransformer.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/LegacyFabricMinecraftTransformer.kt index e5863d6f..13894e23 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/LegacyFabricMinecraftTransformer.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/LegacyFabricMinecraftTransformer.kt @@ -3,7 +3,7 @@ package xyz.wagyourtail.unimined.internal.minecraft.patch.fabric import org.gradle.api.Project import org.gradle.api.artifacts.Dependency import xyz.wagyourtail.unimined.api.minecraft.patch.fabric.LegacyFabricPatcher -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.api.unimined import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider import xyz.wagyourtail.unimined.internal.minecraft.resolver.Library @@ -35,7 +35,7 @@ open class LegacyFabricMinecraftTransformer( project.unimined.legacyFabricMaven() } - override fun configureRemapJar(task: RemapJarTask) { + override fun configureRemapJar(task: AbstractRemapJarTask) { if (fabricDep.version?.let { SemVerUtils.matches(it, ">=0.15.0") } == true) { project.logger.info("enabling mixin extra") task.mixinRemap { diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/OfficialFabricMinecraftTransformer.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/OfficialFabricMinecraftTransformer.kt index c68ab2a5..a664e827 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/OfficialFabricMinecraftTransformer.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/fabric/OfficialFabricMinecraftTransformer.kt @@ -2,8 +2,7 @@ package xyz.wagyourtail.unimined.internal.minecraft.patch.fabric import org.gradle.api.Project import org.gradle.api.artifacts.Dependency -import xyz.wagyourtail.unimined.api.minecraft.MinecraftJar -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider import xyz.wagyourtail.unimined.util.SemVerUtils @@ -26,7 +25,7 @@ open class OfficialFabricMinecraftTransformer( ) } - override fun configureRemapJar(task: RemapJarTask) { + override fun configureRemapJar(task: AbstractRemapJarTask) { if (fabricDep.version?.let { SemVerUtils.matches(it, ">=0.15.0") } == true) { project.logger.info("enabling mixin extra") task.mixinRemap { diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/forge/ForgeLikeMinecraftTransformer.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/forge/ForgeLikeMinecraftTransformer.kt index 68187719..f640fc84 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/forge/ForgeLikeMinecraftTransformer.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/forge/ForgeLikeMinecraftTransformer.kt @@ -17,7 +17,7 @@ import xyz.wagyourtail.unimined.api.minecraft.patch.forge.ForgeLikePatcher import xyz.wagyourtail.unimined.api.minecraft.patch.ataw.AccessTransformerPatcher import xyz.wagyourtail.unimined.api.runs.RunConfig import xyz.wagyourtail.unimined.api.mapping.task.ExportMappingsTask -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.api.unimined import xyz.wagyourtail.unimined.api.uniminedMaybe import xyz.wagyourtail.unimined.internal.mapping.at.AccessTransformerApplier @@ -33,7 +33,6 @@ import xyz.wagyourtail.unimined.internal.minecraft.transform.merge.ClassMerger import xyz.wagyourtail.unimined.util.* import java.io.File import java.io.InputStreamReader -import java.nio.file.FileSystem import java.nio.file.Path import kotlin.io.path.createDirectories @@ -368,7 +367,7 @@ abstract class ForgeLikeMinecraftTransformer( } } - override fun afterRemapJarTask(remapJarTask: RemapJarTask, output: Path) { + override fun afterRemapJarTask(remapJarTask: AbstractRemapJarTask, output: Path) { forgeTransformer.afterRemapJarTask(remapJarTask, output) } @@ -392,11 +391,11 @@ abstract class ForgeLikeMinecraftTransformer( return forgeTransformer.name() } - override fun beforeRemapJarTask(remapJarTask: RemapJarTask, input: Path): Path { + override fun beforeRemapJarTask(remapJarTask: AbstractRemapJarTask, input: Path): Path { return forgeTransformer.beforeRemapJarTask(remapJarTask, input) } - override fun configureRemapJar(task: RemapJarTask) { + override fun configureRemapJar(task: AbstractRemapJarTask) { forgeTransformer.configureRemapJar(task) } diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/forge/NeoForgedMinecraftTransformer.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/forge/NeoForgedMinecraftTransformer.kt index 6bf1dab7..0ad6fdfa 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/forge/NeoForgedMinecraftTransformer.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/forge/NeoForgedMinecraftTransformer.kt @@ -4,7 +4,7 @@ import com.google.gson.JsonObject import org.gradle.api.Project import org.gradle.api.artifacts.Dependency import xyz.wagyourtail.unimined.api.minecraft.patch.forge.NeoForgedPatcher -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.api.unimined import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider import xyz.wagyourtail.unimined.internal.minecraft.patch.forge.fg3.FG3MinecraftTransformer @@ -64,7 +64,7 @@ open class NeoForgedMinecraftTransformer(project: Project, provider: MinecraftPr tweakClassClient = args.split("--tweakClass")[1].trim() } - override fun configureRemapJar(task: RemapJarTask) { + override fun configureRemapJar(task: AbstractRemapJarTask) { val forgeDep = forge.dependencies.first() if (provider.version != "1.20.1") { project.logger.info("setting `disableRefmap()` in mixinRemap") diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/forge/fg3/FG3MinecraftTransformer.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/forge/fg3/FG3MinecraftTransformer.kt index c2440bb6..43cea8ee 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/forge/fg3/FG3MinecraftTransformer.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/forge/fg3/FG3MinecraftTransformer.kt @@ -16,7 +16,7 @@ import org.jetbrains.annotations.VisibleForTesting import xyz.wagyourtail.unimined.* import xyz.wagyourtail.unimined.api.minecraft.EnvType import xyz.wagyourtail.unimined.api.minecraft.MinecraftJar -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.api.runs.RunConfig import xyz.wagyourtail.unimined.api.unimined import xyz.wagyourtail.unimined.internal.minecraft.patch.fabric.FabricLikeMinecraftTransformer @@ -27,7 +27,6 @@ import xyz.wagyourtail.unimined.internal.minecraft.patch.forge.fg3.mcpconfig.Mcp import xyz.wagyourtail.unimined.internal.minecraft.patch.forge.fg3.mcpconfig.McpConfigStep import xyz.wagyourtail.unimined.internal.minecraft.patch.forge.fg3.mcpconfig.McpExecutor import xyz.wagyourtail.unimined.internal.minecraft.patch.jarmod.JarModMinecraftTransformer -import xyz.wagyourtail.unimined.internal.minecraft.resolver.AssetsDownloader import xyz.wagyourtail.unimined.internal.minecraft.transform.fixes.FixFG2ResourceLoading import xyz.wagyourtail.unimined.internal.minecraft.transform.merge.ClassMerger import xyz.wagyourtail.unimined.util.* @@ -571,7 +570,7 @@ open class FG3MinecraftTransformer(project: Project, val parent: ForgeLikeMinecr }) } - private fun doJarJar(remapJarTask: RemapJarTask, output: Path) { + private fun doJarJar(remapJarTask: AbstractRemapJarTask, output: Path) { if (include!!.dependencies.isEmpty()) { return } @@ -606,7 +605,7 @@ open class FG3MinecraftTransformer(project: Project, val parent: ForgeLikeMinecr } } - override fun afterRemapJarTask(remapJarTask: RemapJarTask, output: Path) { + override fun afterRemapJarTask(remapJarTask: AbstractRemapJarTask, output: Path) { if (provider.minecraftData.mcVersionCompare(provider.version, "1.18") >= 0) { doJarJar(remapJarTask, output) } diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/jarmod/JarModAgentMinecraftTransformer.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/jarmod/JarModAgentMinecraftTransformer.kt index 0bc967e5..c8bfb658 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/jarmod/JarModAgentMinecraftTransformer.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/jarmod/JarModAgentMinecraftTransformer.kt @@ -4,7 +4,7 @@ import org.gradle.api.Project import org.gradle.api.artifacts.ExternalDependency import xyz.wagyourtail.unimined.api.minecraft.patch.jarmod.JarModAgentPatcher import xyz.wagyourtail.unimined.api.runs.RunConfig -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.api.unimined import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider import xyz.wagyourtail.unimined.internal.minecraft.patch.forge.fg3.mcpconfig.SubprocessExecutor @@ -104,7 +104,7 @@ open class JarModAgentMinecraftTransformer( //TODO: add mods to priority classpath, and resolve their jma.transformers } - override fun beforeRemapJarTask(remapJarTask: RemapJarTask, input: Path): Path { + override fun beforeRemapJarTask(remapJarTask: AbstractRemapJarTask, input: Path): Path { remapJarTask.mixinRemap { enableJarModAgent() } diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/merged/MergedMinecraftTransformer.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/merged/MergedMinecraftTransformer.kt index 5c3b024d..27e6af14 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/merged/MergedMinecraftTransformer.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/patch/merged/MergedMinecraftTransformer.kt @@ -16,7 +16,7 @@ import xyz.wagyourtail.unimined.api.minecraft.patch.forge.NeoForgedPatcher import xyz.wagyourtail.unimined.api.minecraft.patch.jarmod.JarModAgentPatcher import xyz.wagyourtail.unimined.api.minecraft.patch.rift.RiftPatcher import xyz.wagyourtail.unimined.api.runs.RunConfig -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.internal.minecraft.MinecraftProvider import xyz.wagyourtail.unimined.internal.minecraft.patch.AbstractMinecraftTransformer import xyz.wagyourtail.unimined.api.minecraft.MinecraftJar @@ -34,8 +34,6 @@ import xyz.wagyourtail.unimined.internal.minecraft.patch.jarmod.JarModAgentMinec import xyz.wagyourtail.unimined.internal.minecraft.patch.rift.RiftMinecraftTransformer import xyz.wagyourtail.unimined.internal.minecraft.resolver.Library import xyz.wagyourtail.unimined.util.FinalizeOnRead -import xyz.wagyourtail.unimined.util.MustSet -import java.nio.file.FileSystem import java.nio.file.Path class MergedMinecraftTransformer(project: Project, provider: MinecraftProvider): AbstractMinecraftTransformer(project, provider, "merged"), MergedPatcher { @@ -77,7 +75,7 @@ class MergedMinecraftTransformer(project: Project, provider: MinecraftProvider): } } - override fun beforeRemapJarTask(remapJarTask: RemapJarTask, input: Path): Path { + override fun beforeRemapJarTask(remapJarTask: AbstractRemapJarTask, input: Path): Path { return patchers.fold(input) { acc, patcher -> patcher.beforeRemapJarTask(remapJarTask, acc) } @@ -91,7 +89,7 @@ class MergedMinecraftTransformer(project: Project, provider: MinecraftProvider): patchers.forEach { it.afterEvaluate() } } - override fun afterRemapJarTask(remapJarTask: RemapJarTask, output: Path) { + override fun afterRemapJarTask(remapJarTask: AbstractRemapJarTask, output: Path) { patchers.forEach { it.afterRemapJarTask(remapJarTask, output) } } diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/AbstractRemapJarTask.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/AbstractRemapJarTaskImpl.kt similarity index 88% rename from src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/AbstractRemapJarTask.kt rename to src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/AbstractRemapJarTaskImpl.kt index 07afdc28..d967545a 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/AbstractRemapJarTask.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/AbstractRemapJarTaskImpl.kt @@ -5,7 +5,7 @@ import org.gradle.api.tasks.TaskAction import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree import xyz.wagyourtail.unimined.api.mapping.mixin.MixinRemapOptions import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig -import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask +import xyz.wagyourtail.unimined.api.minecraft.task.AbstractRemapJarTask import xyz.wagyourtail.unimined.util.FinalizeOnRead import xyz.wagyourtail.unimined.util.LazyMutable import xyz.wagyourtail.unimined.util.getField @@ -16,28 +16,28 @@ import javax.inject.Inject import kotlin.io.path.* @Suppress("UNCHECKED_CAST") -abstract class AbstractRemapJarTask @Inject constructor(@get:Internal val provider: MinecraftConfig): RemapJarTask() { +abstract class AbstractRemapJarTaskImpl @Inject constructor(@get:Internal val provider: MinecraftConfig): AbstractRemapJarTask() { @get:Internal protected var mixinRemapOptions: MixinRemapOptions.() -> Unit by FinalizeOnRead {} override fun devNamespace(namespace: String) { - val delegate: FinalizeOnRead = RemapJarTask::class.getField("devNamespace")!!.getDelegate(this) as FinalizeOnRead + val delegate: FinalizeOnRead = AbstractRemapJarTask::class.getField("devNamespace")!!.getDelegate(this) as FinalizeOnRead delegate.setValueIntl(LazyMutable { provider.mappings.getNamespace(namespace) }) } override fun devFallbackNamespace(namespace: String) { - val delegate: FinalizeOnRead = RemapJarTask::class.getField("devFallbackNamespace")!!.getDelegate(this) as FinalizeOnRead + val delegate: FinalizeOnRead = AbstractRemapJarTask::class.getField("devFallbackNamespace")!!.getDelegate(this) as FinalizeOnRead delegate.setValueIntl(LazyMutable { provider.mappings.getNamespace(namespace) }) } override fun prodNamespace(namespace: String) { - val delegate: FinalizeOnRead = RemapJarTask::class.getField("prodNamespace")!!.getDelegate(this) as FinalizeOnRead + val delegate: FinalizeOnRead = AbstractRemapJarTask::class.getField("prodNamespace")!!.getDelegate(this) as FinalizeOnRead delegate.setValueIntl(LazyMutable { provider.mappings.getNamespace(namespace) }) } override fun mixinRemap(action: MixinRemapOptions.() -> Unit) { - val delegate: FinalizeOnRead Unit> = AbstractRemapJarTask::class.getField("mixinRemapOptions")!!.getDelegate(this) as FinalizeOnRead Unit> + val delegate: FinalizeOnRead Unit> = AbstractRemapJarTaskImpl::class.getField("mixinRemapOptions")!!.getDelegate(this) as FinalizeOnRead Unit> val old = delegate.value as MixinRemapOptions.() -> Unit mixinRemapOptions = { old() diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt index 6d7df484..0113f47d 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapJarTaskImpl.kt @@ -7,6 +7,7 @@ import net.fabricmc.tinyremapper.TinyRemapper import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig import xyz.wagyourtail.unimined.api.minecraft.patch.forge.ForgeLikePatcher +import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask import xyz.wagyourtail.unimined.internal.mapping.at.AccessTransformerApplier import xyz.wagyourtail.unimined.internal.mapping.aw.AccessWidenerApplier import xyz.wagyourtail.unimined.internal.mapping.extension.MixinRemapExtension @@ -16,7 +17,8 @@ import javax.inject.Inject import kotlin.io.path.createDirectories import kotlin.io.path.deleteIfExists -abstract class RemapJarTaskImpl @Inject constructor(provider: MinecraftConfig): AbstractRemapJarTask(provider) { +abstract class RemapJarTaskImpl @Inject constructor(provider: MinecraftConfig): + AbstractRemapJarTaskImpl(provider), RemapJarTask { @Suppress("UNNECESSARY_NOT_NULL_ASSERTION") override fun doRemap( diff --git a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt index 3768fac6..ceb63034 100644 --- a/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt +++ b/src/minecraft/kotlin/xyz/wagyourtail/unimined/internal/minecraft/task/RemapSourcesJarTaskImpl.kt @@ -2,6 +2,7 @@ package xyz.wagyourtail.unimined.internal.minecraft.task import xyz.wagyourtail.unimined.api.mapping.MappingNamespaceTree import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig +import xyz.wagyourtail.unimined.api.minecraft.task.RemapSourcesJarTask import xyz.wagyourtail.unimined.util.deleteRecursively import java.nio.file.Path import java.util.jar.JarEntry @@ -10,7 +11,8 @@ import java.util.zip.Deflater import javax.inject.Inject import kotlin.io.path.* -abstract class RemapSourcesJarTaskImpl @Inject constructor(provider: MinecraftConfig): AbstractRemapJarTask(provider) { +abstract class RemapSourcesJarTaskImpl @Inject constructor(provider: MinecraftConfig): + AbstractRemapJarTaskImpl(provider), RemapSourcesJarTask { @OptIn(ExperimentalPathApi::class) override fun doRemap( from: Path, From e9b97c617243c63b760967ed2c8dbc14de4d9883 Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sun, 20 Oct 2024 10:47:29 -0500 Subject: [PATCH 12/13] fix null input tag --- .../mapping/extension/PerInputTagExtension.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/mapping/kotlin/xyz/wagyourtail/unimined/internal/mapping/extension/PerInputTagExtension.kt b/src/mapping/kotlin/xyz/wagyourtail/unimined/internal/mapping/extension/PerInputTagExtension.kt index ba930488..a45f4a61 100644 --- a/src/mapping/kotlin/xyz/wagyourtail/unimined/internal/mapping/extension/PerInputTagExtension.kt +++ b/src/mapping/kotlin/xyz/wagyourtail/unimined/internal/mapping/extension/PerInputTagExtension.kt @@ -16,12 +16,12 @@ abstract class PerInputTagExtension object SKIP companion object { - fun getInputTag(cls: TrClass): List? { - if (cls !is ClassInstance) return null + fun getInputTag(cls: TrClass): List { + if (cls !is ClassInstance) return listOf(null) // InputTag[] getInputTags() ClassInstance::class.java.getDeclaredMethod("getInputTags").apply { isAccessible = true - val arr = (invoke(cls) as Array?) ?: return null + val arr = (invoke(cls) as Array?) ?: return listOf(null) return arr.toList() } } @@ -73,14 +73,12 @@ abstract class PerInputTagExtension private fun preApplyVisitor(cls: TrClass, next: ClassVisitor): ClassVisitor { val tags = getInputTag(cls) - return tags?.reduce(next) { ni -> inputTagExtensions[this]!!.preApplyVisitor(cls, ni) } - ?: inputTagExtensions[SKIP]!!.preApplyVisitor(cls, next) + return tags.reduce(next) { ni -> inputTagExtensions[this ?: SKIP]!!.preApplyVisitor(cls, ni) } } private fun postApplyVisitor(cls: TrClass, next: ClassVisitor): ClassVisitor { val tags = getInputTag(cls) - return tags?.reduce(next) { ni -> inputTagExtensions[this]!!.postApplyVisitor(cls, ni) } - ?: inputTagExtensions[SKIP]!!.postApplyVisitor(cls, next) + return tags.reduce(next) { ni -> inputTagExtensions[this ?: SKIP]!!.postApplyVisitor(cls, ni) } } fun insertExtra(tag: InputTag, fs: FileSystem) { From 55bc832ae27d0500fb1385ca6b8fba6b9ee1c6af Mon Sep 17 00:00:00 2001 From: Wagyourtail Date: Sun, 20 Oct 2024 10:57:50 -0500 Subject: [PATCH 13/13] fix actions --- .github/workflows/build.yml | 6 +++--- .github/workflows/build_snapshot.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8d02afd0..62f844d0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -6,10 +6,10 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v4 with: distribution: 'adopt' java-version: '17' @@ -20,7 +20,7 @@ jobs: - name: Publish run: ./gradlew publish -Pmvn.user=${{ secrets.MAVEN_USER }} -Pmvn.key=${{ secrets.MAVEN_TOKEN }} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: Unimined Artifacts path: ./build/libs/ \ No newline at end of file diff --git a/.github/workflows/build_snapshot.yml b/.github/workflows/build_snapshot.yml index 7adca118..6a689f75 100644 --- a/.github/workflows/build_snapshot.yml +++ b/.github/workflows/build_snapshot.yml @@ -9,10 +9,10 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: distribution: 'temurin' java-version: '17' @@ -24,7 +24,7 @@ jobs: - name: Publish run: ./gradlew publish -Pversion_snapshot -Pmvn.user=${{ secrets.MAVEN_USER }} -Pmvn.key=${{ secrets.MAVEN_TOKEN }} -x test - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: Unimined Snapshot Artifacts path: ./build/libs/