Repository: GradleUp/shadow
Pull request #1075 (2024-12-01 14:56:29)

Overload `RelocateClassContext` and `RelocatePathContext`


Patch:
diff --git a/api/shadow.api b/api/shadow.api
index eaf0e5f6..0b2dea4c 100644
--- a/api/shadow.api
+++ b/api/shadow.api
@@ -117,7 +117,9 @@ public abstract interface annotation class com/github/jengelman/gradle/plugins/s
 
 public final class com/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext {
 	public static final field Companion Lcom/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext$Companion;
+	public fun <init> (Ljava/lang/String;)V
 	public fun <init> (Ljava/lang/String;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;)V
+	public synthetic fun <init> (Ljava/lang/String;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
 	public static final fun builder ()Lcom/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext$Builder;
 	public final fun component1 ()Ljava/lang/String;
 	public final fun component2 ()Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;
@@ -143,7 +145,9 @@ public final class com/github/jengelman/gradle/plugins/shadow/relocation/Relocat
 
 public final class com/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext {
 	public static final field Companion Lcom/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext$Companion;
+	public fun <init> (Ljava/lang/String;)V
 	public fun <init> (Ljava/lang/String;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;)V
+	public synthetic fun <init> (Ljava/lang/String;Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
 	public static final fun builder ()Lcom/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext$Builder;
 	public final fun component1 ()Ljava/lang/String;
 	public final fun component2 ()Lcom/github/jengelman/gradle/plugins/shadow/ShadowStats;
diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext.kt
index 72f8c862..b30c1c31 100644
--- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext.kt
+++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocateClassContext.kt
@@ -2,9 +2,9 @@ package com.github.jengelman.gradle.plugins.shadow.relocation
 
 import com.github.jengelman.gradle.plugins.shadow.ShadowStats
 
-public data class RelocateClassContext(
+public data class RelocateClassContext @JvmOverloads constructor(
   val className: String,
-  val stats: ShadowStats,
+  val stats: ShadowStats = ShadowStats(),
 ) {
   public class Builder {
     private var className = ""
diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext.kt
index 63e4655c..ff8ca328 100644
--- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext.kt
+++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/RelocatePathContext.kt
@@ -2,9 +2,9 @@ package com.github.jengelman.gradle.plugins.shadow.relocation
 
 import com.github.jengelman.gradle.plugins.shadow.ShadowStats
 
-public data class RelocatePathContext(
+public data class RelocatePathContext @JvmOverloads constructor(
   val path: String,
-  val stats: ShadowStats,
+  val stats: ShadowStats = ShadowStats(),
 ) {
   public class Builder {
     private var path = ""


Test patch:
diff --git a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorTest.kt b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorTest.kt
index ad8d042b..bf7c6cf3 100644
--- a/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorTest.kt
+++ b/src/test/kotlin/com/github/jengelman/gradle/plugins/shadow/relocation/SimpleRelocatorTest.kt
@@ -142,48 +142,48 @@ class SimpleRelocatorTest {
   @Test
   fun testCanRelocateAbsClassPath() {
     val relocator = SimpleRelocator("org.apache.velocity", "org.apache.momentum")
-    assertThat(relocator.relocatePath(pathContext("/org/apache/velocity/mass.properties")))
+    assertThat(relocator.relocatePath("/org/apache/velocity/mass.properties"))
       .isEqualTo("/org/apache/momentum/mass.properties")
   }
 
   @Test
   fun testRelocatePath() {
     var relocator = SimpleRelocator("org.foo")
-    assertThat(relocator.relocatePath(pathContext("org/foo/bar/Class.class")))
+    assertThat(relocator.relocatePath("org/foo/bar/Class.class"))
       .isEqualTo("hidden/org/foo/bar/Class.class")
 
     relocator = SimpleRelocator("org.foo", "private.stuff")
-    assertThat(relocator.relocatePath(pathContext("org/foo/bar/Class.class")))
+    assertThat(relocator.relocatePath("org/foo/bar/Class.class"))
       .isEqualTo("private/stuff/bar/Class.class")
   }
 
   @Test
   fun testRelocateClass() {
     var relocator = SimpleRelocator("org.foo")
-    assertThat(relocator.relocateClass(classContext()))
+    assertThat(relocator.relocateClass("org.foo.bar.Class"))
       .isEqualTo("hidden.org.foo.bar.Class")
 
     relocator = SimpleRelocator("org.foo", "private.stuff")
-    assertThat(relocator.relocateClass(classContext()))
+    assertThat(relocator.relocateClass("org.foo.bar.Class"))
       .isEqualTo("private.stuff.bar.Class")
   }
 
   @Test
   fun testRelocateRawString() {
     var relocator = SimpleRelocator("Lorg/foo", "Lhidden/org/foo", _rawString = true)
-    assertThat(relocator.relocatePath(pathContext("(I)Lorg/foo/bar/Class")))
+    assertThat(relocator.relocatePath("(I)Lorg/foo/bar/Class"))
       .isEqualTo("(I)Lhidden/org/foo/bar/Class")
 
     relocator = SimpleRelocator("^META-INF/org.foo.xml\$", "META-INF/hidden.org.foo.xml", _rawString = true)
-    assertThat(relocator.relocatePath(pathContext("META-INF/org.foo.xml")))
+    assertThat(relocator.relocatePath("META-INF/org.foo.xml"))
       .isEqualTo("META-INF/hidden.org.foo.xml")
   }
 
-  private fun pathContext(path: String): RelocatePathContext {
-    return RelocatePathContext.builder().path(path).build()
+  private fun SimpleRelocator.relocatePath(path: String): String {
+    return relocatePath(RelocatePathContext(path))
   }
 
-  private fun classContext(className: String = "org.foo.bar.Class"): RelocateClassContext {
-    return RelocateClassContext.builder().className(className).build()
+  private fun SimpleRelocator.relocateClass(className: String): String {
+    return relocateClass(RelocateClassContext(className))
   }
 }