aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-02-11 14:06:40 +0100
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2016-02-12 13:48:36 +0100
commit9af7d4b6c262fe1e0768221f8450dea459fe4986 (patch)
tree9f6be33b1e111b38bbf11acefb9f2e8fc0721076
parent10d172f208c89f439cbfd2f71a7cb1bfbfe43d9b (diff)
downloadsonarqube-9af7d4b6c262fe1e0768221f8450dea459fe4986.tar.gz
sonarqube-9af7d4b6c262fe1e0768221f8450dea459fe4986.zip
SONAR-7125 use efficient delete dir from NIO in sonar-api
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/DefaultTempFolder.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/DefaultTempFolder.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/DefaultTempFolder.java
index f0d4f06500c..f336064f21a 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/DefaultTempFolder.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/DefaultTempFolder.java
@@ -19,6 +19,9 @@
*/
package org.sonar.api.utils.internal;
+import java.nio.file.FileVisitResult;
+import java.nio.file.SimpleFileVisitor;
+import java.nio.file.attribute.BasicFileAttributes;
import org.apache.commons.io.FileUtils;
import org.sonar.api.utils.TempFolder;
@@ -28,8 +31,11 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
public class DefaultTempFolder implements TempFolder {
+ private static final Logger LOG = Loggers.get(DefaultTempFolder.class);
private final File tempDir;
private final boolean deleteOnExit;
@@ -86,7 +92,11 @@ public class DefaultTempFolder implements TempFolder {
}
public void clean() {
- FileUtils.deleteQuietly(tempDir);
+ try {
+ Files.walkFileTree(tempDir.toPath(), DeleteRecursivelyFileVisitor.INSTANCE);
+ } catch (IOException e) {
+ LOG.trace("Failed to delete temp folder", e);
+ }
}
public void stop() {
@@ -95,4 +105,20 @@ public class DefaultTempFolder implements TempFolder {
}
}
+ private static final class DeleteRecursivelyFileVisitor extends SimpleFileVisitor<Path> {
+ public static final DeleteRecursivelyFileVisitor INSTANCE = new DeleteRecursivelyFileVisitor();
+
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ Files.delete(file);
+ return FileVisitResult.CONTINUE;
+ }
+
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+ Files.delete(dir);
+ return FileVisitResult.CONTINUE;
+ }
+ }
+
}