@Test public void testCopyPathCopiesDirectoryRecursivelyAndMaintainsExecutePermissions() throws IOException { final Path sourceDir = Files.createTempDirectory(generateAlphanumStr()); final Path subdir = Files.createDirectory(sourceDir.resolve(generateAlphanumStr())); final Path fileInSubdir = Files.createFile(subdir.resolve(generateAlphanumStr())); if (!fileInSubdir.toFile().setExecutable(true)) return; assertThat(fileInSubdir.toFile().canExecute()).isTrue(); final Path destination = Files.createTempDirectory(generateAlphanumStr()).resolve(generateAlphanumStr()); Helpers.copyPath(sourceDir, destination); assertThat(destination.toFile().exists()).isTrue(); assertThat(destination.resolve(sourceDir.relativize(subdir)).toFile().exists()).isTrue(); assertThat(destination.resolve(sourceDir.relativize(fileInSubdir)).toFile().exists()).isTrue(); assertThat(destination.resolve(sourceDir.relativize(fileInSubdir)).toFile().canExecute()).isTrue(); }
public static void copyPath(Path source, Path destination) throws IOException { Files.walkFileTree(source, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path destinationDir = destination.resolve(source.relativize(dir)); try { Files.copy(dir, destinationDir); } catch (FileAlreadyExistsException e) { if (!Files.isDirectory(destinationDir)) throw e; } return CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.copy(file, destination.resolve(source.relativize(file))); return CONTINUE; } }); }
Helpers { public static void copyPath(Path source, Path destination) throws IOException { Files.walkFileTree(source, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path destinationDir = destination.resolve(source.relativize(dir)); try { Files.copy(dir, destinationDir); } catch (FileAlreadyExistsException e) { if (!Files.isDirectory(destinationDir)) throw e; } return CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.copy(file, destination.resolve(source.relativize(file))); return CONTINUE; } }); } }
Helpers { public static void copyPath(Path source, Path destination) throws IOException { Files.walkFileTree(source, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path destinationDir = destination.resolve(source.relativize(dir)); try { Files.copy(dir, destinationDir); } catch (FileAlreadyExistsException e) { if (!Files.isDirectory(destinationDir)) throw e; } return CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.copy(file, destination.resolve(source.relativize(file))); return CONTINUE; } }); }  }
Helpers { public static void copyPath(Path source, Path destination) throws IOException { Files.walkFileTree(source, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path destinationDir = destination.resolve(source.relativize(dir)); try { Files.copy(dir, destinationDir); } catch (FileAlreadyExistsException e) { if (!Files.isDirectory(destinationDir)) throw e; } return CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.copy(file, destination.resolve(source.relativize(file))); return CONTINUE; } }); }  static String generateRandomBase36String(int len); static String capitalize(String str); static T randomKeyIn(Map<T, U> m); static T randomElementIn(List<T> l); static String randomSubstring(String s, int len); static Stream<File> listDirectories(Path p); static String loadResourceFileAsString(String resourceFileName); static byte[] loadResourceFile(String resourceFileName); static InputStream openResourceFile(String resourceFileName); static Optional<Path> tryResolve(Path p, Object s); static Optional<Path> tryResolve(Path p, Object... subPaths); static BinaryData streamBinaryData(Path p); static BinaryData streamBinaryData(Path p, String mimeType); static Optional<T> lastElement(List<T> els); static Stream<T> toStream(Iterable<T> iter); static Set<T> setOf(T... vals); static Map<T, U> merge(Map<T, U> first, Map<T, U> second); static Map<V, U> mapKeys(Map<T, U> m, Function<T, V> f); static Map<T, V> mapValues(Map<T, U> m, Function<U, V> f); static Optional<U> tryGet(Map<T, U> m, T v); static Stream<T> intersperse(Stream<T> s, T e); static String join(String delimiter, Stream<T> s); static String commaSeparatedList(Iterable<?> str); static String toJSON(Object o); static JsonNode toJSONNode(Object o); static T loadJSON(Path p, Class<T> klass); static T loadJSON(Path p, TypeReference<T> tr); static T readJSON(String json, Class<T> klass); static T readJSON(String json, TypeReference<T> tr); static T readJSON(Path p, Class<T> klass); static T readJSON(TreeNode t, Class<T> klass); static void writeJSON(Path p, Object o); static T readYAML(String yaml, Class<T> klass); static T readYAML(Path yamlPath, Class<T> klass); static T readYAML(File f, Class<T> klass); static void attachTo(
            Process process,
            Observer<byte[]> stdoutObserver,
            Observer<byte[]> stderrObserver,
            Consumer<Integer> onExit); static Date now(); static String getMimeType(InputStream s, String fileName); static void copyPath(Path source, Path destination); }
Helpers { public static void copyPath(Path source, Path destination) throws IOException { Files.walkFileTree(source, new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { Path destinationDir = destination.resolve(source.relativize(dir)); try { Files.copy(dir, destinationDir); } catch (FileAlreadyExistsException e) { if (!Files.isDirectory(destinationDir)) throw e; } return CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Files.copy(file, destination.resolve(source.relativize(file))); return CONTINUE; } }); }  static String generateRandomBase36String(int len); static String capitalize(String str); static T randomKeyIn(Map<T, U> m); static T randomElementIn(List<T> l); static String randomSubstring(String s, int len); static Stream<File> listDirectories(Path p); static String loadResourceFileAsString(String resourceFileName); static byte[] loadResourceFile(String resourceFileName); static InputStream openResourceFile(String resourceFileName); static Optional<Path> tryResolve(Path p, Object s); static Optional<Path> tryResolve(Path p, Object... subPaths); static BinaryData streamBinaryData(Path p); static BinaryData streamBinaryData(Path p, String mimeType); static Optional<T> lastElement(List<T> els); static Stream<T> toStream(Iterable<T> iter); static Set<T> setOf(T... vals); static Map<T, U> merge(Map<T, U> first, Map<T, U> second); static Map<V, U> mapKeys(Map<T, U> m, Function<T, V> f); static Map<T, V> mapValues(Map<T, U> m, Function<U, V> f); static Optional<U> tryGet(Map<T, U> m, T v); static Stream<T> intersperse(Stream<T> s, T e); static String join(String delimiter, Stream<T> s); static String commaSeparatedList(Iterable<?> str); static String toJSON(Object o); static JsonNode toJSONNode(Object o); static T loadJSON(Path p, Class<T> klass); static T loadJSON(Path p, TypeReference<T> tr); static T readJSON(String json, Class<T> klass); static T readJSON(String json, TypeReference<T> tr); static T readJSON(Path p, Class<T> klass); static T readJSON(TreeNode t, Class<T> klass); static void writeJSON(Path p, Object o); static T readYAML(String yaml, Class<T> klass); static T readYAML(Path yamlPath, Class<T> klass); static T readYAML(File f, Class<T> klass); static void attachTo(
            Process process,
            Observer<byte[]> stdoutObserver,
            Observer<byte[]> stderrObserver,
            Consumer<Integer> onExit); static Date now(); static String getMimeType(InputStream s, String fileName); static void copyPath(Path source, Path destination);  }