]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11622 Server temp files fail to be deleted on MS Windows
authorSimon Brandhof <simon.brandhof@sonarsource.com>
Wed, 9 Jan 2019 15:22:36 +0000 (16:22 +0100)
committerSonarTech <sonartech@sonarsource.com>
Thu, 10 Jan 2019 19:21:03 +0000 (20:21 +0100)
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SignificantCodeRepository.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceLinesHashRepositoryImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisPropertiesStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistAnalysisWarningsStep.java

index bf944b5aa6752db7a13fa6fda755c33526860035..4503cc3f674f3d287411d278c668a60d37e649c0 100644 (file)
@@ -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) {
index 89cb15c351e3b4610281eb13cfa7bc40fb5c888a..a7afa6cd60f691d3893d5d40bb744c73c2341bfb 100644 (file)
@@ -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 {
index 6e4a35ee587234ed98b98b480545fc595649fe06..2557964e411ec215572a404c4e803acd398f65f3 100644 (file)
@@ -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())
index 0c1fc421ce4d12b7ebab7dc5b22f6ba697fa310f..c7aaa116d54e248d81be6154ea8f32e3d1982156 100644 (file)
@@ -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);
     }