use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class CopybaraGenerator method generateOriginFilesConfig.
public String generateOriginFilesConfig() {
SortedSet<DefinitionsChildId> allDefinitionsChildIds = repository.getAllDefinitionsChildIds();
return allDefinitionsChildIds.stream().filter(id -> {
RepositoryFileReference repositoryFileReference = new RepositoryFileReference(id, Constants.LICENSE_FILE_NAME);
if (!repository.exists(repositoryFileReference)) {
return false;
}
try (InputStream inputStream = repository.newInputStream(repositoryFileReference)) {
// we put the whole license file text into a string and check if it starts with "Apache License" after
// trimming it
final String licenceString = "Apache License";
String fileAsString = IOUtils.toString(inputStream);
return fileAsString.trim().startsWith(licenceString);
} catch (IOException e) {
LOGGER.error("Could not create input stream for {}", repositoryFileReference.toString(), e);
return false;
}
}).map(id -> BackendUtils.getPathInsideRepo(id)).collect(Collectors.joining("**\",\n \"", "origin_files = glob([\"README.md\", \"LICENSE\", \"", "**\"]),"));
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class EntityTypeResource method getListOfAllInstances.
/**
* Used by children to implement getListOfAllInstances()
*/
protected SortedSet<Select2OptGroup> getListOfAllInstances(Class<? extends DefinitionsChildId> clazz) throws RepositoryCorruptException {
Select2DataWithOptGroups data = new Select2DataWithOptGroups();
IRepository repo = RepositoryFactory.getRepository();
Collection<? extends DefinitionsChildId> instanceIds = repo.getAllElementsReferencingGivenType(clazz, this.id.getQName());
for (DefinitionsChildId instanceId : instanceIds) {
String groupText = instanceId.getNamespace().getDecoded();
String text = BackendUtils.getName(instanceId, repo);
data.add(groupText, instanceId.getQName().toString(), text);
}
return data.asSortedSet();
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class AvailableSuperclassesApiData method generateList.
private void generateList(Class<? extends DefinitionsChildId> clazz, DefinitionsChildId classToExclude) {
SortedSet<? extends DefinitionsChildId> allDefinitionsChildIds = RepositoryFactory.getRepository().getAllDefinitionsChildIds(clazz);
if (classToExclude != null) {
allDefinitionsChildIds.remove(classToExclude);
}
this.classes = new ArrayList<>();
for (DefinitionsChildId id : allDefinitionsChildIds) {
NameAndQNameApiData q = new NameAndQNameApiData(id);
this.classes.add(q);
}
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class ToscaGraphIsomorphismTest method testServiceTemplateAndComplianceRuleAssociation.
@Test
public void testServiceTemplateAndComplianceRuleAssociation() throws IOException {
HashMap<DefinitionsChildId, TExtensibleElements> allEntities = new HashMap<>();
String dirABC = "/ABC";
String dirBCD = "/BCD";
ServiceTemplateId stId = new ServiceTemplateId(new QName(TEST_TARGET_NAMESPACE + dirABC + dirBCD, "test1"));
TServiceTemplate tServiceTemplate = createTServiceTemplate("ServiceTemplateTestId", TEST_TARGET_NAMESPACE + dirABC + dirBCD);
allEntities.put(stId, tServiceTemplate);
ComplianceRuleId crId1 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE, "test1"));
ComplianceRuleId crId2 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE + dirABC, "test2"));
ComplianceRuleId crId3 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE + dirABC, "test3"));
ComplianceRuleId crId4 = new ComplianceRuleId(new QName(TEST_TARGET_NAMESPACE + dirBCD, "test4"));
OTComplianceRule ruleOne = createTComplianceRule(crId1);
allEntities.put(crId1, ruleOne);
OTComplianceRule ruleTwo = createTComplianceRule(crId2);
allEntities.put(crId2, ruleTwo);
OTComplianceRule ruleThree = createTComplianceRule(crId3);
allEntities.put(crId3, ruleThree);
OTComplianceRule ruleFour = createTComplianceRule(crId4);
allEntities.put(crId4, ruleFour);
persist(allEntities);
ServiceTemplateComplianceRuleRuleChecker checker = new ServiceTemplateComplianceRuleRuleChecker(tServiceTemplate);
List<ComplianceRuleId> ruleIds = checker.getRuleIds(tServiceTemplate);
assertTrue(ruleIds.stream().anyMatch(id -> id.equals(crId1)));
assertTrue(ruleIds.stream().anyMatch(id -> id.equals(crId2)));
assertTrue(ruleIds.stream().anyMatch(id -> id.equals(crId3)));
assertFalse(ruleIds.stream().anyMatch(id -> id.equals(crId4)));
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class GitBasedRepository method hasChangesInFile.
@Override
public boolean hasChangesInFile(DefinitionsChildId id) {
RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(id);
try (Git git = getGit()) {
if (!git.status().call().isClean()) {
List<DiffEntry> diffEntries = git.diff().call();
List<DiffEntry> entries = diffEntries.stream().filter(item -> item.getNewPath().startsWith(BackendUtils.getPathInsideRepo(ref.getParent()))).collect(Collectors.toList());
git.getRepository().close();
return entries.size() > 0;
}
} catch (GitAPIException e) {
LOGGER.trace(e.getMessage(), e);
} catch (IOException e) {
LOGGER.error("Error initializing Git.", e);
}
return false;
}
Aggregations