diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2019-01-09 16:22:36 +0100 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-01-10 20:21:03 +0100 |
commit | 8654f383093aa581029719f7cd424301c9410ea8 (patch) | |
tree | a00f6365eaf80525842aa6275b3483f2cad9971f | |
parent | 33a3b9ca37488ca207b50f2f9053cb0e25ac1d89 (diff) | |
download | sonarqube-8654f383093aa581029719f7cd424301c9410ea8.tar.gz sonarqube-8654f383093aa581029719f7cd424301c9410ea8.zip |
SONAR-11622 Server temp files fail to be deleted on MS Windows
4 files changed, 33 insertions, 21 deletions
diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SignificantCodeRepository.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SignificantCodeRepository.java index bf944b5aa67..4503cc3f674 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SignificantCodeRepository.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SignificantCodeRepository.java @@ -36,8 +36,13 @@ public class SignificantCodeRepository { public Optional<LineRange[]> getRangesPerLine(Component component) { int numLines = component.getFileAttributes().getLines(); - Optional<CloseableIterator<LineSgnificantCode>> significantCode = reportReader.readComponentSignificantCode(component.getReportAttributes().getRef()); - return significantCode.map(s -> toArray(s, numLines)); + Optional<CloseableIterator<LineSgnificantCode>> opt = reportReader.readComponentSignificantCode(component.getReportAttributes().getRef()); + if (!opt.isPresent()) { + return Optional.empty(); + } + try (CloseableIterator<LineSgnificantCode> significantCode = opt.get()) { + return Optional.of(toArray(significantCode, numLines)); + } } private static LineRange[] toArray(CloseableIterator<LineSgnificantCode> lineRanges, int numLines) { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceLinesHashRepositoryImpl.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceLinesHashRepositoryImpl.java index 89cb15c351e..a7afa6cd60f 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceLinesHashRepositoryImpl.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceLinesHashRepositoryImpl.java @@ -85,13 +85,12 @@ public class SourceLinesHashRepositoryImpl implements SourceLinesHashRepository private List<String> createLineHashes(Component component, Optional<LineRange[]> significantCodePerLine) { LineHashesComputer processor = createLineHashesProcessor(component.getFileAttributes().getLines(), significantCodePerLine); - CloseableIterator<String> lines = sourceLinesRepository.readLines(component); - - while (lines.hasNext()) { - processor.addLine(lines.next()); + try (CloseableIterator<String> lines = sourceLinesRepository.readLines(component)) { + while (lines.hasNext()) { + processor.addLine(lines.next()); + } + return processor.getResult(); } - - return processor.getResult(); } public interface LineHashesComputer { diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java index 6e4a35ee587..2557964e411 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java @@ -24,10 +24,12 @@ import java.util.List; import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder; import org.sonar.ce.task.projectanalysis.batch.BatchReportReader; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.core.util.CloseableIterator; import org.sonar.core.util.UuidFactory; import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.component.AnalysisPropertyDto; +import org.sonar.scanner.protocol.output.ScannerReport; import static org.sonar.core.config.CorePropertyDefinitions.SONAR_ANALYSIS; @@ -55,18 +57,20 @@ public class PersistAnalysisPropertiesStep implements ComputationStep { @Override public void execute(ComputationStep.Context context) { - final List<AnalysisPropertyDto> analysisPropertyDtos = new ArrayList<>(); - reportReader.readContextProperties().forEachRemaining( - contextProperty -> { - String propertyKey = contextProperty.getKey(); - if (propertyKey.startsWith(SONAR_ANALYSIS) || propertyKey.startsWith(SONAR_PULL_REQUEST)) { - analysisPropertyDtos.add(new AnalysisPropertyDto() - .setUuid(uuidFactory.create()) - .setKey(propertyKey) - .setValue(contextProperty.getValue()) - .setSnapshotUuid(analysisMetadataHolder.getUuid())); - } - }); + List<AnalysisPropertyDto> analysisPropertyDtos = new ArrayList<>(); + try (CloseableIterator<ScannerReport.ContextProperty> it = reportReader.readContextProperties()) { + it.forEachRemaining( + contextProperty -> { + String propertyKey = contextProperty.getKey(); + if (propertyKey.startsWith(SONAR_ANALYSIS) || propertyKey.startsWith(SONAR_PULL_REQUEST)) { + analysisPropertyDtos.add(new AnalysisPropertyDto() + .setUuid(uuidFactory.create()) + .setKey(propertyKey) + .setValue(contextProperty.getValue()) + .setSnapshotUuid(analysisMetadataHolder.getUuid())); + } + }); + } analysisMetadataHolder.getScmRevisionId().ifPresent(scmRevisionId -> analysisPropertyDtos.add(new AnalysisPropertyDto() .setUuid(uuidFactory.create()) diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisWarningsStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisWarningsStep.java index 0c1fc421ce4..c7aaa116d54 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisWarningsStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisWarningsStep.java @@ -24,6 +24,8 @@ import java.util.Collection; import org.sonar.ce.task.log.CeTaskMessages; import org.sonar.ce.task.projectanalysis.batch.BatchReportReader; import org.sonar.ce.task.step.ComputationStep; +import org.sonar.core.util.CloseableIterator; +import org.sonar.scanner.protocol.output.ScannerReport; /** * Propagate analysis warnings from scanner report. @@ -43,7 +45,9 @@ public class PersistAnalysisWarningsStep implements ComputationStep { @Override public void execute(Context context) { Collection<CeTaskMessages.Message> warnings = new ArrayList<>(); - reportReader.readAnalysisWarnings().forEachRemaining(w -> warnings.add(new CeTaskMessages.Message(w.getText(), w.getTimestamp()))); + try (CloseableIterator<ScannerReport.AnalysisWarning> it = reportReader.readAnalysisWarnings()) { + it.forEachRemaining(w -> warnings.add(new CeTaskMessages.Message(w.getText(), w.getTimestamp()))); + } if (!warnings.isEmpty()) { ceTaskMessages.addAll(warnings); } |