Search in sources :

Example 1 with EPackageRegistryImpl

use of org.eclipse.emf.ecore.impl.EPackageRegistryImpl in project xtext-core by eclipse.

the class XtextPlatformResourceURIHandlerTest method testDontDeresolvePackageNamesEvenThoughTheyLookLikeRelativeURIs.

@Test
public void testDontDeresolvePackageNamesEvenThoughTheyLookLikeRelativeURIs() {
    EPackageRegistryImpl registry = new EPackageRegistryImpl(uriHandler.getResourceSet().getPackageRegistry());
    uriHandler.getResourceSet().setPackageRegistry(registry);
    registry.put("foo.bar", EcorePackage.eINSTANCE);
    uriHandler.setBaseURI(URI.createURI("platform:/resource/org.eclipse.xtext/src/org/eclipse/xtext/Xtext.ecore"));
    assertEquals("foo.bar", uriHandler.resolve(URI.createURI("foo.bar")).toString());
    assertEquals("/foo.bar", uriHandler.resolve(URI.createURI("/foo.bar")).toString());
    assertEquals("foo.bar#/baz", uriHandler.resolve(URI.createURI("foo.bar#/baz")).toString());
    assertEquals("/foo.bar#/baz", uriHandler.resolve(URI.createURI("/foo.bar#/baz")).toString());
}
Also used : EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) Test(org.junit.Test)

Example 2 with EPackageRegistryImpl

use of org.eclipse.emf.ecore.impl.EPackageRegistryImpl in project sirius-web by eclipse-sirius.

the class EditingContextEPackageService method findDynamicEPackages.

/**
 * Returns all the EPackages defined by a Domain definition.
 */
private Stream<EPackage> findDynamicEPackages(Function<Domain, Optional<EPackage>> domainConverter) {
    ResourceSet resourceSet = new ResourceSetImpl();
    EPackageRegistryImpl ePackageRegistry = new EPackageRegistryImpl();
    this.globalEPackageRegistry.forEach(ePackageRegistry::put);
    resourceSet.setPackageRegistry(ePackageRegistry);
    var domainDocumentEntities = this.documentRepository.findAllByType(DomainPackage.eNAME, DomainPackage.eNS_URI);
    for (DocumentEntity domainDocumentEntity : domainDocumentEntities) {
        this.loadDomainDefinitions(resourceSet, domainDocumentEntity);
    }
    return resourceSet.getResources().stream().flatMap(res -> this.convertDomains(res, domainConverter));
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet)

Example 3 with EPackageRegistryImpl

use of org.eclipse.emf.ecore.impl.EPackageRegistryImpl in project sirius-web by eclipse-sirius.

the class EditingContextSearchService method findById.

@Override
public Optional<IEditingContext> findById(String editingContextId) {
    long start = System.currentTimeMillis();
    // $NON-NLS-1$
    this.logger.debug("Loading the editing context {}", editingContextId);
    AdapterFactoryEditingDomain editingDomain = new AdapterFactoryEditingDomain(this.composedAdapterFactory, new BasicCommandStack());
    ResourceSet resourceSet = editingDomain.getResourceSet();
    resourceSet.eAdapters().add(new ECrossReferenceAdapter());
    EPackageRegistryImpl ePackageRegistry = new EPackageRegistryImpl();
    this.globalEPackageRegistry.forEach(ePackageRegistry::put);
    List<EPackage> additionalEPackages = this.editingContextEPackageService.getEPackages(editingContextId);
    additionalEPackages.forEach(ePackage -> ePackageRegistry.put(ePackage.getNsURI(), ePackage));
    resourceSet.setPackageRegistry(ePackageRegistry);
    List<DocumentEntity> documentEntities = new IDParser().parse(editingContextId).map(this.documentRepository::findAllByProjectId).orElseGet(List::of);
    for (DocumentEntity documentEntity : documentEntities) {
        URI uri = URI.createURI(documentEntity.getId().toString());
        JsonResource resource = new SiriusWebJSONResourceFactoryImpl().createResource(uri);
        try (var inputStream = new ByteArrayInputStream(documentEntity.getContent().getBytes())) {
            resourceSet.getResources().add(resource);
            resource.load(inputStream, null);
            resource.eAdapters().add(new DocumentMetadataAdapter(documentEntity.getName()));
        } catch (IOException | IllegalArgumentException exception) {
            // $NON-NLS-1$
            this.logger.warn("An error occured while loading document {}: {}.", documentEntity.getId(), exception.getMessage());
            resourceSet.getResources().remove(resource);
        }
    }
    // $NON-NLS-1$
    this.logger.debug("{} documents loaded for the editing context {}", resourceSet.getResources().size(), editingContextId);
    long end = System.currentTimeMillis();
    this.timer.record(end - start, TimeUnit.MILLISECONDS);
    return Optional.of(new EditingContext(editingContextId, editingDomain));
}
Also used : AdapterFactoryEditingDomain(org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain) DocumentMetadataAdapter(org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter) JsonResource(org.eclipse.sirius.emfjson.resource.JsonResource) BasicCommandStack(org.eclipse.emf.common.command.BasicCommandStack) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) EPackage(org.eclipse.emf.ecore.EPackage) ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) ByteArrayInputStream(java.io.ByteArrayInputStream) IDParser(org.eclipse.sirius.web.services.api.id.IDParser) SiriusWebJSONResourceFactoryImpl(org.eclipse.sirius.components.emf.services.SiriusWebJSONResourceFactoryImpl) List(java.util.List)

