Search in sources :

Example 6 with GitBasedRepository

use of org.eclipse.winery.repository.backend.filebased.GitBasedRepository in project winery by eclipse.

the class YamlCsarImporter method storeDefs.

private void storeDefs(DefinitionsChildId id, TDefinitions defs) {
    RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(id);
    IRepository repo = RepositoryFactory.getRepository();
    FromCanonical converter = null;
    if (repo instanceof GitBasedRepository) {
        GitBasedRepository wrapper = (GitBasedRepository) RepositoryFactory.getRepository();
        converter = new FromCanonical((YamlRepository) wrapper.getRepository());
    } else if (repo instanceof YamlRepository) {
        converter = new FromCanonical((YamlRepository) repo);
    }
    if (Objects.nonNull(converter)) {
        YamlWriter writer = new YamlWriter();
        writer.write(converter.convert((TDefinitions) defs), repo.ref2AbsolutePath(ref));
    }
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) FromCanonical(org.eclipse.winery.repository.yaml.converter.FromCanonical) YamlRepository(org.eclipse.winery.repository.yaml.YamlRepository) IRepository(org.eclipse.winery.repository.backend.IRepository) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) YamlWriter(org.eclipse.winery.repository.converter.writer.YamlWriter)

Example 7 with GitBasedRepository

use of org.eclipse.winery.repository.backend.filebased.GitBasedRepository in project winery by eclipse.

the class AbstractGitResolver method createRepository.

@Override
public GitBasedRepository createRepository(File repositoryLocation) throws IOException, GitAPIException {
    FileBasedRepositoryConfiguration compositeConfiguration = new FileBasedRepositoryConfiguration(Paths.get(repositoryLocation.toString()));
    GitBasedRepositoryConfiguration configuration = new GitBasedRepositoryConfiguration(false, repositoryUrl, repositoryBranch, compositeConfiguration);
    return new GitBasedRepository(configuration, RepositoryFactory.createXmlOrYamlRepository(compositeConfiguration, repositoryLocation.toPath()));
}
Also used : GitBasedRepositoryConfiguration(org.eclipse.winery.common.configuration.GitBasedRepositoryConfiguration) FileBasedRepositoryConfiguration(org.eclipse.winery.common.configuration.FileBasedRepositoryConfiguration) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository)

Example 8 with GitBasedRepository

use of org.eclipse.winery.repository.backend.filebased.GitBasedRepository in project winery by eclipse.

the class RepositoryAdminResource method deleteRepository.

/**
 * Deletes given repository
 *
 * @param name of repository to delete.
 */
@DELETE
@Path("repositories/{repository}")
public Response deleteRepository(@PathParam("repository") String name) {
    String repositoryUrl = "";
    if (RepositoryFactory.getRepository() instanceof MultiRepository) {
        IRepository gitRepo;
        MultiRepositoryManager multiRepositoryManager = new MultiRepositoryManager();
        for (RepositoryProperties repo : multiRepositoryManager.getRepositoriesAsList()) {
            if (repo.getName().equals(name)) {
                repositoryUrl = repo.getUrl();
                break;
            }
        }
        for (IRepository repo : ((MultiRepository) RepositoryFactory.getRepository()).getRepositories()) {
            gitRepo = repo;
            if (gitRepo instanceof GitBasedRepository) {
                if (((GitBasedRepository) gitRepo).getRepositoryUrl() != null) {
                    if (((GitBasedRepository) gitRepo).getRepositoryUrl().equals(repositoryUrl)) {
                        ((GitBasedRepository) gitRepo).forceClear();
                        ((MultiRepository) RepositoryFactory.getRepository()).removeRepository(repositoryUrl);
                        break;
                    }
                }
            }
        }
    }
    return Response.ok().build();
}
Also used : MultiRepositoryManager(org.eclipse.winery.repository.filebased.MultiRepositoryManager) MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) IRepository(org.eclipse.winery.repository.backend.IRepository) RepositoryProperties(org.eclipse.winery.repository.backend.filebased.RepositoryProperties) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 9 with GitBasedRepository

use of org.eclipse.winery.repository.backend.filebased.GitBasedRepository in project winery by eclipse.

the class BackendUtils method commit.

