Repository: GradleUp/shadow
Pull request #1282 (2025-02-26 08:19:00)

Unify jar `Attributes` usages


Patch:
diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestResourceTransformer.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestResourceTransformer.kt
index 7e2ca172..9e03e330 100644
--- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestResourceTransformer.kt
+++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ManifestResourceTransformer.kt
@@ -1,10 +1,11 @@
 package com.github.jengelman.gradle.plugins.shadow.transformers
 
+import com.github.jengelman.gradle.plugins.shadow.internal.mainClassAttributeKey
 import com.github.jengelman.gradle.plugins.shadow.internal.mapProperty
 import com.github.jengelman.gradle.plugins.shadow.internal.property
 import com.github.jengelman.gradle.plugins.shadow.internal.zipEntry
 import java.io.IOException
-import java.util.jar.Attributes
+import java.util.jar.Attributes as JarAttribute
 import java.util.jar.JarFile
 import java.util.jar.Manifest
 import javax.inject.Inject
@@ -40,7 +41,7 @@ public open class ManifestResourceTransformer @Inject constructor(
 
   @get:Optional
   @get:Input
-  public open val manifestEntries: MapProperty<String, Attributes> = objectFactory.mapProperty()
+  public open val manifestEntries: MapProperty<String, JarAttribute> = objectFactory.mapProperty()
 
   override fun canTransformResource(element: FileTreeElement): Boolean {
     return JarFile.MANIFEST_NAME.equals(element.path, ignoreCase = true)
@@ -70,17 +71,17 @@ public open class ManifestResourceTransformer @Inject constructor(
 
     val attributes = manifest!!.mainAttributes
     mainClass.orNull?.let {
-      attributes[Attributes.Name.MAIN_CLASS] = it
+      attributes[mainClassAttributeKey] = it
     }
     manifestEntries.get().forEach { (key, value) ->
-      attributes[Attributes.Name(key)] = value
+      attributes[JarAttribute.Name(key)] = value
     }
 
     os.putNextEntry(zipEntry(JarFile.MANIFEST_NAME, preserveFileTimestamps))
     manifest!!.write(os)
   }
 
-  public open fun attributes(attributes: Map<String, Attributes>): ManifestResourceTransformer = apply {
+  public open fun attributes(attributes: Map<String, JarAttribute>): ManifestResourceTransformer = apply {
     manifestEntries.putAll(attributes)
   }
 


Test patch:
diff --git a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt
index 19a57cec..62dca788 100644
--- a/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt
+++ b/src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt
@@ -11,7 +11,7 @@ import com.github.jengelman.gradle.plugins.shadow.internal.requireResourceAsText
 import com.github.jengelman.gradle.plugins.shadow.util.Issue
 import com.github.jengelman.gradle.plugins.shadow.util.containsEntries
 import com.github.jengelman.gradle.plugins.shadow.util.getStream
-import java.util.jar.Attributes
+import java.util.jar.Attributes as JarAttribute
 import kotlin.io.path.appendText
 import kotlin.io.path.writeText
 import kotlin.reflect.KClass
@@ -152,7 +152,7 @@ class TransformersTest : BaseTransformerTest() {
   }
 
   private fun commonAssertions(
-    mainAttributesBlock: Attributes.() -> Unit = {
+    mainAttributesBlock: JarAttribute.() -> Unit = {
       assertThat(getValue(TEST_ENTRY_ATTR_KEY)).isEqualTo("PASSED")
       assertThat(getValue(mainClassAttributeKey)).isEqualTo("my.Main")
       assertThat(getValue(NEW_ENTRY_ATTR_KEY)).isEqualTo("NEW")