mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-08 22:45:51 +01:00
Merge branch 'master' into new-plugin-system
Conflicts: src/main/scala/servlet/AutoUpdateListener.scala
This commit is contained in:
@@ -62,6 +62,8 @@ object MyBuild extends Build {
|
|||||||
"org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container;provided",
|
"org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container;provided",
|
||||||
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts Artifact("javax.servlet", "jar", "jar"),
|
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts Artifact("javax.servlet", "jar", "jar"),
|
||||||
"junit" % "junit" % "4.11" % "test",
|
"junit" % "junit" % "4.11" % "test",
|
||||||
|
"com.mchange" % "c3p0" % "0.9.5",
|
||||||
|
"com.typesafe" % "config" % "1.2.1",
|
||||||
"com.typesafe.play" %% "twirl-compiler" % "1.0.2"
|
"com.typesafe.play" %% "twirl-compiler" % "1.0.2"
|
||||||
),
|
),
|
||||||
EclipseKeys.withSource := true,
|
EclipseKeys.withSource := true,
|
||||||
|
|||||||
6
src/main/resources/database.conf
Normal file
6
src/main/resources/database.conf
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
db {
|
||||||
|
driver = "org.h2.Driver"
|
||||||
|
url = "jdbc:h2:${DatabaseHome};MVCC=true"
|
||||||
|
user = "sa"
|
||||||
|
password = "sa"
|
||||||
|
}
|
||||||
@@ -3,16 +3,15 @@ package servlet
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
import java.sql.{DriverManager, Connection}
|
import java.sql.{DriverManager, Connection}
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import javax.servlet.{ServletContext, ServletContextListener, ServletContextEvent}
|
import javax.servlet.{ServletContextListener, ServletContextEvent}
|
||||||
import org.apache.commons.io.IOUtils
|
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import util.Directory._
|
import util.Directory._
|
||||||
import util.ControlUtil._
|
import util.ControlUtil._
|
||||||
import util.JDBCUtil._
|
import util.JDBCUtil._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import util.Directory
|
|
||||||
import util.{Version, Versions}
|
import util.{Version, Versions}
|
||||||
import plugin._
|
import plugin._
|
||||||
|
import util.{DatabaseConfig, Directory}
|
||||||
|
|
||||||
object AutoUpdate {
|
object AutoUpdate {
|
||||||
|
|
||||||
@@ -169,7 +168,6 @@ class AutoUpdateListener extends ServletContextListener {
|
|||||||
import AutoUpdate._
|
import AutoUpdate._
|
||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(classOf[AutoUpdateListener])
|
private val logger = LoggerFactory.getLogger(classOf[AutoUpdateListener])
|
||||||
// private val scheduler = StdSchedulerFactory.getDefaultScheduler
|
|
||||||
|
|
||||||
override def contextInitialized(event: ServletContextEvent): Unit = {
|
override def contextInitialized(event: ServletContextEvent): Unit = {
|
||||||
val dataDir = event.getServletContext.getInitParameter("gitbucket.home")
|
val dataDir = event.getServletContext.getInitParameter("gitbucket.home")
|
||||||
@@ -178,16 +176,14 @@ class AutoUpdateListener extends ServletContextListener {
|
|||||||
}
|
}
|
||||||
org.h2.Driver.load()
|
org.h2.Driver.load()
|
||||||
|
|
||||||
val context = event.getServletContext
|
defining(getConnection()){ conn =>
|
||||||
context.setInitParameter("db.url", s"jdbc:h2:${DatabaseHome};MVCC=true")
|
|
||||||
|
|
||||||
defining(getConnection(event.getServletContext)){ conn =>
|
|
||||||
// Migration
|
// Migration
|
||||||
logger.debug("Start schema update")
|
logger.debug("Start schema update")
|
||||||
Versions.update(conn, headVersion, getCurrentVersion(), versions, Thread.currentThread.getContextClassLoader){ conn =>
|
Versions.update(conn, headVersion, getCurrentVersion(), versions, Thread.currentThread.getContextClassLoader){ conn =>
|
||||||
FileUtils.writeStringToFile(versionFile, headVersion.versionString, "UTF-8")
|
FileUtils.writeStringToFile(versionFile, headVersion.versionString, "UTF-8")
|
||||||
}
|
}
|
||||||
// Load plugins
|
// Load plugins
|
||||||
|
logger.debug("Initialize plugins")
|
||||||
PluginRegistry.initialize(conn)
|
PluginRegistry.initialize(conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,16 +194,10 @@ class AutoUpdateListener extends ServletContextListener {
|
|||||||
PluginRegistry.shutdown()
|
PluginRegistry.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
private def getConnection(servletContext: ServletContext): Connection =
|
private def getConnection(): Connection =
|
||||||
DriverManager.getConnection(
|
DriverManager.getConnection(
|
||||||
servletContext.getInitParameter("db.url"),
|
DatabaseConfig.url,
|
||||||
servletContext.getInitParameter("db.user"),
|
DatabaseConfig.user,
|
||||||
servletContext.getInitParameter("db.password"))
|
DatabaseConfig.password)
|
||||||
|
|
||||||
private def getDatabase(servletContext: ServletContext): scala.slick.jdbc.JdbcBackend.Database =
|
|
||||||
slick.jdbc.JdbcBackend.Database.forURL(
|
|
||||||
servletContext.getInitParameter("db.url"),
|
|
||||||
servletContext.getInitParameter("db.user"),
|
|
||||||
servletContext.getInitParameter("db.password"))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package servlet
|
package servlet
|
||||||
|
|
||||||
import javax.servlet._
|
import javax.servlet._
|
||||||
import org.slf4j.LoggerFactory
|
|
||||||
import javax.servlet.http.HttpServletRequest
|
import javax.servlet.http.HttpServletRequest
|
||||||
import util.Keys
|
import com.mchange.v2.c3p0.ComboPooledDataSource
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import slick.jdbc.JdbcBackend.{Database => SlickDatabase, Session}
|
||||||
|
import util.{DatabaseConfig, Keys}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controls the transaction with the open session in view pattern.
|
* Controls the transaction with the open session in view pattern.
|
||||||
@@ -21,7 +23,7 @@ class TransactionFilter extends Filter {
|
|||||||
// assets don't need transaction
|
// assets don't need transaction
|
||||||
chain.doFilter(req, res)
|
chain.doFilter(req, res)
|
||||||
} else {
|
} else {
|
||||||
Database(req.getServletContext) withTransaction { session =>
|
Database() withTransaction { session =>
|
||||||
logger.debug("begin transaction")
|
logger.debug("begin transaction")
|
||||||
req.setAttribute(Keys.Request.DBSession, session)
|
req.setAttribute(Keys.Request.DBSession, session)
|
||||||
chain.doFilter(req, res)
|
chain.doFilter(req, res)
|
||||||
@@ -34,12 +36,24 @@ class TransactionFilter extends Filter {
|
|||||||
|
|
||||||
object Database {
|
object Database {
|
||||||
|
|
||||||
def apply(context: ServletContext): slick.jdbc.JdbcBackend.Database =
|
private val logger = LoggerFactory.getLogger(Database.getClass)
|
||||||
slick.jdbc.JdbcBackend.Database.forURL(context.getInitParameter("db.url"),
|
|
||||||
context.getInitParameter("db.user"),
|
|
||||||
context.getInitParameter("db.password"))
|
|
||||||
|
|
||||||
def getSession(req: ServletRequest): slick.jdbc.JdbcBackend#Session =
|
private val db: SlickDatabase = {
|
||||||
req.getAttribute(Keys.Request.DBSession).asInstanceOf[slick.jdbc.JdbcBackend#Session]
|
val datasource = new ComboPooledDataSource
|
||||||
|
|
||||||
|
datasource.setDriverClass(DatabaseConfig.driver)
|
||||||
|
datasource.setJdbcUrl(DatabaseConfig.url)
|
||||||
|
datasource.setUser(DatabaseConfig.user)
|
||||||
|
datasource.setPassword(DatabaseConfig.password)
|
||||||
|
|
||||||
|
logger.debug("load database connection pool")
|
||||||
|
|
||||||
|
SlickDatabase.forDataSource(datasource)
|
||||||
|
}
|
||||||
|
|
||||||
|
def apply(): SlickDatabase = db
|
||||||
|
|
||||||
|
def getSession(req: ServletRequest): Session =
|
||||||
|
req.getAttribute(Keys.Request.DBSession).asInstanceOf[Session]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ abstract class GitCommand(val context: ServletContext, val owner: String, val re
|
|||||||
|
|
||||||
private def newTask(user: String): Runnable = new Runnable {
|
private def newTask(user: String): Runnable = new Runnable {
|
||||||
override def run(): Unit = {
|
override def run(): Unit = {
|
||||||
Database(context) withSession { implicit session =>
|
Database() withSession { implicit session =>
|
||||||
try {
|
try {
|
||||||
runTask(user)
|
runTask(user)
|
||||||
callback.onExit(0)
|
callback.onExit(0)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import javax.servlet.ServletContext
|
|||||||
class PublicKeyAuthenticator(context: ServletContext) extends PublickeyAuthenticator with SshKeyService {
|
class PublicKeyAuthenticator(context: ServletContext) extends PublickeyAuthenticator with SshKeyService {
|
||||||
|
|
||||||
override def authenticate(username: String, key: PublicKey, session: ServerSession): Boolean = {
|
override def authenticate(username: String, key: PublicKey, session: ServerSession): Boolean = {
|
||||||
Database(context) withSession { implicit session =>
|
Database() withSession { implicit session =>
|
||||||
getPublicKeys(username).exists { sshKey =>
|
getPublicKeys(username).exists { sshKey =>
|
||||||
SshUtil.str2PublicKey(sshKey.publicKey) match {
|
SshUtil.str2PublicKey(sshKey.publicKey) match {
|
||||||
case Some(publicKey) => key.equals(publicKey)
|
case Some(publicKey) => key.equals(publicKey)
|
||||||
|
|||||||
19
src/main/scala/util/DatabaseConfig.scala
Normal file
19
src/main/scala/util/DatabaseConfig.scala
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import com.typesafe.config.ConfigFactory
|
||||||
|
import util.Directory.DatabaseHome
|
||||||
|
|
||||||
|
object DatabaseConfig {
|
||||||
|
|
||||||
|
private val config = ConfigFactory.load("database")
|
||||||
|
private val dbUrl = config.getString("db.url")
|
||||||
|
|
||||||
|
def url(directory: Option[String]): String =
|
||||||
|
dbUrl.replace("${DatabaseHome}", directory.getOrElse(DatabaseHome))
|
||||||
|
|
||||||
|
val url: String = url(None)
|
||||||
|
val user: String = config.getString("db.user")
|
||||||
|
val password: String = config.getString("db.password")
|
||||||
|
val driver: String = config.getString("db.driver")
|
||||||
|
|
||||||
|
}
|
||||||
@@ -67,7 +67,7 @@ class Mailer(private val smtp: Smtp) extends Notifier {
|
|||||||
|
|
||||||
def toNotify(r: RepositoryService.RepositoryInfo, issueId: Int, content: String)
|
def toNotify(r: RepositoryService.RepositoryInfo, issueId: Int, content: String)
|
||||||
(msg: String => String)(implicit context: Context) = {
|
(msg: String => String)(implicit context: Context) = {
|
||||||
val database = Database(context.request.getServletContext)
|
val database = Database()
|
||||||
|
|
||||||
val f = Future {
|
val f = Future {
|
||||||
database withSession { implicit session =>
|
database withSession { implicit session =>
|
||||||
|
|||||||
@@ -9,9 +9,9 @@
|
|||||||
@import view.helpers._
|
@import view.helpers._
|
||||||
|
|
||||||
@sidemenu(path: String, name: String, label: String, count: Int = 0) = {
|
@sidemenu(path: String, name: String, label: String, count: Int = 0) = {
|
||||||
<li @if(active == name){class="active"}>
|
<li @if(active == name){class="active"} @if(!expand){data-toggle="tooltip" data-placement="left" data-original-title="@label"}>
|
||||||
<div class="@if(active == name){margin} else {gradient} pull-left"></div>
|
<div class="@if(active == name){margin} else {gradient} pull-left"></div>
|
||||||
<a href="@url(repository)@path"@* @if(!expand){data-toggle="tooltip" data-placement="left" data-original-title="Code"}*@>
|
<a href="@url(repository)@path">
|
||||||
@if(active == name){
|
@if(active == name){
|
||||||
<img src="@assets/common/images/menu-@{name}-active.png">
|
<img src="@assets/common/images/menu-@{name}-active.png">
|
||||||
} else {
|
} else {
|
||||||
@@ -179,7 +179,10 @@ $(function(){
|
|||||||
$(target).children('img.menu-icon' ).css('display', 'inline');
|
$(target).children('img.menu-icon' ).css('display', 'inline');
|
||||||
});
|
});
|
||||||
|
|
||||||
$('a[rel*=facebox]').facebox();
|
$('a[rel*=facebox]').facebox({
|
||||||
|
'loadingImage': '@assets/vendors/facebox/loading.gif',
|
||||||
|
'closeImage': '@assets/vendors/facebox/closelabel.png',
|
||||||
|
});
|
||||||
|
|
||||||
$(document).on("click", ".js-fork-owner-select-target", function() {
|
$(document).on("click", ".js-fork-owner-select-target", function() {
|
||||||
if (!$(this).hasClass("disabled")) {
|
if (!$(this).hasClass("disabled")) {
|
||||||
|
|||||||
@@ -46,24 +46,6 @@
|
|||||||
<url-pattern>/git/*</url-pattern>
|
<url-pattern>/git/*</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<!-- ===================================================================== -->
|
|
||||||
<!-- H2 database configuration -->
|
|
||||||
<!-- ===================================================================== -->
|
|
||||||
<context-param>
|
|
||||||
<param-name>db.user</param-name>
|
|
||||||
<param-value>sa</param-value>
|
|
||||||
</context-param>
|
|
||||||
|
|
||||||
<context-param>
|
|
||||||
<param-name>db.password</param-name>
|
|
||||||
<param-value>sa</param-value>
|
|
||||||
</context-param>
|
|
||||||
|
|
||||||
<context-param>
|
|
||||||
<param-name>db.tcpServer</param-name>
|
|
||||||
<param-value>-tcpAllowOthers</param-value>
|
|
||||||
</context-param>
|
|
||||||
|
|
||||||
<!-- ===================================================================== -->
|
<!-- ===================================================================== -->
|
||||||
<!-- H2 console configuration -->
|
<!-- H2 console configuration -->
|
||||||
<!-- ===================================================================== -->
|
<!-- ===================================================================== -->
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ $(function(){
|
|||||||
// activate tooltip
|
// activate tooltip
|
||||||
$('img[data-toggle=tooltip]').tooltip();
|
$('img[data-toggle=tooltip]').tooltip();
|
||||||
$('a[data-toggle=tooltip]').tooltip();
|
$('a[data-toggle=tooltip]').tooltip();
|
||||||
|
$('li[data-toggle=tooltip]').tooltip();
|
||||||
|
|
||||||
// anchor icon for markdown
|
// anchor icon for markdown
|
||||||
$('.markdown-head').mouseenter(function(e){
|
$('.markdown-head').mouseenter(function(e){
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package service
|
|||||||
import model.Profile._
|
import model.Profile._
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
import util.ControlUtil._
|
import util.ControlUtil._
|
||||||
|
import util.DatabaseConfig
|
||||||
import java.sql.DriverManager
|
import java.sql.DriverManager
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import scala.util.Random
|
import scala.util.Random
|
||||||
@@ -12,7 +13,7 @@ trait ServiceSpecBase {
|
|||||||
|
|
||||||
def withTestDB[A](action: (Session) => A): A = {
|
def withTestDB[A](action: (Session) => A): A = {
|
||||||
util.FileUtil.withTmpDir(new File(FileUtils.getTempDirectory(), Random.alphanumeric.take(10).mkString)){ dir =>
|
util.FileUtil.withTmpDir(new File(FileUtils.getTempDirectory(), Random.alphanumeric.take(10).mkString)){ dir =>
|
||||||
val (url, user, pass) = (s"jdbc:h2:${dir}", "sa", "sa")
|
val (url, user, pass) = (DatabaseConfig.url(Some(dir.toString)), DatabaseConfig.user, DatabaseConfig.password)
|
||||||
org.h2.Driver.load()
|
org.h2.Driver.load()
|
||||||
using(DriverManager.getConnection(url, user, pass)){ conn =>
|
using(DriverManager.getConnection(url, user, pass)){ conn =>
|
||||||
servlet.AutoUpdate.versions.reverse.foreach(_.update(conn))
|
servlet.AutoUpdate.versions.reverse.foreach(_.update(conn))
|
||||||
|
|||||||
Reference in New Issue
Block a user