Skip to content

Commit

Permalink
Migrate IncludeResourceTransformer
Browse files Browse the repository at this point in the history
  • Loading branch information
Goooler committed Nov 26, 2024
1 parent 1d2994f commit 1df7b3b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
8 changes: 3 additions & 5 deletions api/shadow.api
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,14 @@ public class com/github/jengelman/gradle/plugins/shadow/transformers/GroovyExten
}

public class com/github/jengelman/gradle/plugins/shadow/transformers/IncludeResourceTransformer : com/github/jengelman/gradle/plugins/shadow/transformers/Transformer {
public fun <init> ()V
public fun <init> (Lorg/gradle/api/model/ObjectFactory;)V
public fun canTransformResource (Lorg/gradle/api/file/FileTreeElement;)Z
public final fun getFile ()Ljava/io/File;
public final fun getFile ()Lorg/gradle/api/file/RegularFileProperty;
public fun getName ()Ljava/lang/String;
public fun getObjectFactory ()Lorg/gradle/api/model/ObjectFactory;
public final fun getResource ()Ljava/lang/String;
public final fun getResource ()Lorg/gradle/api/provider/Property;
public fun hasTransformedResource ()Z
public fun modifyOutputStream (Lorg/apache/tools/zip/ZipOutputStream;Z)V
public final fun setFile (Ljava/io/File;)V
public final fun setResource (Ljava/lang/String;)V
public fun transform (Lcom/github/jengelman/gradle/plugins/shadow/transformers/TransformerContext;)V
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.github.jengelman.gradle.plugins.shadow.transformers

import com.github.jengelman.gradle.plugins.shadow.internal.property
import com.github.jengelman.gradle.plugins.shadow.transformers.TransformerContext.Companion.getEntryTimestamp
import java.io.File
import javax.inject.Inject
import org.apache.tools.zip.ZipEntry
import org.apache.tools.zip.ZipOutputStream
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.model.ObjectFactory
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFile
import org.gradle.api.tasks.PathSensitive
Expand All @@ -16,22 +20,24 @@ import org.gradle.api.tasks.PathSensitivity
*
* @author John Engelman
*/
public open class IncludeResourceTransformer : Transformer by NoOpTransformer {
public open class IncludeResourceTransformer @Inject constructor(
override val objectFactory: ObjectFactory,
) : Transformer by NoOpTransformer {
@get:InputFile
@get:PathSensitive(PathSensitivity.NONE)
public var file: File? = null
public val file: RegularFileProperty = objectFactory.fileProperty()

@get:Input
public var resource: String? = null
public val resource: Property<String> = objectFactory.property()

override fun hasTransformedResource(): Boolean = file?.exists() == true
override fun hasTransformedResource(): Boolean = file.get().asFile.exists() == true

override fun modifyOutputStream(os: ZipOutputStream, preserveFileTimestamps: Boolean) {
val entry = ZipEntry(requireNotNull(resource))
val entry = ZipEntry(resource.get())
entry.time = getEntryTimestamp(preserveFileTimestamps, entry.time)
os.putNextEntry(entry)

requireNotNull(file).inputStream().use { inputStream ->
file.get().asFile.inputStream().use { inputStream ->
inputStream.copyTo(os)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@ staticExtensionClasses=com.acme.bar.SomeStaticExtension'''.stripIndent()).write(
'ComponentsXmlResourceTransformer' | ''
'DontIncludeResourceTransformer' | ''
'GroovyExtensionModuleTransformer' | ''
'IncludeResourceTransformer' | '{ resource = "test.file"; file = file("test/some.file") }'
'IncludeResourceTransformer' | '{ resource.set("test.file"); file.fileValue(file("test/some.file")) }'
'Log4j2PluginsCacheFileTransformer' | ''
'ManifestAppenderTransformer' | ''
'ManifestResourceTransformer' | ''
Expand Down

0 comments on commit 1df7b3b

Please sign in to comment.