Search in sources :

Example 41 with DefinitionsChildId

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\", \"", "**\"]),"));
}
Also used : Logger(org.slf4j.Logger) SortedSet(java.util.SortedSet) Files(java.nio.file.Files) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Constants(org.eclipse.winery.common.Constants) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) IOUtils(org.apache.commons.io.IOUtils) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) IRepository(org.eclipse.winery.repository.backend.IRepository) StringJoiner(java.util.StringJoiner) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) Path(java.nio.file.Path) InputStream(java.io.InputStream) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 42 with DefinitionsChildId

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();
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) Select2DataWithOptGroups(org.eclipse.winery.repository.rest.datatypes.select2.Select2DataWithOptGroups) IRepository(org.eclipse.winery.repository.backend.IRepository)

Example 43 with DefinitionsChildId

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);
    }
}
Also used : DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId)

Example 44 with DefinitionsChildId

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)));
}
Also used : Arrays(java.util.Arrays) ToscaModelHelper.createTNodeType(org.eclipse.winery.compliance.ToscaModelHelper.createTNodeType) ToscaModelHelper.createTOSCANode(org.eclipse.winery.compliance.ToscaModelHelper.createTOSCANode) Marshaller(javax.xml.bind.Marshaller) GraphMapping(org.jgrapht.GraphMapping) ServiceTemplateCheckingResult(org.eclipse.winery.compliance.checking.ServiceTemplateCheckingResult) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) HashMap(java.util.HashMap) ToscaModelHelper.createTTopologyTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTTopologyTemplate) ToscaModelHelper.setDerivedFrom(org.eclipse.winery.compliance.ToscaModelHelper.setDerivedFrom) ToscaEdge(org.eclipse.winery.topologygraph.model.ToscaEdge) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) ToscaComplianceRuleMatcher(org.eclipse.winery.compliance.checking.ToscaComplianceRuleMatcher) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ToscaIsomorphismMatcher(org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Map(java.util.Map) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ToscaModelHelper.createTOSCANodeOnlyTypes(org.eclipse.winery.compliance.ToscaModelHelper.createTOSCANodeOnlyTypes) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ToscaModelHelper.createTServiceTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTServiceTemplate) ToscaModelHelper.addEdge(org.eclipse.winery.compliance.ToscaModelHelper.addEdge) JAXBContext(javax.xml.bind.JAXBContext) ServiceTemplateComplianceRuleRuleChecker(org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker) ToscaModelHelper.createTNodeTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTNodeTemplate) Iterator(java.util.Iterator) StringWriter(java.io.StringWriter) IOException(java.io.IOException) TNodeType(org.eclipse.winery.model.tosca.TNodeType) JAXBException(javax.xml.bind.JAXBException) ToscaModelHelper.createTOSCANodeOnlyProperties(org.eclipse.winery.compliance.ToscaModelHelper.createTOSCANodeOnlyProperties) Test(org.junit.jupiter.api.Test) ToscaModelHelper.createTComplianceRule(org.eclipse.winery.compliance.ToscaModelHelper.createTComplianceRule) List(java.util.List) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) TestWithGitBackedRepository(org.eclipse.winery.repository.TestWithGitBackedRepository) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) ToscaModelHelper.createNodeTypeId(org.eclipse.winery.compliance.ToscaModelHelper.createNodeTypeId) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) QName(javax.xml.namespace.QName) TEST_TARGET_NAMESPACE(org.eclipse.winery.compliance.ToscaModelHelper.TEST_TARGET_NAMESPACE) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) ServiceTemplateComplianceRuleRuleChecker(org.eclipse.winery.compliance.checking.ServiceTemplateComplianceRuleRuleChecker) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) ToscaModelHelper.createTServiceTemplate(org.eclipse.winery.compliance.ToscaModelHelper.createTServiceTemplate) Test(org.junit.jupiter.api.Test)

