diff --git a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/JVMDowngraderExtension.kt b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/JVMDowngraderExtension.kt index 5f5259c..651aec8 100644 --- a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/JVMDowngraderExtension.kt +++ b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/JVMDowngraderExtension.kt @@ -10,6 +10,7 @@ import xyz.wagyourtail.jvmdg.ClassDowngrader import xyz.wagyourtail.jvmdg.compile.ZipDowngrader import xyz.wagyourtail.jvmdg.gradle.flags.DowngradeFlags import xyz.wagyourtail.jvmdg.gradle.flags.ShadeFlags +import xyz.wagyourtail.jvmdg.gradle.flags.convention import xyz.wagyourtail.jvmdg.gradle.flags.toFlags import xyz.wagyourtail.jvmdg.gradle.task.DowngradeJar import xyz.wagyourtail.jvmdg.gradle.task.ShadeJar @@ -78,21 +79,6 @@ abstract class JVMDowngraderExtension @Inject constructor(@get:Internal val proj multiReleaseVersions.convention(emptySet()).finalizeValueOnRead() } - fun convention(flags: ShadeFlags) { - convention(flags as DowngradeFlags) - flags.shadePath.convention(shadePath).finalizeValueOnRead() - flags.shadeInlining.convention(shadeInlining).finalizeValueOnRead() - } - - fun convention(flags: DowngradeFlags) { - flags.downgradeTo.convention(downgradeTo).finalizeValueOnRead() - flags.apiJar.convention(apiJar).finalizeValueOnRead() - flags.quiet.convention(quiet).finalizeValueOnRead() - flags.debug.convention(debug).finalizeValueOnRead() - flags.debugSkipStub.convention(debugSkipStub).finalizeValueOnRead() - flags.debugSkipStubs.convention(debugSkipStubs).finalizeValueOnRead() - } - @get:Internal internal val downgradedApis = defaultedMapOf> { version -> val jars = mutableSetOf() @@ -131,7 +117,7 @@ abstract class JVMDowngraderExtension @Inject constructor(@get:Internal val proj spec.to.attribute(artifactType, "jar").attribute(downgradeAttr, true).attribute(shadeAttr, false) spec.parameters { - this@JVMDowngraderExtension.convention(it) + it.convention(this@JVMDowngraderExtension) config(it) javaVersion = it.downgradeTo.get() } @@ -151,7 +137,7 @@ abstract class JVMDowngraderExtension @Inject constructor(@get:Internal val proj spec.to.attribute(artifactType, "jar").attribute(shadeAttr, true).attribute(downgradeAttr, true) spec.parameters { - this@JVMDowngraderExtension.convention(it) + it.convention(this@JVMDowngraderExtension) config(it) } } diff --git a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/flags/toFlags.kt b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/flags/toFlags.kt index e81c087..5bf33e2 100644 --- a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/flags/toFlags.kt +++ b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/flags/toFlags.kt @@ -9,20 +9,40 @@ import xyz.wagyourtail.jvmdg.version.map.FullyQualifiedMemberNameAndDesc fun DowngradeFlags.toFlags(): Flags { val flags = Flags() flags.api = apiJar.orNull - flags.quiet = quiet.getOrElse(false) - flags.logAnsiColors = logAnsiColors.getOrElse(true) - flags.logLevel = Logger.Level.valueOf(logLevel.getOrElse("INFO").uppercase()) - flags.printDebug = debug.getOrElse(false) - flags.classVersion = downgradeTo.getOrElse(JavaVersion.VERSION_1_8).toOpcode() - flags.debugSkipStub = debugSkipStub.getOrElse(emptySet()).map { FullyQualifiedMemberNameAndDesc.of(it) }.toSet() + flags.quiet = quiet.getOrElse(flags.quiet) + flags.logAnsiColors = logAnsiColors.getOrElse(flags.logAnsiColors) + flags.logLevel = Logger.Level.valueOf(logLevel.getOrElse(flags.logLevel.name).uppercase()) + flags.printDebug = debug.getOrElse(flags.printDebug) + flags.classVersion = downgradeTo.getOrElse(JavaVersion.forClassVersion(flags.classVersion)).toOpcode() + flags.debugSkipStub = debugSkipStub.getOrElse(flags.debugSkipStub.map { it.toString() }.toSet()).map { FullyQualifiedMemberNameAndDesc.of(it) }.toSet() flags.debugSkipStubs = debugSkipStubs.getOrElse(emptySet()).map { it.toOpcode() }.toSet() - ignoreWarningsIn.getOrElse(emptyList()).forEach { flags.addIgnore(it) } - flags.debugDumpClasses = debugDumpClasses.getOrElse(false) - flags.multiReleaseOriginal = multiReleaseOriginal.getOrElse(false) - flags.multiReleaseVersions = multiReleaseVersions.getOrElse(emptySet()).map { it.toOpcode() }.toSet() - flags.downgradeFromMultiReleases = downgradeFromMultiReleases.getOrElse(false) + ignoreWarningsIn.getOrElse(flags.ignoreWarningsIn.map { it.key + "*".repeat(it.value.ordinal) }).forEach { flags.addIgnore(it) } + flags.debugDumpClasses = debugDumpClasses.getOrElse(flags.debugDumpClasses) + flags.multiReleaseOriginal = multiReleaseOriginal.getOrElse(flags.multiReleaseOriginal) + flags.multiReleaseVersions = multiReleaseVersions.getOrElse(flags.multiReleaseVersions.map { JavaVersion.forClassVersion(it) }.toSet()).map { it.toOpcode() }.toSet() + flags.downgradeFromMultiReleases = downgradeFromMultiReleases.getOrElse(flags.downgradeFromMultiReleases) if (this is ShadeFlags) { - flags.shadeInlining = shadeInlining.get() + flags.shadeInlining = shadeInlining.getOrElse(flags.shadeInlining) } return flags +} + +fun DowngradeFlags.convention(target: DowngradeFlags) { + apiJar.convention(target.apiJar) + quiet.convention(target.quiet) + logAnsiColors.convention(target.logAnsiColors) + logLevel.convention(target.logLevel) + debug.convention(target.debug) + downgradeTo.convention(target.downgradeTo) + debugSkipStub.convention(target.debugSkipStub) + debugSkipStubs.convention(target.debugSkipStubs) + ignoreWarningsIn.convention(target.ignoreWarningsIn) + debugDumpClasses.convention(target.debugDumpClasses) + multiReleaseOriginal.convention(target.multiReleaseOriginal) + multiReleaseVersions.convention(target.multiReleaseVersions) + downgradeFromMultiReleases.convention(target.downgradeFromMultiReleases) + if (this is ShadeFlags && target is ShadeFlags) { + shadeInlining.convention(target.shadeInlining) + shadePath.convention(target.shadePath) + } } \ No newline at end of file diff --git a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/DowngradeJar.kt b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/DowngradeJar.kt index 5e413d4..b3d850f 100644 --- a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/DowngradeJar.kt +++ b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/DowngradeJar.kt @@ -10,6 +10,7 @@ import xyz.wagyourtail.jvmdg.ClassDowngrader import xyz.wagyourtail.jvmdg.compile.ZipDowngrader import xyz.wagyourtail.jvmdg.gradle.JVMDowngraderExtension import xyz.wagyourtail.jvmdg.gradle.flags.DowngradeFlags +import xyz.wagyourtail.jvmdg.gradle.flags.convention import xyz.wagyourtail.jvmdg.gradle.flags.toFlags import xyz.wagyourtail.jvmdg.util.FinalizeOnRead import xyz.wagyourtail.jvmdg.util.LazyMutable @@ -37,7 +38,7 @@ abstract class DowngradeJar: Jar(), DowngradeFlags { group = "JVMDowngrader" description = "Downgrades the jar to the specified version" - jvmdg.convention(this) + convention(jvmdg) } @TaskAction diff --git a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/ShadeJar.kt b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/ShadeJar.kt index fd46e0e..06555ec 100644 --- a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/ShadeJar.kt +++ b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/ShadeJar.kt @@ -9,6 +9,7 @@ import org.gradle.api.tasks.bundling.Jar import xyz.wagyourtail.jvmdg.compile.ApiShader import xyz.wagyourtail.jvmdg.gradle.JVMDowngraderExtension import xyz.wagyourtail.jvmdg.gradle.flags.ShadeFlags +import xyz.wagyourtail.jvmdg.gradle.flags.convention import xyz.wagyourtail.jvmdg.gradle.flags.toFlags import xyz.wagyourtail.jvmdg.util.deleteIfExists import xyz.wagyourtail.jvmdg.util.readZipInputStreamFor @@ -31,7 +32,7 @@ abstract class ShadeJar: Jar(), ShadeFlags { group = "JVMDowngrader" description = "Downgrades the jar to the specified version" - jvmdg.convention(this) + convention(jvmdg) } @TaskAction diff --git a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/files/DowngradeFiles.kt b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/files/DowngradeFiles.kt index 52c015b..c1397ea 100644 --- a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/files/DowngradeFiles.kt +++ b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/files/DowngradeFiles.kt @@ -10,6 +10,7 @@ import xyz.wagyourtail.jvmdg.ClassDowngrader import xyz.wagyourtail.jvmdg.compile.PathDowngrader import xyz.wagyourtail.jvmdg.gradle.JVMDowngraderExtension import xyz.wagyourtail.jvmdg.gradle.flags.DowngradeFlags +import xyz.wagyourtail.jvmdg.gradle.flags.convention import xyz.wagyourtail.jvmdg.gradle.flags.toFlags import xyz.wagyourtail.jvmdg.util.FinalizeOnRead import xyz.wagyourtail.jvmdg.util.LazyMutable @@ -62,7 +63,7 @@ abstract class DowngradeFiles: ConventionTask(), DowngradeFlags { } init { - jvmdg.convention(this) + convention(jvmdg) } @TaskAction diff --git a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/files/ShadeFiles.kt b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/files/ShadeFiles.kt index 5dd9b48..5f8b320 100644 --- a/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/files/ShadeFiles.kt +++ b/gradle-plugin/src/main/kotlin/xyz/wagyourtail/jvmdg/gradle/task/files/ShadeFiles.kt @@ -8,6 +8,7 @@ import org.gradle.api.tasks.TaskAction import xyz.wagyourtail.jvmdg.compile.ApiShader import xyz.wagyourtail.jvmdg.gradle.JVMDowngraderExtension import xyz.wagyourtail.jvmdg.gradle.flags.ShadeFlags +import xyz.wagyourtail.jvmdg.gradle.flags.convention import xyz.wagyourtail.jvmdg.gradle.flags.toFlags import xyz.wagyourtail.jvmdg.util.FinalizeOnRead import xyz.wagyourtail.jvmdg.util.MustSet @@ -47,7 +48,7 @@ abstract class ShadeFiles: ConventionTask(), ShadeFlags { } init { - jvmdg.convention(this) + convention(jvmdg) } // fun setShadePath(path: String) {