diff options
author | Jenkins CI <ci@sonarsource.com> | 2016-02-15 08:11:57 +0100 |
---|---|---|
committer | Jenkins CI <ci@sonarsource.com> | 2016-02-15 08:11:57 +0100 |
commit | aa82282b15b0ea160d1e227ec1532b4cb7b49520 (patch) | |
tree | 1a07f487eec1e5254473e200e517754e71620218 /sonar-plugin-api | |
parent | 640ae85cdd30643c8c58ab092b998274422758d0 (diff) | |
parent | e93851854a5ab728fba5e83b81b7a4a24208481a (diff) | |
download | sonarqube-aa82282b15b0ea160d1e227ec1532b4cb7b49520.tar.gz sonarqube-aa82282b15b0ea160d1e227ec1532b4cb7b49520.zip |
Automatic merge from branch-5.4
* origin/branch-5.4:
Refactor a bit ComponentContainer
stabilize ProjectDrilldownTest
SONAR-7125 use efficient delete dir code in core, batch and server
SONAR-7125 use efficient delete dir from NIO in sonar-api
SONAR-7125 add FileUtils in sonar-core with efficient delete methods
SONAR-7125 use efficient delete dir method in sonar-process
SONAR-7125 use nio to clean temp directory at startup
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/utils/internal/DefaultTempFolder.java | 28 |
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; + } + } + } |