private String computeRawSourceHash(Component file) {
SourceHashComputer sourceHashComputer = new SourceHashComputer();
- CloseableIterator<String> linesIterator = sourceLinesRepository.readLines(file);
- try {
+ try (CloseableIterator<String> linesIterator = sourceLinesRepository.readLines(file)) {
while (linesIterator.hasNext()) {
sourceHashComputer.addLine(linesIterator.next(), linesIterator.hasNext());
}
return sourceHashComputer.getHash();
- } finally {
- linesIterator.close();
}
}
new TypeAwareVisitorAdapter(CrawlerDepthLimit.FILE, POST_ORDER) {
@Override
public void visitFile(Component file) {
- CloseableIterator<ScannerReport.Duplication> duplications = batchReportReader.readComponentDuplications(file.getReportAttributes().getRef());
- try {
+ try (CloseableIterator<ScannerReport.Duplication> duplications = batchReportReader.readComponentDuplications(file.getReportAttributes().getRef())) {
int idGenerator = 1;
while (duplications.hasNext()) {
loadDuplications(file, duplications.next(), idGenerator);
idGenerator++;
}
- } finally {
- duplications.close();
}
}
}).visit(treeRootHolder.getRoot());
*/
package org.sonar.server.computation.task.projectanalysis.step;
+import java.util.List;
+import javax.annotation.Nullable;
import org.sonar.core.util.CloseableIterator;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
import org.sonar.server.computation.task.projectanalysis.batch.BatchReportReader;
import org.sonar.server.computation.task.projectanalysis.component.Component;
+import org.sonar.server.computation.task.projectanalysis.component.Component.Status;
import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
import org.sonar.server.computation.task.projectanalysis.component.DepthTraversalTypeAwareCrawler;
import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
import org.sonar.server.computation.task.projectanalysis.component.TypeAwareVisitorAdapter;
-import org.sonar.server.computation.task.projectanalysis.component.Component.Status;
import org.sonar.server.computation.task.projectanalysis.duplication.CrossProjectDuplicationStatusHolder;
import org.sonar.server.computation.task.step.ComputationStep;
import static org.sonar.server.computation.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
-import java.util.List;
-
-import javax.annotation.Nullable;
-
/**
* Persist cross project duplications text blocks into DUPLICATIONS_INDEX table
*/
private void readFromReport(Component component) {
int indexInFile = 0;
- CloseableIterator<ScannerReport.CpdTextBlock> blocks = reportReader.readCpdTextBlocks(component.getReportAttributes().getRef());
- try {
+ try (CloseableIterator<ScannerReport.CpdTextBlock> blocks = reportReader.readCpdTextBlocks(component.getReportAttributes().getRef())) {
while (blocks.hasNext()) {
ScannerReport.CpdTextBlock block = blocks.next();
dbClient.duplicationDao().insert(
.setComponentUuid(component.getUuid()));
indexInFile++;
}
- } finally {
- blocks.close();
}
}