diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/Utils.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/Utils.kt index 0871a3a6c..e97b29e2c 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/Utils.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/internal/Utils.kt @@ -1,7 +1,11 @@ package com.github.jengelman.gradle.plugins.shadow.internal +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream import java.io.File import java.io.InputStream +import java.nio.charset.Charset +import java.util.Properties import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.file.RelativePath @@ -45,6 +49,17 @@ internal inline fun unsafeLazy(noinline initializer: () -> T): Lazy { return lazy(LazyThreadSafetyMode.NONE, initializer) } +internal fun Properties.inputStream( + charset: Charset = Charsets.UTF_8, + comments: String = "" +): ByteArrayInputStream { + val os = ByteArrayOutputStream() + os.writer(charset).use { writer -> + store(writer, comments) + } + return os.toByteArray().inputStream() +} + internal fun Class<*>.requireResourceAsText(name: String): String { return requireResourceAsStream(name).bufferedReader().readText() } diff --git a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer.kt b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer.kt index b09a42921..cbdaf9b8c 100644 --- a/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer.kt +++ b/src/main/kotlin/com/github/jengelman/gradle/plugins/shadow/transformers/PropertiesFileTransformer.kt @@ -1,13 +1,12 @@ package com.github.jengelman.gradle.plugins.shadow.transformers import com.github.jengelman.gradle.plugins.shadow.internal.CleanProperties +import com.github.jengelman.gradle.plugins.shadow.internal.inputStream import com.github.jengelman.gradle.plugins.shadow.internal.property import com.github.jengelman.gradle.plugins.shadow.transformers.PropertiesFileTransformer.MergeStrategy import groovy.lang.Closure import groovy.lang.Closure.IDENTITY -import java.io.ByteArrayOutputStream import java.io.InputStream -import java.io.InputStreamReader import java.nio.charset.Charset import java.util.Properties import javax.inject.Inject @@ -226,7 +225,7 @@ public open class PropertiesFileTransformer @Inject constructor( val entry = ZipEntry(path) entry.time = TransformerContext.getEntryTimestamp(preserveFileTimestamps, entry.time) os.putNextEntry(entry) - props.toReader().use { + props.inputStream(charset).reader(charset).use { it.copyTo(zipWriter) } zipWriter.flush() @@ -234,14 +233,6 @@ public open class PropertiesFileTransformer @Inject constructor( } } - private fun Properties.toReader(): InputStreamReader { - val os = ByteArrayOutputStream() - os.writer(charset).use { writer -> - store(writer, "") - } - return os.toByteArray().inputStream().reader(charset) - } - public enum class MergeStrategy { First, Latest,