Search in sources :

Example 1 with IRepositoryResolver

use of org.eclipse.winery.repository.filebased.management.IRepositoryResolver in project winery by eclipse.

the class MultiRepository method createRepository.

/**
 * This method clones a repository into the file system. If the cloned repository contains dependencies in the form
 * of a repositories.json file, the dependencies will be cloned recursively if they are not already in the
 * MultiRepository. The subrepositories are GitbasedRepositories and are added to the list of repositories to the
 * MultiRepository. It the subrepositories have dependencies, they are initialized as MultiRepos
 *
 * @param url    of the repository
 * @param branch which should be cloned
 */
private void createRepository(String url, String branch) {
    IRepositoryResolver resolver = null;
    Optional<IRepositoryResolver> resolverOptional = RepositoryResolverFactory.getResolver(url, branch);
    if (resolverOptional.isPresent()) {
        resolver = resolverOptional.get();
    }
    if (resolver != null && !RepositoryUtils.checkRepositoryDuplicate(url, this)) {
        try {
            String ownerDirectory = URLEncoder.encode(resolver.getRepositoryMaintainerUrl(), "UTF-8");
            Path ownerRoot = this.repositoryRoot.resolve(ownerDirectory);
            if (!ownerRoot.toFile().exists()) {
                Files.createDirectories(ownerRoot);
            }
            Path repositoryLocation = ownerRoot.resolve(resolver.getRepositoryName());
            IRepository newSubRepository = resolver.createRepository(repositoryLocation.toFile());
            this.addRepository(newSubRepository);
            File configurationFile = newSubRepository.getRepositoryRoot().resolve(Filename.FILENAME_JSON_MUTLI_REPOSITORIES).toFile();
            if (configurationFile.exists()) {
                loadRepositoriesByList(loadConfiguration(configurationFile));
            }
            fixNamespaces(newSubRepository);
        } catch (IOException | GitAPIException e) {
            LOGGER.error("Error while creating the repository structure", e);
        }
    }
}
Also used : Path(java.nio.file.Path) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IRepositoryResolver(org.eclipse.winery.repository.filebased.management.IRepositoryResolver) IOException(java.io.IOException) IRepository(org.eclipse.winery.repository.backend.IRepository) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 IRepository (org.eclipse.winery.repository.backend.IRepository)1 IRepositoryResolver (org.eclipse.winery.repository.filebased.management.IRepositoryResolver)1