diff --git a/pom.xml b/pom.xml index 8ca80e9..4bc4c82 100644 --- a/pom.xml +++ b/pom.xml @@ -9,12 +9,11 @@ 0.1.0-SNAPSHOT - 2.12.6 - 3.3.2 + 8 + 1.16.20 + 4.11.0.201803080745-r 5.2.0 3.9.1 - 4.11.0.201803080745-r - 8 @@ -30,9 +29,10 @@ - org.scala-lang - scala-library - ${scala-library.version} + org.projectlombok + lombok + ${lombok.version} + true @@ -66,11 +66,6 @@ - - net.alchim31.maven - scala-maven-plugin - ${scala-maven-plugin.version} - org.apache.maven.plugins maven-compiler-plugin diff --git a/src/main/java/net/kemitix/gitdb/GitDB.java b/src/main/java/net/kemitix/gitdb/GitDB.java new file mode 100644 index 0000000..6f9b4cd --- /dev/null +++ b/src/main/java/net/kemitix/gitdb/GitDB.java @@ -0,0 +1,19 @@ +package net.kemitix.gitdb; + +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.lib.Repository; + +import java.nio.file.Path; + +public interface GitDB { + + static GitDB local(Path dbDir) throws GitAPIException { + return new GitDBLocal(dbDir); + } + + void close(); + + Repository getRepository(); + + Path getGitDir(); +} diff --git a/src/main/java/net/kemitix/gitdb/GitDBLocal.java b/src/main/java/net/kemitix/gitdb/GitDBLocal.java new file mode 100644 index 0000000..da2593e --- /dev/null +++ b/src/main/java/net/kemitix/gitdb/GitDBLocal.java @@ -0,0 +1,32 @@ +package net.kemitix.gitdb; + +import lombok.Getter; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.lib.Repository; + +import java.nio.file.Path; + +class GitDBLocal implements GitDB { + + @Getter + private final Repository repository; + + @Getter + private final Path gitDir; + + GitDBLocal(final Path gitDir) throws GitAPIException { + this.gitDir = gitDir; + this.repository = Git + .init() + .setBare(true) + .setGitDir(gitDir.toFile()) + .call() + .getRepository(); + } + + @Override + public void close() { + repository.close(); + } +} diff --git a/src/main/scala/net/kemitix/gitdb/GitDB.scala b/src/main/scala/net/kemitix/gitdb/GitDB.scala deleted file mode 100644 index c6a51f2..0000000 --- a/src/main/scala/net/kemitix/gitdb/GitDB.scala +++ /dev/null @@ -1,27 +0,0 @@ -package net.kemitix.gitdb - -import java.nio.file.Path - -import org.eclipse.jgit.lib.Repository -import org.eclipse.jgit.storage.file.FileRepositoryBuilder - -import scala.beans.BeanProperty - -class GitDB (val dir: Path) { - - @BeanProperty - val repository: Repository = { - val fileRepositoryBuilder = new FileRepositoryBuilder - fileRepositoryBuilder.setGitDir(dir.toFile) - fileRepositoryBuilder.build() - } - - def close: Unit = repository.close() - -} - -object GitDB { - def init(dir: Path): GitDB = { - new GitDB(dir) - } -} \ No newline at end of file diff --git a/src/test/java/net/kemitix/gitdb/GitDBTest.java b/src/test/java/net/kemitix/gitdb/GitDBTest.java index 5eab848..c9b4034 100644 --- a/src/test/java/net/kemitix/gitdb/GitDBTest.java +++ b/src/test/java/net/kemitix/gitdb/GitDBTest.java @@ -1,5 +1,6 @@ package net.kemitix.gitdb; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.Repository; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Test; @@ -15,21 +16,25 @@ import static org.assertj.core.api.Assertions.assertThat; class GitDBTest { private final Path dbDir = Files.createTempDirectory("gitdb"); - private final GitDB gitDB = GitDB.init(dbDir); + private final GitDB gitDB = GitDB.local(dbDir); - GitDBTest() throws IOException { + GitDBTest() throws IOException, GitAPIException { } @Test void shouldInitialiseGitDB() { //then assertThat(gitDB).isNotNull(); - assertThat(gitDB.dir()).isDirectory() + assertThat(gitDB.getGitDir()).isDirectory() .isEqualTo(dbDir); final Repository repository = gitDB.getRepository(); assertThat(repository.isBare()).isTrue(); + assertThat(repository.getObjectDatabase().exists()).isTrue(); + assertThat(repository.getRefDatabase()).isNotNull(); } + + @AfterEach void tearDown() throws IOException { gitDB.close();