Example 4 with EPackageRegistryImpl

use of org.eclipse.emf.ecore.impl.EPackageRegistryImpl in project sirius-web by eclipse-sirius.

the class EditingContextSearchServiceTests method testEditingContextWithNoDocuments.

// @formatter:on
@Test
public void testEditingContextWithNoDocuments() {
    IProjectRepository projectRepository = new NoOpProjectRepository();
    IDocumentRepository documentRepository = new NoOpDocumentRepository();
    ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory();
    EPackage.Registry ePackageRegistry = new EPackageRegistryImpl();
    ePackageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
    String projectId = UUID.randomUUID().toString();
    IEditingContextEPackageService editingContextEPackageService = editingContextId -> List.of();
    IEditingContextSearchService editingContextSearchService = new EditingContextSearchService(projectRepository, documentRepository, editingContextEPackageService, composedAdapterFactory, ePackageRegistry, new SimpleMeterRegistry());
    IEditingContext editingContext = editingContextSearchService.findById(projectId).get();
    assertThat(editingContext).isInstanceOf(EditingContext.class);
    EditingDomain editingDomain = ((EditingContext) editingContext).getDomain();
    assertThat(editingDomain.getResourceSet().getResources()).hasSize(0);
}
Also used : IProjectRepository(org.eclipse.sirius.web.persistence.repositories.IProjectRepository) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) DocumentMetadataAdapter(org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter) URI(org.eclipse.emf.common.util.URI) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) EcorePackage(org.eclipse.emf.ecore.EcorePackage) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UUID(java.util.UUID) IProjectRepository(org.eclipse.sirius.web.persistence.repositories.IProjectRepository) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) EPackage(org.eclipse.emf.ecore.EPackage) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) Test(org.junit.jupiter.api.Test) List(java.util.List) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) Resource(org.eclipse.emf.ecore.resource.Resource) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) EPackage(org.eclipse.emf.ecore.EPackage) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) Test(org.junit.jupiter.api.Test)

Example 5 with EPackageRegistryImpl

use of org.eclipse.emf.ecore.impl.EPackageRegistryImpl in project sirius-web by eclipse-sirius.

the class EditingContextSearchServiceTests method testEditingContextWithDocuments.

