Search in sources :

Example 16 with URI

use of org.eclipse.emf.common.util.URI 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 17 with URI

use of org.eclipse.emf.common.util.URI 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 18 with URI

use of org.eclipse.emf.common.util.URI in project benchmarx by eMoflon.

the class MediniQVTFamiliesToPersonsConfig method initiateSynchronisationDialogue.

/**
	 * Initiates a synchronization between a source and a target model. The medini QVT engine is initialized,
	 * the required metamodels are registered and empty source, target and configuration models are created.
	 * Finally a FamilyRegister is added to the source model and an initial forward transformation is issued
	 * to create a corresponding PersonRegister.
	 */
@Override
public void initiateSynchronisationDialogue() {
    // delete content of traces folder
    File tracesFolder = new File("./src/org/benchmarx/examples/familiestopersons/implementations/medini/base/traces");
    final File[] files = tracesFolder.listFiles();
    if (files != null) {
        for (File f : files) {
            if (f != null)
                f.delete();
        }
    }
    // in case, no configuration is set, switch to default
    checkConfiguration();
    // Initialise resource set of models
    this.resourceSet = new ResourceSetImpl();
    this.resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
    // Collect all necessary packages from the metamodel(s)
    Collection<EPackage> metaPackages = new ArrayList<EPackage>();
    this.collectMetaModels(metaPackages);
    // Make these packages known to the QVT engine
    init(metaPackages);
    // Create resources for models
    source = resourceSet.createResource(URI.createURI(RESULTPATH + "/source.xmi"));
    config = resourceSet.createResource(URI.createURI(RESULTPATH + "/config.xmi"));
    target = resourceSet.createResource(URI.createURI(RESULTPATH + "/target.xmi"));
    // Collect the models, which should participate in the transformation.
    // You can provide a list of models for each direction.
    // The models must be added in the same order as defined in your transformation!
    Collection<Collection<Resource>> modelResources = new ArrayList<Collection<Resource>>();
    Collection<Resource> firstSetOfModels = new ArrayList<Resource>();
    Collection<Resource> secondSetOfModels = new ArrayList<Resource>();
    Collection<Resource> thirdSetOfModels = new ArrayList<Resource>();
    modelResources.add(firstSetOfModels);
    modelResources.add(secondSetOfModels);
    modelResources.add(thirdSetOfModels);
    firstSetOfModels.add(source);
    secondSetOfModels.add(config);
    thirdSetOfModels.add(target);
    URI directory = URI.createFileURI(basePath + "traces");
    this.preExecution(modelResources, directory);
    // Call setConfigurator, which will initialize the configurator with default decisions
    setConfigurator(new Configurator<Decisions>());
    source.getContents().add(FamiliesFactory.eINSTANCE.createFamilyRegister());
    config.getContents().add(ConfigFactory.eINSTANCE.createConfiguration());
    launchFWD();
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) Decisions(org.benchmarx.examples.familiestopersons.testsuite.Decisions) URI(org.eclipse.emf.common.util.URI) EPackage(org.eclipse.emf.ecore.EPackage) Collection(java.util.Collection) File(java.io.File)

Example 19 with URI

use of org.eclipse.emf.common.util.URI in project applause by applause.

the class ApplauseEclipseResourceFileSystemAccess2 method flushSourceTraces.

/**
	 * Can be used to announce that a builder participant is done with this file system access and
	 * all potentially recorded trace information should be persisted.
	 * @param generatorName the name of the generator. 
	 * @since 2.3
	 */
public void flushSourceTraces(String generatorName) throws CoreException {
    if (sourceTraces != null) {
        Set<URI> keys = sourceTraces.keySet();
        for (URI uri : keys) {
            if (uri.isPlatformResource()) {
                Collection<IPath> paths = sourceTraces.get(uri);
                IFile sourceFile = workspace.getRoot().getFile(new Path(uri.toPlatformString(true)));
                if (sourceFile.exists()) {
                    IPath[] tracePathArray = paths.toArray(new IPath[paths.size()]);
                    traceMarkers.installMarker(sourceFile, generatorName, tracePathArray);
                }
            }
        }
    }
    sourceTraces = null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) URI(org.eclipse.emf.common.util.URI)

Example 20 with URI

use of org.eclipse.emf.common.util.URI in project applause by applause.

the class ApplauseEclipseResourceFileSystemAccess2 method updateTraceInformation.

/**
	 * @throws CoreException if something unexpected happens during resource access
	 * @throws IOException if serialization of the trace data fails 
	 * @since 2.3
	 */
protected void updateTraceInformation(IFile traceFile, CharSequence contents, boolean derived) throws CoreException, IOException {
    if (contents instanceof ITraceRegionProvider) {
        AbstractTraceRegion traceRegion = ((ITraceRegionProvider) contents).getTraceRegion();
        if (sourceTraces == null) {
            sourceTraces = HashMultimap.create();
        }
        IPath tracePath = traceFile.getFullPath();
        Iterator<AbstractTraceRegion> iterator = traceRegion.treeIterator();
        while (iterator.hasNext()) {
            AbstractTraceRegion region = iterator.next();
            for (ILocationData location : region.getAssociatedLocations()) {
                URI path = location.getPath();
                if (path != null) {
                    sourceTraces.put(path, tracePath);
                }
            }
        }
        class AccessibleOutputStream extends ByteArrayOutputStream {

            byte[] internalBuffer() {
                return buf;
            }

            int internalLength() {
                return count;
            }
        }
        AccessibleOutputStream data = new AccessibleOutputStream();
        traceSerializer.writeTraceRegionTo(traceRegion, data);
        // avoid copying the byte array
        InputStream input = new ByteArrayInputStream(data.internalBuffer(), 0, data.internalLength());
        if (traceFile.exists()) {
            traceFile.setContents(input, false, true, monitor);
        } else {
            traceFile.create(input, true, monitor);
        }
        setDerived(traceFile, derived);
        return;
    }
    if (traceFile.exists()) {
        traceFile.delete(IResource.KEEP_HISTORY, monitor);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) StringInputStream(org.eclipse.xtext.util.StringInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AbstractTraceRegion(org.eclipse.xtext.generator.trace.AbstractTraceRegion) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ITraceRegionProvider(org.eclipse.xtext.generator.trace.ITraceRegionProvider) URI(org.eclipse.emf.common.util.URI) ILocationData(org.eclipse.xtext.generator.trace.ILocationData)

Aggregations

URI (org.eclipse.emf.common.util.URI)305 Resource (org.eclipse.emf.ecore.resource.Resource)85 Test (org.junit.Test)79 EObject (org.eclipse.emf.ecore.EObject)55 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)37 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)33 XtextResource (org.eclipse.xtext.resource.XtextResource)32 XtextResourceSet (org.eclipse.xtext.resource.XtextResourceSet)26 BuildRequest (org.eclipse.xtext.build.BuildRequest)23 File (java.io.File)20 AbstractIncrementalBuilderTest (org.eclipse.xtext.testing.builder.AbstractIncrementalBuilderTest)20 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)19 IOException (java.io.IOException)18 InternalEObject (org.eclipse.emf.ecore.InternalEObject)18 EPackage (org.eclipse.emf.ecore.EPackage)15 IResourceDescription (org.eclipse.xtext.resource.IResourceDescription)15 InputStream (java.io.InputStream)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ArrayList (java.util.ArrayList)13 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13