/** * Copies a whole directory to a new location preserving the file dates. This method copies the specified directory and all its child directories and files * to the specified destination. The destination is the new location and name of the directory. The destination directory is created if it does not exist. * If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence. * * @param srcDir an existing directory to copy, must not be <code>null</code> * @param destDir the new directory, must not be <code>null</code> * @throws Fabric3Exception if an IO error occurs during copying * @since Commons IO 1.1 */ public static void copyDirectory(File srcDir, File destDir) throws Fabric3Exception { copyDirectory(srcDir, destDir, true); }
/** * Copies a directory to within another directory preserving the file dates. This method copies the source directory and all its contents to a directory of * the same name in the specified destination directory. The destination directory is created if it does not exist. If the destination directory did exist, * then this method merges the source with the destination, with the source taking precedence. * * @param srcDir an existing directory to copy, must not be <code>null</code> * @param destDir the directory to place the copy in, must not be <code>null</code> * @throws Fabric3Exception if an IO error occurs during copying */ public static void copyDirectoryToDirectory(File srcDir, File destDir) throws Fabric3Exception { if (srcDir == null) { throw new NullPointerException("Source must not be null"); } if (!(srcDir.exists() && srcDir.isDirectory())) { throw new IllegalArgumentException("Source '" + destDir + "' is not a directory"); } if (destDir == null) { throw new NullPointerException("Destination must not be null"); } if (!(destDir.exists() && destDir.isDirectory())) { throw new IllegalArgumentException("Destination '" + destDir + "' is not a directory"); } copyDirectory(srcDir, new File(destDir, srcDir.getName()), true); }
/** * Creates a new read-write runtime directory * * @param sourceConfigDir the configuration directory to use as a template * @param targetDir the target runtime directory */ public static void cloneRuntimeImage(File sourceConfigDir, File targetDir) { File targetConfigDir = new File(targetDir, "config"); FileHelper.forceMkdir(targetConfigDir); FileHelper.copyDirectory(sourceConfigDir, targetConfigDir); FileHelper.forceMkdir(new File(targetDir, "data")); File targetDeployDir = new File(targetDir, "deploy"); FileHelper.forceMkdir(targetDeployDir); File sourceDeployDir = new File(targetConfigDir.getParent(), "deploy"); FileHelper.copyDirectory(sourceDeployDir, targetDeployDir); File repository = new File(targetDir, "repository"); FileHelper.forceMkdir(repository); FileHelper.forceMkdir(new File(repository, "runtime")); FileHelper.forceMkdir(new File(repository, "user")); FileHelper.forceMkdir(new File(targetDir, "tmp")); }