]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7125 use efficient delete dir code in core, batch and server 775/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 11 Feb 2016 13:07:01 +0000 (14:07 +0100)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Fri, 12 Feb 2016 12:48:36 +0000 (13:48 +0100)
use Java NIO rather than Common IO FileUtils

16 files changed:
server/sonar-server/src/main/java/org/sonar/server/app/EmbeddedTomcat.java
server/sonar-server/src/main/java/org/sonar/server/app/TomcatContexts.java
server/sonar-server/src/main/java/org/sonar/server/computation/queue/report/ReportFiles.java
server/sonar-server/src/main/java/org/sonar/server/platform/DefaultServerFileSystem.java
server/sonar-server/src/main/java/org/sonar/server/platform/RailsAppsDeployer.java
server/sonar-server/src/main/java/org/sonar/server/plugins/PluginDownloader.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginJarExploder.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ServerPluginRepository.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/QProfileCopier.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginJarExploder.java
sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalTempFolderProvider.java
sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java
sonar-batch/src/main/java/org/sonar/batch/index/CachesManager.java
sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java
sonar-batch/src/main/java/org/sonar/batch/scan/MutableProjectReactorProvider.java
sonar-core/src/main/java/org/sonar/core/util/DefaultHttpDownloader.java

index 39b5d5c1e0a4a8e6acdc172b83dfeb7998727902..432dbae8ff92a2545f191c5c54c0666e2c5e5ddd 100644 (file)
@@ -24,11 +24,12 @@ import java.io.File;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.Tomcat;
-import org.apache.commons.io.FileUtils;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.process.ProcessProperties;
 import org.sonar.process.Props;
 
+import static org.sonar.core.util.FileUtils.deleteQuietly;
+
 class EmbeddedTomcat {
 
   private final Props props;
@@ -97,7 +98,7 @@ class EmbeddedTomcat {
         Loggers.get(EmbeddedTomcat.class).error("Fail to stop web server", e);
       }
     }
