mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 08:25:44 +01:00
improve bzr repository view
This commit is contained in:
@@ -38,11 +38,15 @@ package sonia.scm.web;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import sonia.scm.io.RegexResourceProcessor;
|
||||
import sonia.scm.io.ResourceProcessor;
|
||||
import sonia.scm.repository.BzrConfig;
|
||||
import sonia.scm.repository.BzrRepositoryHandler;
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.RepositoryManager;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.web.cgi.AbstractCGIServlet;
|
||||
import sonia.scm.web.cgi.EnvList;
|
||||
|
||||
@@ -50,12 +54,15 @@ import sonia.scm.web.cgi.EnvList;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -74,9 +81,22 @@ public class BzrCGIServlet extends AbstractCGIServlet
|
||||
/** Field description */
|
||||
public static final String ENV_REPOSITORY_PATH = "SCM_REPOSITORY_PATH";
|
||||
|
||||
/** Field description */
|
||||
public static final String MIMETYPE_HTML = "text/html";
|
||||
|
||||
/** Field description */
|
||||
public static final String RESOURCE_BZRINDEX = "/sonia/scm/bzr.index.html";
|
||||
|
||||
/** Field description */
|
||||
public static final String SMART_SUFFIX = ".bzr/smart";
|
||||
|
||||
/** Field description */
|
||||
private static final long serialVersionUID = 7674689744455227632L;
|
||||
|
||||
/** Field description */
|
||||
private static final Pattern REGEX_REPOSITORYNAME =
|
||||
Pattern.compile("/bzr/([^/]+)/?.*");
|
||||
|
||||
/** Field description */
|
||||
public static final Pattern PATTERN_REPOSITORYNAME =
|
||||
Pattern.compile("/[^/]+/([^/]+)(?:/.*)?");
|
||||
@@ -161,6 +181,32 @@ public class BzrCGIServlet extends AbstractCGIServlet
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param req
|
||||
* @param resp
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ServletException
|
||||
*/
|
||||
@Override
|
||||
protected void service(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
String uri = req.getRequestURI();
|
||||
|
||||
if (!uri.endsWith(SMART_SUFFIX))
|
||||
{
|
||||
printBazaarInformation(req, resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
super.service(req, resp);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -199,6 +245,54 @@ public class BzrCGIServlet extends AbstractCGIServlet
|
||||
return command;
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private void printBazaarInformation(HttpServletRequest request,
|
||||
HttpServletResponse response)
|
||||
throws IOException
|
||||
{
|
||||
String uri = HttpUtil.getStrippedURI(request);
|
||||
Matcher m = REGEX_REPOSITORYNAME.matcher(uri);
|
||||
String name = "unknown";
|
||||
|
||||
if (m.matches())
|
||||
{
|
||||
name = m.group(1);
|
||||
}
|
||||
|
||||
response.setContentType(MIMETYPE_HTML);
|
||||
|
||||
ResourceProcessor resourceProzessor = new RegexResourceProcessor();
|
||||
|
||||
resourceProzessor.addVariable("name", name);
|
||||
|
||||
InputStream input = null;
|
||||
OutputStream output = null;
|
||||
|
||||
try
|
||||
{
|
||||
input = BzrCGIServlet.class.getResourceAsStream(RESOURCE_BZRINDEX);
|
||||
output = response.getOutputStream();
|
||||
resourceProzessor.process(input, output);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(input);
|
||||
IOUtil.close(output);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
<!--
|
||||
|
||||
Copyright (c) 2010, Sebastian Sdorra
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
3. Neither the name of SCM-Manager; nor the names of its
|
||||
contributors may be used to endorse or promote products derived from this
|
||||
software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
http://bitbucket.org/sdorra/scm-manager
|
||||
|
||||
|
||||
-->
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>SCM :: Manager - Bazaar Repository - ${name}</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
background-color: #ffffff;
|
||||
margin: 10px;
|
||||
color: #202020;
|
||||
font-family: Verdana,Helvetica,Arial,sans-serif;
|
||||
font-size: 75%;
|
||||
}
|
||||
h1, h2, h3, h4, h5 {
|
||||
font-family: Arial, "Arial CE", "Lucida Grande CE", lucida, "Helvetica CE", sans-serif;
|
||||
font-weight: bold;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
color: #D20005;
|
||||
}
|
||||
h1 {
|
||||
font-size: 18px;
|
||||
border-bottom: 1px solid #AFAFAF;
|
||||
}
|
||||
h2 {
|
||||
font-size: 14px;
|
||||
border-bottom: 1px solid #AFAFAF;
|
||||
}
|
||||
a:link, a:visited {
|
||||
color: #045491;
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
}
|
||||
a:link:hover, a:visited:hover {
|
||||
color: #045491;
|
||||
font-weight: bold;
|
||||
text-decoration: underline;
|
||||
}
|
||||
table {
|
||||
border: 0 none;
|
||||
border-collapse: collapse;
|
||||
font-size: 100%;
|
||||
margin: 20px 0;
|
||||
padding: 20px;
|
||||
width: 100%;
|
||||
}
|
||||
td, th {
|
||||
padding: 3px;
|
||||
vertical-align: top;
|
||||
border: 1px solid #CCCCCC;
|
||||
text-align: left;
|
||||
}
|
||||
.small {
|
||||
width: 20%;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>SCM :: Manager - Bazaar Repository - ${name}</h1>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<h2>Bazaar Informations</h2>
|
||||
<ul>
|
||||
<li><a href="http://bazaar.canonical.com/" target="_blank">Bazaar Homepage</a></li>
|
||||
<li><a href="http://doc.bazaar.canonical.com/" target="_blank">Bazaar Documentation</a></li>
|
||||
</ul>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -43,6 +43,7 @@ import org.eclipse.jgit.http.server.resolver.RepositoryResolver;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
||||
import sonia.scm.repository.GitRepositoryHandler;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -106,7 +107,7 @@ public class ScmGitServlet extends GitServlet
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
String uri = getRelativePath(request);
|
||||
String uri = HttpUtil.getStrippedURI(request);
|
||||
|
||||
if (uri.matches(REGEX_GITHTTPBACKEND))
|
||||
{
|
||||
@@ -133,7 +134,7 @@ public class ScmGitServlet extends GitServlet
|
||||
HttpServletResponse response)
|
||||
throws ServletException, IOException
|
||||
{
|
||||
String uri = getRelativePath(request);
|
||||
String uri = HttpUtil.getStrippedURI(request);
|
||||
Matcher m = REGEX_REPOSITORYNAME.matcher(uri);
|
||||
String name = null;
|
||||
Repository repository = null;
|
||||
@@ -168,21 +169,6 @@ public class ScmGitServlet extends GitServlet
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getRelativePath(HttpServletRequest request)
|
||||
{
|
||||
return request.getRequestURI().substring(request.getContextPath().length());
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -35,6 +35,7 @@ package sonia.scm.util;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
@@ -71,4 +72,33 @@ public class HttpUtil
|
||||
response.setHeader(HEADER_CONNECTION, HEADERVALUE_CONNECTION_CLOSE);
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getStrippedURI(HttpServletRequest request)
|
||||
{
|
||||
return getStrippedURI(request, request.getRequestURI());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param uri
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getStrippedURI(HttpServletRequest request, String uri)
|
||||
{
|
||||
return request.getRequestURI().substring(request.getContextPath().length());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user