Repository: GradleUp/shadow
Pull request #1130 (2025-01-06 02:04:11)

Rename const values
Follow up #1129.


Patch:
diff --git a/api/shadow.api b/api/shadow.api
index bbee96bb..f25735c6 100644
--- a/api/shadow.api
+++ b/api/shadow.api
@@ -435,14 +435,14 @@ public class com/github/jengelman/gradle/plugins/shadow/transformers/DontInclude
 
 public class com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformer : com/github/jengelman/gradle/plugins/shadow/transformers/Transformer {
 	public static final field Companion Lcom/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformer$Companion;
-	public static final field EXTENSION_CLASSES_KEY Ljava/lang/String;
-	public static final field GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATH Ljava/lang/String;
-	public static final field GROOVY_LEGACY_EXTENSION_MODULE_DESCRIPTOR_PATH Ljava/lang/String;
+	public static final field KEY_EXTENSION_CLASSES Ljava/lang/String;
+	public static final field KEY_MODULE_NAME Ljava/lang/String;
+	public static final field KEY_MODULE_VERSION Ljava/lang/String;
+	public static final field KEY_STATIC_EXTENSION_CLASSES Ljava/lang/String;
 	public static final field MERGED_MODULE_NAME Ljava/lang/String;
 	public static final field MERGED_MODULE_VERSION Ljava/lang/String;
-	public static final field MODULE_NAME_KEY Ljava/lang/String;
-	public static final field MODULE_VERSION_KEY Ljava/lang/String;
-	public static final field STATIC_EXTENSION_CLASSES_KEY Ljava/lang/String;
+	public static final field PATH_GROOVY_EXTENSION_MODULE_DESCRIPTOR Ljava/lang/String;
+	public static final field PATH_LEGACY_GROOVY_EXTENSION_MODULE_DESCRIPTOR Ljava/lang/String;
 	public fun <init> ()V
 	public fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
 	public fun hasTransformedResource ()Z
diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformer.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformer.kt
index 3cfba575..e001dc5b 100644
--- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformer.kt
+++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformer.kt
@@ -36,12 +36,12 @@ public open class GroovyExtensionModuleTransformer : Transformer {
 
   override fun canTransformResource(element: FileTreeElement): Boolean {
     val path = element.relativePath.pathString
-    if (path == GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATH) {
+    if (path == PATH_GROOVY_EXTENSION_MODULE_DESCRIPTOR) {
       // Groovy 2.5+
       legacy = false
       return true
     }
-    return path == GROOVY_LEGACY_EXTENSION_MODULE_DESCRIPTOR_PATH
+    return path == PATH_LEGACY_GROOVY_EXTENSION_MODULE_DESCRIPTOR
   }
 
   override fun transform(context: TransformerContext) {
@@ -49,14 +49,14 @@ public open class GroovyExtensionModuleTransformer : Transformer {
     props.load(context.inputStream)
     props.forEach { key, value ->
       when (key as String) {
-        MODULE_NAME_KEY -> handle(key, value as String) {
+        KEY_MODULE_NAME -> handle(key, value as String) {
           module.setProperty(key, MERGED_MODULE_NAME)
         }
-        MODULE_VERSION_KEY -> handle(key, value as String) {
+        KEY_MODULE_VERSION -> handle(key, value as String) {
           module.setProperty(key, MERGED_MODULE_VERSION)
         }
-        EXTENSION_CLASSES_KEY,
-        STATIC_EXTENSION_CLASSES_KEY,
+        KEY_EXTENSION_CLASSES,
+        KEY_STATIC_EXTENSION_CLASSES,
         -> handle(key, value as String) { existingValue ->
           module.setProperty(key, "$existingValue,$value")
         }
@@ -76,7 +76,7 @@ public open class GroovyExtensionModuleTransformer : Transformer {
   override fun hasTransformedResource(): Boolean = module.isNotEmpty()
 
   override fun modifyOutputStream(os: ZipOutputStream, preserveFileTimestamps: Boolean) {
-    val name = if (legacy) GROOVY_LEGACY_EXTENSION_MODULE_DESCRIPTOR_PATH else GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATH
+    val name = if (legacy) PATH_LEGACY_GROOVY_EXTENSION_MODULE_DESCRIPTOR else PATH_GROOVY_EXTENSION_MODULE_DESCRIPTOR
     val entry = ZipEntry(name)
     entry.time = getEntryTimestamp(preserveFileTimestamps, entry.time)
     os.putNextEntry(entry)
@@ -87,14 +87,16 @@ public open class GroovyExtensionModuleTransformer : Transformer {
   }
 
   public companion object {
-    public const val GROOVY_LEGACY_EXTENSION_MODULE_DESCRIPTOR_PATH: String =
+    public const val PATH_LEGACY_GROOVY_EXTENSION_MODULE_DESCRIPTOR: String =
       "META-INF/services/org.codehaus.groovy.runtime.ExtensionModule"
-    public const val GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATH: String =
+    public const val PATH_GROOVY_EXTENSION_MODULE_DESCRIPTOR: String =
       "META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule"
-    public const val MODULE_NAME_KEY: String = "moduleName"
-    public const val MODULE_VERSION_KEY: String = "moduleVersion"
-    public const val EXTENSION_CLASSES_KEY: String = "extensionClasses"
-    public const val STATIC_EXTENSION_CLASSES_KEY: String = "staticExtensionClasses"
+
+    public const val KEY_MODULE_NAME: String = "moduleName"
+    public const val KEY_MODULE_VERSION: String = "moduleVersion"
+    public const val KEY_EXTENSION_CLASSES: String = "extensionClasses"
+    public const val KEY_STATIC_EXTENSION_CLASSES: String = "staticExtensionClasses"
+
     public const val MERGED_MODULE_NAME: String = "MergedByShadowJar"
     public const val MERGED_MODULE_VERSION: String = "1.0.0"
   }


Test patch:
diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformerTest.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformerTest.kt
index f12eae11..8838f4cd 100644
--- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformerTest.kt
+++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExtensionModuleTransformerTest.kt
@@ -2,14 +2,14 @@ package com.github.jengelman.gradle.plugins.shadow.transformers
 
 import assertk.assertThat
 import assertk.assertions.isEqualTo
-import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.EXTENSION_CLASSES_KEY
-import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATH
-import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.GROOVY_LEGACY_EXTENSION_MODULE_DESCRIPTOR_PATH
+import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.KEY_EXTENSION_CLASSES
+import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.KEY_MODULE_NAME
+import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.KEY_MODULE_VERSION
+import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.KEY_STATIC_EXTENSION_CLASSES
 import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.MERGED_MODULE_NAME
 import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.MERGED_MODULE_VERSION
-import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.MODULE_NAME_KEY
-import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.MODULE_VERSION_KEY
-import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.STATIC_EXTENSION_CLASSES_KEY
+import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.PATH_GROOVY_EXTENSION_MODULE_DESCRIPTOR
+import com.github.jengelman.gradle.plugins.shadow.transformers.GroovyExtensionModuleTransformer.Companion.PATH_LEGACY_GROOVY_EXTENSION_MODULE_DESCRIPTOR
 import java.nio.file.Path
 import java.util.Properties
 import kotlin.io.path.appendText
@@ -26,7 +26,7 @@ class GroovyExtensionModuleTransformerTest : BaseTransformerTest() {
 
     run(shadowJarTask)
 
-    val props = outputShadowJar.getContent(GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATH).toProperties()
+    val props = outputShadowJar.getContent(PATH_GROOVY_EXTENSION_MODULE_DESCRIPTOR).toProperties()
     commonAssertions(props)
   }
 
@@ -35,15 +35,15 @@ class GroovyExtensionModuleTransformerTest : BaseTransformerTest() {
     projectScriptPath.appendText(
       transform<GroovyExtensionModuleTransformer>(
         shadowJarBlock = fromJar(
-          buildJarFoo(GROOVY_LEGACY_EXTENSION_MODULE_DESCRIPTOR_PATH),
-          buildJarBar(GROOVY_LEGACY_EXTENSION_MODULE_DESCRIPTOR_PATH),
+          buildJarFoo(PATH_LEGACY_GROOVY_EXTENSION_MODULE_DESCRIPTOR),
+          buildJarBar(PATH_LEGACY_GROOVY_EXTENSION_MODULE_DESCRIPTOR),
         ),
       ),
     )
 
     run(shadowJarTask)
 
-    val props = outputShadowJar.getContent(GROOVY_LEGACY_EXTENSION_MODULE_DESCRIPTOR_PATH).toProperties()
+    val props = outputShadowJar.getContent(PATH_LEGACY_GROOVY_EXTENSION_MODULE_DESCRIPTOR).toProperties()
     commonAssertions(props)
   }
 
@@ -60,34 +60,34 @@ class GroovyExtensionModuleTransformerTest : BaseTransformerTest() {
 
     run(shadowJarTask)
 
-    val props = outputShadowJar.getContent(GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATH).toProperties()
+    val props = outputShadowJar.getContent(PATH_GROOVY_EXTENSION_MODULE_DESCRIPTOR).toProperties()
     commonAssertions(props)
   }
 
   private fun buildJarFoo(
-    path: String = GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATH,
+    path: String = PATH_GROOVY_EXTENSION_MODULE_DESCRIPTOR,
   ): Path = buildJar("foo.jar") {
     insert(
       path,
       """
-        $MODULE_NAME_KEY=foo
-        $MODULE_VERSION_KEY=1.0.5
-        $EXTENSION_CLASSES_KEY=$EXTENSION_CLASSES_FOO
-        $STATIC_EXTENSION_CLASSES_KEY=$STATIC_EXTENSION_CLASSES_FOO
+        $KEY_MODULE_NAME=foo
+        $KEY_MODULE_VERSION=1.0.5
+        $KEY_EXTENSION_CLASSES=$EXTENSION_CLASSES_FOO
+        $KEY_STATIC_EXTENSION_CLASSES=$STATIC_EXTENSION_CLASSES_FOO
       """.trimIndent(),
     )
   }
 
   private fun buildJarBar(
-    path: String = GROOVY_EXTENSION_MODULE_DESCRIPTOR_PATH,
+    path: String = PATH_GROOVY_EXTENSION_MODULE_DESCRIPTOR,
   ): Path = buildJar("bar.jar") {
     insert(
       path,
       """
-        $MODULE_NAME_KEY=bar
-        $MODULE_VERSION_KEY=2.3.5
-        $EXTENSION_CLASSES_KEY=$EXTENSION_CLASSES_BAR
-        $STATIC_EXTENSION_CLASSES_KEY=$STATIC_EXTENSION_CLASSES_BAR
+        $KEY_MODULE_NAME=bar
+        $KEY_MODULE_VERSION=2.3.5
+        $KEY_EXTENSION_CLASSES=$EXTENSION_CLASSES_BAR
+        $KEY_STATIC_EXTENSION_CLASSES=$STATIC_EXTENSION_CLASSES_BAR
       """.trimIndent(),
     )
   }
@@ -99,11 +99,11 @@ class GroovyExtensionModuleTransformerTest : BaseTransformerTest() {
     const val STATIC_EXTENSION_CLASSES_BAR = "com.acme.bar.SomeStaticExtension"
 
     fun commonAssertions(properties: Properties) {
-      assertThat(properties.getProperty(MODULE_NAME_KEY)).isEqualTo(MERGED_MODULE_NAME)
-      assertThat(properties.getProperty(MODULE_VERSION_KEY)).isEqualTo(MERGED_MODULE_VERSION)
-      assertThat(properties.getProperty(EXTENSION_CLASSES_KEY))
+      assertThat(properties.getProperty(KEY_MODULE_NAME)).isEqualTo(MERGED_MODULE_NAME)
+      assertThat(properties.getProperty(KEY_MODULE_VERSION)).isEqualTo(MERGED_MODULE_VERSION)
+      assertThat(properties.getProperty(KEY_EXTENSION_CLASSES))
         .isEqualTo("$EXTENSION_CLASSES_FOO,$EXTENSION_CLASSES_BAR")
-      assertThat(properties.getProperty(STATIC_EXTENSION_CLASSES_KEY))
+      assertThat(properties.getProperty(KEY_STATIC_EXTENSION_CLASSES))
         .isEqualTo("$STATIC_EXTENSION_CLASSES_FOO,$STATIC_EXTENSION_CLASSES_BAR")
     }
   }