]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7523 Improve log output in case of error during SCM step 945/head
authorJulien HENRY <julien.henry@sonarsource.com>
Tue, 10 May 2016 14:23:37 +0000 (16:23 +0200)
committerJulien HENRY <julien.henry@sonarsource.com>
Tue, 10 May 2016 15:30:36 +0000 (17:30 +0200)
sonar-scanner-engine/src/main/java/org/sonar/batch/report/ReportPublisher.java
sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java
sonar-scanner-engine/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java
sonar-scanner-engine/src/main/java/org/sonar/batch/scm/ScmSensor.java

index c0487441c10136afc4990b55734b5408da3c902f..8c58555b8566e6c0e6da0e7af8d1c0ca2eabcf10 100644 (file)
@@ -102,10 +102,8 @@ public class ReportPublisher implements Startable {
 
   @Override
   public void stop() {
-    if (!settings.getBoolean(KEEP_REPORT_PROP_KEY) && !settings.getBoolean(VERBOSE_KEY)) {
+    if (!shouldKeepReport()) {
       deleteQuietly(reportDir);
-    } else {
-      LOG.info("Analysis report generated in " + reportDir);
     }
   }
 
@@ -122,6 +120,9 @@ public class ReportPublisher implements Startable {
     String taskId = null;
     if (!analysisMode.isIssues()) {
       File report = generateReportFile();
+      if (shouldKeepReport()) {
+        LOG.info("Analysis report generated in " + reportDir);
+      }
       if (!analysisMode.isMediumTest()) {
         taskId = upload(report);
       }
@@ -129,6 +130,10 @@ public class ReportPublisher implements Startable {
     logSuccess(taskId);
   }
 
+  private boolean shouldKeepReport() {
+    return settings.getBoolean(KEEP_REPORT_PROP_KEY) || settings.getBoolean(VERBOSE_KEY);
+  }
+
   private File generateReportFile() {
     try {
       long startTime = System.currentTimeMillis();
index 314761fabb4edd08a4f2b2c07e1f4f17977c0505..d30e41090f5abd7431c4aaca08372069d863a83a 100644 (file)
@@ -99,7 +99,6 @@ public class ProjectScanContainer extends ComponentContainer {
   private static final Logger LOG = Loggers.get(ProjectScanContainer.class);
 
   private final AnalysisProperties props;
-  private ProjectLock lock;
 
   public ProjectScanContainer(ComponentContainer globalContainer, AnalysisProperties props) {
     super(globalContainer);
@@ -109,7 +108,7 @@ public class ProjectScanContainer extends ComponentContainer {
   @Override
   protected void doBeforeStart() {
     addBatchComponents();
-    lock = getComponentByType(ProjectLock.class);
+    ProjectLock lock = getComponentByType(ProjectLock.class);
     lock.tryLock();
     getComponentByType(WorkDirectoryCleaner.class).execute();
     addBatchExtensions();
@@ -122,19 +121,6 @@ public class ProjectScanContainer extends ComponentContainer {
     }
   }
 
-  @Override
-  public ComponentContainer startComponents() {
-    try {
-      return super.startComponents();
-    } catch (Exception e) {
-      // ensure that lock is released
-      if (lock != null) {
-        lock.stop();
-      }
-      throw e;
-    }
-  }
-
   private void addBatchComponents() {
     add(
       props,
index 69d7d5f2481072c4741902a48d4fdf8868d8c588..cf430a9f840d61a4a82402c4a3a99f91eed757bb 100644 (file)
@@ -39,8 +39,8 @@ import org.sonar.batch.index.BatchComponent;
 import org.sonar.batch.index.BatchComponentCache;
 import org.sonar.batch.util.ProgressReport;
 import org.sonar.scanner.protocol.output.ScannerReport;
-import org.sonar.scanner.protocol.output.ScannerReportWriter;
 import org.sonar.scanner.protocol.output.ScannerReport.Changesets.Builder;
+import org.sonar.scanner.protocol.output.ScannerReportWriter;
 
 class DefaultBlameOutput implements BlameOutput {
 
@@ -134,9 +134,9 @@ class DefaultBlameOutput implements BlameOutput {
     return NON_ASCII_CHARS.matcher(inputString).replaceAll("_");
   }
 
-  public void finish() {
+  public void finish(boolean success) {
     progressReport.stop(count + "/" + total + " files analyzed");
-    if (!allFilesToBlame.isEmpty()) {
+    if (success && !allFilesToBlame.isEmpty()) {
       LOG.warn("Missing blame information for the following files:");
       for (InputFile f : allFilesToBlame) {
         LOG.warn("  * " + f.absolutePath());
index 078224bb6c6e3d4a5b5d5aa01334272de8139430..d6880f11fb3eba43f6c297735299e157d889f5fd 100644 (file)
@@ -81,9 +81,11 @@ public final class ScmSensor implements Sensor {
       DefaultBlameOutput output = new DefaultBlameOutput(publishReportJob.getWriter(), resourceCache, filesToBlame);
       try {
         configuration.provider().blameCommand().blame(new DefaultBlameInput(fs, filesToBlame), output);
-      } finally {
-        output.finish();
+      } catch (Exception e) {
+        output.finish(false);
+        throw e;
       }
+      output.finish(true);
     }
   }