@ -16,8 +16,11 @@
package ro.fortsoft.pf4j.util ;
package ro.fortsoft.pf4j.util ;
import java.io.* ;
import java.io.* ;
import java.nio.file.FileVisitResult ;
import java.nio.file.Files ;
import java.nio.file.Files ;
import java.nio.file.Path ;
import java.nio.file.Path ;
import java.nio.file.SimpleFileVisitor ;
import java.nio.file.attribute.BasicFileAttributes ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.Collection ;
import java.util.Collection ;
import java.util.List ;
import java.util.List ;
@ -67,29 +70,28 @@ public class FileUtils {
}
}
}
}
/ * *
/ * *
* Delete a file or recursively delete a folder .
* Delete a file or recursively delete a folder , do not follow symlinks .
*
*
* @param fileOrFolder
* @param path the file or folder to delete
* @return true , if successful
* @throws IOException if something goes wrong
* /
* /
public static boolean delete ( File fileOrFolder ) {
public static void delete ( Path path ) throws IOException {
boolean success = false ;
Files . walkFileTree ( path , new SimpleFileVisitor < Path > ( ) {
if ( fileOrFolder . isDirectory ( ) ) {
@Override
File [ ] files = fileOrFolder . listFiles ( ) ;
public FileVisitResult visitFile ( Path path , BasicFileAttributes attrs ) throws IOException {
if ( files ! = null ) {
if ( ! attrs . isSymbolicLink ( ) ) {
for ( File file : files ) {
Files . delete ( path ) ;
if ( file . isDirectory ( ) ) {
}
success | = delete ( file ) ;
return FileVisitResult . CONTINUE ;
} else {
}
success | = file . delete ( ) ;
}
}
}
}
success | = fileOrFolder . delete ( ) ;
return success ;
@Override
public FileVisitResult postVisitDirectory ( Path dir , IOException exc ) throws IOException {
Files . delete ( dir ) ;
return FileVisitResult . CONTINUE ;
}
} ) ;
}
}
public static List < File > getJars ( Path folder ) {
public static List < File > getJars ( Path folder ) {
@ -116,5 +118,4 @@ public class FileUtils {
}
}
}
}
}
}
}
}