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