Add tests for CommandUtils, move purgeDirectory to its only use

This commit is contained in:
ljacqu
2015-12-14 21:37:20 +01:00
parent 282f777311
commit bfebf6dc44
3 changed files with 74 additions and 24 deletions
+22 -2
View File
@@ -5,7 +5,6 @@ import com.google.common.io.Files;
import com.google.gson.*;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.Utils;
import org.bukkit.entity.Player;
import java.io.File;
@@ -109,7 +108,7 @@ public class JsonCache {
}
File file = new File(cacheDir, path);
if (file.exists()) {
Utils.purgeDirectory(file);
purgeDirectory(file);
if (!file.delete()) {
ConsoleLogger.showError("Failed to remove" + player.getName() + "cache.");
}
@@ -194,4 +193,25 @@ public class JsonCache {
}
}
/**
* Delete a given directory and all its content.
*
* @param directory The directory to remove
*/
private static void purgeDirectory(File directory) {
if (!directory.isDirectory()) {
return;
}
File[] files = directory.listFiles();
if (files == null) {
return;
}
for (File target : files) {
if (target.isDirectory()) {
purgeDirectory(target);
}
target.delete();
}
}
}
@@ -15,7 +15,6 @@ import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
@@ -207,27 +206,6 @@ public final class Utils {
}
}
/**
* Delete a given directory and all his content.
*
* @param directory File
*/
public static void purgeDirectory(File directory) {
if (!directory.isDirectory()) {
return;
}
File[] files = directory.listFiles();
if (files == null) {
return;
}
for (File target : files) {
if (target.isDirectory()) {
purgeDirectory(target);
}
target.delete();
}
}
/**
* Safe way to retrieve the list of online players from the server. Depending on the
* implementation of the server, either an array of {@link Player} instances is being returned,