Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
654 additions
and
517 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 0 additions & 92 deletions
92
...nalysis/src/main/java/org/sonar/ce/task/projectanalysis/source/ComputeFileSourceData.java
This file was deleted.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
...alysis/src/main/java/org/sonar/ce/task/projectanalysis/source/FileSourceDataComputer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,105 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2018 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.source; | |||
|
|||
import java.util.List; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.scm.Changeset; | |||
import org.sonar.core.hash.SourceHashComputer; | |||
import org.sonar.core.util.CloseableIterator; | |||
import org.sonar.db.protobuf.DbFileSources; | |||
|
|||
public class FileSourceDataComputer { | |||
private final SourceLinesRepository sourceLinesRepository; | |||
private final SourceLineReadersFactory sourceLineReadersFactory; | |||
private final SourceLinesHashRepository sourceLinesHash; | |||
private final SourceHashComputer sourceHashComputer; | |||
|
|||
public FileSourceDataComputer(SourceLinesRepository sourceLinesRepository, SourceLineReadersFactory sourceLineReadersFactory, SourceLinesHashRepository sourceLinesHash) { | |||
this.sourceLinesRepository = sourceLinesRepository; | |||
this.sourceLineReadersFactory = sourceLineReadersFactory; | |||
this.sourceLinesHash = sourceLinesHash; | |||
this.sourceHashComputer = new SourceHashComputer(); | |||
} | |||
|
|||
public Data compute(Component file) { | |||
try (CloseableIterator<String> linesIterator = sourceLinesRepository.readLines(file); | |||
SourceLineReadersFactory.LineReaders lineReaders = sourceLineReadersFactory.getLineReaders(file)) { | |||
|
|||
SourceLinesHashRepositoryImpl.LineHashesComputer lineHashesComputer = sourceLinesHash.getLineHashesComputerToPersist(file); | |||
DbFileSources.Data.Builder fileSourceBuilder = DbFileSources.Data.newBuilder(); | |||
int currentLine = 0; | |||
|
|||
while (linesIterator.hasNext()) { | |||
currentLine++; | |||
read(fileSourceBuilder, lineHashesComputer, lineReaders, currentLine, linesIterator.next(), linesIterator.hasNext()); | |||
} | |||
|
|||
return new Data(fileSourceBuilder.build(), lineHashesComputer.getResult(), sourceHashComputer.getHash(), lineReaders.getLatestChangeWithRevision()); | |||
} | |||
} | |||
|
|||
private void read(DbFileSources.Data.Builder fileSourceBuilder, SourceLinesHashRepositoryImpl.LineHashesComputer lineHashesComputer, | |||
SourceLineReadersFactory.LineReaders lineReaders, int currentLine, String lineSource, boolean hasNextLine) { | |||
sourceHashComputer.addLine(lineSource, hasNextLine); | |||
lineHashesComputer.addLine(lineSource); | |||
|
|||
DbFileSources.Line.Builder lineBuilder = fileSourceBuilder | |||
.addLinesBuilder() | |||
.setSource(lineSource) | |||
.setLine(currentLine); | |||
|
|||
lineReaders.read(lineBuilder); | |||
} | |||
|
|||
public static class Data { | |||
private final DbFileSources.Data fileSourceData; | |||
private final List<String> lineHashes; | |||
private final String srcHash; | |||
private final Changeset latestChangeWithRevision; | |||
|
|||
public Data(DbFileSources.Data fileSourceData, List<String> lineHashes, String srcHash, @Nullable Changeset latestChangeWithRevision) { | |||
this.fileSourceData = fileSourceData; | |||
this.lineHashes = lineHashes; | |||
this.srcHash = srcHash; | |||
this.latestChangeWithRevision = latestChangeWithRevision; | |||
} | |||
|
|||
public String getSrcHash() { | |||
return srcHash; | |||
} | |||
|
|||
public List<String> getLineHashes() { | |||
return lineHashes; | |||
} | |||
|
|||
public DbFileSources.Data getLineData() { | |||
return fileSourceData; | |||
} | |||
|
|||
@CheckForNull | |||
public Changeset getLatestChangeWithRevision() { | |||
return latestChangeWithRevision; | |||
} | |||
} | |||
|
|||
} |
114 changes: 114 additions & 0 deletions
114
...ysis/src/main/java/org/sonar/ce/task/projectanalysis/source/SourceLineReadersFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,114 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2018 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.ce.task.projectanalysis.source; | |||
|
|||
import java.util.ArrayList; | |||
import java.util.List; | |||
import java.util.Optional; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
import org.sonar.ce.task.projectanalysis.batch.BatchReportReader; | |||
import org.sonar.ce.task.projectanalysis.component.Component; | |||
import org.sonar.ce.task.projectanalysis.duplication.DuplicationRepository; | |||
import org.sonar.ce.task.projectanalysis.scm.Changeset; | |||
import org.sonar.ce.task.projectanalysis.scm.ScmInfo; | |||
import org.sonar.ce.task.projectanalysis.scm.ScmInfoRepository; | |||
import org.sonar.ce.task.projectanalysis.source.linereader.CoverageLineReader; | |||
import org.sonar.ce.task.projectanalysis.source.linereader.DuplicationLineReader; | |||
import org.sonar.ce.task.projectanalysis.source.linereader.HighlightingLineReader; | |||
import org.sonar.ce.task.projectanalysis.source.linereader.LineReader; | |||
import org.sonar.ce.task.projectanalysis.source.linereader.RangeOffsetConverter; | |||
import org.sonar.ce.task.projectanalysis.source.linereader.ScmLineReader; | |||
import org.sonar.ce.task.projectanalysis.source.linereader.SymbolsLineReader; | |||
import org.sonar.core.util.CloseableIterator; | |||
import org.sonar.db.protobuf.DbFileSources; | |||
import org.sonar.scanner.protocol.output.ScannerReport; | |||
|
|||
public class SourceLineReadersFactory { | |||
private final BatchReportReader reportReader; | |||
private final ScmInfoRepository scmInfoRepository; | |||
private final DuplicationRepository duplicationRepository; | |||
|
|||
SourceLineReadersFactory(BatchReportReader reportReader, ScmInfoRepository scmInfoRepository, DuplicationRepository duplicationRepository) { | |||
this.reportReader = reportReader; | |||
this.scmInfoRepository = scmInfoRepository; | |||
this.duplicationRepository = duplicationRepository; | |||
} | |||
|
|||
public LineReaders getLineReaders(Component component) { | |||
List<LineReader> readers = new ArrayList<>(); | |||
List<CloseableIterator<?>> closeables = new ArrayList<>(); | |||
ScmLineReader scmLineReader = null; | |||
|
|||
int componentRef = component.getReportAttributes().getRef(); | |||
CloseableIterator<ScannerReport.LineCoverage> coverageIt = reportReader.readComponentCoverage(componentRef); | |||
closeables.add(coverageIt); | |||
readers.add(new CoverageLineReader(coverageIt)); | |||
|
|||
Optional<ScmInfo> scmInfoOptional = scmInfoRepository.getScmInfo(component); | |||
if (scmInfoOptional.isPresent()) { | |||
scmLineReader = new ScmLineReader(scmInfoOptional.get()); | |||
readers.add(scmLineReader); | |||
} | |||
|
|||
RangeOffsetConverter rangeOffsetConverter = new RangeOffsetConverter(); | |||
CloseableIterator<ScannerReport.SyntaxHighlightingRule> highlightingIt = reportReader.readComponentSyntaxHighlighting(componentRef); | |||
closeables.add(highlightingIt); | |||
readers.add(new HighlightingLineReader(component, highlightingIt, rangeOffsetConverter)); | |||
|
|||
CloseableIterator<ScannerReport.Symbol> symbolsIt = reportReader.readComponentSymbols(componentRef); | |||
closeables.add(symbolsIt); | |||
readers.add(new SymbolsLineReader(component, symbolsIt, rangeOffsetConverter)); | |||
readers.add(new DuplicationLineReader(duplicationRepository.getDuplications(component))); | |||
|
|||
return new LineReaders(readers, scmLineReader, closeables); | |||
} | |||
|
|||
static class LineReaders implements AutoCloseable, LineReader { | |||
final List<LineReader> readers; | |||
@Nullable | |||
final ScmLineReader scmLineReader; | |||
final List<CloseableIterator<?>> closeables; | |||
|
|||
LineReaders(List<LineReader> readers, @Nullable ScmLineReader scmLineReader, List<CloseableIterator<?>> closeables) { | |||
this.readers = readers; | |||
this.scmLineReader = scmLineReader; | |||
this.closeables = closeables; | |||
} | |||
|
|||
@Override public void close() { | |||
for (CloseableIterator<?> reportIterator : closeables) { | |||
reportIterator.close(); | |||
} | |||
} | |||
|
|||
@Override public void read(DbFileSources.Line.Builder lineBuilder) { | |||
for (LineReader r : readers) { | |||
r.read(lineBuilder); | |||
} | |||
} | |||
|
|||
@CheckForNull | |||
public Changeset getLatestChangeWithRevision() { | |||
return scmLineReader == null ? null : scmLineReader.getLatestChangeWithRevision(); | |||
} | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.