aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-04-13 13:48:15 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-04-13 13:48:51 +0200
commita7b6712ecd7c63b9a9626035632aef1de064b1af (patch)
tree6171f329a34ec87f5d91faec0434b702776666df /server
parent4fabf1ed5f71619481f54b95cd1b6ce447d81799 (diff)
downloadsonarqube-a7b6712ecd7c63b9a9626035632aef1de064b1af.tar.gz
sonarqube-a7b6712ecd7c63b9a9626035632aef1de064b1af.zip
SONAR-6258 Close LineReaders when all lines have been read
Diffstat (limited to 'server')
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java56
1 files changed, 38 insertions, 18 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
index de2fa9ca7aa..26e71e31af9 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/computation/step/PersistFileSourcesStep.java
@@ -20,8 +20,6 @@
package org.sonar.server.computation.step;
-import com.google.common.base.Predicates;
-import com.google.common.collect.Iterables;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
@@ -91,12 +89,14 @@ public class PersistFileSourcesStep implements ComputationStep {
BatchReport.Component component = reportReader.readComponent(componentRef);
if (component.getType().equals(Constants.ComponentType.FILE)) {
LineIterator linesIterator = sourceLinesIterator(reportReader.readFileSource(componentRef));
+ LineReaders lineReaders = new LineReaders(reportReader, componentRef);
try {
- ComputeFileSourceData computeFileSourceData = new ComputeFileSourceData(linesIterator, dataLineReaders(reportReader, componentRef), component.getLines());
+ ComputeFileSourceData computeFileSourceData = new ComputeFileSourceData(linesIterator, lineReaders.readers(), component.getLines());
ComputeFileSourceData.Data fileSourceData = computeFileSourceData.compute();
persistSource(fileSourcesContext, fileSourceData, component);
} finally {
linesIterator.close();
+ lineReaders.close();
}
}
@@ -113,21 +113,6 @@ public class PersistFileSourcesStep implements ComputationStep {
}
}
- private List<LineReader> dataLineReaders(BatchReportReader reportReader, int componentRef) {
- List<LineReader> lineReaders = newArrayList();
-
- File coverageFile = reportReader.readComponentCoverage(componentRef);
- BatchReport.Scm scmReport = reportReader.readComponentScm(componentRef);
- File highlightingFile = reportReader.readComponentSyntaxHighlighting(componentRef);
-
- lineReaders.add(coverageFile != null ? new CoverageLineReader(new ReportIterator<>(coverageFile, BatchReport.Coverage.PARSER)) : null);
- lineReaders.add(scmReport != null ? new ScmLineReader(scmReport) : null);
- lineReaders.add(highlightingFile != null ? new HighlightingLineReader(new ReportIterator<>(highlightingFile, BatchReport.SyntaxHighlighting.PARSER)) : null);
-
- Iterables.removeIf(lineReaders, Predicates.isNull());
- return lineReaders;
- }
-
private void persistSource(FileSourcesContext fileSourcesContext, ComputeFileSourceData.Data fileSourceData, BatchReport.Component component) {
FileSourceDb.Data fileData = fileSourceData.getFileSourceData();
@@ -183,6 +168,41 @@ public class PersistFileSourcesStep implements ComputationStep {
}
}
+ private static class LineReaders {
+ private final List<LineReader> lineReaders = newArrayList();
+ private final List<ReportIterator> reportIterators = newArrayList();
+
+ LineReaders(BatchReportReader reportReader, int componentRef) {
+ File coverageFile = reportReader.readComponentCoverage(componentRef);
+ BatchReport.Scm scmReport = reportReader.readComponentScm(componentRef);
+ File highlightingFile = reportReader.readComponentSyntaxHighlighting(componentRef);
+
+ if (coverageFile != null) {
+ ReportIterator<BatchReport.Coverage> coverageReportIterator = new ReportIterator<>(coverageFile, BatchReport.Coverage.PARSER);
+ reportIterators.add(coverageReportIterator);
+ lineReaders.add(new CoverageLineReader(coverageReportIterator));
+ }
+ if (scmReport != null) {
+ lineReaders.add(new ScmLineReader(scmReport));
+ }
+ if (highlightingFile != null) {
+ ReportIterator<BatchReport.SyntaxHighlighting> syntaxHighlightingReportIterator = new ReportIterator<>(highlightingFile, BatchReport.SyntaxHighlighting.PARSER);
+ reportIterators.add(syntaxHighlightingReportIterator);
+ lineReaders.add(new HighlightingLineReader(syntaxHighlightingReportIterator));
+ }
+ }
+
+ List<LineReader> readers(){
+ return lineReaders;
+ }
+
+ void close(){
+ for (ReportIterator reportIterator : reportIterators) {
+ reportIterator.close();
+ }
+ }
+ }
+
@Override
public String getDescription() {
return "Persist file sources";