Search in sources :

Example 6 with ResourceSetImpl

use of org.eclipse.emf.ecore.resource.impl.ResourceSetImpl 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 7 with ResourceSetImpl

use of org.eclipse.emf.ecore.resource.impl.ResourceSetImpl 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 8 with ResourceSetImpl

use of org.eclipse.emf.ecore.resource.impl.ResourceSetImpl in project tdi-studio-se by Talend.

the class TestComponentsAction method generateCode.

public void generateCode(File[] tempFile, String componentPath) {
    for (File file : tempFile) {
        if (file.length() > 0) {
            URI uri = URI.createFileURI(file.toString());
            TalendFilePackage.eINSTANCE.getNsURI();
            Resource resource = new ResourceSetImpl().getResource(uri, true);
            ProcessType processType = (ProcessType) EcoreUtil.getObjectByType(resource.getContents(), TalendFilePackage.eINSTANCE.getProcessType());
            IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
            ProcessItem item = PropertiesFactory.eINSTANCE.createProcessItem();
            item.setProcess(processType);
            item.setProperty(PropertiesFactory.eINSTANCE.createProperty());
            item.getProperty().setLabel(TestParameter.TEST_DIR);
            item.getProperty().setAuthor(PropertiesFactory.eINSTANCE.createUser());
            item.getProperty().setId(file.getName());
            item.getProperty().setStatusCode(file.getName());
            item.getProperty().setVersion(TestParameter.VERSION);
            IProcess process = service.getProcessFromProcessItem(item);
            setDefaultProperties(process, componentPath);
            IProcessor processor = ProcessorUtilities.getProcessor(process, item.getProperty(), process.getContextManager().getDefaultContext());
            try {
                // generate
                //$NON-NLS-1$
                log.info(TestParameter.GENERATE_START + " : " + file.getName());
                // processor.generateCode(process.getContextManager().getDefaultContext(), false, false, true);
                processor.generateCode(false, false, true);
                //$NON-NLS-1$
                log.info(TestParameter.GENERATE_END + " : " + file.getName());
                // run
                //$NON-NLS-1$
                log.info(TestParameter.RUN_START + " : " + file.getName());
                java.lang.Process runningProcess = processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
                StringBuffer errBuff = new StringBuffer();
                if (isRunOK(runningProcess, errBuff)) {
                    //$NON-NLS-1$
                    log.info(TestParameter.RUN_SUCCESS + " : " + file.getName());
                } else {
                    // 2 possibilities : OK not found / error stream
                    //$NON-NLS-1$
                    log.error(TestParameter.RUN_FAIL + " : " + file.getName(), new Exception(errBuff.toString()));
                }
            } catch (ProcessorException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) ProcessorException(org.talend.designer.runprocess.ProcessorException) Resource(org.eclipse.emf.ecore.resource.Resource) IProcessor(org.talend.designer.runprocess.IProcessor) URI(org.eclipse.emf.common.util.URI) ProcessorException(org.talend.designer.runprocess.ProcessorException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProcessItem(org.talend.core.model.properties.ProcessItem) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) File(java.io.File) IProcess(org.talend.core.model.process.IProcess)

Example 9 with ResourceSetImpl

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

the class MediniQVTFamiliesToPersonsConfig 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)

Aggregations

Resource (org.eclipse.emf.ecore.resource.Resource)9 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)9 URI (org.eclipse.emf.common.util.URI)7 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)6 XMIResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)6 IOException (java.io.IOException)5 EObject (org.eclipse.emf.ecore.EObject)5 File (java.io.File)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 EPackage (org.eclipse.emf.ecore.EPackage)2 FileNotFoundException (java.io.FileNotFoundException)1 Decisions (org.benchmarx.examples.familiestopersons.testsuite.Decisions)1 WrappedException (org.eclipse.emf.common.util.WrappedException)1 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)1 IDialogSettings (org.eclipse.jface.dialogs.IDialogSettings)1 Wizard (org.eclipse.jface.wizard.Wizard)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 IProcess (org.talend.core.model.process.IProcess)1 ProcessItem (org.talend.core.model.properties.ProcessItem)1