Skip to content

Commit

Permalink
Add .md support to the Apache License and Notice transformers (#1041)
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler authored Nov 25, 2024
1 parent 28a6207 commit 853e5d8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/docs/changes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

## [Unreleased]

**Added**

- Add .md support to the Apache License and Notice transformers. ([#1041](https://github.com/GradleUp/shadow/pull/1041))

**Changed**

- **BREAKING CHANGE:** Rewrite this plugin in Kotlin. ([#1012](https://github.com/GradleUp/shadow/pull/1012))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ public open class ApacheLicenseResourceTransformer : Transformer by NoOpTransfor
override fun canTransformResource(element: FileTreeElement): Boolean {
val path = element.relativePath.pathString
return LICENSE_PATH.equals(path, ignoreCase = true) ||
LICENSE_TXT_PATH.regionMatches(0, path, 0, LICENSE_TXT_PATH.length, ignoreCase = true)
LICENSE_TXT_PATH.regionMatches(0, path, 0, LICENSE_TXT_PATH.length, ignoreCase = true) ||
LICENSE_MD_PATH.regionMatches(0, path, 0, LICENSE_MD_PATH.length, ignoreCase = true)
}

private companion object {
private const val LICENSE_PATH = "META-INF/LICENSE"
private const val LICENSE_TXT_PATH = "META-INF/LICENSE.txt"
private const val LICENSE_MD_PATH = "META-INF/LICENSE.md"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public open class ApacheNoticeResourceTransformer : Transformer {

override fun canTransformResource(element: FileTreeElement): Boolean {
val path = element.relativePath.pathString
return NOTICE_PATH.equals(path, ignoreCase = true) || NOTICE_TXT_PATH.equals(path, ignoreCase = true)
return NOTICE_PATH.equals(path, ignoreCase = true) ||
NOTICE_TXT_PATH.equals(path, ignoreCase = true) ||
NOTICE_MD_PATH.equals(path, ignoreCase = true)
}

override fun transform(context: TransformerContext) {
Expand Down Expand Up @@ -174,5 +176,6 @@ public open class ApacheNoticeResourceTransformer : Transformer {
private companion object {
private const val NOTICE_PATH = "META-INF/NOTICE"
private const val NOTICE_TXT_PATH = "META-INF/NOTICE.txt"
private const val NOTICE_MD_PATH = "META-INF/NOTICE.md"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class ApacheLicenseResourceTransformerTest extends TransformerTestSupport<Apache
assertTrue(transformer.canTransformResource(getFileElement("META-INF/LICENSE")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/LICENSE.TXT")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/License.txt")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/LICENSE.md")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/License.md")))
assertFalse(transformer.canTransformResource(getFileElement("META-INF/MANIFEST.MF")))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ class ApacheNoticeResourceTransformerParameterTests extends TransformerTestSuppo
stats = new ShadowStats()
}

@Test
void testCanTransformResource() {
assertTrue(transformer.canTransformResource(getFileElement("META-INF/NOTICE")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/NOTICE.TXT")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/Notice.txt")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/NOTICE.md")))
assertTrue(transformer.canTransformResource(getFileElement("META-INF/Notice.md")))
}

@Test
void testNoParametersShouldNotThrowNullPointerWhenNoInput() {
processAndFailOnNullPointer("")
Expand Down

0 comments on commit 853e5d8

Please sign in to comment.