mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 14:13:43 +01:00
Renamed SnapshotRepositorySource to SnapshotRepositoryBuilder and created WLBridgedProject to replace the old SnapshotRepositoryBuilder.
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
package uk.ac.ic.wlgitbridge.bridge;
|
||||
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
|
||||
/**
|
||||
* Created by Winston on 05/11/14.
|
||||
*/
|
||||
public class BridgedProject {
|
||||
|
||||
private final Repository repository;
|
||||
|
||||
public BridgedProject(Repository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package uk.ac.ic.wlgitbridge.bridge;
|
||||
|
||||
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.SnapshotDBAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Winston on 05/11/14.
|
||||
*/
|
||||
public class WLBridgedProject {
|
||||
|
||||
private final Repository repository;
|
||||
private final String name;
|
||||
private final File repositoryDirectory;
|
||||
private final SnapshotDBAPI snapshotDBAPI;
|
||||
|
||||
public WLBridgedProject(Repository repository, String name, File repositoryDirectory, SnapshotDBAPI snapshotDBAPI) {
|
||||
this.repository = repository;
|
||||
this.name = name;
|
||||
this.repositoryDirectory = repositoryDirectory;
|
||||
this.snapshotDBAPI = snapshotDBAPI;
|
||||
}
|
||||
|
||||
public void buildRepository() throws RepositoryNotFoundException {
|
||||
if (repository.getObjectDatabase().exists()) {
|
||||
updateRepositoryFromSnapshots(repository);
|
||||
} else {
|
||||
buildRepositoryFromScratch(repository);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRepositoryFromSnapshots(Repository repository) {
|
||||
List<Snapshot> snapshotsToAdd = snapshotDBAPI.getSnapshotsToAddToRepository(repository);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
updateRepositoryFromSnapshots(repository);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import uk.ac.ic.wlgitbridge.git.exception.InvalidRootDirectoryPathException;
|
||||
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.SnapshotRepositorySource;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.SnapshotRepositoryBuilder;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
|
||||
@@ -16,7 +16,7 @@ import javax.servlet.ServletException;
|
||||
public class WLGitServlet extends GitServlet {
|
||||
|
||||
public WLGitServlet(ServletContextHandler servletContextHandler, String rootGitDirectoryPath) throws ServletException, InvalidRootDirectoryPathException {
|
||||
setRepositoryResolver(new WLRepositoryResolver(rootGitDirectoryPath, new SnapshotRepositorySource()));
|
||||
setRepositoryResolver(new WLRepositoryResolver(rootGitDirectoryPath, new SnapshotRepositoryBuilder()));
|
||||
setReceivePackFactory(new WLReceivePackFactory());
|
||||
setUploadPackFactory(new WLUploadPackFactory());
|
||||
init(new WLGitServletConfig(servletContextHandler));
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
|
||||
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
|
||||
import uk.ac.ic.wlgitbridge.git.exception.InvalidRootDirectoryPathException;
|
||||
import uk.ac.ic.wlgitbridge.bridge.RepositorySource;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.SnapshotRepositorySource;
|
||||
import uk.ac.ic.wlgitbridge.writelatex.SnapshotRepositoryBuilder;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.File;
|
||||
@@ -21,7 +21,7 @@ public class WLRepositoryResolver implements RepositoryResolver<HttpServletReque
|
||||
private File rootGitDirectory;
|
||||
private RepositorySource repositorySource;
|
||||
|
||||
public WLRepositoryResolver(String rootGitDirectoryPath, SnapshotRepositorySource repositorySource) throws InvalidRootDirectoryPathException {
|
||||
public WLRepositoryResolver(String rootGitDirectoryPath, SnapshotRepositoryBuilder repositorySource) throws InvalidRootDirectoryPathException {
|
||||
this.repositorySource = repositorySource;
|
||||
initRootGitDirectory(rootGitDirectoryPath);
|
||||
}
|
||||
|
||||
+16
-21
@@ -2,41 +2,36 @@ package uk.ac.ic.wlgitbridge.writelatex;
|
||||
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
||||
import uk.ac.ic.wlgitbridge.bridge.RepositorySource;
|
||||
import uk.ac.ic.wlgitbridge.bridge.WLBridgedProject;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by Winston on 03/11/14.
|
||||
*/
|
||||
public class SnapshotRepositoryBuilder implements RepositoryBuilder {
|
||||
public class SnapshotRepositoryBuilder implements RepositorySource {
|
||||
|
||||
private SnapshotDBAPI snapshotDBAPI;
|
||||
private SnapshotAPI snapshotAPI;
|
||||
private final SnapshotDBAPI snapshotDBAPI;
|
||||
|
||||
public SnapshotRepositoryBuilder() {
|
||||
snapshotDBAPI = new DummySnapshotDBAPI();
|
||||
snapshotAPI = new DummySnapshotAPI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildRepository(Repository repository) throws RepositoryNotFoundException {
|
||||
if (repository.getObjectDatabase().exists()) {
|
||||
updateRepositoryFromSnapshots(repository);
|
||||
} else {
|
||||
buildRepositoryFromScratch(repository);
|
||||
}
|
||||
}
|
||||
public Repository getRepositoryWithNameAtRootDirectory(String name, File rootDirectory) throws RepositoryNotFoundException {
|
||||
File repositoryDirectory = new File(rootDirectory.getAbsolutePath(), name);
|
||||
|
||||
private void updateRepositoryFromSnapshots(Repository repository) {
|
||||
List<Snapshot> snapshotsToAdd = snapshotDBAPI.getSnapshotsToAddToRepository(repository);
|
||||
}
|
||||
|
||||
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());
|
||||
Repository repository = null;
|
||||
try {
|
||||
repository = new FileRepositoryBuilder().setWorkTree(repositoryDirectory).build();
|
||||
} catch (IOException e) {
|
||||
throw new RepositoryNotFoundException(name);
|
||||
}
|
||||
updateRepositoryFromSnapshots(repository);
|
||||
new WLBridgedProject(repository, name, repositoryDirectory, snapshotDBAPI).buildRepository();
|
||||
return repository;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package uk.ac.ic.wlgitbridge.writelatex;
|
||||
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
|
||||
import uk.ac.ic.wlgitbridge.bridge.RepositorySource;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Created by Winston on 03/11/14.
|
||||
*/
|
||||
public class SnapshotRepositorySource implements RepositorySource {
|
||||
|
||||
private RepositoryBuilder repositoryBuilder;
|
||||
|
||||
public SnapshotRepositorySource() {
|
||||
repositoryBuilder = new SnapshotRepositoryBuilder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Repository getRepositoryWithNameAtRootDirectory(String name, File rootDirectory) throws RepositoryNotFoundException {
|
||||
File repositoryDirectory = new File(rootDirectory.getAbsolutePath(), name);
|
||||
|
||||
Repository repository = null;
|
||||
try {
|
||||
repository = new FileRepositoryBuilder().setWorkTree(repositoryDirectory).build();
|
||||
} catch (IOException e) {
|
||||
throw new RepositoryNotFoundException(name);
|
||||
}
|
||||
repositoryBuilder.buildRepository(repository);
|
||||
return repository;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user