From 1f2c882f2efd2ae7515fa9f9dd17b71bb202c378 Mon Sep 17 00:00:00 2001 From: roxchkplusony Date: Tue, 9 Oct 2018 13:44:13 -0500 Subject: [PATCH] clean up transform --- .../shadow/tasks/ShadowCopyAction.groovy | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.groovy b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.groovy index 632dc7c70..f94f1f3b3 100644 --- a/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.groovy +++ b/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/tasks/ShadowCopyAction.groovy @@ -251,19 +251,22 @@ class ShadowCopyAction implements CopyAction { private void processArchive(FileCopyDetails fileDetails) { stats.startJar() ZipFile archive = new ZipFile(fileDetails.file) - List archiveElements = archive.entries.collect { - new ArchiveFileTreeElement(new RelativeArchivePath(it, fileDetails)) - } - Spec patternSpec = patternSet.getAsSpec() - List filteredArchiveElements = archiveElements.findAll { ArchiveFileTreeElement archiveElement -> - patternSpec.isSatisfiedBy(archiveElement) - } - filteredArchiveElements.each { ArchiveFileTreeElement archiveElement -> - if (archiveElement.relativePath.file) { - visitArchiveFile(archiveElement, archive) + try { + List archiveElements = archive.entries.collect { + new ArchiveFileTreeElement(new RelativeArchivePath(it, fileDetails)) + } + Spec patternSpec = patternSet.getAsSpec() + List filteredArchiveElements = archiveElements.findAll { ArchiveFileTreeElement archiveElement -> + patternSpec.isSatisfiedBy(archiveElement) } + filteredArchiveElements.each { ArchiveFileTreeElement archiveElement -> + if (archiveElement.relativePath.file) { + visitArchiveFile(archiveElement, archive) + } + } + } finally { + archive.close() } - archive.close() stats.finishJar() } @@ -399,30 +402,29 @@ class ShadowCopyAction implements CopyAction { } private void transform(ArchiveFileTreeElement element, ZipFile archive) { - InputStream is = archive.getInputStream(element.relativePath.entry) + transformAndClose(element, archive.getInputStream(element.relativePath.entry)) + } + + private void transform(FileCopyDetails details) { + transformAndClose(details, details.file.newInputStream()) + } + + private void transformAndClose(FileTreeElement element, InputStream is) { try { - transform(element, is) + String mappedPath = remapper.map(element.relativePath.pathString) + transformers.find { it.canTransformResource(element) }.transform( + TransformerContext.builder() + .path(mappedPath) + .is(is) + .relocators(relocators) + .stats(stats) + .build() + ) } finally { is.close() } } - private void transform(FileCopyDetails details) { - transform(details, details.file.newInputStream()) - } - - private void transform(FileTreeElement element, InputStream is) { - String mappedPath = remapper.map(element.relativePath.pathString) - transformers.find { it.canTransformResource(element) }.transform( - TransformerContext.builder() - .path(mappedPath) - .is(is) - .relocators(relocators) - .stats(stats) - .build() - ) - } - private boolean isTransformable(FileTreeElement element) { return transformers.any { it.canTransformResource(element) } }