Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fixes #408] always close input streams we create #411

Merged
merged 1 commit into from
Oct 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,22 @@ class ShadowCopyAction implements CopyAction {
private void processArchive(FileCopyDetails fileDetails) {
stats.startJar()
ZipFile archive = new ZipFile(fileDetails.file)
List<ArchiveFileTreeElement> archiveElements = archive.entries.collect {
new ArchiveFileTreeElement(new RelativeArchivePath(it, fileDetails))
}
Spec<FileTreeElement> patternSpec = patternSet.getAsSpec()
List<ArchiveFileTreeElement> filteredArchiveElements = archiveElements.findAll { ArchiveFileTreeElement archiveElement ->
patternSpec.isSatisfiedBy(archiveElement)
}
filteredArchiveElements.each { ArchiveFileTreeElement archiveElement ->
if (archiveElement.relativePath.file) {
visitArchiveFile(archiveElement, archive)
try {
List<ArchiveFileTreeElement> archiveElements = archive.entries.collect {
new ArchiveFileTreeElement(new RelativeArchivePath(it, fileDetails))
}
Spec<FileTreeElement> patternSpec = patternSet.getAsSpec()
List<ArchiveFileTreeElement> 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()
}

Expand Down Expand Up @@ -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) }
}
Expand Down