mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 13:35:50 +01:00
(refs #341)Fix compilation error of delete statements
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package object model extends {
|
package object model extends {
|
||||||
// TODO
|
// TODO
|
||||||
val profile = slick.driver.H2Driver
|
val profile = slick.driver.H2Driver
|
||||||
|
val simple = profile.simple
|
||||||
|
|
||||||
} with AccountComponent
|
} with AccountComponent
|
||||||
with ActivityComponent
|
with ActivityComponent
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import model._
|
import model._
|
||||||
import profile.simple._
|
import simple._
|
||||||
import service.SystemSettingsService.SystemSettings
|
import service.SystemSettingsService.SystemSettings
|
||||||
import util.StringUtil._
|
import util.StringUtil._
|
||||||
import util.LDAPUtil
|
import util.LDAPUtil
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import model._
|
import model._
|
||||||
import profile.simple._
|
import simple._
|
||||||
|
|
||||||
trait ActivityService {
|
trait ActivityService {
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import scala.slick.jdbc.{StaticQuery => Q}
|
|||||||
import Q.interpolation
|
import Q.interpolation
|
||||||
|
|
||||||
import model._
|
import model._
|
||||||
import profile.simple._
|
import simple._
|
||||||
import util.Implicits._
|
import util.Implicits._
|
||||||
import util.StringUtil._
|
import util.StringUtil._
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import model._
|
import model._
|
||||||
import profile.simple._
|
import simple._
|
||||||
|
|
||||||
trait LabelsService {
|
trait LabelsService {
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import model._
|
import model._
|
||||||
import profile.simple._
|
import simple._
|
||||||
|
|
||||||
trait MilestonesService {
|
trait MilestonesService {
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import model._
|
import model._
|
||||||
import profile.simple._
|
import simple._
|
||||||
|
|
||||||
trait PullRequestService { self: IssuesService =>
|
trait PullRequestService { self: IssuesService =>
|
||||||
import PullRequestService._
|
import PullRequestService._
|
||||||
|
|||||||
@@ -3,12 +3,12 @@ package service
|
|||||||
import util.{FileUtil, StringUtil, JGitUtil}
|
import util.{FileUtil, StringUtil, JGitUtil}
|
||||||
import util.Directory._
|
import util.Directory._
|
||||||
import util.ControlUtil._
|
import util.ControlUtil._
|
||||||
import model.Issue
|
|
||||||
import org.eclipse.jgit.revwalk.RevWalk
|
import org.eclipse.jgit.revwalk.RevWalk
|
||||||
import org.eclipse.jgit.treewalk.TreeWalk
|
import org.eclipse.jgit.treewalk.TreeWalk
|
||||||
import org.eclipse.jgit.lib.FileMode
|
import org.eclipse.jgit.lib.FileMode
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import model.profile.simple.Session
|
import model._
|
||||||
|
import simple._
|
||||||
|
|
||||||
trait RepositorySearchService { self: IssuesService =>
|
trait RepositorySearchService { self: IssuesService =>
|
||||||
import RepositorySearchService._
|
import RepositorySearchService._
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import model._
|
import model._
|
||||||
import profile.simple._
|
import simple._
|
||||||
import util.JGitUtil
|
import util.JGitUtil
|
||||||
|
|
||||||
trait RepositoryService { self: AccountService =>
|
trait RepositoryService { self: AccountService =>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import model._
|
import model._
|
||||||
import profile.simple._
|
import simple._
|
||||||
|
|
||||||
trait SshKeyService {
|
trait SshKeyService {
|
||||||
|
|
||||||
|
|||||||
@@ -1,190 +1,190 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import util.Directory._
|
import util.Directory._
|
||||||
import util.ControlUtil._
|
import util.ControlUtil._
|
||||||
import SystemSettingsService._
|
import SystemSettingsService._
|
||||||
import javax.servlet.http.HttpServletRequest
|
import javax.servlet.http.HttpServletRequest
|
||||||
|
|
||||||
trait SystemSettingsService {
|
trait SystemSettingsService {
|
||||||
|
|
||||||
def baseUrl(implicit request: HttpServletRequest): String = loadSystemSettings().baseUrl(request)
|
def baseUrl(implicit request: HttpServletRequest): String = loadSystemSettings().baseUrl(request)
|
||||||
|
|
||||||
def saveSystemSettings(settings: SystemSettings): Unit = {
|
def saveSystemSettings(settings: SystemSettings): Unit = {
|
||||||
defining(new java.util.Properties()){ props =>
|
defining(new java.util.Properties()){ props =>
|
||||||
settings.baseUrl.foreach(x => props.setProperty(BaseURL, x.replaceFirst("/\\Z", "")))
|
settings.baseUrl.foreach(x => props.setProperty(BaseURL, x.replaceFirst("/\\Z", "")))
|
||||||
props.setProperty(AllowAccountRegistration, settings.allowAccountRegistration.toString)
|
props.setProperty(AllowAccountRegistration, settings.allowAccountRegistration.toString)
|
||||||
props.setProperty(Gravatar, settings.gravatar.toString)
|
props.setProperty(Gravatar, settings.gravatar.toString)
|
||||||
props.setProperty(Notification, settings.notification.toString)
|
props.setProperty(Notification, settings.notification.toString)
|
||||||
props.setProperty(Ssh, settings.ssh.toString)
|
props.setProperty(Ssh, settings.ssh.toString)
|
||||||
settings.sshPort.foreach(x => props.setProperty(SshPort, x.toString))
|
settings.sshPort.foreach(x => props.setProperty(SshPort, x.toString))
|
||||||
if(settings.notification) {
|
if(settings.notification) {
|
||||||
settings.smtp.foreach { smtp =>
|
settings.smtp.foreach { smtp =>
|
||||||
props.setProperty(SmtpHost, smtp.host)
|
props.setProperty(SmtpHost, smtp.host)
|
||||||
smtp.port.foreach(x => props.setProperty(SmtpPort, x.toString))
|
smtp.port.foreach(x => props.setProperty(SmtpPort, x.toString))
|
||||||
smtp.user.foreach(props.setProperty(SmtpUser, _))
|
smtp.user.foreach(props.setProperty(SmtpUser, _))
|
||||||
smtp.password.foreach(props.setProperty(SmtpPassword, _))
|
smtp.password.foreach(props.setProperty(SmtpPassword, _))
|
||||||
smtp.ssl.foreach(x => props.setProperty(SmtpSsl, x.toString))
|
smtp.ssl.foreach(x => props.setProperty(SmtpSsl, x.toString))
|
||||||
smtp.fromAddress.foreach(props.setProperty(SmtpFromAddress, _))
|
smtp.fromAddress.foreach(props.setProperty(SmtpFromAddress, _))
|
||||||
smtp.fromName.foreach(props.setProperty(SmtpFromName, _))
|
smtp.fromName.foreach(props.setProperty(SmtpFromName, _))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
props.setProperty(LdapAuthentication, settings.ldapAuthentication.toString)
|
props.setProperty(LdapAuthentication, settings.ldapAuthentication.toString)
|
||||||
if(settings.ldapAuthentication){
|
if(settings.ldapAuthentication){
|
||||||
settings.ldap.map { ldap =>
|
settings.ldap.map { ldap =>
|
||||||
props.setProperty(LdapHost, ldap.host)
|
props.setProperty(LdapHost, ldap.host)
|
||||||
ldap.port.foreach(x => props.setProperty(LdapPort, x.toString))
|
ldap.port.foreach(x => props.setProperty(LdapPort, x.toString))
|
||||||
ldap.bindDN.foreach(x => props.setProperty(LdapBindDN, x))
|
ldap.bindDN.foreach(x => props.setProperty(LdapBindDN, x))
|
||||||
ldap.bindPassword.foreach(x => props.setProperty(LdapBindPassword, x))
|
ldap.bindPassword.foreach(x => props.setProperty(LdapBindPassword, x))
|
||||||
props.setProperty(LdapBaseDN, ldap.baseDN)
|
props.setProperty(LdapBaseDN, ldap.baseDN)
|
||||||
props.setProperty(LdapUserNameAttribute, ldap.userNameAttribute)
|
props.setProperty(LdapUserNameAttribute, ldap.userNameAttribute)
|
||||||
ldap.fullNameAttribute.foreach(x => props.setProperty(LdapFullNameAttribute, x))
|
ldap.fullNameAttribute.foreach(x => props.setProperty(LdapFullNameAttribute, x))
|
||||||
props.setProperty(LdapMailAddressAttribute, ldap.mailAttribute)
|
props.setProperty(LdapMailAddressAttribute, ldap.mailAttribute)
|
||||||
ldap.tls.foreach(x => props.setProperty(LdapTls, x.toString))
|
ldap.tls.foreach(x => props.setProperty(LdapTls, x.toString))
|
||||||
ldap.keystore.foreach(x => props.setProperty(LdapKeystore, x))
|
ldap.keystore.foreach(x => props.setProperty(LdapKeystore, x))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
using(new java.io.FileOutputStream(GitBucketConf)){ out =>
|
using(new java.io.FileOutputStream(GitBucketConf)){ out =>
|
||||||
props.store(out, null)
|
props.store(out, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def loadSystemSettings(): SystemSettings = {
|
def loadSystemSettings(): SystemSettings = {
|
||||||
defining(new java.util.Properties()){ props =>
|
defining(new java.util.Properties()){ props =>
|
||||||
if(GitBucketConf.exists){
|
if(GitBucketConf.exists){
|
||||||
using(new java.io.FileInputStream(GitBucketConf)){ in =>
|
using(new java.io.FileInputStream(GitBucketConf)){ in =>
|
||||||
props.load(in)
|
props.load(in)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SystemSettings(
|
SystemSettings(
|
||||||
getOptionValue[String](props, BaseURL, None).map(x => x.replaceFirst("/\\Z", "")),
|
getOptionValue[String](props, BaseURL, None).map(x => x.replaceFirst("/\\Z", "")),
|
||||||
getValue(props, AllowAccountRegistration, false),
|
getValue(props, AllowAccountRegistration, false),
|
||||||
getValue(props, Gravatar, true),
|
getValue(props, Gravatar, true),
|
||||||
getValue(props, Notification, false),
|
getValue(props, Notification, false),
|
||||||
getValue(props, Ssh, false),
|
getValue(props, Ssh, false),
|
||||||
getOptionValue(props, SshPort, Some(DefaultSshPort)),
|
getOptionValue(props, SshPort, Some(DefaultSshPort)),
|
||||||
if(getValue(props, Notification, false)){
|
if(getValue(props, Notification, false)){
|
||||||
Some(Smtp(
|
Some(Smtp(
|
||||||
getValue(props, SmtpHost, ""),
|
getValue(props, SmtpHost, ""),
|
||||||
getOptionValue(props, SmtpPort, Some(DefaultSmtpPort)),
|
getOptionValue(props, SmtpPort, Some(DefaultSmtpPort)),
|
||||||
getOptionValue(props, SmtpUser, None),
|
getOptionValue(props, SmtpUser, None),
|
||||||
getOptionValue(props, SmtpPassword, None),
|
getOptionValue(props, SmtpPassword, None),
|
||||||
getOptionValue[Boolean](props, SmtpSsl, None),
|
getOptionValue[Boolean](props, SmtpSsl, None),
|
||||||
getOptionValue(props, SmtpFromAddress, None),
|
getOptionValue(props, SmtpFromAddress, None),
|
||||||
getOptionValue(props, SmtpFromName, None)))
|
getOptionValue(props, SmtpFromName, None)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
getValue(props, LdapAuthentication, false),
|
getValue(props, LdapAuthentication, false),
|
||||||
if(getValue(props, LdapAuthentication, false)){
|
if(getValue(props, LdapAuthentication, false)){
|
||||||
Some(Ldap(
|
Some(Ldap(
|
||||||
getValue(props, LdapHost, ""),
|
getValue(props, LdapHost, ""),
|
||||||
getOptionValue(props, LdapPort, Some(DefaultLdapPort)),
|
getOptionValue(props, LdapPort, Some(DefaultLdapPort)),
|
||||||
getOptionValue(props, LdapBindDN, None),
|
getOptionValue(props, LdapBindDN, None),
|
||||||
getOptionValue(props, LdapBindPassword, None),
|
getOptionValue(props, LdapBindPassword, None),
|
||||||
getValue(props, LdapBaseDN, ""),
|
getValue(props, LdapBaseDN, ""),
|
||||||
getValue(props, LdapUserNameAttribute, ""),
|
getValue(props, LdapUserNameAttribute, ""),
|
||||||
getOptionValue(props, LdapFullNameAttribute, None),
|
getOptionValue(props, LdapFullNameAttribute, None),
|
||||||
getValue(props, LdapMailAddressAttribute, ""),
|
getValue(props, LdapMailAddressAttribute, ""),
|
||||||
getOptionValue[Boolean](props, LdapTls, None),
|
getOptionValue[Boolean](props, LdapTls, None),
|
||||||
getOptionValue(props, LdapKeystore, None)))
|
getOptionValue(props, LdapKeystore, None)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object SystemSettingsService {
|
object SystemSettingsService {
|
||||||
import scala.reflect.ClassTag
|
import scala.reflect.ClassTag
|
||||||
|
|
||||||
case class SystemSettings(
|
case class SystemSettings(
|
||||||
baseUrl: Option[String],
|
baseUrl: Option[String],
|
||||||
allowAccountRegistration: Boolean,
|
allowAccountRegistration: Boolean,
|
||||||
gravatar: Boolean,
|
gravatar: Boolean,
|
||||||
notification: Boolean,
|
notification: Boolean,
|
||||||
ssh: Boolean,
|
ssh: Boolean,
|
||||||
sshPort: Option[Int],
|
sshPort: Option[Int],
|
||||||
smtp: Option[Smtp],
|
smtp: Option[Smtp],
|
||||||
ldapAuthentication: Boolean,
|
ldapAuthentication: Boolean,
|
||||||
ldap: Option[Ldap]){
|
ldap: Option[Ldap]){
|
||||||
def baseUrl(request: HttpServletRequest): String = baseUrl.getOrElse {
|
def baseUrl(request: HttpServletRequest): String = baseUrl.getOrElse {
|
||||||
defining(request.getRequestURL.toString){ url =>
|
defining(request.getRequestURL.toString){ url =>
|
||||||
url.substring(0, url.length - (request.getRequestURI.length - request.getContextPath.length))
|
url.substring(0, url.length - (request.getRequestURI.length - request.getContextPath.length))
|
||||||
}
|
}
|
||||||
}.stripSuffix("/")
|
}.stripSuffix("/")
|
||||||
}
|
}
|
||||||
|
|
||||||
case class Ldap(
|
case class Ldap(
|
||||||
host: String,
|
host: String,
|
||||||
port: Option[Int],
|
port: Option[Int],
|
||||||
bindDN: Option[String],
|
bindDN: Option[String],
|
||||||
bindPassword: Option[String],
|
bindPassword: Option[String],
|
||||||
baseDN: String,
|
baseDN: String,
|
||||||
userNameAttribute: String,
|
userNameAttribute: String,
|
||||||
fullNameAttribute: Option[String],
|
fullNameAttribute: Option[String],
|
||||||
mailAttribute: String,
|
mailAttribute: String,
|
||||||
tls: Option[Boolean],
|
tls: Option[Boolean],
|
||||||
keystore: Option[String])
|
keystore: Option[String])
|
||||||
|
|
||||||
case class Smtp(
|
case class Smtp(
|
||||||
host: String,
|
host: String,
|
||||||
port: Option[Int],
|
port: Option[Int],
|
||||||
user: Option[String],
|
user: Option[String],
|
||||||
password: Option[String],
|
password: Option[String],
|
||||||
ssl: Option[Boolean],
|
ssl: Option[Boolean],
|
||||||
fromAddress: Option[String],
|
fromAddress: Option[String],
|
||||||
fromName: Option[String])
|
fromName: Option[String])
|
||||||
|
|
||||||
val DefaultSshPort = 29418
|
val DefaultSshPort = 29418
|
||||||
val DefaultSmtpPort = 25
|
val DefaultSmtpPort = 25
|
||||||
val DefaultLdapPort = 389
|
val DefaultLdapPort = 389
|
||||||
|
|
||||||
private val BaseURL = "base_url"
|
private val BaseURL = "base_url"
|
||||||
private val AllowAccountRegistration = "allow_account_registration"
|
private val AllowAccountRegistration = "allow_account_registration"
|
||||||
private val Gravatar = "gravatar"
|
private val Gravatar = "gravatar"
|
||||||
private val Notification = "notification"
|
private val Notification = "notification"
|
||||||
private val Ssh = "ssh"
|
private val Ssh = "ssh"
|
||||||
private val SshPort = "ssh.port"
|
private val SshPort = "ssh.port"
|
||||||
private val SmtpHost = "smtp.host"
|
private val SmtpHost = "smtp.host"
|
||||||
private val SmtpPort = "smtp.port"
|
private val SmtpPort = "smtp.port"
|
||||||
private val SmtpUser = "smtp.user"
|
private val SmtpUser = "smtp.user"
|
||||||
private val SmtpPassword = "smtp.password"
|
private val SmtpPassword = "smtp.password"
|
||||||
private val SmtpSsl = "smtp.ssl"
|
private val SmtpSsl = "smtp.ssl"
|
||||||
private val SmtpFromAddress = "smtp.from_address"
|
private val SmtpFromAddress = "smtp.from_address"
|
||||||
private val SmtpFromName = "smtp.from_name"
|
private val SmtpFromName = "smtp.from_name"
|
||||||
private val LdapAuthentication = "ldap_authentication"
|
private val LdapAuthentication = "ldap_authentication"
|
||||||
private val LdapHost = "ldap.host"
|
private val LdapHost = "ldap.host"
|
||||||
private val LdapPort = "ldap.port"
|
private val LdapPort = "ldap.port"
|
||||||
private val LdapBindDN = "ldap.bindDN"
|
private val LdapBindDN = "ldap.bindDN"
|
||||||
private val LdapBindPassword = "ldap.bind_password"
|
private val LdapBindPassword = "ldap.bind_password"
|
||||||
private val LdapBaseDN = "ldap.baseDN"
|
private val LdapBaseDN = "ldap.baseDN"
|
||||||
private val LdapUserNameAttribute = "ldap.username_attribute"
|
private val LdapUserNameAttribute = "ldap.username_attribute"
|
||||||
private val LdapFullNameAttribute = "ldap.fullname_attribute"
|
private val LdapFullNameAttribute = "ldap.fullname_attribute"
|
||||||
private val LdapMailAddressAttribute = "ldap.mail_attribute"
|
private val LdapMailAddressAttribute = "ldap.mail_attribute"
|
||||||
private val LdapTls = "ldap.tls"
|
private val LdapTls = "ldap.tls"
|
||||||
private val LdapKeystore = "ldap.keystore"
|
private val LdapKeystore = "ldap.keystore"
|
||||||
|
|
||||||
private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A =
|
private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A =
|
||||||
defining(props.getProperty(key)){ value =>
|
defining(props.getProperty(key)){ value =>
|
||||||
if(value == null || value.isEmpty) default
|
if(value == null || value.isEmpty) default
|
||||||
else convertType(value).asInstanceOf[A]
|
else convertType(value).asInstanceOf[A]
|
||||||
}
|
}
|
||||||
|
|
||||||
private def getOptionValue[A: ClassTag](props: java.util.Properties, key: String, default: Option[A]): Option[A] =
|
private def getOptionValue[A: ClassTag](props: java.util.Properties, key: String, default: Option[A]): Option[A] =
|
||||||
defining(props.getProperty(key)){ value =>
|
defining(props.getProperty(key)){ value =>
|
||||||
if(value == null || value.isEmpty) default
|
if(value == null || value.isEmpty) default
|
||||||
else Some(convertType(value)).asInstanceOf[Option[A]]
|
else Some(convertType(value)).asInstanceOf[Option[A]]
|
||||||
}
|
}
|
||||||
|
|
||||||
private def convertType[A: ClassTag](value: String) =
|
private def convertType[A: ClassTag](value: String) =
|
||||||
defining(implicitly[ClassTag[A]].runtimeClass){ c =>
|
defining(implicitly[ClassTag[A]].runtimeClass){ c =>
|
||||||
if(c == classOf[Boolean]) value.toBoolean
|
if(c == classOf[Boolean]) value.toBoolean
|
||||||
else if(c == classOf[Int]) value.toInt
|
else if(c == classOf[Int]) value.toInt
|
||||||
else value
|
else value
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import model._
|
import model._
|
||||||
import profile.simple._
|
import simple._
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import service.RepositoryService.RepositoryInfo
|
import service.RepositoryService.RepositoryInfo
|
||||||
import util.JGitUtil
|
import util.JGitUtil
|
||||||
|
|||||||
@@ -1,282 +1,278 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.apache.commons.io.FileUtils
|
import util._
|
||||||
import util._
|
import _root_.util.ControlUtil._
|
||||||
import _root_.util.ControlUtil._
|
import org.eclipse.jgit.treewalk.CanonicalTreeParser
|
||||||
import org.eclipse.jgit.treewalk.{TreeWalk, CanonicalTreeParser}
|
import org.eclipse.jgit.lib._
|
||||||
import org.eclipse.jgit.lib._
|
import org.eclipse.jgit.dircache.DirCache
|
||||||
import org.eclipse.jgit.dircache.{DirCache, DirCacheEntry}
|
import org.eclipse.jgit.diff.{DiffEntry, DiffFormatter}
|
||||||
import org.eclipse.jgit.revwalk.RevWalk
|
import java.io.ByteArrayInputStream
|
||||||
import org.eclipse.jgit.diff.{DiffEntry, DiffFormatter}
|
import org.eclipse.jgit.patch._
|
||||||
import java.io.ByteArrayInputStream
|
import org.eclipse.jgit.api.errors.PatchFormatException
|
||||||
import org.eclipse.jgit.patch._
|
import scala.collection.JavaConverters._
|
||||||
import org.eclipse.jgit.api.errors.PatchFormatException
|
import service.RepositoryService.RepositoryInfo
|
||||||
import scala.collection.JavaConverters._
|
|
||||||
import scala.Some
|
object WikiService {
|
||||||
import service.RepositoryService.RepositoryInfo
|
|
||||||
|
/**
|
||||||
|
* The model for wiki page.
|
||||||
object WikiService {
|
*
|
||||||
|
* @param name the page name
|
||||||
/**
|
* @param content the page content
|
||||||
* The model for wiki page.
|
* @param committer the last committer
|
||||||
*
|
* @param time the last modified time
|
||||||
* @param name the page name
|
* @param id the latest commit id
|
||||||
* @param content the page content
|
*/
|
||||||
* @param committer the last committer
|
case class WikiPageInfo(name: String, content: String, committer: String, time: Date, id: String)
|
||||||
* @param time the last modified time
|
|
||||||
* @param id the latest commit id
|
/**
|
||||||
*/
|
* The model for wiki page history.
|
||||||
case class WikiPageInfo(name: String, content: String, committer: String, time: Date, id: String)
|
*
|
||||||
|
* @param name the page name
|
||||||
/**
|
* @param committer the committer the committer
|
||||||
* The model for wiki page history.
|
* @param message the commit message
|
||||||
*
|
* @param date the commit date
|
||||||
* @param name the page name
|
*/
|
||||||
* @param committer the committer the committer
|
case class WikiPageHistoryInfo(name: String, committer: String, message: String, date: Date)
|
||||||
* @param message the commit message
|
|
||||||
* @param date the commit date
|
def httpUrl(repository: RepositoryInfo) = repository.httpUrl.replaceFirst("\\.git\\Z", ".wiki.git")
|
||||||
*/
|
|
||||||
case class WikiPageHistoryInfo(name: String, committer: String, message: String, date: Date)
|
def sshUrl(repository: RepositoryInfo, settings: SystemSettingsService.SystemSettings, userName: String) =
|
||||||
|
repository.sshUrl(settings.sshPort.getOrElse(SystemSettingsService.DefaultSshPort), userName).replaceFirst("\\.git\\Z", ".wiki.git")
|
||||||
def httpUrl(repository: RepositoryInfo) = repository.httpUrl.replaceFirst("\\.git\\Z", ".wiki.git")
|
}
|
||||||
|
|
||||||
def sshUrl(repository: RepositoryInfo, settings: SystemSettingsService.SystemSettings, userName: String) =
|
trait WikiService {
|
||||||
repository.sshUrl(settings.sshPort.getOrElse(SystemSettingsService.DefaultSshPort), userName).replaceFirst("\\.git\\Z", ".wiki.git")
|
import WikiService._
|
||||||
}
|
|
||||||
|
def createWikiRepository(loginAccount: model.Account, owner: String, repository: String): Unit =
|
||||||
trait WikiService {
|
LockUtil.lock(s"${owner}/${repository}/wiki"){
|
||||||
import WikiService._
|
defining(Directory.getWikiRepositoryDir(owner, repository)){ dir =>
|
||||||
|
if(!dir.exists){
|
||||||
def createWikiRepository(loginAccount: model.Account, owner: String, repository: String): Unit =
|
JGitUtil.initRepository(dir)
|
||||||
LockUtil.lock(s"${owner}/${repository}/wiki"){
|
saveWikiPage(owner, repository, "Home", "Home", s"Welcome to the ${repository} wiki!!", loginAccount, "Initial Commit", None)
|
||||||
defining(Directory.getWikiRepositoryDir(owner, repository)){ dir =>
|
}
|
||||||
if(!dir.exists){
|
}
|
||||||
JGitUtil.initRepository(dir)
|
}
|
||||||
saveWikiPage(owner, repository, "Home", "Home", s"Welcome to the ${repository} wiki!!", loginAccount, "Initial Commit", None)
|
|
||||||
}
|
/**
|
||||||
}
|
* Returns the wiki page.
|
||||||
}
|
*/
|
||||||
|
def getWikiPage(owner: String, repository: String, pageName: String): Option[WikiPageInfo] = {
|
||||||
/**
|
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
||||||
* Returns the wiki page.
|
if(!JGitUtil.isEmpty(git)){
|
||||||
*/
|
JGitUtil.getFileList(git, "master", ".").find(_.name == pageName + ".md").map { file =>
|
||||||
def getWikiPage(owner: String, repository: String, pageName: String): Option[WikiPageInfo] = {
|
WikiPageInfo(file.name, StringUtil.convertFromByteArray(git.getRepository.open(file.id).getBytes),
|
||||||
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
file.committer, file.time, file.commitId)
|
||||||
if(!JGitUtil.isEmpty(git)){
|
}
|
||||||
JGitUtil.getFileList(git, "master", ".").find(_.name == pageName + ".md").map { file =>
|
} else None
|
||||||
WikiPageInfo(file.name, StringUtil.convertFromByteArray(git.getRepository.open(file.id).getBytes),
|
}
|
||||||
file.committer, file.time, file.commitId)
|
}
|
||||||
}
|
|
||||||
} else None
|
/**
|
||||||
}
|
* Returns the content of the specified file.
|
||||||
}
|
*/
|
||||||
|
def getFileContent(owner: String, repository: String, path: String): Option[Array[Byte]] =
|
||||||
/**
|
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
||||||
* Returns the content of the specified file.
|
if(!JGitUtil.isEmpty(git)){
|
||||||
*/
|
val index = path.lastIndexOf('/')
|
||||||
def getFileContent(owner: String, repository: String, path: String): Option[Array[Byte]] =
|
val parentPath = if(index < 0) "." else path.substring(0, index)
|
||||||
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
val fileName = if(index < 0) path else path.substring(index + 1)
|
||||||
if(!JGitUtil.isEmpty(git)){
|
|
||||||
val index = path.lastIndexOf('/')
|
JGitUtil.getFileList(git, "master", parentPath).find(_.name == fileName).map { file =>
|
||||||
val parentPath = if(index < 0) "." else path.substring(0, index)
|
git.getRepository.open(file.id).getBytes
|
||||||
val fileName = if(index < 0) path else path.substring(index + 1)
|
}
|
||||||
|
} else None
|
||||||
JGitUtil.getFileList(git, "master", parentPath).find(_.name == fileName).map { file =>
|
}
|
||||||
git.getRepository.open(file.id).getBytes
|
|
||||||
}
|
/**
|
||||||
} else None
|
* Returns the list of wiki page names.
|
||||||
}
|
*/
|
||||||
|
def getWikiPageList(owner: String, repository: String): List[String] = {
|
||||||
/**
|
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
||||||
* Returns the list of wiki page names.
|
JGitUtil.getFileList(git, "master", ".")
|
||||||
*/
|
.filter(_.name.endsWith(".md"))
|
||||||
def getWikiPageList(owner: String, repository: String): List[String] = {
|
.map(_.name.stripSuffix(".md"))
|
||||||
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
.sortBy(x => x)
|
||||||
JGitUtil.getFileList(git, "master", ".")
|
}
|
||||||
.filter(_.name.endsWith(".md"))
|
}
|
||||||
.map(_.name.stripSuffix(".md"))
|
|
||||||
.sortBy(x => x)
|
/**
|
||||||
}
|
* Reverts specified changes.
|
||||||
}
|
*/
|
||||||
|
def revertWikiPage(owner: String, repository: String, from: String, to: String,
|
||||||
/**
|
committer: model.Account, pageName: Option[String]): Boolean = {
|
||||||
* Reverts specified changes.
|
|
||||||
*/
|
case class RevertInfo(operation: String, filePath: String, source: String)
|
||||||
def revertWikiPage(owner: String, repository: String, from: String, to: String,
|
|
||||||
committer: model.Account, pageName: Option[String]): Boolean = {
|
try {
|
||||||
|
LockUtil.lock(s"${owner}/${repository}/wiki"){
|
||||||
case class RevertInfo(operation: String, filePath: String, source: String)
|
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
||||||
|
|
||||||
try {
|
val reader = git.getRepository.newObjectReader
|
||||||
LockUtil.lock(s"${owner}/${repository}/wiki"){
|
val oldTreeIter = new CanonicalTreeParser
|
||||||
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
oldTreeIter.reset(reader, git.getRepository.resolve(from + "^{tree}"))
|
||||||
|
|
||||||
val reader = git.getRepository.newObjectReader
|
val newTreeIter = new CanonicalTreeParser
|
||||||
val oldTreeIter = new CanonicalTreeParser
|
newTreeIter.reset(reader, git.getRepository.resolve(to + "^{tree}"))
|
||||||
oldTreeIter.reset(reader, git.getRepository.resolve(from + "^{tree}"))
|
|
||||||
|
val diffs = git.diff.setNewTree(oldTreeIter).setOldTree(newTreeIter).call.asScala.filter { diff =>
|
||||||
val newTreeIter = new CanonicalTreeParser
|
pageName match {
|
||||||
newTreeIter.reset(reader, git.getRepository.resolve(to + "^{tree}"))
|
case Some(x) => diff.getNewPath == x + ".md"
|
||||||
|
case None => true
|
||||||
val diffs = git.diff.setNewTree(oldTreeIter).setOldTree(newTreeIter).call.asScala.filter { diff =>
|
}
|
||||||
pageName match {
|
}
|
||||||
case Some(x) => diff.getNewPath == x + ".md"
|
|
||||||
case None => true
|
val patch = using(new java.io.ByteArrayOutputStream()){ out =>
|
||||||
}
|
val formatter = new DiffFormatter(out)
|
||||||
}
|
formatter.setRepository(git.getRepository)
|
||||||
|
formatter.format(diffs.asJava)
|
||||||
val patch = using(new java.io.ByteArrayOutputStream()){ out =>
|
new String(out.toByteArray, "UTF-8")
|
||||||
val formatter = new DiffFormatter(out)
|
}
|
||||||
formatter.setRepository(git.getRepository)
|
|
||||||
formatter.format(diffs.asJava)
|
val p = new Patch()
|
||||||
new String(out.toByteArray, "UTF-8")
|
p.parse(new ByteArrayInputStream(patch.getBytes("UTF-8")))
|
||||||
}
|
if(!p.getErrors.isEmpty){
|
||||||
|
throw new PatchFormatException(p.getErrors())
|
||||||
val p = new Patch()
|
}
|
||||||
p.parse(new ByteArrayInputStream(patch.getBytes("UTF-8")))
|
val revertInfo = (p.getFiles.asScala.map { fh =>
|
||||||
if(!p.getErrors.isEmpty){
|
fh.getChangeType match {
|
||||||
throw new PatchFormatException(p.getErrors())
|
case DiffEntry.ChangeType.MODIFY => {
|
||||||
}
|
val source = getWikiPage(owner, repository, fh.getNewPath.stripSuffix(".md")).map(_.content).getOrElse("")
|
||||||
val revertInfo = (p.getFiles.asScala.map { fh =>
|
val applied = PatchUtil.apply(source, patch, fh)
|
||||||
fh.getChangeType match {
|
if(applied != null){
|
||||||
case DiffEntry.ChangeType.MODIFY => {
|
Seq(RevertInfo("ADD", fh.getNewPath, applied))
|
||||||
val source = getWikiPage(owner, repository, fh.getNewPath.stripSuffix(".md")).map(_.content).getOrElse("")
|
} else Nil
|
||||||
val applied = PatchUtil.apply(source, patch, fh)
|
}
|
||||||
if(applied != null){
|
case DiffEntry.ChangeType.ADD => {
|
||||||
Seq(RevertInfo("ADD", fh.getNewPath, applied))
|
val applied = PatchUtil.apply("", patch, fh)
|
||||||
} else Nil
|
if(applied != null){
|
||||||
}
|
Seq(RevertInfo("ADD", fh.getNewPath, applied))
|
||||||
case DiffEntry.ChangeType.ADD => {
|
} else Nil
|
||||||
val applied = PatchUtil.apply("", patch, fh)
|
}
|
||||||
if(applied != null){
|
case DiffEntry.ChangeType.DELETE => {
|
||||||
Seq(RevertInfo("ADD", fh.getNewPath, applied))
|
Seq(RevertInfo("DELETE", fh.getNewPath, ""))
|
||||||
} else Nil
|
}
|
||||||
}
|
case DiffEntry.ChangeType.RENAME => {
|
||||||
case DiffEntry.ChangeType.DELETE => {
|
val applied = PatchUtil.apply("", patch, fh)
|
||||||
Seq(RevertInfo("DELETE", fh.getNewPath, ""))
|
if(applied != null){
|
||||||
}
|
Seq(RevertInfo("DELETE", fh.getOldPath, ""), RevertInfo("ADD", fh.getNewPath, applied))
|
||||||
case DiffEntry.ChangeType.RENAME => {
|
} else {
|
||||||
val applied = PatchUtil.apply("", patch, fh)
|
Seq(RevertInfo("DELETE", fh.getOldPath, ""))
|
||||||
if(applied != null){
|
}
|
||||||
Seq(RevertInfo("DELETE", fh.getOldPath, ""), RevertInfo("ADD", fh.getNewPath, applied))
|
}
|
||||||
} else {
|
case _ => Nil
|
||||||
Seq(RevertInfo("DELETE", fh.getOldPath, ""))
|
}
|
||||||
}
|
}).flatten
|
||||||
}
|
|
||||||
case _ => Nil
|
if(revertInfo.nonEmpty){
|
||||||
}
|
val builder = DirCache.newInCore.builder()
|
||||||
}).flatten
|
val inserter = git.getRepository.newObjectInserter()
|
||||||
|
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
|
||||||
if(revertInfo.nonEmpty){
|
|
||||||
val builder = DirCache.newInCore.builder()
|
JGitUtil.processTree(git, headId){ (path, tree) =>
|
||||||
val inserter = git.getRepository.newObjectInserter()
|
if(revertInfo.find(x => x.filePath == path).isEmpty){
|
||||||
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
|
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
||||||
|
}
|
||||||
JGitUtil.processTree(git, headId){ (path, tree) =>
|
}
|
||||||
if(revertInfo.find(x => x.filePath == path).isEmpty){
|
|
||||||
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
revertInfo.filter(_.operation == "ADD").foreach { x =>
|
||||||
}
|
builder.add(JGitUtil.createDirCacheEntry(x.filePath, FileMode.REGULAR_FILE, inserter.insert(Constants.OBJ_BLOB, x.source.getBytes("UTF-8"))))
|
||||||
}
|
}
|
||||||
|
builder.finish()
|
||||||
revertInfo.filter(_.operation == "ADD").foreach { x =>
|
|
||||||
builder.add(JGitUtil.createDirCacheEntry(x.filePath, FileMode.REGULAR_FILE, inserter.insert(Constants.OBJ_BLOB, x.source.getBytes("UTF-8"))))
|
JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter), committer.fullName, committer.mailAddress,
|
||||||
}
|
pageName match {
|
||||||
builder.finish()
|
case Some(x) => s"Revert ${from} ... ${to} on ${x}"
|
||||||
|
case None => s"Revert ${from} ... ${to}"
|
||||||
JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter), committer.fullName, committer.mailAddress,
|
})
|
||||||
pageName match {
|
}
|
||||||
case Some(x) => s"Revert ${from} ... ${to} on ${x}"
|
}
|
||||||
case None => s"Revert ${from} ... ${to}"
|
}
|
||||||
})
|
true
|
||||||
}
|
} catch {
|
||||||
}
|
case e: Exception => {
|
||||||
}
|
e.printStackTrace()
|
||||||
true
|
false
|
||||||
} catch {
|
}
|
||||||
case e: Exception => {
|
}
|
||||||
e.printStackTrace()
|
}
|
||||||
false
|
|
||||||
}
|
/**
|
||||||
}
|
* Save the wiki page.
|
||||||
}
|
*/
|
||||||
|
def saveWikiPage(owner: String, repository: String, currentPageName: String, newPageName: String,
|
||||||
/**
|
content: String, committer: model.Account, message: String, currentId: Option[String]): Option[String] = {
|
||||||
* Save the wiki page.
|
LockUtil.lock(s"${owner}/${repository}/wiki"){
|
||||||
*/
|
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
||||||
def saveWikiPage(owner: String, repository: String, currentPageName: String, newPageName: String,
|
val builder = DirCache.newInCore.builder()
|
||||||
content: String, committer: model.Account, message: String, currentId: Option[String]): Option[String] = {
|
val inserter = git.getRepository.newObjectInserter()
|
||||||
LockUtil.lock(s"${owner}/${repository}/wiki"){
|
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
|
||||||
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
var created = true
|
||||||
val builder = DirCache.newInCore.builder()
|
var updated = false
|
||||||
val inserter = git.getRepository.newObjectInserter()
|
var removed = false
|
||||||
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
|
|
||||||
var created = true
|
if(headId != null){
|
||||||
var updated = false
|
JGitUtil.processTree(git, headId){ (path, tree) =>
|
||||||
var removed = false
|
if(path == currentPageName + ".md" && currentPageName != newPageName){
|
||||||
|
removed = true
|
||||||
if(headId != null){
|
} else if(path != newPageName + ".md"){
|
||||||
JGitUtil.processTree(git, headId){ (path, tree) =>
|
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
||||||
if(path == currentPageName + ".md" && currentPageName != newPageName){
|
} else {
|
||||||
removed = true
|
created = false
|
||||||
} else if(path != newPageName + ".md"){
|
updated = JGitUtil.getContentFromId(git, tree.getEntryObjectId, true).map(new String(_, "UTF-8") != content).getOrElse(false)
|
||||||
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
}
|
||||||
} else {
|
}
|
||||||
created = false
|
}
|
||||||
updated = JGitUtil.getContentFromId(git, tree.getEntryObjectId, true).map(new String(_, "UTF-8") != content).getOrElse(false)
|
|
||||||
}
|
if(created || updated || removed){
|
||||||
}
|
builder.add(JGitUtil.createDirCacheEntry(newPageName + ".md", FileMode.REGULAR_FILE, inserter.insert(Constants.OBJ_BLOB, content.getBytes("UTF-8"))))
|
||||||
}
|
builder.finish()
|
||||||
|
val newHeadId = JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter), committer.fullName, committer.mailAddress,
|
||||||
if(created || updated || removed){
|
if(message.trim.length == 0) {
|
||||||
builder.add(JGitUtil.createDirCacheEntry(newPageName + ".md", FileMode.REGULAR_FILE, inserter.insert(Constants.OBJ_BLOB, content.getBytes("UTF-8"))))
|
if(removed){
|
||||||
builder.finish()
|
s"Rename ${currentPageName} to ${newPageName}"
|
||||||
val newHeadId = JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter), committer.fullName, committer.mailAddress,
|
} else if(created){
|
||||||
if(message.trim.length == 0) {
|
s"Created ${newPageName}"
|
||||||
if(removed){
|
} else {
|
||||||
s"Rename ${currentPageName} to ${newPageName}"
|
s"Updated ${newPageName}"
|
||||||
} else if(created){
|
}
|
||||||
s"Created ${newPageName}"
|
} else {
|
||||||
} else {
|
message
|
||||||
s"Updated ${newPageName}"
|
})
|
||||||
}
|
|
||||||
} else {
|
Some(newHeadId.getName)
|
||||||
message
|
} else None
|
||||||
})
|
}
|
||||||
|
}
|
||||||
Some(newHeadId.getName)
|
}
|
||||||
} else None
|
|
||||||
}
|
/**
|
||||||
}
|
* Delete the wiki page.
|
||||||
}
|
*/
|
||||||
|
def deleteWikiPage(owner: String, repository: String, pageName: String,
|
||||||
/**
|
committer: String, mailAddress: String, message: String): Unit = {
|
||||||
* Delete the wiki page.
|
LockUtil.lock(s"${owner}/${repository}/wiki"){
|
||||||
*/
|
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
||||||
def deleteWikiPage(owner: String, repository: String, pageName: String,
|
val builder = DirCache.newInCore.builder()
|
||||||
committer: String, mailAddress: String, message: String): Unit = {
|
val inserter = git.getRepository.newObjectInserter()
|
||||||
LockUtil.lock(s"${owner}/${repository}/wiki"){
|
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
|
||||||
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
var removed = false
|
||||||
val builder = DirCache.newInCore.builder()
|
|
||||||
val inserter = git.getRepository.newObjectInserter()
|
JGitUtil.processTree(git, headId){ (path, tree) =>
|
||||||
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
|
if(path != pageName + ".md"){
|
||||||
var removed = false
|
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
||||||
|
} else {
|
||||||
JGitUtil.processTree(git, headId){ (path, tree) =>
|
removed = true
|
||||||
if(path != pageName + ".md"){
|
}
|
||||||
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
}
|
||||||
} else {
|
if(removed){
|
||||||
removed = true
|
builder.finish()
|
||||||
}
|
JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter), committer, mailAddress, message)
|
||||||
}
|
}
|
||||||
if(removed){
|
}
|
||||||
builder.finish()
|
}
|
||||||
JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter), committer, mailAddress, message)
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user