Improve handling of failed dependency relocation

This commit is contained in:
Jason Penilla committed 2023-08-23 09:18:48 -07:00
1 parent 7ed005afeb
commit e2baa90f9b
1 file changed
+7 -4
@@ -90,17 +90,20 @@ public final class DependencyDownloader {
ret.add(resolve); ret.add(resolve);
return null; return null;
} }
final Path output = resolve.resolveSibling(resolve.getFileName().toString().replace(".jar", "-relocated.jar")); final Path relocated = resolve.resolveSibling(resolve.getFileName().toString().replace(".jar", "-relocated.jar"));
ret.add(output); ret.add(relocated);
if (Files.isRegularFile(output)) { if (Files.isRegularFile(relocated)) {
return null; return null;
} }
doingWork.run(); doingWork.run();
final Path output = relocated.resolveSibling(relocated.getFileName().toString() + ".tmp");
Files.deleteIfExists(output);
final JarRelocator relocator = new JarRelocator(resolve.toFile(), output.toFile(), this.relocations); final JarRelocator relocator = new JarRelocator(resolve.toFile(), output.toFile(), this.relocations);
//this.logger.info("relocating {}", resolve); //this.logger.info("relocating {}", resolve);
relocator.run(); relocator.run();
Files.move(output, relocated);
//this.logger.info("done relocating {}", resolve); //this.logger.info("done relocating {}", resolve);
} catch (final IOException e) { } catch (final IOException | IllegalArgumentException e) {
throw new RuntimeException("Exception resolving " + dep, e); throw new RuntimeException("Exception resolving " + dep, e);
} }
return null; return null;