diff --git a/help.txt b/help.txt
new file mode 100644
index 0000000..b29f0c9
--- /dev/null
+++ b/help.txt
@@ -0,0 +1,74 @@
+
+gitbucket-src
+ directory is the source cloned from github
+
+Jetty help:
+ https://www.jrebel.com/blog/jetty-server
+
+Downloaded the latest gitbucket.war from my server to get a basic gitbucket started using Jetty.
+
+Unpacking the war file in the gitbucket-from-src directory was picked up by jetty immediately.
+ jar -xf gitbucket.war
+ available at:
+ http://localhost:8080/gitbucket-from-src/
+
+Hacking the source
+------------------
+ The following shows files in the main gitbucket jar:
+ unzip -l WEB-INF/lib/gitbucket_2.13-4.41.0.jar | grep view
+
+ which were also located at:
+ /opt/gitbucket-from-src/gitbucket-src/src/main/scala/gitbucket/core/view/
+
+ So I installed scala
+ apt-get install scala
+
+ and create a classes directory to try and compile into:
+ /opt/gitbucket-from-src/gitbucket-src/classes
+ but it was not clear how to include javax dependencies amoung other things.
+ So I decided instead to use the build.sbt file.
+
+ Installed sbt (https://www.scala-sbt.org/download)
+ Ran sbt in the directory and it immediately did some shit. No idea what.
+ To compile, type compile
+ compiled into gitbucket-src/target/scala-2.13
+
+ Some help:
+ https://www.scala-sbt.org/1.x/docs/sbt-by-example.html
+
+
+Build WAR
+---------
+
+ https://github.com/gitbucket/gitbucket/blob/master/doc/build.md
+ Since I've been forced to install all of their dev crap.
+ sbt doesn't work properly, might be a class file version issue but both war files build ok
+
+ Found out eventually that the following item should be added to web.xml for the home directory to be picked up
+ since we cannot set app specific items any other way. This is because jetty is started as a server to support
+ multiple apps.
+
+
+
+ gitbucket.home
+ /opt/gitbucket-from-src
+
+
+
+27-08-24___________
+
+
+ After downloading the source, build with:
+ sbt executable
+
+ find the war file in target/executable
+
+ (If running in a multi-webapp environment, makes sure to be running with my changes as noted above.)
+
+ Other than that, the latest git-pull is actually runctioning correctly using the gitbucket-home parameter:
+
+ /usr/bin/java -jar /opt/gitbucket/gitbucket.war --host=0.0.0.0 --port=8080 --gitbucket.home=/opt/gitbucket
+
+ They must have fixed it since verion 4.41.0 which was built May 24.
+
+ Checked into my repository at http://pearcey.net:8080/johnpearcey/gitbucket_jkp
diff --git a/src/main/scala/gitbucket/core/servlet/GitAuthenticationFilter.scala b/src/main/scala/gitbucket/core/servlet/GitAuthenticationFilter.scala
index 4f6574d..dc2f4d2 100644
--- a/src/main/scala/gitbucket/core/servlet/GitAuthenticationFilter.scala
+++ b/src/main/scala/gitbucket/core/servlet/GitAuthenticationFilter.scala
@@ -28,6 +28,16 @@
override def destroy(): Unit = {}
def doFilter(req: ServletRequest, res: ServletResponse, chain: FilterChain): Unit = {
+
+ //println("GitAuthenticationFilter.doFilter" );
+ /*try {
+ throw new Exception("doFilter");
+ } catch {
+ case ex: Exception => {
+ ex.printStackTrace();
+ }
+ }*/
+
val request = req.asInstanceOf[HttpServletRequest]
val response = res.asInstanceOf[HttpServletResponse]
@@ -68,6 +78,9 @@
isUpdating: Boolean,
filter: GitRepositoryFilter
): Unit = {
+
+ //println("GitAuthenticationFilter.pluginRepository" );
+
Database() withSession { implicit session =>
val account = for {
authorizationHeader <- Option(request.getHeader("Authorization"))
@@ -92,11 +105,25 @@
settings: SystemSettings,
isUpdating: Boolean
): Unit = {
- val action = request.paths match {
+
+ logger.info("GitAuthenticationFilter.defaultRepository: request.paths = " + request.paths.mkString(",") );
+
+ // JKP - fix for recognition of the context path in the request. This happens when gitbucket is set up as one of many servlets
+ val buf = request.paths.toBuffer
+ if( request.getContextPath().length()>=1 && request.getContextPath().substring(1).equals( buf(1) )){
+ buf.remove(1);
+ }
+ var arr = buf.toArray
+
+ val action = arr match {
case Array(_, repositoryOwner, repositoryName, _*) =>
Database() withSession { implicit session =>
getRepository(repositoryOwner, repositoryName.replaceFirst("(\\.wiki)?\\.git$", "")) match {
+
case Some(repository) => {
+
+ //logger.info( "repository: owner/name" + s"${repository.owner}/${repository.name}" )
+
val execute =
if (!isUpdating && !repository.repository.isPrivate && settings.basicBehavior.allowAnonymousAccess) {
// Authentication is not required
@@ -122,6 +149,8 @@
passed.getOrElse(false)
}
+ //if (execute) logger.info(s"GitAuthenticationFilter: doFilter " + chain )
+
if (execute) { () =>
chain.doFilter(request, response)
} else { () =>
@@ -130,14 +159,14 @@
}
case None =>
() => {
- logger.debug(s"Repository ${repositoryOwner}/${repositoryName} is not found.")
+ logger.info(s"GitAuthenticationFilter: Repository ${repositoryOwner}/${repositoryName} not found.")
response.sendError(HttpServletResponse.SC_NOT_FOUND)
}
}
}
case _ =>
() => {
- logger.debug(s"Not enough path arguments: ${request.paths.mkString(", ")}")
+ logger.info(s"Not enough path arguments: ${request.paths.mkString(", ")}")
response.sendError(HttpServletResponse.SC_NOT_FOUND)
}
}
diff --git a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala
index 386b78d..9ed80c2 100644
--- a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala
+++ b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala
@@ -40,40 +40,50 @@
import javax.servlet.ServletConfig
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.eclipse.jgit.diff.DiffEntry.ChangeType
-import org.eclipse.jgit.internal.storage.file.FileRepository
+import org.eclipse.jgit.internal.storage.file.FileRepository //https://download.eclipse.org/jgit/site/6.2.0.202206071550-r/apidocs/org/eclipse/jgit/internal/storage/file/FileRepository.html
import org.json4s.Formats
import org.json4s.convertToJsonInput
import org.json4s.jackson.Serialization._
/**
* Provides Git repository via HTTP.
- *
+ * https://archive.eclipse.org/jgit/site/5.1.1.201809181055-r/apidocs/org/eclipse/jgit/http/server/GitServlet.html
+ *
* This servlet provides only Git repository functionality.
* Authentication is provided by [[GitAuthenticationFilter]].
*/
class GitRepositoryServlet extends GitServlet with SystemSettingsService {
- private implicit val jsonFormats: Formats = gitbucket.core.api.JsonFormat.jsonFormats
+ private implicit val jsonFormats: Formats = gitbucket.core.api.JsonFormat.jsonFormats
+ private val logger = LoggerFactory.getLogger(classOf[GitRepositoryServlet])
- override def init(config: ServletConfig): Unit = {
+
+ override def init(config: ServletConfig): Unit = {
setReceivePackFactory(new GitBucketReceivePackFactory())
setRepositoryResolver(new GitBucketRepositoryResolver)
+ //https://javadoc.jetty.org/jetty-12/org/eclipse/jetty/ee10/servlet/ServletHolder.Config.html
super.init(config)
}
override def service(req: HttpServletRequest, res: HttpServletResponse): Unit = {
+
val agent = req.getHeader("USER-AGENT")
val index = req.getRequestURI.indexOf(".git")
+
if (index >= 0 && (agent == null || agent.toLowerCase.indexOf("git") < 0)) {
- // redirect for browsers
+ // redirect for browsers
val paths = req.getRequestURI.substring(0, index).split("/")
- res.sendRedirect(baseUrl(req) + "/" + paths.dropRight(1).last + "/" + paths.last)
-
+ val strRd = baseUrl(req) + "/" + paths.dropRight(1).last + "/" + paths.last
+ logger.debug("GitRepositoryServlet.redirect: " + strRd );
+ res.sendRedirect( strRd )
+
} else if (req.getMethod.toUpperCase == "POST" && req.getRequestURI.endsWith("/info/lfs/objects/batch")) {
+ logger.debug("GitRepositoryServlet.lfs support: " +req.getRequestURI );
withLockRepository(req) {
serviceGitLfsBatchAPI(req, res)
}
} else {
+ logger.debug("GitRepositoryServlet.client" );
// response for git client
withLockRepository(req) {
super.service(req, res)
@@ -168,16 +178,45 @@
class GitBucketRepositoryResolver extends RepositoryResolver[HttpServletRequest] {
- override def open(req: HttpServletRequest, name: String): Repository = {
+ private val logger = LoggerFactory.getLogger(classOf[GitBucketRepositoryResolver])
+
+
+ override def open(req: HttpServletRequest, pathname: String): Repository = {
+
+ // JKP - fix for recognition of the context path in the request. This happens when gitbucket is set up as one of many servlets
+ // e.g. gitbucket-from-src/root/newrepo should be root/newrepo
+ var name = pathname;
+ if( req.getContextPath().length()>=1 ){
+ val appName = req.getContextPath().substring(1) + '/';
+ if( pathname.startsWith( appName ) ){
+ name = pathname.substring( appName.length() );
+ }
+ }
+
+ logger.debug("GitRepositoryServlet: Directory.RepositoryHome => " + Directory.RepositoryHome );
+ logger.debug("GitRepositoryServlet: using PluginRegistry => " + PluginRegistry().getRepositoryRouting("/" + name) );
+
// Rewrite repository path if routing is marched
- PluginRegistry()
- .getRepositoryRouting("/" + name)
- .map { case GitRepositoryRouting(urlPattern, localPath, _) =>
- val path = urlPattern.r.replaceFirstIn(name, localPath)
- new FileRepository(new File(Directory.GitBucketHome, path))
- }
- .getOrElse {
- new FileRepository(new File(Directory.RepositoryHome, name))
+ PluginRegistry().getRepositoryRouting("/" + name).map {
+
+ case GitRepositoryRouting(urlPattern, localPath, _) =>
+ val path = urlPattern.r.replaceFirstIn(name, localPath)
+ new FileRepository(new File(Directory.GitBucketHome, path))
+
+ }.getOrElse {
+
+ var fRepo = new File(Directory.RepositoryHome, name);
+ if(!fRepo.exists() ){
+ name += ".git";
+ }
+ fRepo = new File(Directory.RepositoryHome, name);
+ if(!fRepo.exists() ){
+ logger.warn("Repository at " + fRepo + " does not exist: " );
+ }
+
+ val fr = new FileRepository( fRepo )
+ //logger.info("FileRepository: " + fr.getConfig() );
+ fr
}
}
diff --git a/src/main/scala/gitbucket/core/servlet/InitializeListener.scala b/src/main/scala/gitbucket/core/servlet/InitializeListener.scala
index 863be82..79e0738 100644
--- a/src/main/scala/gitbucket/core/servlet/InitializeListener.scala
+++ b/src/main/scala/gitbucket/core/servlet/InitializeListener.scala
@@ -50,10 +50,18 @@
// )
override def contextInitialized(event: ServletContextEvent): Unit = {
+
+ logger.info("\"gitbucket.home\" => " + System.getProperty("gitbucket.home") );
+
val dataDir = event.getServletContext.getInitParameter("gitbucket.home")
- if (dataDir != null) {
+ if (dataDir != null) {
+ logger.info("\"gitbucket.home\" overridden (by web.xml) to => " + dataDir );
System.setProperty("gitbucket.home", dataDir)
- }
+ }
+
+ //check the Directory object
+ logger.info("Check: Directory.GitBucketHome => " + GitBucketHome );
+
org.h2.Driver.load()
Database() withTransaction { session =>
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index 7d5656d..3fe4984 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -4,6 +4,13 @@
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
+
+
+ gitbucket.home
+ /opt/gitbucket
+
+
+
@@ -14,9 +21,9 @@
-
- gitbucket.core.servlet.InitializeListener
-
+
+ gitbucket.core.servlet.InitializeListener
+
@@ -85,4 +92,13 @@
image/svg+xml
+
+
+