@Test
public void testEditingContextWithDocuments() {
    UUID projectId = UUID.randomUUID();
    ProjectEntity projectEntity = new ProjectEntity();
    projectEntity.setId(projectId);
    // $NON-NLS-1$
    projectEntity.setName("");
    DocumentEntity firstDocumentEntity = new DocumentEntity();
    firstDocumentEntity.setId(UUID.randomUUID());
    // $NON-NLS-1$
    firstDocumentEntity.setName("First Document");
    firstDocumentEntity.setProject(projectEntity);
    firstDocumentEntity.setContent(CONTENT);
    DocumentEntity secondDocumentEntity = new DocumentEntity();
    secondDocumentEntity.setId(UUID.randomUUID());
    // $NON-NLS-1$
    secondDocumentEntity.setName("Second Document");
    secondDocumentEntity.setProject(projectEntity);
    secondDocumentEntity.setContent(CONTENT);
    IProjectRepository projectRepository = new NoOpProjectRepository();
    IDocumentRepository documentRepository = new NoOpDocumentRepository() {

        @Override
        public List<DocumentEntity> findAllByProjectId(UUID projectId) {
            return List.of(firstDocumentEntity, secondDocumentEntity);
        }
    };
    ComposedAdapterFactory composedAdapterFactory = new ComposedAdapterFactory();
    EPackage.Registry ePackageRegistry = new EPackageRegistryImpl();
    ePackageRegistry.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE);
    IEditingContextEPackageService editingContextEPackageService = editingContextId -> List.of();
    IEditingContextSearchService editingContextSearchService = new EditingContextSearchService(projectRepository, documentRepository, editingContextEPackageService, composedAdapterFactory, ePackageRegistry, new SimpleMeterRegistry());
    IEditingContext editingContext = editingContextSearchService.findById(projectId.toString()).get();
    assertThat(editingContext).isInstanceOf(EditingContext.class);
    EditingDomain editingDomain = ((EditingContext) editingContext).getDomain();
    assertThat(editingDomain.getResourceSet().getResources()).hasSize(2);
    Resource firstResource = editingDomain.getResourceSet().getResource(URI.createURI(firstDocumentEntity.getId().toString()), true);
    this.assertProperResourceLoading(firstResource, firstDocumentEntity);
    Resource secondResource = editingDomain.getResourceSet().getResource(URI.createURI(secondDocumentEntity.getId().toString()), true);
    this.assertProperResourceLoading(secondResource, secondDocumentEntity);
}
Also used : IProjectRepository(org.eclipse.sirius.web.persistence.repositories.IProjectRepository) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) DocumentMetadataAdapter(org.eclipse.sirius.web.services.documents.DocumentMetadataAdapter) URI(org.eclipse.emf.common.util.URI) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) EcorePackage(org.eclipse.emf.ecore.EcorePackage) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UUID(java.util.UUID) IProjectRepository(org.eclipse.sirius.web.persistence.repositories.IProjectRepository) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) EPackage(org.eclipse.emf.ecore.EPackage) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) Test(org.junit.jupiter.api.Test) List(java.util.List) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) ECrossReferenceAdapter(org.eclipse.emf.ecore.util.ECrossReferenceAdapter) Resource(org.eclipse.emf.ecore.resource.Resource) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Resource(org.eclipse.emf.ecore.resource.Resource) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) IEditingContextEPackageService(org.eclipse.sirius.components.emf.services.IEditingContextEPackageService) EditingDomain(org.eclipse.emf.edit.domain.EditingDomain) EPackage(org.eclipse.emf.ecore.EPackage) IDocumentRepository(org.eclipse.sirius.web.persistence.repositories.IDocumentRepository) DocumentEntity(org.eclipse.sirius.web.persistence.entities.DocumentEntity) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) IEditingContext(org.eclipse.sirius.components.core.api.IEditingContext) EditingContext(org.eclipse.sirius.components.emf.services.EditingContext) ProjectEntity(org.eclipse.sirius.web.persistence.entities.ProjectEntity) EPackageRegistryImpl(org.eclipse.emf.ecore.impl.EPackageRegistryImpl) IEditingContextSearchService(org.eclipse.sirius.components.core.api.IEditingContextSearchService) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Aggregations

EPackageRegistryImpl (org.eclipse.emf.ecore.impl.EPackageRegistryImpl)12 EPackage (org.eclipse.emf.ecore.EPackage)9 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 URI (org.eclipse.emf.common.util.URI)5 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)5 ECrossReferenceAdapter (org.eclipse.emf.ecore.util.ECrossReferenceAdapter)5 Resource (org.eclipse.emf.ecore.resource.Resource)4 ComposedAdapterFactory (org.eclipse.emf.edit.provider.ComposedAdapterFactory)4 DocumentEntity (org.eclipse.sirius.web.persistence.entities.DocumentEntity)4 Test (org.junit.jupiter.api.Test)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 List (java.util.List)3 BasicCommandStack (org.eclipse.emf.common.command.BasicCommandStack)3 XMIResourceImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl)3 AdapterFactoryEditingDomain (org.eclipse.emf.edit.domain.AdapterFactoryEditingDomain)3 IEditingContext (org.eclipse.sirius.components.core.api.IEditingContext)3 EditingContext (org.eclipse.sirius.components.emf.services.EditingContext)3 SiriusWebJSONResourceFactoryImpl (org.eclipse.sirius.components.emf.services.SiriusWebJSONResourceFactoryImpl)3 JsonResource (org.eclipse.sirius.emfjson.resource.JsonResource)3