More control over copying files
This commit is contained in:
parent
1c3a6ee439
commit
628ace4716
|
@ -33,6 +33,17 @@ package org.hl7.fhir.utilities;
|
||||||
|
|
||||||
public interface FileNotifier {
|
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);
|
public void copyFile(String src, String dst);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -63,6 +63,7 @@ import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
|
import org.hl7.fhir.utilities.FileNotifier.FileNotifier2;
|
||||||
|
|
||||||
public class Utilities {
|
public class Utilities {
|
||||||
|
|
||||||
|
@ -306,8 +307,9 @@ public class Utilities {
|
||||||
String[] files = src.list();
|
String[] files = src.list();
|
||||||
for (String f : files) {
|
for (String f : files) {
|
||||||
if (new CSFile(sourceFolder + File.separator + f).isDirectory()) {
|
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);
|
copyDirectory(sourceFolder + File.separator + f, destFolder + File.separator + f, notifier);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (notifier != null)
|
if (notifier != null)
|
||||||
notifier.copyFile(sourceFolder + File.separator + f, destFolder + File.separator + f);
|
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 {
|
public static void copyFile(String source, String dest) throws IOException {
|
||||||
copyFile(new File(source), new File(dest));
|
copyFile(new File(source), new File(dest));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue