diff --git a/api/shadow.api b/api/shadow.api index e7c4d8a76..147c42d41 100644 --- a/api/shadow.api +++ b/api/shadow.api @@ -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 ()V + public fun (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 } diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/IncludeResourceTransformer.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/IncludeResourceTransformer.kt index 14f20385c..3b4d1ddef 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/IncludeResourceTransformer.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/IncludeResourceTransformer.kt @@ -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 @@ -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 = 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) } } diff --git a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/TransformerSpec.groovy b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/TransformerSpec.groovy index f9eb12b58..aac98bc18 100644 --- a/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/TransformerSpec.groovy +++ b/src/test/groovy/com/github/jengelman/gradle/plugins/shadow/TransformerSpec.groovy @@ -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' | ''