diff options
Diffstat (limited to 'sonar-batch')
6 files changed, 43 insertions, 46 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginJarExploder.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginJarExploder.java index 3e8a4b3f6f4..a91a6b38cbc 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginJarExploder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchPluginJarExploder.java @@ -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; diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalTempFolderProvider.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalTempFolderProvider.java index 78de896f011..2ea3bff55a3 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalTempFolderProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/GlobalTempFolderProvider.java @@ -19,19 +19,6 @@ */ 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()); } } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java b/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java index 80aa01cde17..45baaecacc8 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java +++ b/sonar-batch/src/main/java/org/sonar/batch/cache/DefaultProjectCacheStatus.java @@ -19,10 +19,6 @@ */ 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); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/CachesManager.java b/sonar-batch/src/main/java/org/sonar/batch/index/CachesManager.java index 6700f8c0832..010375a84eb 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/CachesManager.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/CachesManager.java @@ -19,18 +19,17 @@ */ 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; } diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java index 35c747d11d3..5ab75c42f2a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/ReportPublisher.java @@ -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() diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/MutableProjectReactorProvider.java b/sonar-batch/src/main/java/org/sonar/batch/scan/MutableProjectReactorProvider.java index ac101e62822..c3d34a23a30 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/MutableProjectReactorProvider.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/MutableProjectReactorProvider.java @@ -19,13 +19,11 @@ */ 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); } |