Example 45 with DefinitionsChildId

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;
}
Also used : IWrappingRepository(org.eclipse.winery.repository.backend.IWrappingRepository) Status(org.eclipse.jgit.api.Status) RequirementTypeId(org.eclipse.winery.model.ids.definitions.RequirementTypeId) FileTime(java.nio.file.attribute.FileTime) OTTopologyFragmentRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTopologyFragmentRefinementModel) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) OTComplianceRule(org.eclipse.winery.model.tosca.extensions.OTComplianceRule) ResetCommand(org.eclipse.jgit.api.ResetCommand) Map(java.util.Map) GenericId(org.eclipse.winery.model.ids.GenericId) Path(java.nio.file.Path) TArtifactType(org.eclipse.winery.model.tosca.TArtifactType) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) TEntityType(org.eclipse.winery.model.tosca.TEntityType) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Constants(org.eclipse.winery.common.Constants) CommitCommand(org.eclipse.jgit.api.CommitCommand) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) NoWorkTreeException(org.eclipse.jgit.errors.NoWorkTreeException) QName(javax.xml.namespace.QName) TRequirementType(org.eclipse.winery.model.tosca.TRequirementType) Iterables(com.google.common.collect.Iterables) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TopologyFragmentRefinementModelId(org.eclipse.winery.model.ids.extensions.TopologyFragmentRefinementModelId) MediaType(org.apache.tika.mime.MediaType) GitBasedRepositoryConfiguration(org.eclipse.winery.common.configuration.GitBasedRepositoryConfiguration) ArrayList(java.util.ArrayList) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) TestRefinementModelId(org.eclipse.winery.model.ids.extensions.TestRefinementModelId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TCapabilityType(org.eclipse.winery.model.tosca.TCapabilityType) XsdImportManager(org.eclipse.winery.repository.backend.xsd.XsdImportManager) CleanCommand(org.eclipse.jgit.api.CleanCommand) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) PushCommand(org.eclipse.jgit.api.PushCommand) Files(java.nio.file.Files) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Configuration(org.apache.commons.configuration2.Configuration) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) Repository(org.eclipse.jgit.lib.Repository) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) PullCommand(org.eclipse.jgit.api.PullCommand) SortedSet(java.util.SortedSet) Date(java.util.Date) ComplianceRuleId(org.eclipse.winery.model.ids.extensions.ComplianceRuleId) LoggerFactory(org.slf4j.LoggerFactory) Namespace(org.eclipse.winery.model.ids.Namespace) WineryRepositoryException(org.eclipse.winery.repository.exceptions.WineryRepositoryException) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) AddCommand(org.eclipse.jgit.api.AddCommand) TPolicyType(org.eclipse.winery.model.tosca.TPolicyType) OTRefinementModel(org.eclipse.winery.model.tosca.extensions.OTRefinementModel) OTTestRefinementModel(org.eclipse.winery.model.tosca.extensions.OTTestRefinementModel) ResetType(org.eclipse.jgit.api.ResetCommand.ResetType) FileRepositoryBuilder(org.eclipse.jgit.storage.file.FileRepositoryBuilder) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Collection(java.util.Collection) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) List(java.util.List) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) GenericImportId(org.eclipse.winery.model.ids.definitions.imports.GenericImportId) RepositoryCorruptException(org.eclipse.winery.repository.exceptions.RepositoryCorruptException) Ref(org.eclipse.jgit.lib.Ref) Optional(java.util.Optional) ListBranchCommand(org.eclipse.jgit.api.ListBranchCommand) RmCommand(org.eclipse.jgit.api.RmCommand) UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) OTPatternRefinementModel(org.eclipse.winery.model.tosca.extensions.OTPatternRefinementModel) EventBus(com.google.common.eventbus.EventBus) PatternRefinementModelId(org.eclipse.winery.model.ids.extensions.PatternRefinementModelId) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) Environments(org.eclipse.winery.common.configuration.Environments) TImplementationArtifact(org.eclipse.winery.model.tosca.TImplementationArtifact) HasInheritanceId(org.eclipse.winery.model.ids.definitions.HasInheritanceId) RefinementId(org.eclipse.winery.model.ids.extensions.RefinementId) CheckoutCommand(org.eclipse.jgit.api.CheckoutCommand) ToscaElementId(org.eclipse.winery.model.ids.elements.ToscaElementId) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) JGitInternalException(org.eclipse.jgit.api.errors.JGitInternalException) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) Git(org.eclipse.jgit.api.Git) DiffEntry(org.eclipse.jgit.diff.DiffEntry) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) TPolicyTemplate(org.eclipse.winery.model.tosca.TPolicyTemplate) InputStream(java.io.InputStream) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) Git(org.eclipse.jgit.api.Git) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) IOException(java.io.IOException) DiffEntry(org.eclipse.jgit.diff.DiffEntry)

Aggregations

DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)77 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)29 Test (org.junit.jupiter.api.Test)21 QName (javax.xml.namespace.QName)19 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 ServiceTemplateId (org.eclipse.winery.model.ids.definitions.ServiceTemplateId)16 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)16 HashMap (java.util.HashMap)15 IRepository (org.eclipse.winery.repository.backend.IRepository)14 TNodeType (org.eclipse.winery.model.tosca.TNodeType)13 Path (java.nio.file.Path)12 Map (java.util.Map)12 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)12 TExtensibleElements (org.eclipse.winery.model.tosca.TExtensibleElements)12 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 InputStream (java.io.InputStream)10 HashSet (java.util.HashSet)10 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)10