/** * Copies all files and subdirectories (infinitely recursively) in a directory to another. * Any existing files are overwritten. * * @param sourceLocation the source directory * @param targetLocation the target directory * @throws IOException if copying any file fails. This will typically result in some files being copied and * others not, i.e this method is not exception safe */ public static void copyDirectory(File sourceLocation , File targetLocation) throws IOException { copyDirectory(sourceLocation, targetLocation, -1); }
/** * Copies all files and subdirectories in a directory to another. * Any existing files are overwritten. * * @param sourceLocation the source directory * @param targetLocation the target directory * @param maxRecurseLevel if this is 1, only files immediately in sourceLocation are copied, * if it is 2, then files contained in immediate subdirectories are copied, etc. * If it is 0, sourceLocation will only be copied if it is a file, not a directory. * If it is negative, recursion is infinite. * @throws IOException if copying any file fails. This will typically result in some files being copied and * others not, i.e this method is not exception safe */ public static void copyDirectory(File sourceLocation , File targetLocation, int maxRecurseLevel) throws IOException { copyDirectory(sourceLocation, targetLocation, maxRecurseLevel, new FilenameFilter() { @Override public boolean accept(File dir, String name) { return true; } }); }
/** * Copies the whole source directory (infinitely recursively) into the target directory. * @throws IOException if copying any file fails. This will typically result in some files being copied and * others not, i.e this method is not exception safe */ public static void copyDirectoryInto(File sourceLocation, File targetLocation) throws IOException { File destination = new File(targetLocation, sourceLocation.getAbsoluteFile().getName()); copyDirectory(sourceLocation, destination); }
copyDirectory(new File(sourceLocation, children[i]), new File(targetLocation, children[i]), maxRecurseLevel-1);
@Override public ApplicationPackage preprocess(Zone zone, DeployLogger logger) throws IOException, TransformerException, ParserConfigurationException, SAXException { IOUtils.recursiveDeleteDir(preprocessedDir); IOUtils.copyDirectory(appDir, preprocessedDir, -1, (dir, name) -> ! name.equals(preprocessed) && ! name.equals(SERVICES) && ! name.equals(HOSTS) && ! name.equals(CONFIG_DEFINITIONS_DIR)); preprocessXML(new File(preprocessedDir, SERVICES), getServicesFile(), zone); if (getHostsFile().exists()) { preprocessXML(new File(preprocessedDir, HOSTS), getHostsFile(), zone); } FilesApplicationPackage preprocessed = FilesApplicationPackage.fromFile(preprocessedDir, includeSourceFiles); preprocessed.copyUserDefsIntoApplication(); return preprocessed; }