Skip to content

Commit

Permalink
Delete image folder if exists
Browse files Browse the repository at this point in the history
Otherwise jlink throws an error.
  • Loading branch information
Nicolai Parlog authored and gunnarmorling committed May 25, 2021
1 parent 3de7ce0 commit 5bf3a80
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions core/src/main/java/org/moditect/commands/CreateRuntimeImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -85,11 +88,36 @@ private static List<String> getModules(List<String> modules) {
}

public void run() throws IOException {
deleteImageFolder();
runJlink();
log.info("Done creating image");
copyJars();
}

private void deleteImageFolder() throws IOException {
if (!Files.exists(outputDirectory)) {
return;
}

log.info("Deleting image directory " + outputDirectory);

Files.walkFileTree(outputDirectory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (exc != null)
throw exc;
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
}

private void copyJars() throws IOException {
Path jarDirectory = outputDirectory.resolve(DEPENDENCIES_DIRECTORY);
Files.createDirectories(jarDirectory);
Expand Down

0 comments on commit 5bf3a80

Please sign in to comment.