-    FileUtils.deleteQuietly(tomcatBasedir());
+    deleteQuietly(tomcatBasedir());
   }
 
   void awaitTermination() {
index deece74787a1e009508739f6043b7f7e37ab9c33..7ed8a009486b3a4552154920e86a4488f7c0185c 100644 (file)
@@ -136,7 +136,7 @@ public class TomcatContexts {
   static class Fs {
     void createOrCleanupDir(File dir) throws IOException {
       FileUtils.forceMkdir(dir);
-      FileUtils.cleanDirectory(dir);
+      org.sonar.core.util.FileUtils.cleanDirectory(dir);
     }
   }
 }
index 255f1d61cbbb7eeb44128766412eeeddff72197f..1bc74abf9733b1abc3141a5161ef22de4d0964c0 100644 (file)
@@ -49,21 +49,21 @@ public class ReportFiles {
     try {
       FileUtils.copyInputStreamToFile(reportInput, file);
     } catch (Exception e) {
-      FileUtils.deleteQuietly(file);
+      org.sonar.core.util.FileUtils.deleteQuietly(file);
       IOUtils.closeQuietly(reportInput);
       throw new IllegalStateException(format("Fail to copy report to file: %s", file.getAbsolutePath()), e);
     }
   }
 
   public void deleteIfExists(String taskUuid) {
-    FileUtils.deleteQuietly(fileForUuid(taskUuid));
+    org.sonar.core.util.FileUtils.deleteQuietly(fileForUuid(taskUuid));
   }
 
   public void deleteAll() {
     File dir = reportDir();
     if (dir.exists()) {
       try {
-        FileUtils.cleanDirectory(dir);
+        org.sonar.core.util.FileUtils.cleanDirectory(dir);
       } catch (Exception e) {
         throw new IllegalStateException(format("Fail to clean directory: %s", dir.getAbsolutePath()), e);
       }
index dc41d22473301cd6f8af171f30633c4ddfc3513b..176f533dbe3c9ae43f34c143f9fddca309b8e1e0 100644 (file)
@@ -74,7 +74,7 @@ public class DefaultServerFileSystem implements ServerFileSystem, Startable {
     File deprecated = getDeprecatedPluginsDir();
     try {
       FileUtils.forceMkdir(deprecated);
-      FileUtils.cleanDirectory(deprecated);
+      org.sonar.core.util.FileUtils.cleanDirectory(deprecated);
     } catch (IOException e) {
       throw new IllegalStateException("The following directory can not be created: " + deprecated.getAbsolutePath(), e);
     }
index b4f6391b30f86cf3aba07d8ce7515338105d03b6..ee56ab6226d4ec3277924a9cfd2c7c19066d854e 100644 (file)
@@ -111,7 +111,7 @@ public class RailsAppsDeployer implements Startable {
   private void prepareDir(File appsDir) {
     if (appsDir.exists() && appsDir.isDirectory()) {
       try {
-        FileUtils.deleteDirectory(appsDir);
+        org.sonar.core.util.FileUtils.deleteDirectory(appsDir);
       } catch (IOException e) {
         throw new IllegalStateException("Fail to delete temp directory: " + appsDir, e);
       }
index c85905a927fc99e453c287bcbed2e5cf37eafdb2..436e657efa444b9c762cd0e0d8ef3df422f1552f 100644 (file)
@@ -42,14 +42,13 @@ import org.sonar.updatecenter.common.Version;
 
 import static com.google.common.collect.Iterables.transform;
 import static com.google.common.collect.Lists.newArrayList;
-import static org.apache.commons.io.FileUtils.cleanDirectory;
 import static org.apache.commons.io.FileUtils.copyFile;
 import static org.apache.commons.io.FileUtils.copyFileToDirectory;
-import static org.apache.commons.io.FileUtils.deleteQuietly;
 import static org.apache.commons.io.FileUtils.forceMkdir;
 import static org.apache.commons.io.FileUtils.toFile;
 import static org.apache.commons.lang.StringUtils.substringAfterLast;
 import static org.sonar.core.platform.PluginInfo.jarToPluginInfo;
+import static org.sonar.core.util.FileUtils.deleteQuietly;
 
 /**
  * Downloads plugins from update center. Files are copied in the directory extensions/downloads and then
@@ -95,7 +94,7 @@ public class PluginDownloader implements Startable {
   public void cancelDownloads() {
     try {
       if (downloadDir.exists()) {
-        cleanDirectory(downloadDir);
+        org.sonar.core.util.FileUtils.cleanDirectory(downloadDir);
       }
     } catch (IOException e) {
       throw new IllegalStateException("Fail to clean the plugin downloads directory: " + downloadDir, e);
index e29e063a6aa885d31c151bbe13cdf9393b5a74f6..db74246c80f23eca0e4ca6a7eb27cf49b15887c7 100644 (file)
  */
 package org.sonar.server.plugins;
 
+import java.io.File;
 import org.apache.commons.io.FileUtils;
 import org.sonar.api.server.ServerSide;
 import org.sonar.api.utils.ZipUtils;
 import org.sonar.core.platform.ExplodedPlugin;
-import org.sonar.core.platform.PluginJarExploder;
 import org.sonar.core.platform.PluginInfo;
+import org.sonar.core.platform.PluginJarExploder;
 import org.sonar.server.platform.DefaultServerFileSystem;
 
-import java.io.File;
-
-import static org.apache.commons.io.FileUtils.cleanDirectory;
 import static org.apache.commons.io.FileUtils.forceMkdir;
 
 @ServerSide
@@ -51,7 +49,7 @@ public class ServerPluginJarExploder extends PluginJarExploder {
     File toDir = new File(fs.getDeployedPluginsDir(), pluginInfo.getKey());
     try {
       forceMkdir(toDir);
-      cleanDirectory(toDir);
+      org.sonar.core.util.FileUtils.cleanDirectory(toDir);
 
       File jarSource = pluginInfo.getNonNullJarFile();
       File jarTarget = new File(toDir, jarSource.getName());
index 90f5d726e928ebe67046f5b664dbdfd7cb2da92c..40bcc6b20dc1e76f36ed3ac79fce63918ef00386 100644 (file)
@@ -53,7 +53,7 @@ import static com.google.common.collect.Iterables.transform;
 import static com.google.common.collect.Lists.newArrayList;
 import static java.lang.String.format;
 import static org.apache.commons.io.FileUtils.copyFile;
-import static org.apache.commons.io.FileUtils.deleteQuietly;
+import static org.sonar.core.util.FileUtils.deleteQuietly;
 import static org.apache.commons.io.FileUtils.moveFile;
 import static org.apache.commons.io.FileUtils.moveFileToDirectory;
 import static org.sonar.core.platform.PluginInfo.jarToPluginInfo;
@@ -159,7 +159,7 @@ public class ServerPluginRepository implements PluginRepository, Startable {
   private void registerPluginInfo(PluginInfo info) {
     if (blacklistedPluginKeys.contains(info.getKey())) {
       LOG.warn("Plugin {} [{}] is blacklisted and is being uninstalled.", info.getName(), info.getKey());
-      deleteQuietly(info.getNonNullJarFile());
+      org.sonar.core.util.FileUtils.deleteQuietly(info.getNonNullJarFile());
       return;
     }
     PluginInfo existing = pluginInfosByKeys.put(info.getKey(), info);
index 8844f5977511dd5740b371f9c7524ac32747ddee..621717a2d6c2edea8561e805f8945ea97529d8b2 100644 (file)
  */
 package org.sonar.server.qualityprofile;
 
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.server.ServerSide;
-import org.sonar.api.utils.TempFolder;
-import org.sonar.db.DbSession;
-import org.sonar.db.qualityprofile.QualityProfileDto;
-import org.sonar.db.DbClient;
-
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
@@ -35,6 +26,14 @@ import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.io.Writer;
 import java.nio.charset.StandardCharsets;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringUtils;
+import org.sonar.api.server.ServerSide;
+import org.sonar.api.utils.TempFolder;
+import org.sonar.db.DbClient;
+import org.sonar.db.DbSession;
+import org.sonar.db.qualityprofile.QualityProfileDto;
 
 @ServerSide
 public class QProfileCopier {
@@ -59,7 +58,7 @@ public class QProfileCopier {
       restore(backupFile, QProfileName.createFor(to.getLanguage(), to.getName()));
       return to;
     } finally {
-      FileUtils.deleteQuietly(backupFile);
+      org.sonar.core.util.FileUtils.deleteQuietly(backupFile);
     }
   }
 
index 3e8a4b3f6f4d87ea526d94717690fbaf03dcd243..a91a6b38cbc5659af73883d9515b565434ff5ce2 100644 (file)
@@ -31,6 +31,8 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 
+import static org.sonar.core.util.FileUtils.deleteQuietly;
+
 @BatchSide
 public class BatchPluginJarExploder extends PluginJarExploder {
 
@@ -70,7 +72,7 @@ public class BatchPluginJarExploder extends PluginJarExploder {
         }
       } finally {
         out.close();
-        FileUtils.deleteQuietly(lockFile);
+        deleteQuietly(lockFile);
       }
     }
     return destDir;
index 78de896f0111e621548ce5b1703b669d827e50f4..2ea3bff55a34f7bf88c7d3879c7af99069eca198 100644 (file)
  */
 package org.sonar.batch.bootstrap;
 
-import org.picocontainer.ComponentLifecycle;
-
-import org.picocontainer.PicoContainer;
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.utils.System2;
-import org.sonar.api.utils.log.Logger;
-import org.sonar.api.utils.log.Loggers;
-import org.apache.commons.io.FileUtils;
-import org.sonar.api.utils.TempFolder;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.utils.internal.DefaultTempFolder;
-
 import java.io.IOException;
 import java.nio.file.DirectoryStream;
 import java.nio.file.Files;
@@ -39,6 +26,18 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.concurrent.TimeUnit;
+import org.apache.commons.lang.StringUtils;
+import org.picocontainer.ComponentLifecycle;
+import org.picocontainer.PicoContainer;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.CoreProperties;
+import org.sonar.api.utils.System2;
+import org.sonar.api.utils.TempFolder;
+import org.sonar.api.utils.internal.DefaultTempFolder;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
+
+import static org.sonar.core.util.FileUtils.deleteQuietly;
 
 public class GlobalTempFolderProvider extends ProviderAdapter implements ComponentLifecycle<TempFolder> {
   private static final Logger LOG = Loggers.get(GlobalTempFolderProvider.class);
@@ -113,7 +112,7 @@ public class GlobalTempFolderProvider extends ProviderAdapter implements Compone
     if (Files.exists(path)) {
       try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, new CleanFilter())) {
         for (Path p : stream) {
-          FileUtils.deleteQuietly(p.toFile());
+          deleteQuietly(p.toFile());
         }
       }
     }
index 80aa01cde17889c15ecc1bb1c4e755f7182651ba..45baaecacc8003a40dc0ce8079763c59dd91986c 100644 (file)
  */
 package org.sonar.batch.cache;
 
-import org.apache.commons.io.FileUtils;
-
-import org.sonar.home.cache.PersistentCache;
-
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -31,6 +27,9 @@ import java.io.ObjectOutputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Date;
+import org.sonar.home.cache.PersistentCache;
+
+import static org.sonar.core.util.FileUtils.deleteQuietly;
 
 public class DefaultProjectCacheStatus implements ProjectCacheStatus {
   private static final String STATUS_FILENAME = "cache-sync-status";
@@ -56,7 +55,7 @@ public class DefaultProjectCacheStatus implements ProjectCacheStatus {
   @Override
   public void delete() {
     cache.clear();
-    FileUtils.deleteQuietly(getStatusFilePath().toFile());
+    deleteQuietly(getStatusFilePath().toFile());
   }
 
   @Override
@@ -70,7 +69,7 @@ public class DefaultProjectCacheStatus implements ProjectCacheStatus {
         return (Date) objInput.readObject();
       }
     } catch (IOException | ClassNotFoundException e) {
-      FileUtils.deleteQuietly(p.toFile());
+      deleteQuietly(p.toFile());
       throw new IllegalStateException("Failed to read cache sync status", e);
     }
   }
index 6700f8c08326f46db3542ba715237f5d0bcc78c4..010375a84eb779e66a555ac85005cf4375116aa8 100644 (file)
  */
 package org.sonar.batch.index;
 
-import org.sonar.api.utils.TempFolder;
-
 import com.persistit.Persistit;
 import com.persistit.exception.PersistitException;
 import com.persistit.logging.Slf4jAdapter;
-import org.apache.commons.io.FileUtils;
+import java.io.File;
+import java.util.Properties;
 import org.picocontainer.Startable;
 import org.slf4j.LoggerFactory;
 import org.sonar.api.batch.BatchSide;
+import org.sonar.api.utils.TempFolder;
 
-import java.io.File;
-import java.util.Properties;
+import static org.sonar.core.util.FileUtils.deleteQuietly;
 
 /**
  * Factory of caches
@@ -85,7 +84,7 @@ public class CachesManager implements Startable {
         throw new IllegalStateException("Fail to close caches", e);
       }
     }
-    FileUtils.deleteQuietly(tempDir);
+    deleteQuietly(tempDir);
     tempDir = null;
   }
 
index 35c747d11d31ba0d30959e50b677d82c66e69c08..5ab75c42f2a1dac676336fdf74f3ea4016a7f385 100644 (file)
@@ -23,6 +23,15 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Throwables;
 import com.google.common.io.Files;
 import com.squareup.okhttp.HttpUrl;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Writer;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import javax.annotation.Nullable;
 import org.apache.commons.io.FileUtils;
 import org.picocontainer.Startable;
 import org.sonar.api.CoreProperties;
@@ -42,15 +51,7 @@ import org.sonarqube.ws.WsCe;
 import org.sonarqube.ws.client.PostRequest;
 import org.sonarqube.ws.client.WsResponse;
 
-import javax.annotation.Nullable;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Writer;
-import java.net.URL;
-import java.nio.charset.StandardCharsets;
-import java.util.LinkedHashMap;
-import java.util.Map;
+import static org.sonar.core.util.FileUtils.deleteQuietly;
 
 @BatchSide
 public class ReportPublisher implements Startable {
@@ -73,7 +74,7 @@ public class ReportPublisher implements Startable {
   private BatchReportWriter writer;
 
   public ReportPublisher(Settings settings, BatchWsClient wsClient, AnalysisContextReportPublisher contextPublisher,
-                         ImmutableProjectReactor projectReactor, DefaultAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers) {
+    ImmutableProjectReactor projectReactor, DefaultAnalysisMode analysisMode, TempFolder temp, ReportPublisherStep[] publishers) {
     this.settings = settings;
     this.wsClient = wsClient;
     this.contextPublisher = contextPublisher;
@@ -93,7 +94,7 @@ public class ReportPublisher implements Startable {
   @Override
   public void stop() {
     if (!settings.getBoolean(KEEP_REPORT_PROP_KEY) && !settings.getBoolean(VERBOSE_KEY)) {
-      FileUtils.deleteQuietly(reportDir);
+      deleteQuietly(reportDir);
     } else {
       LOG.info("Analysis report generated in " + reportDir);
     }
@@ -174,7 +175,7 @@ public class ReportPublisher implements Startable {
       String effectiveKey = projectReactor.getRoot().getKeyWithBranch();
       metadata.put("projectKey", effectiveKey);
       metadata.put("serverUrl", publicUrl());
-      
+
       URL dashboardUrl = HttpUrl.parse(publicUrl()).newBuilder()
         .addPathSegment("dashboard").addPathSegment("index").addPathSegment(effectiveKey)
         .build()
index ac101e628229fa7864ef93c282131d211f03def7..c3d34a23a30d10243c2457df91f722f2d4fe2be8 100644 (file)
  */
 package org.sonar.batch.scan;
 
-import org.apache.commons.io.FileUtils;
-import org.picocontainer.injectors.ProviderAdapter;
-import org.sonar.api.batch.bootstrap.ProjectReactor;
-
 import java.io.File;
 import java.io.IOException;
-import java.nio.file.Files;
+import org.picocontainer.injectors.ProviderAdapter;
+import org.sonar.api.batch.bootstrap.ProjectReactor;
+import org.sonar.core.util.FileUtils;
 
 public class MutableProjectReactorProvider extends ProviderAdapter {
   private ProjectReactor reactor = null;
@@ -40,8 +38,7 @@ public class MutableProjectReactorProvider extends ProviderAdapter {
 
   private static void cleanDirectory(File dir) {
     try {
-      FileUtils.deleteDirectory(dir);
-      Files.createDirectories(dir.toPath());
+      FileUtils.cleanDirectory(dir);
     } catch (IOException e) {
       throw new IllegalStateException("Failed to recreate working directory: " + dir.getAbsolutePath(), e);
     }
index 5f6f9820844b6b014db27fdb47dcd6d734d0db0a..a1572554d8688abe1cda3dc328b7712ef70b3c7b 100644 (file)
@@ -29,7 +29,6 @@ import com.google.common.io.ByteStreams;
 import com.google.common.io.CharStreams;
 import com.google.common.io.Files;
 import com.google.common.io.InputSupplier;
-
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
@@ -44,11 +43,8 @@ import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Map;
 import java.util.zip.GZIPInputStream;
-
 import javax.annotation.Nullable;
-
 import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.sonar.api.config.Settings;
 import org.sonar.api.platform.Server;
@@ -56,6 +52,8 @@ import org.sonar.api.utils.HttpDownloader;
 import org.sonar.api.utils.SonarException;
 import org.sonar.api.utils.log.Loggers;
 
+import static org.sonar.core.util.FileUtils.deleteQuietly;
+
 /**
  * This component downloads HTTP files
  *
@@ -150,7 +148,7 @@ public class DefaultHttpDownloader extends HttpDownloader {
     try {
       Files.copy(downloader.newInputSupplier(uri, this.connectTimeout, this.readTimeout), toFile);
     } catch (IOException e) {
-      FileUtils.deleteQuietly(toFile);
+      deleteQuietly(toFile);
       throw failToDownload(uri, e);
     }
   }