Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into g/lazy-properties
Browse files Browse the repository at this point in the history
// Conflicts:
//	api/shadow.api
//	src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/ShadowApplicationPlugin.kt
//	src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowJar.kt
//	src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/ApacheNoticeResourceTransformer.kt
  • Loading branch information
Goooler committed Nov 26, 2024
2 parents 9119797 + d5e3cec commit b8f956c
Show file tree
Hide file tree
Showing 19 changed files with 57 additions and 32 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ tasks.withType<Test>().configureEach {
maxHeapSize = "1g"
}

// Add src/docs as an input directory to trigger ManualCodeSnippetTests re-run on changes.
inputs.dir(file("src/docs"))
systemProperty("shadowVersion", version)

// Required to test configuration cache in tests when using withDebug()
Expand Down
8 changes: 8 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 All @@ -11,6 +15,10 @@

- **BREAKING CHANGE:** Remove Develocity integration. ([#1013](https://github.com/GradleUp/shadow/pull/1013))

**Fixed**

- Fix single Log4j2Plugins.dat isn't included into fat jar. ([#1039](https://github.com/GradleUp/shadow/issues/1039)).


## [v8.3.5] (2024-11-03)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ public abstract class ShadowApplicationPlugin : Plugin<Project> {
}
}
task.doLast {
task.eachFile { details ->
if (details.path == "bin/${applicationName.get()}") {
details.permissions {
it.unix(755)
}
task.eachFile {
if (it.path == "bin/${applicationName.get()}") {
it.permissions { permissions -> permissions.unix(755) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ package com.github.jengelman.gradle.plugins.shadow.transformers
import org.gradle.api.file.FileTreeElement

/**
* Prevents duplicate copies of the license
* Prevents duplicate copies of the license.
*
* Modified from `org.apache.maven.plugins.shade.resouce.ApacheLicenseResourceTransformer.java`
* Modified from [org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer.java](https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/resource/ApacheLicenseResourceTransformer.java).
*
* @author John Engelman
*/
public open class ApacheLicenseResourceTransformer : Transformer by NoOpTransformer {
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 @@ -19,7 +19,7 @@ import org.gradle.api.tasks.Optional
/**
* Merges `META-INF/NOTICE.TXT` files.
*
* Modified from `org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer.java`
* Modified from [org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer.java](https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/resource/ApacheNoticeResourceTransformer.java).
*
* @author John Engelman
*/
Expand Down Expand Up @@ -76,7 +76,9 @@ public open class ApacheNoticeResourceTransformer @Inject constructor(

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 @@ -184,5 +186,6 @@ public open class ApacheNoticeResourceTransformer @Inject constructor(
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 @@ -14,9 +14,8 @@ import org.gradle.api.tasks.Optional
/**
* A resource processor that appends content for a resource, separated by a newline.
*
* Modified from `org.apache.maven.plugins.shade.resource.AppendingTransformer.java`
* Modified from [org.apache.maven.plugins.shade.resource.AppendingTransformer.java](https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/resource/AppendingTransformer.java).
*
* Modifications
* @author John Engelman
*/
@CacheableTransformer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.gradle.api.file.FileTreeElement
/**
* A resource processor that aggregates plexus `components.xml` files.
*
* Modified from `org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer.java`
* Modified from [org.apache.maven.plugins.shade.resource.ComponentsXmlResourceTransformer.java](https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/resource/ComponentsXmlResourceTransformer.java).
*
* @author John Engelman
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.gradle.api.tasks.Optional
/**
* A resource processor that prevents the inclusion of an arbitrary resource into the shaded JAR.
*
* Modified from `org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer.java`
* Modified from [org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer.java](https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/resource/DontIncludeResourceTransformer.java).
*
* @author John Engelman
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.apache.tools.zip.ZipOutputStream
import org.gradle.api.file.FileTreeElement

/**
* Modified from `eu.appsatori.gradle.fatjar.tasks.PrepareFiles.groovy`
* Aggregate Apache Groovy extension modules descriptors.
*
* Resource transformer that merges Groovy extension module descriptor files into a single file.
* Groovy extension module descriptor files have the name org.codehaus.groovy.runtime.ExtensionModule
Expand All @@ -23,6 +23,9 @@ import org.gradle.api.file.FileTreeElement
* It will live in the legacy directory (META-INF/services) if all the processed descriptor
* files came from the legacy location, otherwise it will be written into the now standard location (META-INF/groovy).
* Note that certain JDK9+ tooling will break when using the legacy location.
*
* Modified from [eu.appsatori.gradle.fatjar.tasks.PrepareFiles.groovy](https://github.com/musketyr/gradle-fatjar-plugin/blob/master/src/main/groovy/eu/appsatori/gradle/fatjar/tasks/PrepareFiles.groovy).
* Related to [org.apache.maven.plugins.shade.resource.GroovyResourceTransformer.java](https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/resource/GroovyResourceTransformer.java).
*/
@CacheableTransformer
public open class GroovyExtensionModuleTransformer : Transformer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import org.gradle.api.tasks.PathSensitive
import org.gradle.api.tasks.PathSensitivity

/**
* A resource processor that allows the addition of an arbitrary file
* content into the shaded JAR.
* A resource processor that allows the addition of an arbitrary file content into the shaded JAR.
*
* Modified from `org.apache.maven.plugins.shade.resource.IncludeResourceTransformer.java`
* Modified from [org.apache.maven.plugins.shade.resource.IncludeResourceTransformer.java](https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/resource/IncludeResourceTransformer.java).
*
* @author John Engelman
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import org.gradle.api.file.FileTreeElement
/**
* Modified from the maven equivalent to work with gradle
*
* Modified from [org.apache.logging.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer.java](https://github.com/apache/logging-log4j-transform/blob/main/log4j-transform-maven-shade-plugin-extensions/src/main/java/org/apache/logging/log4j/maven/plugins/shade/transformer/Log4j2PluginCacheFileTransformer.java).
*
* @author Paul Nelson Baker
* @see [LinkedIn](https://www.linkedin.com/in/paul-n-baker/)
* @see [GitHub](https://github.com/paul-nelson-baker/)
* @see [PluginsCacheFileTransformer.java](https://github.com/edwgiz/maven-shaded-log4j-transformer/blob/master/src/main/java/com/github/edwgiz/mavenShadePlugin/log4j2CacheTransformer/PluginsCacheFileTransformer.java)
* @author John Engelman
*/
@CacheableTransformer
public open class Log4j2PluginsCacheFileTransformer : Transformer {
Expand Down Expand Up @@ -53,9 +53,7 @@ public open class Log4j2PluginsCacheFileTransformer : Transformer {
// This functionality matches the original plugin, however, I'm not clear what
// the exact logic is. From what I can tell temporaryFiles should be never be empty
// if anything has been performed.
val hasTransformedMultipleFiles = temporaryFiles.size > 1
val hasAtLeastOneFileAndRelocator = temporaryFiles.isNotEmpty() && relocators.isNotEmpty()
return hasTransformedMultipleFiles || hasAtLeastOneFileAndRelocator
return temporaryFiles.isNotEmpty() || relocators.isNotEmpty()
}

override fun modifyOutputStream(os: ZipOutputStream, preserveFileTimestamps: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import org.slf4j.LoggerFactory
* the first MANIFEST.MF that is found in the set of JARs being processed, or
* to a newly created manifest for the shaded JAR.
*
* Modified from `org.apache.maven.plugins.shade.resource.ManifestResourceTransformer`
* Modified from [org.apache.maven.plugins.shade.resource.ManifestResourceTransformer.java](https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/resource/ManifestResourceTransformer.java).
*
* @author Jason van Zyl
* @author John Engelman
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ import org.gradle.api.tasks.Internal
* }
* ```
*
* Related to [org.apache.maven.plugins.shade.resource.properties.PropertiesTransformer.java](https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/resource/properties/PropertiesTransformer.java).
*
* @author Andres Almiray
* @author Marc Philipp
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import org.gradle.api.tasks.util.PatternFilterable
import org.gradle.api.tasks.util.PatternSet

/**
* Modified from `org.apache.maven.plugins.shade.resource.ServiceResourceTransformer.java`
*
* Resources transformer that appends entries in `META-INF/services` resources into
* a single resource. For example, if there are several `META-INF/services/org.apache.maven.project.ProjectBuilder`
* resources spread across many JARs the individual entries will all be concatenated into a single
* `META-INF/services/org.apache.maven.project.ProjectBuilder` resource packaged into the resultant JAR produced
* by the shading process.
*
* Modified from [org.apache.maven.plugins.shade.resource.ServicesResourceTransformer.java](https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/resource/ServicesResourceTransformer.java).
*
* @author jvanzyl
* @author Charlie Knudsen
* @author John Engelman
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.gradle.api.model.ObjectFactory
import org.gradle.api.tasks.Internal

/**
* Modified from `org.apache.maven.plugins.shade.resource.ResourceTransformer.java`
* Modified from [org.apache.maven.plugins.shade.resource.ResourceTransformer.java](https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/resource/ResourceTransformer.java).
*
* @author Jason van Zyl
* @author Charlie Knudsen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import org.xml.sax.InputSource
/**
* Appends multiple occurrences of some XML file.
*
* Modified from `org.apache.maven.plugins.shade.resource.XmlAppendingTransformer.java`
* Modified from [org.apache.maven.plugins.shade.resource.XmlAppendingTransformer.java](https://github.com/apache/maven-shade-plugin/blob/master/src/main/java/org/apache/maven/plugins/shade/resource/XmlAppendingTransformer.java).
*
* @author John Engelman
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import static org.junit.jupiter.api.Assertions.*
* @author Benjamin Bentmann
* @version $Id: ApacheLicenseResourceTransformerTest.java 673906 2008-07-04 05:03:20Z brett $
*
* Modified from org.apache.maven.plugins.shade.resources.ApacheLicenseResourceTransformerTest.java
* Modified from org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformerTest.java
*/
class ApacheLicenseResourceTransformerTest extends TransformerTestSupport<ApacheLicenseResourceTransformer> {

Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class Log4j2PluginsCacheFileTransformerSpec extends Specification {
transformer = new Log4j2PluginsCacheFileTransformer()
}

void "should not transformer"() {
void "should transform for a single file"() {
when:
transformer.transform(new TransformerContext(PLUGIN_CACHE_FILE, getResourceStream(PLUGIN_CACHE_FILE)))

then:
!transformer.hasTransformedResource()
transformer.hasTransformedResource()
}

void "should transform"() {
Expand Down

0 comments on commit b8f956c

Please sign in to comment.