Skip to content

Commit

Permalink
fix convention & defaults.
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Dec 7, 2024
1 parent e28efaa commit 08a74da
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<JavaVersion, Set<File>> { version ->
val jars = mutableSetOf<File>()
Expand Down Expand Up @@ -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()
}
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -62,7 +63,7 @@ abstract class DowngradeFiles: ConventionTask(), DowngradeFlags {
}

init {
jvmdg.convention(this)
convention(jvmdg)
}

@TaskAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,7 +48,7 @@ abstract class ShadeFiles: ConventionTask(), ShadeFlags {
}

init {
jvmdg.convention(this)
convention(jvmdg)
}

// fun setShadePath(path: String) {
Expand Down

0 comments on commit 08a74da

Please sign in to comment.