Creating repositories dynamically.

This commit is contained in:
Winston Li
2014-11-05 18:18:43 +00:00
parent d9a164d673
commit 0a793dccc8
9 changed files with 235 additions and 203 deletions
@@ -7,6 +7,7 @@ import org.eclipse.jetty.util.log.Log;
import uk.ac.ic.wlgitbridge.application.jetty.NullLogger;
import uk.ac.ic.wlgitbridge.git.WLGitServlet;
import uk.ac.ic.wlgitbridge.git.exception.InvalidRootDirectoryPathException;
import uk.ac.ic.wlgitbridge.writelatex.api.DummySnapshotDBAPI;
import javax.servlet.ServletException;
import java.net.BindException;
@@ -64,7 +65,7 @@ public class WLGitBridgeServer {
servletContextHandler.setContextPath("/");
servletContextHandler.addServlet(
new ServletHolder(
new WLGitServlet(servletContextHandler, rootGitDirectoryPath)),
new WLGitServlet(servletContextHandler, new DummySnapshotDBAPI(), rootGitDirectoryPath)),
"/*"
);
jettyServer.setHandler(servletContextHandler);
@@ -1,11 +1,16 @@
package uk.ac.ic.wlgitbridge.bridge;
import org.eclipse.jgit.api.AddCommand;
import org.eclipse.jgit.api.CommitCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.errors.RepositoryNotFoundException;
import org.eclipse.jgit.lib.Repository;
import uk.ac.ic.wlgitbridge.writelatex.Snapshot;
import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotDBAPI;
import java.io.File;
import java.io.IOException;
import java.util.List;
/**
@@ -38,9 +43,13 @@ public class WLBridgedProject {
}
private void buildRepositoryFromScratch(Repository repository) throws RepositoryNotFoundException {
System.out.println("Need to build repo: " + repository.getDirectory().getAbsolutePath());
if (!snapshotDBAPI.repositoryExists(repository)) {
throw new RepositoryNotFoundException(repository.getDirectory());
if (!snapshotDBAPI.repositoryExists(name)) {
throw new RepositoryNotFoundException(name);
}
try {
repository.create();
} catch (IOException e) {
e.printStackTrace();
}
updateRepositoryFromSnapshots(repository);
}
@@ -7,6 +7,8 @@ import uk.ac.ic.wlgitbridge.git.handler.WLReceivePackFactory;
import uk.ac.ic.wlgitbridge.git.handler.WLRepositoryResolver;
import uk.ac.ic.wlgitbridge.git.handler.WLUploadPackFactory;
import uk.ac.ic.wlgitbridge.writelatex.SnapshotRepositoryBuilder;
import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotAPI;
import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotDBAPI;
import javax.servlet.ServletException;
@@ -15,9 +17,9 @@ import javax.servlet.ServletException;
*/
public class WLGitServlet extends GitServlet {
public WLGitServlet(ServletContextHandler servletContextHandler, String rootGitDirectoryPath) throws ServletException, InvalidRootDirectoryPathException {
setRepositoryResolver(new WLRepositoryResolver(rootGitDirectoryPath, new SnapshotRepositoryBuilder()));
setReceivePackFactory(new WLReceivePackFactory());
public WLGitServlet(ServletContextHandler servletContextHandler, SnapshotDBAPI snapshotDBAPI, String rootGitDirectoryPath) throws ServletException, InvalidRootDirectoryPathException {
setRepositoryResolver(new WLRepositoryResolver(rootGitDirectoryPath, new SnapshotRepositoryBuilder(snapshotDBAPI)));
setReceivePackFactory(new WLReceivePackFactory(snapshotDBAPI));
setUploadPackFactory(new WLUploadPackFactory());
init(new WLGitServletConfig(servletContextHandler));
}
@@ -6,6 +6,8 @@ import org.eclipse.jgit.transport.resolver.ReceivePackFactory;
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
import uk.ac.ic.wlgitbridge.git.handler.hook.CheckNonFastForwardHook;
import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotAPI;
import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotDBAPI;
import javax.servlet.http.HttpServletRequest;
@@ -15,6 +17,10 @@ import javax.servlet.http.HttpServletRequest;
/* */
public class WLReceivePackFactory implements ReceivePackFactory<HttpServletRequest> {
public WLReceivePackFactory(SnapshotDBAPI snapshotDBAPI) {
}
@Override
public ReceivePack create(HttpServletRequest httpServletRequest, Repository repository) throws ServiceNotEnabledException, ServiceNotAuthorizedException {
ReceivePack receivePack = new ReceivePack(repository);
@@ -18,8 +18,8 @@ public class SnapshotRepositoryBuilder implements RepositorySource {
private final SnapshotDBAPI snapshotDBAPI;
public SnapshotRepositoryBuilder() {
snapshotDBAPI = new DummySnapshotDBAPI();
public SnapshotRepositoryBuilder(SnapshotDBAPI snapshotDBAPI) {
this.snapshotDBAPI = snapshotDBAPI;
}
@Override
@@ -12,8 +12,8 @@ import java.util.List;
public class DummySnapshotDBAPI implements SnapshotDBAPI {
@Override
public boolean repositoryExists(Repository repository) {
return false;
public boolean repositoryExists(String name) {
return true;
}
@Override
@@ -10,7 +10,7 @@ import java.util.List;
*/
public interface SnapshotDBAPI {
public boolean repositoryExists(Repository repository);
public boolean repositoryExists(String name);
public List<Snapshot> getSnapshotsToAddToRepository(Repository repository);
}