Skip to content

Commit 9e1517b

Browse files
committed
Fixed issue
1 parent 07fda80 commit 9e1517b

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/main/java/org/mangorage/bootstrap/internal/JarHandler.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,28 @@
1111
import java.util.Comparator;
1212
import java.util.HashMap;
1313
import java.util.Map;
14+
import java.util.concurrent.atomic.AtomicReference;
1415
import java.util.jar.JarFile;
1516
import java.util.jar.Manifest;
1617
import java.util.zip.ZipEntry;
1718

1819
public final class JarHandler {
1920

21+
interface UnsafeRunnable {
22+
void run() throws Exception;
23+
}
24+
2025
enum ModuleNameOrigin {
2126
MANIFEST,
2227
MODULE_INFO,
2328
GUESSED
2429
}
2530

26-
record Result(String name, ModuleNameOrigin origin, Path jar) {}
31+
record Result(String name, ModuleNameOrigin origin, Path jar, AtomicReference<UnsafeRunnable> task) {
32+
public Result(String name, ModuleNameOrigin origin, Path jar) {
33+
this(name, origin, jar, new AtomicReference<>());
34+
}
35+
}
2736

2837
static void safeHandle(final Path source, final Path target) {
2938
try {
@@ -53,16 +62,16 @@ static void handle(final Path source, final Path target) throws IOException {
5362

5463
if (!seenModules.containsKey(module.name())) {
5564
Path dest = target.resolve(jar.getFileName());
56-
Files.copy(jar, dest, StandardCopyOption.REPLACE_EXISTING);
65+
module.task().set(() -> Files.copy(jar, dest, StandardCopyOption.REPLACE_EXISTING));
5766
seenModules.put(module.name(), module);
5867
System.out.println("Added module: " + module.name() + " from " + jar);
5968
} else {
6069
if (seenModules.get(module.name()).origin() == ModuleNameOrigin.GUESSED && module.origin() != ModuleNameOrigin.GUESSED) {
6170
var oldModule = seenModules.get(module.name());
6271
Path dest = target.resolve(jar.getFileName());
63-
Files.copy(jar, dest, StandardCopyOption.REPLACE_EXISTING);
72+
module.task().set(() -> Files.copy(jar, dest, StandardCopyOption.REPLACE_EXISTING));
6473
seenModules.put(module.name(), module);
65-
System.out.println("Swapped to module: " + module.name() + "to " + jar + " from" + oldModule.jar());
74+
System.out.println("Swapped module: " + module.name() + " jar to " + jar + " from" + oldModule.jar());
6675
return;
6776
}
6877

@@ -71,6 +80,16 @@ static void handle(final Path source, final Path target) throws IOException {
7180
}
7281
}
7382

83+
seenModules.forEach((string, result) -> {
84+
final var runnable = result.task().get();
85+
if (runnable != null)
86+
try {
87+
runnable.run();
88+
} catch (Exception e) {
89+
e.printStackTrace();
90+
}
91+
});
92+
7493
System.out.println("Finished deduplicating modules. Result at: " + target);
7594
}
7695

0 commit comments

Comments
 (0)