use of org.guvnor.ala.source.git.UFLocal in project kie-wb-common by kiegroup.
the class GitConfigExecutor method apply.
@Override
public Optional<Source> apply(final GitConfig gitConfig) {
checkNotEmpty("repo-name parameter is mandatory", gitConfig.getRepoName());
if (Boolean.parseBoolean(gitConfig.getCreateRepo())) {
final URI uri = URI.create("git://" + gitConfig.getRepoName());
FileSystems.newFileSystem(uri, new HashMap<String, Object>() {
{
if (gitConfig.getOrigin() != null && !gitConfig.getOrigin().isEmpty()) {
put("origin", gitConfig.getOrigin());
} else {
put("init", Boolean.TRUE);
}
if (gitConfig.getOutPath() != null && !gitConfig.getOutPath().isEmpty()) {
put("out-dir", gitConfig.getOutPath());
}
}
});
} else {
final URI uri = URI.create("git://" + gitConfig.getRepoName() + "?sync");
try {
FileSystems.getFileSystem(uri);
} catch (Exception ex) {
// The repo might not support sync, because it doesn't have an origin, we should move forward for now.
}
}
final GitRepository gitRepository = (GitRepository) new UFLocal().getRepository(gitConfig.getRepoName(), Collections.emptyMap());
final Optional<Source> source_ = Optional.ofNullable(gitRepository.getSource((gitConfig.getBranch() != null && !gitConfig.getBranch().isEmpty()) ? gitConfig.getBranch() : "master"));
if (source_.isPresent()) {
Source source = source_.get();
sourceRegistry.registerRepositorySources(source.getPath(), gitRepository);
sourceRegistry.registerSource(gitRepository, source);
}
return source_;
}
use of org.guvnor.ala.source.git.UFLocal in project kie-wb-common by kiegroup.
the class UFLocalTestJUnitTest method sourceCloneTest.
@Test
public void sourceCloneTest() throws Exception {
final URI uri = URI.create("git://tempx");
final FileSystem fs = FileSystems.newFileSystem(uri, new HashMap<String, Object>() {
{
put("init", Boolean.TRUE);
put("internal", Boolean.TRUE);
put("out-dir", tempPath.getAbsolutePath());
}
});
final UFLocal local = new UFLocal();
final GitRepository repository = (GitRepository) local.getRepository("tempx", Collections.emptyMap());
final Source source = repository.getSource("master");
assertNotNull(source);
assertEquals(source.getPath().getFileSystem(), fs);
}
Aggregations