@** * Yobi, Project Hosting SW * * Copyright 2013 NAVER Corp. * http://yobi.io * * @author Yi EungJun * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. **@ @(diff: playRepository.FileDiff, threads: java.util.List[_ <: CodeCommentThread], projectB: Project, projectA: Project) @import playRepository.DiffLineType @import playRepository.DiffLine @import playRepository.FileDiff @import playRepository.Hunk @import org.eclipse.jgit.diff.DiffEntry @import org.eclipse.jgit.diff.RawText @import utils.TemplateHelper.DiffRenderer._ @import utils.TemplateHelper._ @import scala.collection.immutable.Map @import scala.collection.immutable.List @import FileDiff.Error._ @import scala.collection.JavaConversions._ @import org.apache.commons.lang.StringEscapeUtils.escapeHtml @import org.apache.commons.lang3.StringUtils @renderDiffLines(diff: playRepository.FileDiff, threads: Map[String, List[CodeCommentThread]]) = { @if(diff.isFileModeChanged) {
@Messages("code.fileModeChanged") } @null match { case _ if diff.hasError(OTHERS_SIZE_EXCEEDED) => { @Messages("code.skipDiff") } case _ if diff.hasAnyError(A_SIZE_EXCEEDED, B_SIZE_EXCEEDED) => { @Messages("code.tooBigFile") } case _ if diff.hasError(DIFF_SIZE_EXCEEDED) => { @Messages("code.tooBigDiff") } case _ if diff.hasError => { @Messages("code.unknownError") } case _ => { @diff.getHunks match { case hunks if (hunks.size <= 0) => { @diff.isFileModeChanged match { case true => { } case false => { @Messages("code.noChanges") } } } case hunks => { @for(hunk <- diff.getHunks) {
@@@@ -@(hunk.beginA + 1),@(hunk.endA - hunk.beginA) +@(hunk.beginB + 1),@(hunk.endB - hunk.beginB) @@@@ @Html(renderLines(hunk.lines.toList, threads, eolMissingChecker(diff))) } } } } } } @renderRawFile(klass: String, path: String, rawText: RawText, side: CodeRange.Side, prefix: String, comments: Map[String, List[_ <: CodeCommentThread]]) = { @defining(new StringBuilder) { builder => @for(i <- 0 until rawText.size) @{ builder.append("
") builder.append("
")
            builder.append(prefix)
            builder.append(escapeHtml(rawText.getString(i)))
            if ((i + 1 == rawText.size) && rawText.isMissingNewlineAtEnd) {
                builder.append(noNewlineAtEof)
            }
            builder.append("
") builder.append(partial_diff_comment_on_line(threadsOrEmpty(comments, threadKey(path, side, i + 1))).toString.trim) } @Html(builder.toString) } } @renderAddedLines(diff: FileDiff, threads:Map[String, List[_ <: CodeCommentThread]], isBinaryOverwritten: Boolean = false) = { @null match { case _ if diff.hasError(OTHERS_SIZE_EXCEEDED) => { @Messages("code.skipDiff") } case _ if diff.hasError(B_SIZE_EXCEEDED) => { @Messages("code.tooBigFile") } case _ if diff.hasError => { @Messages("code.unknownError") } case null => {
@@@@ -0,0 +1,@diff.b.size @@@@ @if(isBinaryOverwritten ) { @renderCodeIsBinary("remove", "-") } @renderRawFile("add", diff.pathB, diff.b, CodeRange.Side.B, "+", threads) } } } @renderRemovedLines(diff: FileDiff, threads:Map[String, List[_ <: CodeCommentThread]], isOverwrittenByBinary: Boolean = false) = { @null match { case _ if diff.hasError(OTHERS_SIZE_EXCEEDED) => { @Messages("code.skipDiff") } case _ if diff.hasError(A_SIZE_EXCEEDED) => { @Messages("code.tooBigFile") } case _ if diff.hasError => { @Messages("code.unknownError") } case _ => {
@@@@ -1,@diff.a.size +0,0 @@@@ @renderRawFile("remove", diff.pathA, diff.a, CodeRange.Side.A, "-", threads) @if(isOverwrittenByBinary) { @renderCodeIsBinary("add", "+") } } } } @getShortenedCommitId(commitId:String) = @{ if(commitId.length < 7){ commitId } else { commitId.substring(0,7) } } @getFileHeadId(diff: FileDiff) = @{ defining(Option(diff.pathB).getOrElse(diff.pathA)) { path => path.replace("/", "-").replace(".", "-") } } @renderFile(diff: FileDiff, fileHeader: String, renderedLines: Html) = {
@if(diff.commitA != null && diff.pathA != null){ @getShortenedCommitId(diff.commitA) } else {   }
@if(diff.commitB != null && diff.pathB != null){ @getShortenedCommitId(diff.commitB) } else {   }
@if(StringUtils.isNotEmpty(diff.pathA)){--- @diff.pathA} @if(StringUtils.isNotEmpty(diff.pathB)){+++ @diff.pathB}
@renderedLines
} @getPathPostfixedBinary(path:String, isBinary:Boolean) = @{ path + (if (isBinary) { " (Binary)" } else { "" } ) } @getFileHeaderMessage(headerType:DiffEntry.ChangeType, diff:FileDiff) = @{ headerType match { case DiffEntry.ChangeType.MODIFY => { getPathPostfixedBinary(diff.pathB, diff.isBinaryB) } case DiffEntry.ChangeType.ADD => { Messages("code.addedPath", getPathPostfixedBinary(diff.pathB, diff.isBinaryB)) } case DiffEntry.ChangeType.DELETE => { Messages("code.deletedPath", getPathPostfixedBinary(diff.pathA, diff.isBinaryA)) } case DiffEntry.ChangeType.RENAME => { Messages("code.renamedPath", getPathPostfixedBinary(diff.pathA, diff.isBinaryA), getPathPostfixedBinary(diff.pathB, diff.isBinaryB)) } case DiffEntry.ChangeType.COPY => { Messages("code.copiedPath", getPathPostfixedBinary(diff.pathA, diff.isBinaryA), getPathPostfixedBinary(diff.pathB, diff.isBinaryB)) } case _ => { "" } } } @renderCodeIsBinary(klass:String = "", prefix:String = "") = {
@prefix@Messages("code.isBinary") } @getThreads(threads: java.util.List[_ <: CodeCommentThread]) = @{ if(threads != null){ threads.toList.filter(v => v.codeRange != null).groupBy((thread: CodeCommentThread) => threadKey(thread.codeRange.path, thread.codeRange.endSide, thread.codeRange.endLine)) } else { null } } @defining(getThreads(threads)) { threads => @diff.changeType match { case DiffEntry.ChangeType.MODIFY => { @(diff.isBinaryA, diff.isBinaryB) match { case (true, true) => { @renderFile(diff, getFileHeaderMessage(DiffEntry.ChangeType.MODIFY, diff), renderCodeIsBinary()) } case (true, false) => { @renderFile(diff, getFileHeaderMessage(DiffEntry.ChangeType.MODIFY, diff), renderAddedLines(diff, threads, true)) } case (false, true) => { @renderFile(diff, getFileHeaderMessage(DiffEntry.ChangeType.MODIFY, diff), renderRemovedLines(diff, threads, true)) } case (false, false) => { @renderFile(diff, diff.pathB, renderDiffLines(diff, threads)) } } } case DiffEntry.ChangeType.ADD => { @if(diff.isBinaryB){ @renderFile(diff, getFileHeaderMessage(DiffEntry.ChangeType.ADD, diff), renderCodeIsBinary()) } else { @renderFile(diff, getFileHeaderMessage(DiffEntry.ChangeType.ADD, diff), renderAddedLines(diff, threads)) } } case DiffEntry.ChangeType.DELETE => { @if(diff.isBinaryA){ @renderFile(diff, getFileHeaderMessage(DiffEntry.ChangeType.DELETE, diff), renderCodeIsBinary()) } else { @renderFile(diff, Messages("code.deletedPath", diff.pathA), renderRemovedLines(diff, threads)) } } case DiffEntry.ChangeType.RENAME => { @(diff.isBinaryA, diff.isBinaryB) match { case (true, true) => { @renderFile(diff, getFileHeaderMessage(DiffEntry.ChangeType.RENAME, diff), renderCodeIsBinary()) } case (true, false) => { @renderFile(diff, getFileHeaderMessage(DiffEntry.ChangeType.RENAME, diff), renderAddedLines(diff, threads, true)) } case (false, true) => { @renderFile(diff, getFileHeaderMessage(DiffEntry.ChangeType.RENAME, diff), renderRemovedLines(diff, threads, true)) } case (false, false) => { @renderFile(diff, Messages("code.renamedPath", diff.pathA, diff.pathB), renderDiffLines(diff, threads)) } } } case DiffEntry.ChangeType.COPY => { @if(diff.isBinaryB){ @renderFile(diff, getFileHeaderMessage(DiffEntry.ChangeType.COPY, diff), renderCodeIsBinary()) } else { @renderFile(diff, Messages("code.copiedPath", diff.pathA, diff.pathB), renderAddedLines(diff, threads)) } } } }