use of org.eclipse.emf.ecore.resource.Resource 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();
}
}
use of org.eclipse.emf.ecore.resource.Resource 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();
}
use of org.eclipse.emf.ecore.resource.Resource in project benchmarx by eMoflon.
the class NMFFamiliesToPersonsIncremental method loadModel.
@SuppressWarnings("unchecked")
private <M> M loadModel(String path, ResourceSet resourceSet) {
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
Resource resource = resourceSet.createResource(URI.createFileURI(path));
try {
resource.load(null);
} catch (IOException e) {
e.printStackTrace();
}
return (M) resource.getContents().get(0);
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class AbstractXtendTestCase method file.
protected XtendFile file(String string, boolean validate, boolean shouldBeSyntacticallyValid) throws Exception {
XtextResourceSet set = getResourceSet();
String fileName = getFileName(string);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new StringInputStream(string), null);
if (shouldBeSyntacticallyValid) {
assertEquals(resource.getErrors().toString(), 0, resource.getErrors().size());
}
if (validate) {
List<Issue> issues = Lists.newArrayList(Iterables.filter(((XtextResource) resource).getResourceServiceProvider().getResourceValidator().validate(resource, CheckMode.ALL, CancelIndicator.NullImpl), new Predicate<Issue>() {
@Override
public boolean apply(Issue issue) {
return issue.getSeverity() == Severity.ERROR;
}
}));
assertTrue("Resource contained errors : " + issues.toString(), issues.isEmpty());
}
XtendFile file = (XtendFile) resource.getContents().get(0);
return file;
}
use of org.eclipse.emf.ecore.resource.Resource in project xtext-xtend by eclipse.
the class AbstractXtendTestCase method fileWithErrors.
protected XtendFile fileWithErrors(String string) throws Exception {
XtextResourceSet set = getResourceSet();
String fileName = getFileName(string);
Resource resource = set.createResource(URI.createURI(fileName + ".xtend"));
resource.load(new StringInputStream(string), null);
assertTrue(resource.getErrors().toString(), resource.getErrors().size() > 0);
XtendFile file = (XtendFile) resource.getContents().get(0);
return file;
}
Aggregations