for (DbFileSources.Line line : lines) { json.beginObject() .prop("line", line.getLine()) .prop("code", htmlSourceDecorator.getDecoratedSourceAsHtml(line.getSource(), line.getHighlighting(), line.getSymbols())) .prop("scmRevision", line.getScmRevision()); if (!filterScmAuthors) { json.prop("scmAuthor", line.getScmAuthor()); if (line.hasScmDate()) { json.prop("scmDate", DateUtils.formatDateTime(new Date(line.getScmDate()))); json.prop("coveredConditions", coveredConditions.get()); json.prop("duplicated", line.getDuplicationCount() > 0); if (line.hasIsNewLine()) { json.prop("isNew", line.getIsNewLine()); } else { if (periodDate == null) { periodDate = periodDateSupplier.get(); json.prop("isNew", periodDate.isPresent() && line.getScmDate() > periodDate.get());
}) .toArray(LineReader[]::new); DbFileSources.Line.Builder builder = DbFileSources.Line.newBuilder(); SourceLineReadersFactory.LineReadersImpl underTest = new SourceLineReadersFactory.LineReadersImpl( stream(lineReaders).collect(toList()), null, Collections.emptyList());
private static Optional<Integer> getConditions(DbFileSources.Line line) { if (line.hasConditions()) { return Optional.of(line.getConditions()); } else if (line.hasDeprecatedOverallConditions()) { return Optional.of(line.getDeprecatedOverallConditions()); } else if (line.hasDeprecatedUtConditions()) { return Optional.of(line.getDeprecatedUtConditions()); } else if (line.hasDeprecatedItConditions()) { return Optional.of(line.getDeprecatedItConditions()); } return Optional.empty(); }
public Builder mergeFrom(org.sonar.db.protobuf.DbFileSources.Line other) { if (other == org.sonar.db.protobuf.DbFileSources.Line.getDefaultInstance()) return this; if (other.hasLine()) { setLine(other.getLine()); if (other.hasSource()) { bitField0_ |= 0x00000002; source_ = other.source_; onChanged(); if (other.hasScmRevision()) { bitField0_ |= 0x00000004; scmRevision_ = other.scmRevision_; onChanged(); if (other.hasScmAuthor()) { bitField0_ |= 0x00000008; scmAuthor_ = other.scmAuthor_; onChanged(); if (other.hasScmDate()) { setScmDate(other.getScmDate()); if (other.hasDeprecatedUtLineHits()) { setDeprecatedUtLineHits(other.getDeprecatedUtLineHits()); if (other.hasDeprecatedUtConditions()) { setDeprecatedUtConditions(other.getDeprecatedUtConditions()); if (other.hasDeprecatedUtCoveredConditions()) {
for (DbFileSources.Line line : lines) { json.beginObject() .prop("line", line.getLine()) .prop("code", htmlSourceDecorator.getDecoratedSourceAsHtml(line.getSource(), line.getHighlighting(), line.getSymbols())) .prop("scmAuthor", line.getScmAuthor()) .prop("scmRevision", line.getScmRevision()); if (line.hasScmDate()) { json.prop("scmDate", DateUtils.formatDateTime(new Date(line.getScmDate()))); json.prop("coveredConditions", coveredConditions.get()); json.prop("duplicated", line.getDuplicationCount() > 0); json.endObject();
@Override @Nullable public Changeset apply(@Nonnull DbFileSources.Line input) { if (input.hasScmDate()) { Changeset cs = builder .setRevision(input.hasScmRevision() ? input.getScmRevision() : null) .setAuthor(input.hasScmAuthor() ? input.getScmAuthor() : null) .setDate(input.getScmDate()) .build(); if (cache.containsKey(cs)) { return cache.get(cs); } cache.put(cs, cs); return cs; } return null; } }
private static void writeSource(Iterable<DbFileSources.Line> lines, boolean showCommitsByLine, JsonWriter json) { json.name("scm").beginArray(); DbFileSources.Line previousLine = null; boolean started = false; for (DbFileSources.Line lineDoc : lines) { if (hasScm(lineDoc) && (!started || showCommitsByLine || !isSameCommit(previousLine, lineDoc))) { json.beginArray() .value(lineDoc.getLine()) .value(lineDoc.getScmAuthor()); json.value(lineDoc.hasScmDate() ? DateUtils.formatDateTime(new Date(lineDoc.getScmDate())) : null); json.value(lineDoc.getScmRevision()); json.endArray(); started = true; } previousLine = lineDoc; } json.endArray(); }
public Builder newBuilderForType() { return newBuilder(); } public static Builder newBuilder() {
/** * <code>optional string scm_revision = 3;</code> * * <pre> * SCM * </pre> */ public Builder clearScmRevision() { bitField0_ = (bitField0_ & ~0x00000004); scmRevision_ = getDefaultInstance().getScmRevision(); onChanged(); return this; } /**
private Function<DbFileSources.Line, String> lineToHtml() { return line -> htmlDecorator.getDecoratedSourceAsHtml(line.getSource(), line.getHighlighting(), line.getSymbols()); }
public static Optional<DbScmInfo> create(Iterable<DbFileSources.Line> lines, String fileHash) { LineToChangeset lineToChangeset = new LineToChangeset(); Map<Integer, Changeset> lineChanges = new LinkedHashMap<>(); for (DbFileSources.Line line : lines) { Changeset changeset = lineToChangeset.apply(line); if (changeset == null) { continue; } lineChanges.put(line.getLine(), changeset); } if (lineChanges.isEmpty()) { return Optional.empty(); } return Optional.of(new DbScmInfo(new ScmInfoImpl(lineChanges), fileHash)); }
private <E> Optional<Iterable<E>> getLines(DbSession dbSession, String fileUuid, int from, int toInclusive, Function<DbFileSources.Line, E> function) { verifyLine(from); checkArgument(toInclusive >= from, String.format("Line number must greater than or equal to %d, got %d", from, toInclusive)); FileSourceDto dto = dbClient.fileSourceDao().selectSourceByFileUuid(dbSession, fileUuid); if (dto == null) { return Optional.empty(); } return Optional.of(dto.getSourceData().getLinesList().stream() .filter(line -> line.hasLine() && line.getLine() >= from) .limit((toInclusive - from) + 1L) .map(function) .collect(MoreCollectors.toList())); }
private static boolean hasScm(DbFileSources.Line line) { return !Strings.isNullOrEmpty(line.getScmAuthor()) || line.hasScmDate() || !Strings.isNullOrEmpty(line.getScmRevision()); } }
private static Optional<Integer> getConditions(DbFileSources.Line line) { if (line.hasConditions()) { return Optional.of(line.getConditions()); } else if (line.hasDeprecatedOverallConditions()) { return Optional.of(line.getDeprecatedOverallConditions()); } else if (line.hasDeprecatedUtConditions()) { return Optional.of(line.getDeprecatedUtConditions()); } else if (line.hasDeprecatedItConditions()) { return Optional.of(line.getDeprecatedItConditions()); } return Optional.empty(); }
private static Optional<Integer> getCoveredConditions(DbFileSources.Line line) { if (line.hasCoveredConditions()) { return Optional.of(line.getCoveredConditions()); } else if (line.hasDeprecatedOverallCoveredConditions()) { return Optional.of(line.getDeprecatedOverallCoveredConditions()); } else if (line.hasDeprecatedUtCoveredConditions()) { return Optional.of(line.getDeprecatedUtCoveredConditions()); } else if (line.hasDeprecatedItCoveredConditions()) { return Optional.of(line.getDeprecatedItCoveredConditions()); } return Optional.empty(); }
private static boolean isSameCommit(DbFileSources.Line previousLine, DbFileSources.Line currentLine) { return new EqualsBuilder() .append(previousLine.getScmAuthor(), currentLine.getScmAuthor()) .append(previousLine.getScmDate(), currentLine.getScmDate()) .append(previousLine.getScmRevision(), currentLine.getScmRevision()) .isEquals(); }
/** * <code>optional string highlighting = 15;</code> */ public Builder clearHighlighting() { bitField0_ = (bitField0_ & ~0x00004000); highlighting_ = getDefaultInstance().getHighlighting(); onChanged(); return this; } /**
/** * <code>optional string scm_author = 4;</code> */ public Builder clearScmAuthor() { bitField0_ = (bitField0_ & ~0x00000008); scmAuthor_ = getDefaultInstance().getScmAuthor(); onChanged(); return this; } /**
/** * <code>optional string source = 2;</code> */ public Builder clearSource() { bitField0_ = (bitField0_ & ~0x00000002); source_ = getDefaultInstance().getSource(); onChanged(); return this; } /**
.setDataHash("6cad150e3d065976c230cddc5a09efaa") .setSourceData(DbFileSources.Data.newBuilder() .addLines(DbFileSources.Line.newBuilder() .setLine(1) .setSource("old line") .addLines(DbFileSources.Line.newBuilder() .setLine(1) .setSource("old line")