diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2017-07-31 13:12:10 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2017-08-04 14:58:16 +0200 |
commit | 75e47ba5a19b3d4ab901d2ed7a180714b141d580 (patch) | |
tree | 9f15f196571ed354b9a17e0a790734813d7493ed /sonar-core | |
parent | 2183aa17c17e8cb7385bf1662a57368c0b2979fd (diff) | |
download | sonarqube-75e47ba5a19b3d4ab901d2ed7a180714b141d580.tar.gz sonarqube-75e47ba5a19b3d4ab901d2ed7a180714b141d580.zip |
Rework file indexing
* Drop cycle ModuleFileSystem -> FileIndexer -> ModuleFileSystem
* Ensure basedir is initialized once
* Drop useless FileSystemLogger, and log in ModuleFileSystemInitializer
Diffstat (limited to 'sonar-core')
-rw-r--r-- | sonar-core/src/main/java/org/sonar/core/util/FileUtils.java | 37 | ||||
-rw-r--r-- | sonar-core/src/test/java/org/sonar/core/util/FileUtilsTest.java | 5 |
2 files changed, 36 insertions, 6 deletions
diff --git a/sonar-core/src/main/java/org/sonar/core/util/FileUtils.java b/sonar-core/src/main/java/org/sonar/core/util/FileUtils.java index 2608f6d3bbc..04aa4980808 100644 --- a/sonar-core/src/main/java/org/sonar/core/util/FileUtils.java +++ b/sonar-core/src/main/java/org/sonar/core/util/FileUtils.java @@ -55,11 +55,21 @@ public final class FileUtils { */ public static void deleteDirectory(File directory) throws IOException { requireNonNull(directory, DIRECTORY_CAN_NOT_BE_NULL); - deleteDirectoryImpl(directory.toPath()); } /** + * Deletes a directory recursively. + * + * @param directory directory to delete + * @throws IOException in case deletion is unsuccessful + */ + public static void deleteDirectory(Path directory) throws IOException { + requireNonNull(directory, DIRECTORY_CAN_NOT_BE_NULL); + deleteDirectoryImpl(directory); + } + + /** * Cleans a directory recursively. * * @param directory directory to delete @@ -92,12 +102,31 @@ public final class FileUtils { if (file == null) { return false; } + return deleteQuietly(file.toPath()); + } + + /** + * Deletes a file, never throwing an exception. If file is a directory, delete it and all sub-directories. + * <p> + * The difference between File.delete() and this method are: + * <ul> + * <li>A directory to be deleted does not have to be empty.</li> + * <li>No exceptions are thrown when a file or directory cannot be deleted.</li> + * </ul> + * + * @param file file or directory to delete, can be {@code null} + * @return {@code true} if the file or directory was deleted, otherwise {@code false} + */ + public static boolean deleteQuietly(@Nullable Path path) { + if (path == null) { + return false; + } try { - if (file.isDirectory()) { - deleteDirectory(file); + if (Files.isDirectory(path)) { + deleteDirectory(path); } else { - Files.delete(file.toPath()); + Files.delete(path); } return true; } catch (IOException | SecurityException ignored) { diff --git a/sonar-core/src/test/java/org/sonar/core/util/FileUtilsTest.java b/sonar-core/src/test/java/org/sonar/core/util/FileUtilsTest.java index 38df109b402..a1054b47650 100644 --- a/sonar-core/src/test/java/org/sonar/core/util/FileUtilsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/util/FileUtilsTest.java @@ -124,7 +124,8 @@ public class FileUtilsTest { @Test public void deleteQuietly_does_not_fail_if_argument_is_null() { - FileUtils.deleteQuietly(null); + FileUtils.deleteQuietly((File) null); + FileUtils.deleteQuietly((Path) null); } @Test @@ -178,7 +179,7 @@ public class FileUtilsTest { public void deleteDirectory_throws_NPE_if_argument_is_null() throws IOException { expectDirectoryCanNotBeNullNPE(); - FileUtils.deleteDirectory(null); + FileUtils.deleteDirectory((File) null); } @Test |