Search in sources :

Example 51 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class ClassloaderClasspathUriResolverTest method normalizeUriAndLoadResource.

private void normalizeUriAndLoadResource(URI classpathUri, String expectedUri) {
    URI normalizedUri = _resolver.resolve(getClass().getClassLoader(), classpathUri);
    assertEquals(expectedUri, normalizedUri.toString());
    ResourceSet resourceSet = new ResourceSetImpl();
    System.out.println(normalizedUri);
    Resource resource = resourceSet.getResource(normalizedUri, true);
    assertNotNull("Classpth URI ot registered", resource);
    assertTrue("Resource not loaded", resource.isLoaded());
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) URI(org.eclipse.emf.common.util.URI)

Example 52 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class ConcurrentAccessTest method testMultiThreadedUnitOfWork.

@Ignore
@Test
public void testMultiThreadedUnitOfWork() throws InterruptedException {
    ResourceSet resourceSet = new XtextResourceSet();
    resourceSet.getResources().add(resource);
    boolean wasOk = resolveAllReferencesStateAccess((EPackage) resource.getContents().get(0));
    if (wasOk)
        assertFalse(101 == resourceSet.getResources().size());
    assertFalse("unresolvedProxy", wasOk);
}
Also used : ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 53 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class ConcurrentAccessTest method setUp.

@Before
public void setUp() throws Exception {
    globalStateMemento = GlobalRegistries.makeCopyOfGlobalState();
    EPackage.Registry.INSTANCE.put(XMLTypePackage.eNS_URI, XMLTypePackage.eINSTANCE);
    ResourceSet resourceSet = new ResourceSetImpl();
    resource = new XtextResource(URI.createFileURI("something.ecore"));
    resourceSet.getResources().add(resource);
    EPackage start = EcoreFactory.eINSTANCE.createEPackage();
    resource.getContents().add(start);
    for (int i = 0; i < 100; i++) {
        File tempFile = temporaryFolder.createTempFile("Package" + i, ".ecore");
        URI fileURI = URI.createFileURI(tempFile.getAbsolutePath());
        Resource toBeProxified = resourceSet.createResource(fileURI);
        EPackage ePackage = EcoreFactory.eINSTANCE.createEPackage();
        ePackage.setNsURI("http://www.test.me/" + i);
        toBeProxified.getContents().add(ePackage);
        for (int j = 0; j < 100; j++) {
            EAnnotation annotation = EcoreFactory.eINSTANCE.createEAnnotation();
            annotation.setSource("Source" + j);
            start.getEAnnotations().add(annotation);
            EClass superClass = EcoreFactory.eINSTANCE.createEClass();
            superClass.setName("SuperClass" + j);
            ePackage.getEClassifiers().add(superClass);
            annotation.getReferences().add(superClass);
        }
        toBeProxified.save(null);
    }
    EcoreUtil.resolveAll(resourceSet);
    for (int i = 100; i >= 1; i--) {
        Resource toBeProxified = resourceSet.getResources().get(i);
        toBeProxified.unload();
        resourceSet.getResources().remove(toBeProxified);
    }
}
Also used : EAnnotation(org.eclipse.emf.ecore.EAnnotation) EClass(org.eclipse.emf.ecore.EClass) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) File(java.io.File) URI(org.eclipse.emf.common.util.URI) EPackage(org.eclipse.emf.ecore.EPackage) Before(org.junit.Before)

Example 54 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class AbstractLiveContainerTest method testGlobalScope.

@Test
public void testGlobalScope() throws Exception {
    EReference ref = createRefToRoot();
    ResourceSet resourceSet = new XtextResourceSet();
    Resource res = parse("local", resourceSet).eResource();
    parse("other", resourceSet);
    assertEquals("other", format(scopeProvider.getScope(res, ref).getAllElements()));
    Resource foo = parse("foo", resourceSet).eResource();
    assertEquals("foo, other", format(scopeProvider.getScope(res, ref).getAllElements()));
    resourceSet.getResources().remove(foo);
    assertEquals("other", format(scopeProvider.getScope(res, ref).getAllElements()));
}
Also used : XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 55 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project xtext-core by eclipse.

the class AbstractLiveContainerTest method testContainerLoadUnload.

@Test
public void testContainerLoadUnload() throws Exception {
    ResourceSet resourceSet = new XtextResourceSet();
    Resource res = parse("local", resourceSet).eResource();
    Resource foo = resourceSet.createResource(computeUnusedUri(resourceSet));
    IResourceDescription resourceDescription = descriptionManager.getResourceDescription(res);
    IResourceDescriptions resourceDescriptions = descriptionsProvider.getResourceDescriptions(res);
    List<IContainer> containers = containerManager.getVisibleContainers(resourceDescription, resourceDescriptions);
    assertEquals(1, containers.size());
    IContainer container = containers.get(0);
    // assertEquals("local", format(container.getExportedObjects()));
    foo.load(new StringInputStream("foo"), null);
    assertEquals("foo, local", format(container.getExportedObjects()));
// foo.unload();
// assertEquals("local", format(container.getExportedObjects()));
}
Also used : StringInputStream(org.eclipse.xtext.util.StringInputStream) IResourceDescription(org.eclipse.xtext.resource.IResourceDescription) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IContainer(org.eclipse.xtext.resource.IContainer) Test(org.junit.Test)

Aggregations

ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)123 Resource (org.eclipse.emf.ecore.resource.Resource)71 Test (org.junit.Test)51 EObject (org.eclipse.emf.ecore.EObject)34 URI (org.eclipse.emf.common.util.URI)32 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)32 IChangeSerializer (org.eclipse.xtext.ide.serializer.IChangeSerializer)21 InMemoryURIHandler (org.eclipse.xtext.testing.util.InMemoryURIHandler)21 IEmfResourceChange (org.eclipse.xtext.ide.serializer.IEmfResourceChange)20 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)17 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)17 XtextResource (org.eclipse.xtext.resource.XtextResource)16 EPackage (org.eclipse.emf.ecore.EPackage)12 IFile (org.eclipse.core.resources.IFile)10 Node (org.eclipse.xtext.ide.tests.testlanguage.partialSerializationTestLanguage.Node)10 ArrayList (java.util.ArrayList)9 EClass (org.eclipse.emf.ecore.EClass)9 ChangeSerializer (org.eclipse.xtext.ide.serializer.impl.ChangeSerializer)9 IOException (java.io.IOException)8 XtendFile (org.eclipse.xtend.core.xtend.XtendFile)8