Skip to content

Commit

Permalink
Fix threading issues with ZIP archives (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte authored Dec 30, 2023
1 parent ee42db0 commit 7c8d016
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void process(FileSource source, FileSink sink, List<SourceTransformer> tr
transformer.beforeRun(context);
}

if (sink.isOrdered()) {
if (source.isOrdered() && sink.isOrdered()) {
try (var stream = source.streamEntries()) {
stream.forEach(entry -> {
try {
Expand Down Expand Up @@ -82,7 +82,8 @@ private void processEntry(FileEntry entry, VirtualFile sourceRoot, List<SourceTr
try (var in = entry.openInputStream()) {
byte[] content = in.readAllBytes();
var lastModified = entry.lastModified();
if (entry.hasExtension("java")) {

if (!transformers.isEmpty() && entry.hasExtension("java")) {
var orgContent = content;
content = transformSource(sourceRoot, entry.relativePath(), transformers, content);
if (orgContent != content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import java.util.zip.ZipFile;

class ArchiveFileSource implements FileSource {
Expand All @@ -28,7 +31,13 @@ public VirtualFile createSourceRoot(VirtualFileManager vfsManager) {

@Override
public Stream<FileEntry> streamEntries() {
return zipFile.stream().map(ze -> FileEntries.ofZipEntry(zipFile, ze));
var spliterator = Spliterators.spliterator(
zipFile.entries().asIterator(),
zipFile.size(),
Spliterator.IMMUTABLE | Spliterator.ORDERED
);
return StreamSupport.stream(spliterator, false)
.map(ze -> FileEntries.ofZipEntry(zipFile, ze));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ protected final void runTest(String testDirName, String mappingsFilename) throws
Files.write(librariesFile, List.of("-e=" + junitJarPath));

runTool(
"--max-queue-depth=1",
"--libraries-list",
librariesFile.toString(),
"--enable-parchment",
Expand Down

0 comments on commit 7c8d016

Please sign in to comment.