use of org.eclipse.winery.repository.backend.IRepository 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);
}
}
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class MultiRepository method addNamespacesToRepository.
private void addNamespacesToRepository(IRepository repository, GenericId id) {
if (id instanceof DefinitionsChildId) {
Namespace namespace = ((DefinitionsChildId) id).getNamespace();
String ns = namespace.getDecoded();
IRepository r = determineRepositoryRef(repository);
Set<String> set = repositoryGlobal.get(r);
set.add(ns);
repositoryGlobal.put(r, set);
String pns;
try {
if (this.localRepository.getRepository() instanceof XmlRepository) {
pns = namespace.getEncoded().substring(0, namespace.getEncoded().lastIndexOf(RepositoryUtils.getUrlSeparatorEncoded()));
} else {
pns = namespace.getEncoded();
}
} catch (UnsupportedEncodingException ex) {
LOGGER.error("Error when generating the namespace", ex);
return;
}
Set<Namespace> setPre = repositoryCommonNamespace.get(r);
setPre.add(new Namespace(pns, true));
repositoryCommonNamespace.put(r, setPre);
}
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class MultiRepository method putContentToFile.
@Override
public void putContentToFile(RepositoryFileReference ref, InputStream inputStream, MediaType mediaType) throws IOException {
IRepository repository = RepositoryUtils.getRepositoryByRef(ref, this);
repository.putContentToFile(ref, inputStream, mediaType);
addNamespacesToRepository(repository, ref);
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class MultiRepository method putDefinition.
@Override
public void putDefinition(RepositoryFileReference ref, TDefinitions content) throws IOException {
IRepository repository = RepositoryUtils.getRepositoryByRef(ref, this);
repository.putDefinition(ref, content);
addNamespacesToRepository(repository, ref);
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class JsonBasedMultiNamespaceManager method replaceAll.
@Override
public void replaceAll(Map<String, NamespaceProperties> map) {
map.forEach((namespace, properties) -> {
IRepository repository = RepositoryUtils.getRepositoryByNamespace(namespace, this.repository);
repository.getNamespaceManager().replaceAll(map);
});
this.repository.updateNamespaces();
}
Aggregations