Search in sources :

Example 1 with MultiRepository

use of org.eclipse.winery.repository.filebased.MultiRepository in project winery by eclipse.

the class RepositoryFactory method reconfigure.

public static void reconfigure(GitBasedRepositoryConfiguration configuration) throws IOException, GitAPIException {
    RepositoryFactory.gitBasedRepositoryConfiguration = configuration;
    RepositoryFactory.fileBasedRepositoryConfiguration = null;
    if (repositoryContainsMultiRepositoryConfiguration(configuration)) {
        repository = new MultiRepository(configuration.getRepositoryPath().get());
    } else if (Environments.getInstance().getRepositoryConfig().isTenantRepository()) {
        repository = new TenantRepository(configuration.getRepositoryPath().get());
    } else {
        // if a repository root is specified, use it instead of the root specified in the config
        AbstractFileBasedRepository localRepository = configuration.getRepositoryPath().isPresent() ? createXmlOrYamlRepository(configuration, configuration.getRepositoryPath().get()) : createXmlOrYamlRepository(configuration, Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot()));
        repository = new GitBasedRepository(configuration, localRepository);
    }
}
Also used : MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) AbstractFileBasedRepository(org.eclipse.winery.repository.backend.filebased.AbstractFileBasedRepository) TenantRepository(org.eclipse.winery.repository.filebased.TenantRepository) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository)

Example 2 with MultiRepository

use of org.eclipse.winery.repository.filebased.MultiRepository in project winery by eclipse.

the class RepositoryFactory method reconfigure.

public static void reconfigure(FileBasedRepositoryConfiguration configuration) {
    RepositoryFactory.fileBasedRepositoryConfiguration = configuration;
    RepositoryFactory.gitBasedRepositoryConfiguration = null;
    if (repositoryContainsMultiRepositoryConfiguration(configuration)) {
        try {
            repository = new MultiRepository(configuration.getRepositoryPath().get());
        } catch (IOException | GitAPIException e) {
            LOGGER.error("Error while initializing Multi-Repository!");
        }
    } else if (Environments.getInstance().getRepositoryConfig().isTenantRepository()) {
        try {
            repository = new TenantRepository(configuration.getRepositoryPath().get());
        } catch (IOException | GitAPIException e) {
            LOGGER.error("Error while initializing Tenant-Repository");
        }
    } else {
        // if a repository root is specified, use it instead of the root specified in the config
        repository = configuration.getRepositoryPath().isPresent() ? createXmlOrYamlRepository(configuration, configuration.getRepositoryPath().get()) : createXmlOrYamlRepository(configuration, Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot()));
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) TenantRepository(org.eclipse.winery.repository.filebased.TenantRepository) IOException(java.io.IOException)

Example 3 with MultiRepository

use of org.eclipse.winery.repository.filebased.MultiRepository in project winery by eclipse.

the class GitWebSocket method onMessage.

@OnMessage
public void onMessage(String message, Session session) {
    try {
        GitData data = JacksonProvider.mapper.readValue(message, GitData.class);
        Map<String, Map<DiffEntry, String>> repoEntryList = new HashMap<>();
        if (RepositoryFactory.getRepository() instanceof MultiRepository) {
            IRepository gitRepo;
            for (IRepository repo : ((MultiRepository) RepositoryFactory.getRepository()).getRepositories()) {
                gitRepo = repo;
                if (gitRepo instanceof GitBasedRepository) {
                    handleGitRepository((GitBasedRepository) gitRepo, data, repoEntryList);
                }
            }
            setGitDifferences(repoEntryList);
        } else if (RepositoryFactory.getRepository() instanceof GitBasedRepository) {
            handleGitRepository((GitBasedRepository) RepositoryFactory.getRepository(), data, repoEntryList);
            setGitDifferences(repoEntryList);
        }
    } catch (IOException e) {
        writeInSession(session, "{ \"error\": \"Could not parse message!\" }");
    }
}
Also used : MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) HashMap(java.util.HashMap) GitData(org.eclipse.winery.repository.rest.datatypes.GitData) IOException(java.io.IOException) IRepository(org.eclipse.winery.repository.backend.IRepository) HashMap(java.util.HashMap) Map(java.util.Map) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) OnMessage(javax.websocket.OnMessage)

Example 4 with MultiRepository

use of org.eclipse.winery.repository.filebased.MultiRepository 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 5 with MultiRepository

use of org.eclipse.winery.repository.filebased.MultiRepository 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

MultiRepository (org.eclipse.winery.repository.filebased.MultiRepository)6 GitBasedRepository (org.eclipse.winery.repository.backend.filebased.GitBasedRepository)5 IOException (java.io.IOException)2 IRepository (org.eclipse.winery.repository.backend.IRepository)2 TenantRepository (org.eclipse.winery.repository.filebased.TenantRepository)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 OnMessage (javax.websocket.OnMessage)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 WineryVersion (org.eclipse.winery.common.version.WineryVersion)1 AbstractFileBasedRepository (org.eclipse.winery.repository.backend.filebased.AbstractFileBasedRepository)1 RepositoryProperties (org.eclipse.winery.repository.backend.filebased.RepositoryProperties)1 MultiRepositoryManager (org.eclipse.winery.repository.filebased.MultiRepositoryManager)1 GitData (org.eclipse.winery.repository.rest.datatypes.GitData)1 GitWebSocket (org.eclipse.winery.repository.rest.websockets.GitWebSocket)1