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);
}
}
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()));
}
}
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!\" }");
}
}
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();
}
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;
}
Aggregations