@Test void verifyEmptyOrCreateOutputFolderThrowsNotEmpty (@TempDir Path tempDirectoryPath) throws IOException { Packr packr = new Packr(); Path outputPath = tempDirectoryPath.resolve("output"); Files.createDirectories(outputPath); Path someFileThatIsInOutputDir = outputPath.resolve("someFile.txt"); Files.write(someFileThatIsInOutputDir, "Hello world!".getBytes(StandardCharsets.UTF_8)); PackrOutput packrOutput = new PackrOutput(outputPath.toFile(), outputPath.toFile()); try { packr.verifyEmptyOrCreateOutputFolder(packrOutput); } catch (IOException exception) { assertTrue(exception.getMessage().contains("is not empty")); return; } fail("Should have thrown a not empty exception"); }
void verifyEmptyOrCreateOutputFolder (PackrOutput output) throws IOException { Path outputPath = output.executableFolder.toPath(); if (Files.exists(outputPath)) { if (!Files.isDirectory(outputPath)) { System.err.println("Output directory \"" + outputPath + "\" must be a directory."); throw new IOException("Output directory \"" + outputPath + "\" is not a directory."); } try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(outputPath)) { if (dirStream.iterator().hasNext()) { System.err.println("Output directory \"" + outputPath + "\" must be empty."); throw new IOException("Output directory \"" + outputPath + "\" is not empty."); } } } Files.createDirectories(outputPath); }
Packr { void verifyEmptyOrCreateOutputFolder (PackrOutput output) throws IOException { Path outputPath = output.executableFolder.toPath(); if (Files.exists(outputPath)) { if (!Files.isDirectory(outputPath)) { System.err.println("Output directory \"" + outputPath + "\" must be a directory."); throw new IOException("Output directory \"" + outputPath + "\" is not a directory."); } try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(outputPath)) { if (dirStream.iterator().hasNext()) { System.err.println("Output directory \"" + outputPath + "\" must be empty."); throw new IOException("Output directory \"" + outputPath + "\" is not empty."); } } } Files.createDirectories(outputPath); } }
Packr { void verifyEmptyOrCreateOutputFolder (PackrOutput output) throws IOException { Path outputPath = output.executableFolder.toPath(); if (Files.exists(outputPath)) { if (!Files.isDirectory(outputPath)) { System.err.println("Output directory \"" + outputPath + "\" must be a directory."); throw new IOException("Output directory \"" + outputPath + "\" is not a directory."); } try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(outputPath)) { if (dirStream.iterator().hasNext()) { System.err.println("Output directory \"" + outputPath + "\" must be empty."); throw new IOException("Output directory \"" + outputPath + "\" is not empty."); } } } Files.createDirectories(outputPath); }  }
Packr { void verifyEmptyOrCreateOutputFolder (PackrOutput output) throws IOException { Path outputPath = output.executableFolder.toPath(); if (Files.exists(outputPath)) { if (!Files.isDirectory(outputPath)) { System.err.println("Output directory \"" + outputPath + "\" must be a directory."); throw new IOException("Output directory \"" + outputPath + "\" is not a directory."); } try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(outputPath)) { if (dirStream.iterator().hasNext()) { System.err.println("Output directory \"" + outputPath + "\" must be empty."); throw new IOException("Output directory \"" + outputPath + "\" is not empty."); } } } Files.createDirectories(outputPath); }  static void main(String[] args); @SuppressWarnings("unused") Packr setRemovePlatformLibsFileFilter(Predicate<File> filter); @SuppressWarnings("WeakerAccess") void pack(PackrConfig config); }
Packr { void verifyEmptyOrCreateOutputFolder (PackrOutput output) throws IOException { Path outputPath = output.executableFolder.toPath(); if (Files.exists(outputPath)) { if (!Files.isDirectory(outputPath)) { System.err.println("Output directory \"" + outputPath + "\" must be a directory."); throw new IOException("Output directory \"" + outputPath + "\" is not a directory."); } try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(outputPath)) { if (dirStream.iterator().hasNext()) { System.err.println("Output directory \"" + outputPath + "\" must be empty."); throw new IOException("Output directory \"" + outputPath + "\" is not empty."); } } } Files.createDirectories(outputPath); }  static void main(String[] args); @SuppressWarnings("unused") Packr setRemovePlatformLibsFileFilter(Predicate<File> filter); @SuppressWarnings("WeakerAccess") void pack(PackrConfig config); static final String JRE_RELATIVE_PATH_NAME; }