mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-02-06 22:59:12 +01:00
Remove old type dependant repo uri functions
This commit is contained in:
@@ -38,7 +38,6 @@ package sonia.scm.repository;
|
||||
import sonia.scm.AlreadyExistsException;
|
||||
import sonia.scm.TypeManager;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -99,29 +98,6 @@ public interface RepositoryManager
|
||||
*/
|
||||
public Collection<RepositoryType> getConfiguredTypes();
|
||||
|
||||
/**
|
||||
* Returns the {@link Repository} associated to the request uri.
|
||||
*
|
||||
*
|
||||
* @param request the current http request
|
||||
*
|
||||
* @return associated to the request uri
|
||||
* @since 1.9
|
||||
*/
|
||||
public Repository getFromRequest(HttpServletRequest request);
|
||||
|
||||
/**
|
||||
* Returns the {@link Repository} associated to the request uri.
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param uri request uri without context path
|
||||
*
|
||||
* @return associated to the request uri
|
||||
* @since 1.9
|
||||
*/
|
||||
public Repository getFromUri(String uri);
|
||||
|
||||
/**
|
||||
* Returns a {@link RepositoryHandler} by the given type (hg, git, svn ...).
|
||||
*
|
||||
|
||||
@@ -39,7 +39,6 @@ import sonia.scm.AlreadyExistsException;
|
||||
import sonia.scm.ManagerDecorator;
|
||||
import sonia.scm.Type;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -120,34 +119,6 @@ public class RepositoryManagerDecorator
|
||||
return decorated;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Repository getFromRequest(HttpServletRequest request)
|
||||
{
|
||||
return decorated.getFromRequest(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
*
|
||||
* @param uri
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Repository getFromUri(String uri)
|
||||
{
|
||||
return decorated.getFromUri(uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
|
||||
@@ -2,9 +2,6 @@ package sonia.scm.repository.spi;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
|
||||
public abstract class DefaultHttpScmProtocol implements HttpScmProtocol {
|
||||
|
||||
private final Repository repository;
|
||||
@@ -12,9 +9,4 @@ public abstract class DefaultHttpScmProtocol implements HttpScmProtocol {
|
||||
protected DefaultHttpScmProtocol(Repository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(Repository repository, UriInfo uriInfo) {
|
||||
return uriInfo.getBaseUri().resolve(URI.create("../../" + this.repository.getType() + "/" + this.repository.getNamespace() + "/" + this.repository.getName())).toASCIIString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
import sonia.scm.repository.api.ScmProtocol;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
public interface HttpScmProtocol extends ScmProtocol {
|
||||
@Override
|
||||
@@ -14,5 +17,10 @@ public interface HttpScmProtocol extends ScmProtocol {
|
||||
return "http";
|
||||
}
|
||||
|
||||
@Override
|
||||
default String getUrl(Repository repository, UriInfo uriInfo) {
|
||||
return uriInfo.getBaseUri().resolve(URI.create("../../repo/" + repository.getNamespace() + "/" + repository.getName())).toASCIIString();
|
||||
}
|
||||
|
||||
void serve(HttpServletRequest request, HttpServletResponse response, ServletConfig config) throws ServletException, IOException;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
package sonia.scm.repository.spi;
|
||||
|
||||
import sonia.scm.repository.Repository;
|
||||
|
||||
import javax.inject.Provider;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
public abstract class InitializingHttpScmProtocolWrapper implements HttpScmProtocol {
|
||||
|
||||
@@ -40,10 +36,4 @@ public abstract class InitializingHttpScmProtocolWrapper implements HttpScmProto
|
||||
protected void initializeServlet(ServletConfig config, HttpServlet httpServlet) throws ServletException {
|
||||
httpServlet.init(config);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getUrl(Repository repository, UriInfo uriInfo) {
|
||||
return uriInfo.getBaseUri().resolve(URI.create("../../repo/" + repository.getNamespace() + "/" + repository.getName())).toASCIIString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import sonia.scm.repository.spi.RepositoryServiceProvider;
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -33,16 +32,6 @@ public class RepositoryServiceTest {
|
||||
assertThat(sizeOf(supportedProtocols)).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindProtocolFromProvider() {
|
||||
when(provider.getSupportedProtocols()).thenReturn(Collections.singleton(new DummyHttpProtocol()));
|
||||
|
||||
RepositoryService repositoryService = new RepositoryService(null, provider, repository, null);
|
||||
HttpScmProtocol protocol = repositoryService.getProtocol(HttpScmProtocol.class);
|
||||
|
||||
assertThat(protocol.getUrl(repository, null)).isEqualTo("dummy");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailForUnknownProtocol() {
|
||||
when(provider.getSupportedProtocols()).thenReturn(Collections.emptySet());
|
||||
@@ -55,11 +44,6 @@ public class RepositoryServiceTest {
|
||||
}
|
||||
|
||||
private static class DummyHttpProtocol implements HttpScmProtocol {
|
||||
@Override
|
||||
public String getUrl(Repository repository, UriInfo uriInfo) {
|
||||
return "dummy";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serve(HttpServletRequest request, HttpServletResponse response, ServletConfig config) {
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ public class LfsServletFactoryTest {
|
||||
String repositoryName = "git-lfs-demo";
|
||||
|
||||
String result = LfsServletFactory.buildBaseUri(new Repository("", "GIT", repositoryNamespace, repositoryName), RequestWithUri(repositoryName, true));
|
||||
assertThat(result, is(equalTo("http://localhost:8081/scm/git/space/git-lfs-demo.git/info/lfs/objects/")));
|
||||
assertThat(result, is(equalTo("http://localhost:8081/scm/repo/space/git-lfs-demo.git/info/lfs/objects/")));
|
||||
|
||||
|
||||
//result will be with dot-git suffix, ide
|
||||
result = LfsServletFactory.buildBaseUri(new Repository("", "GIT", repositoryNamespace, repositoryName), RequestWithUri(repositoryName, false));
|
||||
assertThat(result, is(equalTo("http://localhost:8081/scm/git/space/git-lfs-demo.git/info/lfs/objects/")));
|
||||
assertThat(result, is(equalTo("http://localhost:8081/scm/repo/space/git-lfs-demo.git/info/lfs/objects/")));
|
||||
}
|
||||
|
||||
private HttpServletRequest RequestWithUri(String repositoryName, boolean withDotGitSuffix) {
|
||||
@@ -44,12 +44,10 @@ public class LfsServletFactoryTest {
|
||||
|
||||
//build from valid live request data
|
||||
when(mockedRequest.getRequestURL()).thenReturn(
|
||||
new StringBuffer(String.format("http://localhost:8081/scm/git/%s%s/info/lfs/objects/batch", repositoryName, suffix)));
|
||||
when(mockedRequest.getRequestURI()).thenReturn(String.format("/scm/git/%s%s/info/lfs/objects/batch", repositoryName, suffix));
|
||||
new StringBuffer(String.format("http://localhost:8081/scm/repo/%s%s/info/lfs/objects/batch", repositoryName, suffix)));
|
||||
when(mockedRequest.getRequestURI()).thenReturn(String.format("/scm/repo/%s%s/info/lfs/objects/batch", repositoryName, suffix));
|
||||
when(mockedRequest.getContextPath()).thenReturn("/scm");
|
||||
|
||||
return mockedRequest;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -65,10 +65,8 @@ import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Base64;
|
||||
import java.util.Enumeration;
|
||||
|
||||
@@ -354,11 +352,6 @@ public class HgCGIServlet extends HttpServlet implements HttpScmProtocol
|
||||
service(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(Repository repository, UriInfo uriInfo) {
|
||||
return uriInfo.getBaseUri().resolve(URI.create("../../hg/" + repository.getNamespace() + "/" + repository.getName())).toASCIIString();
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -54,9 +54,7 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletRequestWrapper;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
@@ -292,12 +290,6 @@ public class SvnDAVServlet extends DAVServlet implements HttpScmProtocol
|
||||
service(request, response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(Repository repository, UriInfo uriInfo) {
|
||||
return uriInfo.getBaseUri().resolve(URI.create("../../repo/" + repository.getNamespace() + "/" + repository.getName())).toASCIIString();
|
||||
}
|
||||
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
|
||||
@@ -4,6 +4,7 @@ import sonia.scm.repository.NamespaceAndName;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.net.URI;
|
||||
|
||||
class ResourceLinks {
|
||||
|
||||
|
||||
@@ -52,11 +52,9 @@ import sonia.scm.config.ScmConfiguration;
|
||||
import sonia.scm.security.KeyGenerator;
|
||||
import sonia.scm.util.AssertUtil;
|
||||
import sonia.scm.util.CollectionAppender;
|
||||
import sonia.scm.util.HttpUtil;
|
||||
import sonia.scm.util.IOUtil;
|
||||
import sonia.scm.util.Util;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -315,31 +313,6 @@ public class DefaultRepositoryManager extends AbstractRepositoryManager {
|
||||
return validTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository getFromRequest(HttpServletRequest request) {
|
||||
AssertUtil.assertIsNotNull(request);
|
||||
|
||||
return getFromUri(HttpUtil.getStrippedURI(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository getFromUri(String uri) {
|
||||
AssertUtil.assertIsNotEmpty(uri);
|
||||
|
||||
if (uri.startsWith(HttpUtil.SEPARATOR_PATH)) {
|
||||
uri = uri.substring(1);
|
||||
}
|
||||
|
||||
Repository repository = null;
|
||||
|
||||
String namespace = uri.substring(0, uri.indexOf(HttpUtil.SEPARATOR_PATH));
|
||||
String name = uri.substring(uri.indexOf(HttpUtil.SEPARATOR_PATH) + 1, uri.indexOf(HttpUtil.SEPARATOR_PATH, uri.indexOf(HttpUtil.SEPARATOR_PATH) + 1));
|
||||
|
||||
repository = get(new NamespaceAndName(namespace, name));
|
||||
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RepositoryHandler getHandler(String type) {
|
||||
return handlerMap.get(type);
|
||||
|
||||
@@ -383,69 +383,6 @@ public class DefaultRepositoryManagerTest extends ManagerTestBase<Repository> {
|
||||
assertEquals("default_namespace", repository.getNamespace());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRepositoryFromRequestUri_withoutLeadingSlash() throws AlreadyExistsException {
|
||||
RepositoryManager m = createManager();
|
||||
m.init(contextProvider);
|
||||
|
||||
createUriTestRepositories(m);
|
||||
|
||||
assertEquals("scm-test", m.getFromUri("hg/namespace/scm-test").getName());
|
||||
assertEquals("namespace", m.getFromUri("hg/namespace/scm-test").getNamespace());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRepositoryFromRequestUri_withLeadingSlash() throws AlreadyExistsException {
|
||||
RepositoryManager m = createManager();
|
||||
m.init(contextProvider);
|
||||
|
||||
createUriTestRepositories(m);
|
||||
|
||||
assertEquals("scm-test", m.getFromUri("/hg/namespace/scm-test").getName());
|
||||
assertEquals("namespace", m.getFromUri("/hg/namespace/scm-test").getNamespace());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRepositoryFromRequestUri_withPartialName() throws AlreadyExistsException {
|
||||
RepositoryManager m = createManager();
|
||||
m.init(contextProvider);
|
||||
|
||||
createUriTestRepositories(m);
|
||||
|
||||
assertEquals("scm", m.getFromUri("hg/namespace/scm").getName());
|
||||
assertEquals("namespace", m.getFromUri("hg/namespace/scm").getNamespace());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRepositoryFromRequestUri_withTrailingFilePath() throws AlreadyExistsException {
|
||||
RepositoryManager m = createManager();
|
||||
m.init(contextProvider);
|
||||
|
||||
createUriTestRepositories(m);
|
||||
|
||||
assertEquals("test-1", m.getFromUri("/git/namespace/test-1/ka/some/path").getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRepositoryFromRequestUri_forNotExistingRepositoryName() throws AlreadyExistsException {
|
||||
RepositoryManager m = createManager();
|
||||
m.init(contextProvider);
|
||||
|
||||
createUriTestRepositories(m);
|
||||
|
||||
assertNull(m.getFromUri("/git/namespace/test-3/ka/some/path"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRepositoryFromRequestUri_forWrongNamespace() throws AlreadyExistsException {
|
||||
RepositoryManager m = createManager();
|
||||
m.init(contextProvider);
|
||||
|
||||
createUriTestRepositories(m);
|
||||
|
||||
assertNull(m.getFromUri("/git/other/other/test-2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldSetNamespace() throws AlreadyExistsException {
|
||||
Repository repository = new Repository(null, "hg", null, "scm");
|
||||
|
||||
Reference in New Issue
Block a user