diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-04-13 11:59:54 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-04-13 11:59:54 +0200 |
commit | 1434abc6dcf716a06267a109908c7dc920fad9c8 (patch) | |
tree | d64988b92b74bc4372fd1836f4296d9796b676e3 /sonar-batch | |
parent | b80b6a014a747f42f589cc9c7cc59b5a42b21e9a (diff) | |
download | sonarqube-1434abc6dcf716a06267a109908c7dc920fad9c8.tar.gz sonarqube-1434abc6dcf716a06267a109908c7dc920fad9c8.zip |
Restore old behavior for InputFile::lines() -> returns 1 for empty files
Diffstat (limited to 'sonar-batch')
6 files changed, 16 insertions, 19 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java index 978dbdb9643..53950bec479 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourceDataFactory.java @@ -31,13 +31,12 @@ import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.utils.KeyValueFormat; import org.sonar.batch.duplication.DuplicationCache; -import org.sonar.batch.protocol.output.BatchReport; +import org.sonar.batch.protocol.output.*; import org.sonar.batch.protocol.output.BatchReport.Range; import org.sonar.batch.protocol.output.BatchReport.Scm; import org.sonar.batch.protocol.output.BatchReport.Scm.Changeset; import org.sonar.batch.protocol.output.BatchReport.Symbols; import org.sonar.batch.protocol.output.BatchReport.SyntaxHighlighting; -import org.sonar.batch.protocol.output.BatchReportReader; import org.sonar.batch.report.BatchReportUtils; import org.sonar.batch.report.ReportPublisher; import org.sonar.batch.scan.measure.MeasureCache; @@ -73,7 +72,9 @@ public class SourceDataFactory implements BatchComponent { public byte[] consolidateData(DefaultInputFile inputFile) throws IOException { FileSourceDb.Data.Builder dataBuilder = createForSource(inputFile); - applyLineMeasures(inputFile, dataBuilder); + if (!inputFile.isEmpty()) { + applyLineMeasures(inputFile, dataBuilder); + } applyScm(inputFile, dataBuilder); applyDuplications(inputFile.key(), dataBuilder); applyHighlighting(inputFile, dataBuilder); diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java index a55562c88f2..d1defb7b7ca 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java +++ b/sonar-batch/src/main/java/org/sonar/batch/index/SourcePersister.java @@ -19,15 +19,14 @@ */ package org.sonar.batch.index; -import org.sonar.api.batch.fs.internal.FileMetadata; -import org.sonar.api.batch.fs.internal.FileMetadata.LineHashConsumer; - import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.digest.DigestUtils; import org.apache.ibatis.session.ResultContext; import org.apache.ibatis.session.ResultHandler; import org.sonar.api.batch.fs.InputFile; import org.sonar.api.batch.fs.internal.DefaultInputFile; +import org.sonar.api.batch.fs.internal.FileMetadata; +import org.sonar.api.batch.fs.internal.FileMetadata.LineHashConsumer; import org.sonar.api.utils.System2; import org.sonar.batch.ProjectTree; import org.sonar.batch.scan.filesystem.InputPathCache; @@ -126,9 +125,6 @@ public class SourcePersister implements ScanPersister { @CheckForNull private String lineHashesAsMd5Hex(DefaultInputFile f) { - if (f.lines() == 0) { - return null; - } // A md5 string is 32 char long + '\n' = 33 final StringBuilder result = new StringBuilder(f.lines() * (32 + 1)); diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/DatabaseLessPhaseExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/DatabaseLessPhaseExecutor.java index 644cf8bf724..e116bb80565 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/DatabaseLessPhaseExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/DatabaseLessPhaseExecutor.java @@ -47,12 +47,12 @@ public final class DatabaseLessPhaseExecutor implements PhaseExecutor { private final IssueExclusionsLoader issueExclusionsLoader; private final IssuesReports issuesReport; private final LocalIssueTracking localIssueTracking; - private final ReportPublisher publishReportJob; + private final ReportPublisher reportPublisher; public DatabaseLessPhaseExecutor(Phases phases, InitializersExecutor initializersExecutor, SensorsExecutor sensorsExecutor, SensorContext sensorContext, DefaultIndex index, EventBus eventBus, ProjectInitializer pi, FileSystemLogger fsLogger, IssuesReports jsonReport, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier, - IssueExclusionsLoader issueExclusionsLoader, LocalIssueTracking localIssueTracking, ReportPublisher publishReportJob) { + IssueExclusionsLoader issueExclusionsLoader, LocalIssueTracking localIssueTracking, ReportPublisher reportPublisher) { this.phases = phases; this.initializersExecutor = initializersExecutor; this.sensorsExecutor = sensorsExecutor; @@ -66,7 +66,7 @@ public final class DatabaseLessPhaseExecutor implements PhaseExecutor { this.profileVerifier = profileVerifier; this.issueExclusionsLoader = issueExclusionsLoader; this.localIssueTracking = localIssueTracking; - this.publishReportJob = publishReportJob; + this.reportPublisher = reportPublisher; } /** @@ -106,7 +106,7 @@ public final class DatabaseLessPhaseExecutor implements PhaseExecutor { private void publishReportJob() { String stepName = "Publish report"; eventBus.fireEvent(new BatchStepEvent(stepName, true)); - this.publishReportJob.execute(); + this.reportPublisher.execute(); eventBus.fireEvent(new BatchStepEvent(stepName, false)); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/DatabaseModePhaseExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/DatabaseModePhaseExecutor.java index 657a58083f2..7d01ad44a3c 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/DatabaseModePhaseExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/DatabaseModePhaseExecutor.java @@ -49,7 +49,7 @@ public final class DatabaseModePhaseExecutor implements PhaseExecutor { private final PostJobsExecutor postJobsExecutor; private final InitializersExecutor initializersExecutor; private final SensorsExecutor sensorsExecutor; - private final ReportPublisher publishReportJob; + private final ReportPublisher reportPublisher; private final SensorContext sensorContext; private final DefaultIndex index; private final ProjectInitializer pi; @@ -66,7 +66,7 @@ public final class DatabaseModePhaseExecutor implements PhaseExecutor { public DatabaseModePhaseExecutor(Phases phases, DecoratorsExecutor decoratorsExecutor, InitializersExecutor initializersExecutor, PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor, SensorContext sensorContext, DefaultIndex index, - EventBus eventBus, ReportPublisher publishReportJob, ProjectInitializer pi, + EventBus eventBus, ReportPublisher reportPublisher, ProjectInitializer pi, ScanPersister[] persisters, FileSystemLogger fsLogger, IssuesReports jsonReport, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier, IssueExclusionsLoader issueExclusionsLoader, DefaultAnalysisMode analysisMode, DatabaseSession session, ResourcePersister resourcePersister) { this.phases = phases; @@ -77,7 +77,7 @@ public final class DatabaseModePhaseExecutor implements PhaseExecutor { this.sensorContext = sensorContext; this.index = index; this.eventBus = eventBus; - this.publishReportJob = publishReportJob; + this.reportPublisher = reportPublisher; this.pi = pi; this.persisters = persisters; this.fsLogger = fsLogger; @@ -168,7 +168,7 @@ public final class DatabaseModePhaseExecutor implements PhaseExecutor { private void publishReportJob() { String stepName = "Publish report"; eventBus.fireEvent(new BatchStepEvent(stepName, true)); - this.publishReportJob.execute(); + this.reportPublisher.execute(); eventBus.fireEvent(new BatchStepEvent(stepName, false)); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java index 941f7d42f61..51365f6d5c6 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scm/ScmSensor.java @@ -106,7 +106,7 @@ public final class ScmSensor implements Sensor { } private void addIfNotEmpty(List<InputFile> filesToBlame, InputFile f) { - if (f.lines() > 0) { + if (!f.isEmpty()) { filesToBlame.add(f); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/EmptyFileTest.java b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/EmptyFileTest.java index 62ea53ce6ae..ac5d983c1e9 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/EmptyFileTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/mediumtest/preview/EmptyFileTest.java @@ -84,7 +84,7 @@ public class EmptyFileTest { .property("sonar.xoo.internalKey", "my/internal/key") .start(); - assertThat(result.issues()).hasSize(10); + assertThat(result.issues()).hasSize(11); } } |