WLBridgedProject.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package uk.ac.ic.wlgitbridge.bridge;
  2. import org.eclipse.jgit.errors.RepositoryNotFoundException;
  3. import org.eclipse.jgit.lib.Repository;
  4. import uk.ac.ic.wlgitbridge.writelatex.Snapshot;
  5. import uk.ac.ic.wlgitbridge.writelatex.api.SnapshotDBAPI;
  6. import java.io.File;
  7. import java.util.List;
  8. /**
  9. * Created by Winston on 05/11/14.
  10. */
  11. public class WLBridgedProject {
  12. private final Repository repository;
  13. private final String name;
  14. private final File repositoryDirectory;
  15. private final SnapshotDBAPI snapshotDBAPI;
  16. public WLBridgedProject(Repository repository, String name, File repositoryDirectory, SnapshotDBAPI snapshotDBAPI) {
  17. this.repository = repository;
  18. this.name = name;
  19. this.repositoryDirectory = repositoryDirectory;
  20. this.snapshotDBAPI = snapshotDBAPI;
  21. }
  22. public void buildRepository() throws RepositoryNotFoundException {
  23. if (repository.getObjectDatabase().exists()) {
  24. updateRepositoryFromSnapshots(repository);
  25. } else {
  26. buildRepositoryFromScratch(repository);
  27. }
  28. }
  29. private void updateRepositoryFromSnapshots(Repository repository) {
  30. List<Snapshot> snapshotsToAdd = snapshotDBAPI.getSnapshotsToAddToRepository(repository);
  31. }
  32. private void buildRepositoryFromScratch(Repository repository) throws RepositoryNotFoundException {
  33. System.out.println("Need to build repo: " + repository.getDirectory().getAbsolutePath());
  34. if (!snapshotDBAPI.repositoryExists(repository)) {
  35. throw new RepositoryNotFoundException(repository.getDirectory());
  36. }
  37. updateRepositoryFromSnapshots(repository);
  38. }
  39. }