diff --git a/src/main/scala/app/RepositoryViewerController.scala b/src/main/scala/app/RepositoryViewerController.scala index 627acda..7b5b5ac 100644 --- a/src/main/scala/app/RepositoryViewerController.scala +++ b/src/main/scala/app/RepositoryViewerController.scala @@ -3,72 +3,15 @@ import util.Directory._ import util.Implicits._ import util.{JGitUtil, FileTypeUtil, CompressUtil} -import model._ import service._ import org.scalatra._ import java.io.File -import java.util.Date import org.eclipse.jgit.api.Git import org.eclipse.jgit.lib._ import org.apache.commons.io.FileUtils import org.eclipse.jgit.treewalk._ -import org.eclipse.jgit.diff.DiffEntry.ChangeType // TODO Should models move to other package? -/** - * The repository data. - * - * @param owner the user name of the repository owner - * @param name the repository name - * @param url the repository URL - * @param branchList the list of branch names - * @param tags the list of tags - */ -case class RepositoryInfo(owner: String, name: String, url: String, branchList: List[String], tags: List[TagInfo]) - -/** - * The file data for the file list of the repository viewer. - * - * @param id the object id - * @param isDirectory whether is it directory - * @param name the file (or directory) name - * @param time the last modified time - * @param message the last commit message - * @param committer the last committer name - */ -case class FileInfo(id: ObjectId, isDirectory: Boolean, name: String, time: Date, message: String, committer: String) - -/** - * The commit data. - * - * @param id the commit id - * @param time the commit time - * @param committer the commiter name - * @param message the commit message - */ -case class CommitInfo(id: String, time: Date, committer: String, message: String){ - def this(rev: org.eclipse.jgit.revwalk.RevCommit) = - this(rev.getName, rev.getCommitterIdent.getWhen, rev.getCommitterIdent.getName, rev.getFullMessage) -} - -case class DiffInfo(changeType: ChangeType, oldPath: String, newPath: String, oldContent: Option[String], newContent: Option[String]) - -/** - * The file content data for the file content view of the repository viewer. - * - * @param viewType "image", "large" or "other" - * @param content the string content - */ -case class ContentInfo(viewType: String, content: Option[String]) - -/** - * The tag data. - * - * @param name the tag name - * @param time the tagged date - * @param id the commit id - */ -case class TagInfo(name: String, time: Date, id: String) class RepositoryViewerController extends RepositoryViewerControllerBase with ProjectService with AccountService @@ -191,10 +134,10 @@ // Viewer val large = FileTypeUtil.isLarge(git.getRepository.getObjectDatabase.open(objectId).getSize) val viewer = if(FileTypeUtil.isImage(path)) "image" else if(large) "large" else "text" - val content = ContentInfo(viewer, + val content = JGitUtil.ContentInfo(viewer, if(viewer == "text") JGitUtil.getContent(git, objectId, false).map(new String(_, "UTF-8")) else None) - repo.html.blob(id, repositoryInfo, path.split("/").toList, content, new CommitInfo(revCommit)) + repo.html.blob(id, repositoryInfo, path.split("/").toList, content, new JGitUtil.CommitInfo(revCommit)) } } } @@ -209,7 +152,7 @@ JGitUtil.withGit(getRepositoryDir(owner, repository)){ git => val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id)) - repo.html.commit(id, new CommitInfo(revCommit), + repo.html.commit(id, new JGitUtil.CommitInfo(revCommit), JGitUtil.getRepositoryInfo(owner, repository, servletContext), JGitUtil.getDiffs(git, id)) } } @@ -300,7 +243,7 @@ // current path if(path == ".") Nil else path.split("/").toList, // latest commit - new CommitInfo(revCommit), + new JGitUtil.CommitInfo(revCommit), // file list files, // readme diff --git a/src/main/scala/service/ProjectService.scala b/src/main/scala/service/ProjectService.scala index 9f0ac96..05679a8 100644 --- a/src/main/scala/service/ProjectService.scala +++ b/src/main/scala/service/ProjectService.scala @@ -56,5 +56,5 @@ } object ProjectService { - case class RepositoryInfo(owner: String, name: String, project: Project, branchList: List[String], tagInfo: List[app.TagInfo]) + case class RepositoryInfo(owner: String, name: String, project: Project, branchList: List[String], tagInfo: List[util.JGitUtil.TagInfo]) } \ No newline at end of file diff --git a/src/main/scala/service/WikiService.scala b/src/main/scala/service/WikiService.scala index edf31d5..f33bb63 100644 --- a/src/main/scala/service/WikiService.scala +++ b/src/main/scala/service/WikiService.scala @@ -4,7 +4,7 @@ import java.util.Date import org.eclipse.jgit.api.Git import org.apache.commons.io.FileUtils -import app.DiffInfo +import util.JGitUtil.DiffInfo import util.{Directory, JGitUtil} import org.eclipse.jgit.lib.RepositoryBuilder import org.eclipse.jgit.treewalk.CanonicalTreeParser diff --git a/src/main/scala/util/JGitUtil.scala b/src/main/scala/util/JGitUtil.scala index e32ee40..641a1cd 100644 --- a/src/main/scala/util/JGitUtil.scala +++ b/src/main/scala/util/JGitUtil.scala @@ -1,7 +1,6 @@ package util import org.eclipse.jgit.api.Git -import app.{RepositoryInfo, FileInfo, CommitInfo, DiffInfo, TagInfo} import util.Directory._ import scala.collection.JavaConverters._ import javax.servlet.ServletContext @@ -14,12 +13,68 @@ import org.eclipse.jgit.diff.DiffEntry.ChangeType import org.eclipse.jgit.util.io.DisabledOutputStream import org.eclipse.jgit.errors.MissingObjectException +import java.util.Date /** * Provides complex JGit operations. */ object JGitUtil { - + + /** + * The repository data. + * + * @param owner the user name of the repository owner + * @param name the repository name + * @param url the repository URL + * @param branchList the list of branch names + * @param tags the list of tags + */ + case class RepositoryInfo(owner: String, name: String, url: String, branchList: List[String], tags: List[TagInfo]) + + /** + * The file data for the file list of the repository viewer. + * + * @param id the object id + * @param isDirectory whether is it directory + * @param name the file (or directory) name + * @param time the last modified time + * @param message the last commit message + * @param committer the last committer name + */ + case class FileInfo(id: ObjectId, isDirectory: Boolean, name: String, time: Date, message: String, committer: String) + + /** + * The commit data. + * + * @param id the commit id + * @param time the commit time + * @param committer the commiter name + * @param message the commit message + */ + case class CommitInfo(id: String, time: Date, committer: String, message: String){ + def this(rev: org.eclipse.jgit.revwalk.RevCommit) = + this(rev.getName, rev.getCommitterIdent.getWhen, rev.getCommitterIdent.getName, rev.getFullMessage) + } + + case class DiffInfo(changeType: ChangeType, oldPath: String, newPath: String, oldContent: Option[String], newContent: Option[String]) + + /** + * The file content data for the file content view of the repository viewer. + * + * @param viewType "image", "large" or "other" + * @param content the string content + */ + case class ContentInfo(viewType: String, content: Option[String]) + + /** + * The tag data. + * + * @param name the tag name + * @param time the tagged date + * @param id the commit id + */ + case class TagInfo(name: String, time: Date, id: String) + /** * Use this method to use the Git object. * Repository resources are released certainly after processing. diff --git a/src/main/scala/view/helpers.scala b/src/main/scala/view/helpers.scala index 7d81ca7..d351847 100644 --- a/src/main/scala/view/helpers.scala +++ b/src/main/scala/view/helpers.scala @@ -25,7 +25,7 @@ /** * Converts the issue number and the commit id to the link. */ - private def markdownFilter(value: String, repository: app.RepositoryInfo)(implicit context: app.Context): String = { + private def markdownFilter(value: String, repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context): String = { value .replaceAll("#([0-9]+)", "[$0](%s/%s/%s/issue/$1)".format(context.path, repository.owner, repository.name)) .replaceAll("[0-9a-z]{10,40}", "[$0](%s/%s/%s/commit/$0)".format(context.path, repository.owner, repository.name)) @@ -34,7 +34,7 @@ /** * Converts Markdown of Wiki pages to HTML. */ - def markdown(value: String, repository: app.RepositoryInfo, wikiLink: Boolean)(implicit context: app.Context): twirl.api.Html = { + def markdown(value: String, repository: util.JGitUtil.RepositoryInfo, wikiLink: Boolean)(implicit context: app.Context): twirl.api.Html = { import org.pegdown._ val html = new PegDownProcessor(Extensions.AUTOLINKS|Extensions.WIKILINKS|Extensions.FENCED_CODE_BLOCKS) .markdownToHtml(markdownFilter(value, repository), new LinkRenderer(){ diff --git a/src/main/twirl/diff.scala.html b/src/main/twirl/diff.scala.html index 859c6e7..c1f7be6 100644 --- a/src/main/twirl/diff.scala.html +++ b/src/main/twirl/diff.scala.html @@ -1,4 +1,4 @@ -@(diffs: Seq[app.DiffInfo], repository: app.RepositoryInfo, commitId: Option[String])(implicit context: app.Context) +@(diffs: Seq[util.JGitUtil.DiffInfo], repository: util.JGitUtil.RepositoryInfo, commitId: Option[String])(implicit context: app.Context) @import context._ @import org.eclipse.jgit.diff.DiffEntry.ChangeType @diffs.zipWithIndex.map { case (diff, i) => diff --git a/src/main/twirl/header.scala.html b/src/main/twirl/header.scala.html index ba87449..3613e7b 100644 --- a/src/main/twirl/header.scala.html +++ b/src/main/twirl/header.scala.html @@ -1,4 +1,4 @@ -@(active: String, repository: app.RepositoryInfo)(implicit context: app.Context) +@(active: String, repository: util.JGitUtil.RepositoryInfo)(implicit context: app.Context) @import context._