@Test public void testDelete() throws Exception { Path[] paths = createEnv(1); Path root = paths[0]; Path fs = paths[1]; Path module = paths[2]; try { assertThat(exists(PathUtils.get(fs, "dir2/dir21/f21.txt")), is(true)); assertThat(exists(PathUtils.get(fs, "dir2")), is(true)); assertThat(exists(PathUtils.get(fs, "dir1/f1.txt")), is(true)); assertThat(exists(PathUtils.get(fs, "f.txt")), is(true)); assertThat(exists(PathUtils.get(fs, "ff.txt")), is(false)); new EnvConfiguratorMock(build(module)).deleteFiles(); assertThat(exists(PathUtils.get(fs, "dir1/f1.txt")), is(false)); assertThat(exists(PathUtils.get(fs, "dir2/dir21/f21.txt")), is(false)); assertThat(exists(PathUtils.get(fs, "dir2")), is(false)); assertThat(exists(PathUtils.get(fs, "f.txt")), is(false)); assertThat(exists(PathUtils.get(fs, "dir3/f3.txt")), is(true)); assertThat(exists(PathUtils.get(fs, "ff.txt")), is(false)); } finally { FileUtils.delete(root); } }
protected void deleteFiles() { Path module = conf.getModule(); FileUtils.deleteDir(module, new DeleteVisitor("*" + DELETE_SUFFIX){ private FileHookEvaluator hook; @Override protected boolean mustDelete(Path source) { if(source.toString().endsWith(HOOK_SUFFIX)){ return false; } final Path target = pathHelper.getTargetWithoutSuffix(source, DELETE_SUFFIX); hook = new FileHookEvaluator(source, target, conf); boolean mustDelete = super.mustDelete(source); boolean fileExists = exists(target); boolean pre = true; try { return mustDelete && fileExists && (pre = hook.pre()); } finally { if(!pre) { hook.finish(); } } } @Override protected void delete(Path source) throws IOException { try { Path target = pathHelper.getTargetWithoutSuffix(source, DELETE_SUFFIX); backupHelper.backupFileOrDir(target); FileUtils.delete(target); LOGGER.info(" :DELETED"); LOGGER.info("\t" + target); hook.post(); } finally { hook.finish(); } } }); }
EnvConfigurator { protected void deleteFiles() { Path module = conf.getModule(); FileUtils.deleteDir(module, new DeleteVisitor("*" + DELETE_SUFFIX){ private FileHookEvaluator hook; @Override protected boolean mustDelete(Path source) { if(source.toString().endsWith(HOOK_SUFFIX)){ return false; } final Path target = pathHelper.getTargetWithoutSuffix(source, DELETE_SUFFIX); hook = new FileHookEvaluator(source, target, conf); boolean mustDelete = super.mustDelete(source); boolean fileExists = exists(target); boolean pre = true; try { return mustDelete && fileExists && (pre = hook.pre()); } finally { if(!pre) { hook.finish(); } } } @Override protected void delete(Path source) throws IOException { try { Path target = pathHelper.getTargetWithoutSuffix(source, DELETE_SUFFIX); backupHelper.backupFileOrDir(target); FileUtils.delete(target); LOGGER.info(" :DELETED"); LOGGER.info("\t" + target); hook.post(); } finally { hook.finish(); } } }); } }
EnvConfigurator { protected void deleteFiles() { Path module = conf.getModule(); FileUtils.deleteDir(module, new DeleteVisitor("*" + DELETE_SUFFIX){ private FileHookEvaluator hook; @Override protected boolean mustDelete(Path source) { if(source.toString().endsWith(HOOK_SUFFIX)){ return false; } final Path target = pathHelper.getTargetWithoutSuffix(source, DELETE_SUFFIX); hook = new FileHookEvaluator(source, target, conf); boolean mustDelete = super.mustDelete(source); boolean fileExists = exists(target); boolean pre = true; try { return mustDelete && fileExists && (pre = hook.pre()); } finally { if(!pre) { hook.finish(); } } } @Override protected void delete(Path source) throws IOException { try { Path target = pathHelper.getTargetWithoutSuffix(source, DELETE_SUFFIX); backupHelper.backupFileOrDir(target); FileUtils.delete(target); LOGGER.info(" :DELETED"); LOGGER.info("\t" + target); hook.post(); } finally { hook.finish(); } } }); } EnvConfigurator(Configuration conf); }
EnvConfigurator { protected void deleteFiles() { Path module = conf.getModule(); FileUtils.deleteDir(module, new DeleteVisitor("*" + DELETE_SUFFIX){ private FileHookEvaluator hook; @Override protected boolean mustDelete(Path source) { if(source.toString().endsWith(HOOK_SUFFIX)){ return false; } final Path target = pathHelper.getTargetWithoutSuffix(source, DELETE_SUFFIX); hook = new FileHookEvaluator(source, target, conf); boolean mustDelete = super.mustDelete(source); boolean fileExists = exists(target); boolean pre = true; try { return mustDelete && fileExists && (pre = hook.pre()); } finally { if(!pre) { hook.finish(); } } } @Override protected void delete(Path source) throws IOException { try { Path target = pathHelper.getTargetWithoutSuffix(source, DELETE_SUFFIX); backupHelper.backupFileOrDir(target); FileUtils.delete(target); LOGGER.info(" :DELETED"); LOGGER.info("\t" + target); hook.post(); } finally { hook.finish(); } } }); } EnvConfigurator(Configuration conf); void execute(); }
EnvConfigurator { protected void deleteFiles() { Path module = conf.getModule(); FileUtils.deleteDir(module, new DeleteVisitor("*" + DELETE_SUFFIX){ private FileHookEvaluator hook; @Override protected boolean mustDelete(Path source) { if(source.toString().endsWith(HOOK_SUFFIX)){ return false; } final Path target = pathHelper.getTargetWithoutSuffix(source, DELETE_SUFFIX); hook = new FileHookEvaluator(source, target, conf); boolean mustDelete = super.mustDelete(source); boolean fileExists = exists(target); boolean pre = true; try { return mustDelete && fileExists && (pre = hook.pre()); } finally { if(!pre) { hook.finish(); } } } @Override protected void delete(Path source) throws IOException { try { Path target = pathHelper.getTargetWithoutSuffix(source, DELETE_SUFFIX); backupHelper.backupFileOrDir(target); FileUtils.delete(target); LOGGER.info(" :DELETED"); LOGGER.info("\t" + target); hook.post(); } finally { hook.finish(); } } }); } EnvConfigurator(Configuration conf); void execute();  }