-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow architectures to be loaded from git repository (#7)
- Loading branch information
1 parent
cb4edcf
commit ecaeda8
Showing
8 changed files
with
133 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/main/java/org/lowfer/repository/ArchitectureGitRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.lowfer.repository; | ||
|
||
import org.eclipse.jgit.api.Git; | ||
import org.eclipse.jgit.api.errors.GitAPIException; | ||
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; | ||
import org.lowfer.domain.common.SoftwareArchitecture; | ||
import org.lowfer.serde.MasterManifestDeserializer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
@Repository | ||
@ConditionalOnProperty(prefix = "application.architectures.", value = "repository.uri") | ||
public class ArchitectureGitRepository implements ArchitectureRepository { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(ArchitectureGitRepository.class); | ||
|
||
private final Git repository; | ||
private final ArchitectureDirectoryRepository architectureDirectoryRepository; | ||
|
||
public ArchitectureGitRepository( | ||
MasterManifestDeserializer masterManifestDeserializer, | ||
@Value("${application.architectures.repository.uri}") String uri, | ||
@Value("${application.architectures.repository.branch:master}") String branch, | ||
@Value("${application.architectures.repository.path:/}") String path, | ||
@Value("${application.architectures.repository.username:}") String username, | ||
@Value("${application.architectures.repository.password:}") String password) throws IOException, GitAPIException { | ||
|
||
final File directoryFile = Files.createTempDirectory("lowfer-git").toFile(); | ||
|
||
LOG.info("Created temp directory ({}) for repository: {}", directoryFile, uri); | ||
|
||
LOG.info("Cloning branch {} of git repository: {}...", branch, uri); | ||
|
||
this.repository = Git.cloneRepository() | ||
.setURI(uri) | ||
.setDirectory(directoryFile) | ||
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)) | ||
.setBranch(branch) | ||
.call(); | ||
|
||
LOG.info("Cloned git repository ({}) with {} branch(es)", uri, repository.branchList().call().size()); | ||
|
||
final Path fullPath = Path.of(directoryFile.getPath(), path); | ||
|
||
this.architectureDirectoryRepository = | ||
new ArchitectureDirectoryRepository(fullPath.toString(), masterManifestDeserializer); | ||
} | ||
|
||
@Override | ||
public Optional<SoftwareArchitecture> findByName(String name) { | ||
return architectureDirectoryRepository.findByName(name); | ||
} | ||
|
||
@Override | ||
public List<SoftwareArchitecture> findAll() { | ||
return architectureDirectoryRepository.findAll(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/lowfer/repository/ArchitectureRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.lowfer.repository; | ||
|
||
import org.lowfer.domain.common.SoftwareArchitecture; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface ArchitectureRepository { | ||
|
||
Optional<SoftwareArchitecture> findByName(String name); | ||
|
||
List<SoftwareArchitecture> findAll(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/test/java/org/lowfer/repository/ArchitectureGitRepositoryTestIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.lowfer.repository; | ||
|
||
import org.eclipse.jgit.api.errors.GitAPIException; | ||
import org.junit.jupiter.api.Test; | ||
import org.lowfer.domain.common.SoftwareArchitecture; | ||
import org.lowfer.serde.ManifestYamlParser; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
|
||
class ArchitectureGitRepositoryTestIT { | ||
|
||
@Test | ||
public void testInitializeArchitectureGitRepository() throws IOException, GitAPIException { | ||
final ArchitectureGitRepository repository = new ArchitectureGitRepository( | ||
new ManifestYamlParser(), | ||
"https://github.com/mbouchenoire/lowfer.git", | ||
"0.1.0", | ||
"src/test/resources/architectures/demo", | ||
"", | ||
""); | ||
|
||
final List<SoftwareArchitecture> architectures = repository.findAll(); | ||
assertFalse(architectures.isEmpty()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters