]> source.dussan.org Git - sonarqube.git/commitdiff
Fix Quality flaws
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Mon, 30 Jul 2018 15:34:02 +0000 (17:34 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 2 Aug 2018 18:21:36 +0000 (20:21 +0200)
sonar-core/src/main/java/org/sonar/core/util/FileUtils.java
sonar-core/src/test/java/org/sonar/core/util/FileUtilsTest.java

index 5b91a8055f342298f9cc919be9f588fb4ca19048..85d55a3b1cd4b1bd2902e6fbd6c68a94f4ad005e 100644 (file)
@@ -50,7 +50,7 @@ public final class FileUtils {
   /**
    * Deletes a directory recursively.
    *
-   * @param directory  directory to delete
+   * @param directory directory to delete
    * @throws IOException in case deletion is unsuccessful
    */
   public static void deleteDirectory(File directory) throws IOException {
@@ -61,7 +61,7 @@ public final class FileUtils {
   /**
    * Deletes a directory recursively.
    *
-   * @param directory  directory to delete
+   * @param directory directory to delete
    * @throws IOException in case deletion is unsuccessful
    */
   public static void deleteDirectory(Path directory) throws IOException {
@@ -72,7 +72,7 @@ public final class FileUtils {
   /**
    * Cleans a directory recursively.
    *
-   * @param directory  directory to delete
+   * @param directory directory to delete
    * @throws IOException in case deletion is unsuccessful
    */
   public static void cleanDirectory(File directory) throws IOException {
@@ -95,7 +95,7 @@ public final class FileUtils {
    * <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}
+   * @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 File file) {
@@ -114,7 +114,7 @@ public final class FileUtils {
    * <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}
+   * @param path 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) {
@@ -123,7 +123,7 @@ public final class FileUtils {
     }
 
     try {
-      if (Files.isDirectory(path)) {
+      if (path.toFile().isDirectory()) {
         deleteDirectory(path);
       } else {
         Files.delete(path);
@@ -160,13 +160,6 @@ public final class FileUtils {
 
     checkIO(!file.exists(), "Unable to delete directory '%s'", path);
   }
-  
-  
-  public static Path getPack200FilePath(Path jarFilePath) {
-    String jarFileName = jarFilePath.getFileName().toString();
-    String filename = jarFileName.substring(0, jarFileName.length() - 3) + "pack.gz";
-    return jarFilePath.resolveSibling(filename);
-  }
 
   /**
    * This visitor is intended to be used to visit direct children of directory <strong>or a symLink to a directory</strong>,
@@ -174,12 +167,12 @@ public final class FileUtils {
    * or recursively deleted (if directory).
    */
   private static class CleanDirectoryFileVisitor extends SimpleFileVisitor<Path> {
-    public static final int VISIT_MAX_DEPTH = 1;
+    private static final int VISIT_MAX_DEPTH = 1;
 
     private final Path path;
     private final boolean symLink;
 
-    public CleanDirectoryFileVisitor(Path path) {
+    private CleanDirectoryFileVisitor(Path path) {
       this.path = path;
       this.symLink = Files.isSymbolicLink(path);
     }
index 258fda584086997b35a34077b3c481b4f50ea53d..bc47bfd9618c401bf34c9e7ffa8c7fa8a5ffeb86 100644 (file)
@@ -23,7 +23,6 @@ import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.nio.file.attribute.BasicFileAttributes;
 import javax.annotation.CheckForNull;
 import org.apache.commons.lang.SystemUtils;
@@ -239,12 +238,6 @@ public class FileUtilsTest {
     assertThat(childDir2).doesNotExist();
   }
 
-  @Test
-  public void getPack200FilePath_transforms_jar_name() {
-    Path jarPath = Paths.get("plugin.jar");
-    assertThat(FileUtils.getPack200FilePath(jarPath)).isEqualTo(Paths.get("plugin.pack.gz"));
-  }
-
   private void expectDirectoryCanNotBeNullNPE() {
     expectedException.expect(NullPointerException.class);
     expectedException.expectMessage("Directory can not be null");