@Test public void testCopyWithoutTmpl() throws Exception { Path[] paths = createEnv(2); Path root = paths[0]; Path fs = paths[1]; Path module = paths[2]; try { assertThat(exists(PathUtils.get(fs, "dir2/dir21/f21.txt")), is(false)); assertThat(exists(PathUtils.get(fs, "dir2/f2.txt")), is(true)); assertThat(exists(PathUtils.get(fs, "dir1/f1.txt")), is(false)); assertThat(exists(PathUtils.get(fs, "f.txt")), is(false)); assertThat(exists(PathUtils.get(fs, "ff.txt")), is(true)); new EnvConfiguratorMock(build(module)).copyFiles(); assertThat(exists(PathUtils.get(fs, "dir1/f1.txt")), is(true)); assertThat(exists(PathUtils.get(fs, "dir2/dir21/f21.txt")), is(true)); assertThat(exists(PathUtils.get(fs, "f.txt")), is(true)); assertThat(exists(PathUtils.get(fs, "ff.txt")), is(true)); assertThat(exists(PathUtils.get(fs, "dir3/f3.txt")), is(true)); } finally { FileUtils.delete(root); } }
protected void copyFiles() { final Path module = conf.getModule(); final Map<String, Object> properties = conf.getProps(); final Path target = pathHelper.getTarget(module); FileUtils.copy(new CopyVisitor(module, target, "*" + DELETE_SUFFIX){ private FileHookEvaluator hook; @Override protected boolean mustCopy(Path source) { if(source.toString().endsWith(HOOK_SUFFIX)){ return false; } final Path target = pathHelper.getTargetWithoutSuffix(source, TEMPLATE_SUFFIX); hook = new FileHookEvaluator(source, target, conf); boolean mustCopy = !matcher.matches(source.getFileName()); boolean pre = true; try { return mustCopy && (pre = hook.pre()); } finally { if(!pre){ hook.finish(); } } } @Override protected void copy(Path source, final Path target) throws IOException { try { if(source.toString().endsWith(TEMPLATE_SUFFIX)) { File resolvedTargetFile = new File(target.toString().replace(TEMPLATE_SUFFIX, "")); backupHelper.backupFile(resolvedTargetFile.toPath()); try (Writer out = new BufferedWriter(new FileWriter(resolvedTargetFile))) { engine.createTemplate(source) .make(properties) .writeTo(out); } catch (Exception e) { throw new IOException(e); } LOGGER.info(" :TMPL_MERGED"); LOGGER.info("\t" + source + " -> " + resolvedTargetFile); hook.post(); } else { backupHelper.backupFile(target); Files.copy(source, target, REPLACE_EXISTING); LOGGER.info(" :COPIED"); LOGGER.info("\t" + source + " -> " + target); hook.post(); } } finally { hook.finish(); } } @Override protected Path resolveVars(Path path) { return pathHelper.replaceVars(path); } }); }
EnvConfigurator { protected void copyFiles() { final Path module = conf.getModule(); final Map<String, Object> properties = conf.getProps(); final Path target = pathHelper.getTarget(module); FileUtils.copy(new CopyVisitor(module, target, "*" + DELETE_SUFFIX){ private FileHookEvaluator hook; @Override protected boolean mustCopy(Path source) { if(source.toString().endsWith(HOOK_SUFFIX)){ return false; } final Path target = pathHelper.getTargetWithoutSuffix(source, TEMPLATE_SUFFIX); hook = new FileHookEvaluator(source, target, conf); boolean mustCopy = !matcher.matches(source.getFileName()); boolean pre = true; try { return mustCopy && (pre = hook.pre()); } finally { if(!pre){ hook.finish(); } } } @Override protected void copy(Path source, final Path target) throws IOException { try { if(source.toString().endsWith(TEMPLATE_SUFFIX)) { File resolvedTargetFile = new File(target.toString().replace(TEMPLATE_SUFFIX, "")); backupHelper.backupFile(resolvedTargetFile.toPath()); try (Writer out = new BufferedWriter(new FileWriter(resolvedTargetFile))) { engine.createTemplate(source) .make(properties) .writeTo(out); } catch (Exception e) { throw new IOException(e); } LOGGER.info(" :TMPL_MERGED"); LOGGER.info("\t" + source + " -> " + resolvedTargetFile); hook.post(); } else { backupHelper.backupFile(target); Files.copy(source, target, REPLACE_EXISTING); LOGGER.info(" :COPIED"); LOGGER.info("\t" + source + " -> " + target); hook.post(); } } finally { hook.finish(); } } @Override protected Path resolveVars(Path path) { return pathHelper.replaceVars(path); } }); } }
EnvConfigurator { protected void copyFiles() { final Path module = conf.getModule(); final Map<String, Object> properties = conf.getProps(); final Path target = pathHelper.getTarget(module); FileUtils.copy(new CopyVisitor(module, target, "*" + DELETE_SUFFIX){ private FileHookEvaluator hook; @Override protected boolean mustCopy(Path source) { if(source.toString().endsWith(HOOK_SUFFIX)){ return false; } final Path target = pathHelper.getTargetWithoutSuffix(source, TEMPLATE_SUFFIX); hook = new FileHookEvaluator(source, target, conf); boolean mustCopy = !matcher.matches(source.getFileName()); boolean pre = true; try { return mustCopy && (pre = hook.pre()); } finally { if(!pre){ hook.finish(); } } } @Override protected void copy(Path source, final Path target) throws IOException { try { if(source.toString().endsWith(TEMPLATE_SUFFIX)) { File resolvedTargetFile = new File(target.toString().replace(TEMPLATE_SUFFIX, "")); backupHelper.backupFile(resolvedTargetFile.toPath()); try (Writer out = new BufferedWriter(new FileWriter(resolvedTargetFile))) { engine.createTemplate(source) .make(properties) .writeTo(out); } catch (Exception e) { throw new IOException(e); } LOGGER.info(" :TMPL_MERGED"); LOGGER.info("\t" + source + " -> " + resolvedTargetFile); hook.post(); } else { backupHelper.backupFile(target); Files.copy(source, target, REPLACE_EXISTING); LOGGER.info(" :COPIED"); LOGGER.info("\t" + source + " -> " + target); hook.post(); } } finally { hook.finish(); } } @Override protected Path resolveVars(Path path) { return pathHelper.replaceVars(path); } }); } EnvConfigurator(Configuration conf); }
EnvConfigurator { protected void copyFiles() { final Path module = conf.getModule(); final Map<String, Object> properties = conf.getProps(); final Path target = pathHelper.getTarget(module); FileUtils.copy(new CopyVisitor(module, target, "*" + DELETE_SUFFIX){ private FileHookEvaluator hook; @Override protected boolean mustCopy(Path source) { if(source.toString().endsWith(HOOK_SUFFIX)){ return false; } final Path target = pathHelper.getTargetWithoutSuffix(source, TEMPLATE_SUFFIX); hook = new FileHookEvaluator(source, target, conf); boolean mustCopy = !matcher.matches(source.getFileName()); boolean pre = true; try { return mustCopy && (pre = hook.pre()); } finally { if(!pre){ hook.finish(); } } } @Override protected void copy(Path source, final Path target) throws IOException { try { if(source.toString().endsWith(TEMPLATE_SUFFIX)) { File resolvedTargetFile = new File(target.toString().replace(TEMPLATE_SUFFIX, "")); backupHelper.backupFile(resolvedTargetFile.toPath()); try (Writer out = new BufferedWriter(new FileWriter(resolvedTargetFile))) { engine.createTemplate(source) .make(properties) .writeTo(out); } catch (Exception e) { throw new IOException(e); } LOGGER.info(" :TMPL_MERGED"); LOGGER.info("\t" + source + " -> " + resolvedTargetFile); hook.post(); } else { backupHelper.backupFile(target); Files.copy(source, target, REPLACE_EXISTING); LOGGER.info(" :COPIED"); LOGGER.info("\t" + source + " -> " + target); hook.post(); } } finally { hook.finish(); } } @Override protected Path resolveVars(Path path) { return pathHelper.replaceVars(path); } }); } EnvConfigurator(Configuration conf); void execute(); }
EnvConfigurator { protected void copyFiles() { final Path module = conf.getModule(); final Map<String, Object> properties = conf.getProps(); final Path target = pathHelper.getTarget(module); FileUtils.copy(new CopyVisitor(module, target, "*" + DELETE_SUFFIX){ private FileHookEvaluator hook; @Override protected boolean mustCopy(Path source) { if(source.toString().endsWith(HOOK_SUFFIX)){ return false; } final Path target = pathHelper.getTargetWithoutSuffix(source, TEMPLATE_SUFFIX); hook = new FileHookEvaluator(source, target, conf); boolean mustCopy = !matcher.matches(source.getFileName()); boolean pre = true; try { return mustCopy && (pre = hook.pre()); } finally { if(!pre){ hook.finish(); } } } @Override protected void copy(Path source, final Path target) throws IOException { try { if(source.toString().endsWith(TEMPLATE_SUFFIX)) { File resolvedTargetFile = new File(target.toString().replace(TEMPLATE_SUFFIX, "")); backupHelper.backupFile(resolvedTargetFile.toPath()); try (Writer out = new BufferedWriter(new FileWriter(resolvedTargetFile))) { engine.createTemplate(source) .make(properties) .writeTo(out); } catch (Exception e) { throw new IOException(e); } LOGGER.info(" :TMPL_MERGED"); LOGGER.info("\t" + source + " -> " + resolvedTargetFile); hook.post(); } else { backupHelper.backupFile(target); Files.copy(source, target, REPLACE_EXISTING); LOGGER.info(" :COPIED"); LOGGER.info("\t" + source + " -> " + target); hook.post(); } } finally { hook.finish(); } } @Override protected Path resolveVars(Path path) { return pathHelper.replaceVars(path); } }); } EnvConfigurator(Configuration conf); void execute();  }