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