Reimplement in Java
This commit is contained in:
parent
9d4ea21111
commit
e29f08c4f9
5 changed files with 66 additions and 42 deletions
19
pom.xml
19
pom.xml
|
@ -9,12 +9,11 @@
|
|||
<version>0.1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<scala-library.version>2.12.6</scala-library.version>
|
||||
<scala-maven-plugin.version>3.3.2</scala-maven-plugin.version>
|
||||
<java.version>8</java.version>
|
||||
<lombok.version>1.16.20</lombok.version>
|
||||
<jgit.version>4.11.0.201803080745-r</jgit.version>
|
||||
<junit.version>5.2.0</junit.version>
|
||||
<assertj.version>3.9.1</assertj.version>
|
||||
<jgit.version>4.11.0.201803080745-r</jgit.version>
|
||||
<java.version>8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -30,9 +29,10 @@
|
|||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.scala-lang</groupId>
|
||||
<artifactId>scala-library</artifactId>
|
||||
<version>${scala-library.version}</version>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -66,11 +66,6 @@
|
|||
</dependencyManagement>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>net.alchim31.maven</groupId>
|
||||
<artifactId>scala-maven-plugin</artifactId>
|
||||
<version>${scala-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
|
|
19
src/main/java/net/kemitix/gitdb/GitDB.java
Normal file
19
src/main/java/net/kemitix/gitdb/GitDB.java
Normal file
|
@ -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();
|
||||
}
|
32
src/main/java/net/kemitix/gitdb/GitDBLocal.java
Normal file
32
src/main/java/net/kemitix/gitdb/GitDBLocal.java
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue