Skip to content

Commit a304484

Browse files
Gooolersnazy
andauthored
Support overriding output path of ApacheNoticeResourceTransformer (#1851)
* Add `outputPath` for `ApacheNoticeResourceTransformer` * Update src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformer.kt Co-authored-by: Robert Stupp <[email protected]> * Update changelog * Dump API * Test `overrideOutputPathOfNoticeFile` --------- Co-authored-by: Robert Stupp <[email protected]>
1 parent 29a06a5 commit a304484

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

api/shadow.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ public class com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNotic
266266
public final fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
267267
public fun getOrganizationName ()Lorg/gradle/api/provider/Property;
268268
public fun getOrganizationURL ()Lorg/gradle/api/provider/Property;
269+
public fun getOutputPath ()Lorg/gradle/api/provider/Property;
269270
public fun getPreamble1 ()Lorg/gradle/api/provider/Property;
270271
public fun getPreamble2 ()Lorg/gradle/api/provider/Property;
271272
public fun getPreamble3 ()Lorg/gradle/api/provider/Property;

docs/changes/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Expose `patternSet` of `ServiceFileTransformer` as `public`. ([#1849](https://github.com/GradleUp/shadow/pull/1849))
1010
- Expose `patternSet` of `ApacheLicenseResourceTransformer` as `public`. ([#1850](https://github.com/GradleUp/shadow/pull/1850))
1111
- Expose `patternSet` of `ApacheNoticeResourceTransformer` as `public`. ([#1850](https://github.com/GradleUp/shadow/pull/1850))
12+
- Support overriding output path of `ApacheNoticeResourceTransformer`. ([#1851](https://github.com/GradleUp/shadow/pull/1851))
1213

1314
### Changed
1415

src/functionalTest/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/TransformersTest.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,45 @@ class TransformersTest : BaseTransformerTest() {
251251
}
252252
}
253253

254+
@Test
255+
fun overrideOutputPathOfNoticeFile() {
256+
val noticeEntry = "META-INF/NOTICE"
257+
val customNoticeEntry = "META-INF/CUSTOM_NOTICE"
258+
val one = buildJarOne {
259+
insert(noticeEntry, "Notice from A")
260+
}
261+
val two = buildJarTwo {
262+
insert(noticeEntry, "Notice from B")
263+
}
264+
projectScript.appendText(
265+
transform<ApacheNoticeResourceTransformer>(
266+
dependenciesBlock = implementationFiles(one, two),
267+
transformerBlock = "addHeader = false; outputPath = '$customNoticeEntry'",
268+
),
269+
)
270+
271+
runWithSuccess(shadowJarPath)
272+
273+
assertThat(outputShadowedJar).useAll {
274+
containsOnly(
275+
customNoticeEntry,
276+
*manifestEntries,
277+
)
278+
getContent(customNoticeEntry).isEqualTo(
279+
"""
280+
Copyright 2006-2025 The Apache Software Foundation
281+
282+
This product includes software developed at
283+
The Apache Software Foundation (https://www.apache.org/).
284+
285+
Notice from A
286+
287+
Notice from B
288+
""".trimIndent(),
289+
)
290+
}
291+
}
292+
254293
@ParameterizedTest
255294
@MethodSource("transformerConfigProvider")
256295
fun otherTransformers(pair: Pair<String, KClass<*>>) {

src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformer.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ public open class ApacheNoticeResourceTransformer(
7676
@get:Input
7777
public open val charsetName: Property<String> = objectFactory.property(Charsets.UTF_8.name())
7878

79+
/**
80+
* The output path of the `NOTICE` file.
81+
*
82+
* Defaults to `META-INF/NOTICE`.
83+
*/
84+
@get:Input
85+
public open val outputPath: Property<String> = objectFactory.property(NOTICE_PATH)
86+
7987
@Inject
8088
public constructor(objectFactory: ObjectFactory) : this(
8189
objectFactory,
@@ -190,7 +198,7 @@ public open class ApacheNoticeResourceTransformer(
190198
}
191199
}
192200

193-
os.putNextEntry(zipEntry(NOTICE_PATH, preserveFileTimestamps))
201+
os.putNextEntry(zipEntry(outputPath.get(), preserveFileTimestamps))
194202
os.write(sb.toString().trim().toByteArray(charset))
195203
os.closeEntry()
196204

0 commit comments

Comments
 (0)