public static void commit(DefinitionsChildId componentToCommit, String commitMessagePrefix, IRepository repository) throws GitAPIException {
    if (repository instanceof GitBasedRepository) {
        GitBasedRepository gitRepo = (GitBasedRepository) repository;
        List<String> filePatternsToCommit = new ArrayList<>();
        if (gitRepo.hasChangesInFile(componentToCommit)) {
            /*WineryVersion predecessor = BackendUtils.getPredecessor(componentToCommit);
                ToscaDiff diff = BackendUtils.compare(componentToCommit, predecessor);
                String changeLog = diff.getChangeLog();
                // get changelog.md and append changeLog*/
            filePatternsToCommit.add(Util.getPathInsideRepo(componentToCommit));
            gitRepo.addCommit(filePatternsToCommit.toArray(new String[filePatternsToCommit.size()]), commitMessagePrefix + " " + componentToCommit.getQName());
        }
    } else {
        throw new RuntimeException("Repository does not support git!");
    }
}
Also used : ArrayList(java.util.ArrayList) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository)

Example 10 with GitBasedRepository

use of org.eclipse.winery.repository.backend.filebased.GitBasedRepository in project winery by eclipse.

the class WineryVersionUtils method getVersionsList.

/**
 * @param current returns the current version in element [0] of this variable. Has to be non-null.
 * @return a list of available versions
 */
private static List<WineryVersion> getVersionsList(DefinitionsChildId id, final WineryVersion[] current, IRepository repository) {
    List<WineryVersion> versionList = getOtherVersionDefinitionsFromDefinition(id, repository).stream().map(element -> {
        WineryVersion version = VersionUtils.getVersionWithCurrentFlag(element.getXmlId().getDecoded(), id.getXmlId().getDecoded());
        if (version.isCurrentVersion()) {
            current[0] = version;
        }
        return version;
    }).sorted(Comparator.reverseOrder()).collect(Collectors.toList());
    // explicitly set the latest version and releasable flag
    versionList.get(0).setLatestVersion(true);
    versionList.get(0).setReleasable(true);
    boolean changesInFile = false;
    if (current[0].isVersionedInWinery() && repository instanceof MultiRepository) {
        for (IRepository inner : ((MultiRepository) repository).getRepositories()) {
            // notably not instanceof because possible subclasses of GitRepository may need separate handling
            if (inner.getClass().equals(GitBasedRepository.class)) {
                GitBasedRepository gitRepo = (GitBasedRepository) inner;
                if (gitRepo.hasChangesInFile(id)) {
                    changesInFile = true;
                }
            }
        }
    }
    if (repository.hasChangesInFile(id)) {
        changesInFile = true;
    }
    if (!current[0].isVersionedInWinery()) {
        changesInFile = true;
    }
    if (!current[0].isLatestVersion()) {
        // The current version may still be releasable, if it's the latest WIP version of a component version.
        List<WineryVersion> collect = versionList.stream().filter(version -> version.getComponentVersion().equals(current[0].getComponentVersion())).sorted(Comparator.reverseOrder()).collect(Collectors.toList());
        current[0].setReleasable(collect.get(0).isCurrentVersion());
        // And if there are changes, it's also editable.
        current[0].setEditable(changesInFile && current[0].isReleasable());
    } else {
        current[0].setEditable(changesInFile);
    }
    // In RADON, all versions should always be editable
    if (Environments.isFeatureEnabled("radon")) {
        versionList.forEach(v -> v.setEditable(true));
    }
    return versionList;
}
Also used : MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) WineryVersion(org.eclipse.winery.common.version.WineryVersion)

Aggregations

GitBasedRepository (org.eclipse.winery.repository.backend.filebased.GitBasedRepository)11 IRepository (org.eclipse.winery.repository.backend.IRepository)5 MultiRepository (org.eclipse.winery.repository.filebased.MultiRepository)5 IOException (java.io.IOException)3 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)2 WineryVersion (org.eclipse.winery.common.version.WineryVersion)2 YamlRepository (org.eclipse.winery.repository.yaml.YamlRepository)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 URI (java.net.URI)1 Path (java.nio.file.Path)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 OnMessage (javax.websocket.OnMessage)1 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1