Search in sources :

Example 6 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project benchmarx by eMoflon.

the class EMoflonFamiliesToPersons method saveModels.

public void saveModels(String name) {
    ResourceSet set = new ResourceSetImpl();
    set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    URI srcURI = URI.createFileURI(RESULTPATH + "/" + name + "Family.xmi");
    URI trgURI = URI.createFileURI(RESULTPATH + "/" + name + "Person.xmi");
    Resource resSource = set.createResource(srcURI);
    Resource resTarget = set.createResource(trgURI);
    EObject colSource = EcoreUtil.copy(getSourceModel());
    EObject colTarget = EcoreUtil.copy(getTargetModel());
    resSource.getContents().add(colSource);
    resTarget.getContents().add(colTarget);
    try {
        resSource.save(null);
        resTarget.save(null);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI)

Example 7 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project benchmarx by eMoflon.

the class MediniQVTFamiliesToPersons method saveModels.

/**
	 * Allows to save the current state of the source and target models
	 * 
	 * @param name : Filename 
	 */
public void saveModels(String name) {
    ResourceSet set = new ResourceSetImpl();
    set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    URI srcURI = URI.createFileURI(RESULTPATH + "/" + name + "Family.xmi");
    URI trgURI = URI.createFileURI(RESULTPATH + "/" + name + "Person.xmi");
    Resource resSource = set.createResource(srcURI);
    Resource resTarget = set.createResource(trgURI);
    EObject colSource = EcoreUtil.copy(getSourceModel());
    EObject colTarget = EcoreUtil.copy(getTargetModel());
    resSource.getContents().add(colSource);
    resTarget.getContents().add(colTarget);
    try {
        resSource.save(null);
        resTarget.save(null);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI)

Example 8 with ResourceSet

use of org.eclipse.emf.ecore.resource.ResourceSet in project benchmarx by eMoflon.

the class UbtXtendFamiliesToPersons method saveModels.

/**
	 * Allows to save the current state of the source and target models
	 * 
	 * @param name : Filename 
	 */
@Override
public void saveModels(String name) {
    ResourceSet set = new ResourceSetImpl();
    set.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    URI srcURI = URI.createFileURI(RESULTPATH + "/" + name + "Family.xmi");
    URI trgURI = URI.createFileURI(RESULTPATH + "/" + name + "Person.xmi");
    Resource resSource = set.createResource(srcURI);
    Resource resTarget = set.createResource(trgURI);
    EObject colSource = EcoreUtil.copy(getSourceModel());
    EObject colTarget = EcoreUtil.copy(getTargetModel());
    resSource.getContents().add(colSource);
    resTarget.getContents().add(colTarget);
    try {
        resSource.save(null);
        resTarget.save(null);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) EObject(org.eclipse.emf.ecore.EObject) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI)

Example 9 with ResourceSet

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

the class AbstractSmokeTest method doParseAndCheckForSmokeWithoutResourceSet.

protected void doParseAndCheckForSmokeWithoutResourceSet(final String model) throws Exception {
    try {
        LazyLinkingResource resource = createResource(model);
        // simulate closed editor
        ResourceSet resourceSet = resource.getResourceSet();
        resourceSet.eSetDeliver(false);
        resourceSet.getResources().clear();
        resourceSet.eAdapters().clear();
        checkForSmoke(model, resource);
    } catch (Throwable e) {
        e.printStackTrace();
        assertEquals(e.getMessage() + " : Model was : \n\n" + model, model, "");
        // just to make sure we fail for empty model, too
        fail(e.getMessage() + " : Model was : \n\n" + model);
    }
}
Also used : LazyLinkingResource(org.eclipse.xtext.linking.lazy.LazyLinkingResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet)

Example 10 with ResourceSet

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

the class ProcessorInstanceForJvmTypeProvider method getClassLoader.

public ClassLoader getClassLoader(final EObject ctx) {
    final ResourceSet resourceSet = ctx.eResource().getResourceSet();
    final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter = IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(resourceSet.eAdapters(), ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class));
    if ((adapter != null)) {
        return adapter.getClassLoader();
    }
    boolean _matched = false;
    if (resourceSet instanceof XtextResourceSet) {
        _matched = true;
        final Object classLoaderCtx = ((XtextResourceSet) resourceSet).getClasspathURIContext();
        ClassLoader _switchResult_1 = null;
        boolean _matched_1 = false;
        if (classLoaderCtx instanceof ClassLoader) {
            _matched_1 = true;
            _switchResult_1 = ((ClassLoader) classLoaderCtx);
        }
        if (!_matched_1) {
            if (classLoaderCtx instanceof Class) {
                _matched_1 = true;
                _switchResult_1 = ((Class<?>) classLoaderCtx).getClassLoader();
            }
        }
        final ClassLoader jvmTypeLoader = _switchResult_1;
        ClassLoader _xifexpression = null;
        if ((jvmTypeLoader instanceof URLClassLoader)) {
            URLClassLoader _xblockexpression = null;
            {
                final ArrayList<URL> urls = CollectionLiterals.<URL>newArrayList();
                URL[] _uRLs = ((URLClassLoader) jvmTypeLoader).getURLs();
                Iterables.<URL>addAll(urls, ((Iterable<? extends URL>) Conversions.doWrapArray(_uRLs)));
                final ClassLoader bootClassloader = ((URLClassLoader) jvmTypeLoader).getParent();
                if ((bootClassloader instanceof AlternateJdkLoader)) {
                    URL[] _uRLs_1 = ((AlternateJdkLoader) bootClassloader).getURLs();
                    Iterables.<URL>addAll(urls, ((Iterable<? extends URL>) Conversions.doWrapArray(_uRLs_1)));
                }
                ClassLoader _classLoader = TransformationContext.class.getClassLoader();
                final FilteringClassLoader filtered = new FilteringClassLoader(_classLoader, Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("org.eclipse.xtext.xbase.lib", "org.eclipse.xtend.lib", "org.eclipse.xtend2.lib", "com.google.common")));
                _xblockexpression = new URLClassLoader(((URL[]) Conversions.unwrapArray(urls, URL.class)), filtered);
            }
            _xifexpression = _xblockexpression;
        } else {
            _xifexpression = jvmTypeLoader;
        }
        final ClassLoader processorClassLoader = _xifexpression;
        if ((processorClassLoader != null)) {
            EList<Adapter> _eAdapters = ((XtextResourceSet) resourceSet).eAdapters();
            ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter = new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(processorClassLoader);
            _eAdapters.add(_processorClassloaderAdapter);
            return processorClassLoader;
        }
    }
    ProcessorInstanceForJvmTypeProvider.logger.info("No class loader configured. Trying with this class classloader.");
    return this.getClass().getClassLoader();
}
Also used : AlternateJdkLoader(org.eclipse.xtext.util.internal.AlternateJdkLoader) ArrayList(java.util.ArrayList) Adapter(org.eclipse.emf.common.notify.Adapter) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) TransformationContext(org.eclipse.xtend.lib.macro.TransformationContext) URL(java.net.URL) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) URLClassLoader(java.net.URLClassLoader) FilteringClassLoader(org.eclipse.xtend.core.macro.FilteringClassLoader) URLClassLoader(java.net.URLClassLoader) FilteringClassLoader(org.eclipse.xtend.core.macro.FilteringClassLoader) EObject(org.eclipse.emf.ecore.EObject)

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