Search in sources :

Example 31 with IRepository

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);
        }
    }
}
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)

Example 32 with IRepository

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);
    }
}
Also used : XmlRepository(org.eclipse.winery.repository.xml.XmlRepository) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IRepository(org.eclipse.winery.repository.backend.IRepository) Namespace(org.eclipse.winery.model.ids.Namespace)

Example 33 with IRepository

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);
}
Also used : IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 34 with IRepository

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);
}
Also used : IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 35 with IRepository

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();
}
Also used : IRepository(org.eclipse.winery.repository.backend.IRepository)

Aggregations

IRepository (org.eclipse.winery.repository.backend.IRepository)75 TNodeType (org.eclipse.winery.model.tosca.TNodeType)29 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)28 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)27 IOException (java.io.IOException)24 QName (javax.xml.namespace.QName)24 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)22 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)21 ArrayList (java.util.ArrayList)20 Map (java.util.Map)20 HashMap (java.util.HashMap)15 LoggerFactory (org.slf4j.LoggerFactory)15 LinkedHashMap (java.util.LinkedHashMap)14 List (java.util.List)14 TServiceTemplate (org.eclipse.winery.model.tosca.TServiceTemplate)14 RepositoryFactory (org.eclipse.winery.repository.backend.RepositoryFactory)14 Collectors (java.util.stream.Collectors)13 POST (javax.ws.rs.POST)13 Path (javax.ws.rs.Path)13 Produces (javax.ws.rs.Produces)13