diff --git a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarBuilder.kt b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarBuilder.kt index d4c81cabb..c2993238c 100644 --- a/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarBuilder.kt +++ b/src/intiTest/kotlin/com/github/jengelman/gradle/plugins/shadow/util/JarBuilder.kt @@ -5,20 +5,17 @@ import java.util.jar.JarEntry import java.util.jar.JarOutputStream class JarBuilder(os: OutputStream) { - private val entries = mutableListOf() + private val entries = mutableSetOf() private val jos = JarOutputStream(os) private fun addDirectory(name: String) { - if (!entries.contains(name)) { + if (entries.add(name)) { val parent = name.substringBeforeLast('/', "") if (parent.isNotEmpty() && !entries.contains(parent)) { addDirectory(parent) } - // directory entries must end in "/" - val entry = JarEntry("$name/") - jos.putNextEntry(entry) - entries.add(name) + jos.putNextEntry(JarEntry("$name/")) } } @@ -27,11 +24,9 @@ class JarBuilder(os: OutputStream) { if (idx != -1) { addDirectory(path.substring(0, idx)) } - if (!entries.contains(path)) { - val entry = JarEntry(path) - jos.putNextEntry(entry) - entries.add(path) - data.byteInputStream().use { it.copyTo(jos) } + if (entries.add(path)) { + jos.putNextEntry(JarEntry(path)) + data.byteInputStream().copyTo(jos) } return this }