KarafBoot implements IPentahoSystemListener { protected void deleteRecursiveIfExists( File item ) { if ( !item.exists() ) { return; } if ( !Files.isSymbolicLink( item.toPath() ) && item.isDirectory() ) { File[] subitems = item.listFiles(); for ( File subitem : subitems ) { deleteRecursiveIfExists( subitem ); } } try { if ( !item.delete() ) { logger.warn( item.toURI().toString() + " could not be deleted." ); } } catch ( SecurityException exception ) { logger.warn( item.toURI().toString() + " cannot delete file. Access denied." ); } }  @Override boolean startup( IPentahoSession session ); @Override void shutdown(); static final String CLEAN_KARAF_CACHE; static final String PENTAHO_KARAF_ROOT_COPY_DEST_FOLDER; static final String PENTAHO_KARAF_ROOT_TRANSIENT; static final String PENTAHO_KARAF_ROOT_TRANSIENT_DIRECTORY_ATTEMPTS; static final String PENTAHO_KARAF_ROOT_COPY_FOLDER_SYMLINK_FILES; static final String PENTAHO_KARAF_ROOT_COPY_FOLDER_EXCLUDE_FILES; static final String ORG_OSGI_FRAMEWORK_SYSTEM_PACKAGES_EXTRA; static final String PENTAHO_KARAF_INSTANCE_RESOLVER_CLASS; }
@Test public void deleteRecursiveIfExistsTest() { File dir = new File( "dir" ); dir.mkdir(); File file = new File( dir, "file" ); try { file.createNewFile(); boot.deleteRecursiveIfExists( dir ); assertNull( dir.listFiles() ); } catch ( IOException e ) { fail( "Couldn't create file to test deleteRecursiveIfExists()" ); } }