From: Julien HENRY Date: Tue, 10 May 2016 14:23:37 +0000 (+0200) Subject: SONAR-7523 Improve log output in case of error during SCM step X-Git-Tag: 5.6-RC1~169 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=437bf3bf7259b5f6f1f914c3fc0dcd2c2cc0b6df;p=sonarqube.git SONAR-7523 Improve log output in case of error during SCM step --- diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/report/ReportPublisher.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/report/ReportPublisher.java index c0487441c10..8c58555b856 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/report/ReportPublisher.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/report/ReportPublisher.java @@ -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(); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java index 314761fabb4..d30e41090f5 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java @@ -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, diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java index 69d7d5f2481..cf430a9f840 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/scm/DefaultBlameOutput.java @@ -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()); diff --git a/sonar-scanner-engine/src/main/java/org/sonar/batch/scm/ScmSensor.java b/sonar-scanner-engine/src/main/java/org/sonar/batch/scm/ScmSensor.java index 078224bb6c6..d6880f11fb3 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/batch/scm/ScmSensor.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/batch/scm/ScmSensor.java @@ -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); } }