From 628ace47169d8f7621ff9de38050ca5788b9cf59 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Sun, 23 Oct 2022 23:13:45 +1100 Subject: [PATCH] More control over copying files --- .../org/hl7/fhir/utilities/FileNotifier.java | 11 +++++++ .../org/hl7/fhir/utilities/Utilities.java | 29 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FileNotifier.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FileNotifier.java index 84fe05d49..63ee3e624 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FileNotifier.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FileNotifier.java @@ -33,6 +33,17 @@ package org.hl7.fhir.utilities; public interface FileNotifier { + + public interface FileNotifier2 { + + /// if return false, not copy + public boolean copyFile(String src, String dst); + + /// if return false, not copy + public boolean copyFolder(String src, String dst); + + } public void copyFile(String src, String dst); + } \ No newline at end of file diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java index b626de371..72125ecd3 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/Utilities.java @@ -63,6 +63,7 @@ import java.util.zip.ZipInputStream; import org.apache.commons.io.FileUtils; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.utilities.FileNotifier.FileNotifier2; public class Utilities { @@ -306,8 +307,9 @@ public class Utilities { String[] files = src.list(); for (String f : files) { if (new CSFile(sourceFolder + File.separator + f).isDirectory()) { - if (!f.startsWith(".")) // ignore .git files... + if (!f.startsWith(".")) { // ignore .git files... copyDirectory(sourceFolder + File.separator + f, destFolder + File.separator + f, notifier); + } } else { if (notifier != null) notifier.copyFile(sourceFolder + File.separator + f, destFolder + File.separator + f); @@ -316,6 +318,31 @@ public class Utilities { } } + + public static void copyDirectory2(String sourceFolder, String destFolder, FileNotifier2 notifier) throws IOException, FHIRException { + CSFile src = new CSFile(sourceFolder); + if (!src.exists()) + throw new FHIRException("Folder " + sourceFolder + " not found"); + createDirectory(destFolder); + + String[] files = src.list(); + for (String f : files) { + if (new CSFile(sourceFolder + File.separator + f).isDirectory()) { + if (!f.startsWith(".")) { // ignore .git files... + boolean doCopy = notifier != null ? notifier.copyFolder(sourceFolder + File.separator + f, destFolder + File.separator + f) : true; + if (doCopy) { + copyDirectory2(sourceFolder + File.separator + f, destFolder + File.separator + f, notifier); + } + } + } else { + boolean doCopy = notifier != null ? notifier.copyFile(sourceFolder + File.separator + f, destFolder + File.separator + f) : true; + if (doCopy) { + copyFile(new CSFile(sourceFolder + File.separator + f), new CSFile(destFolder + File.separator + f)); + } + } + } + } + public static void copyFile(String source, String dest) throws IOException { copyFile(new File(source), new File(dest)); }