use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.
the class RefactoringWorkspaceTest method testChangeNamespaceIgnoringSpecificNamespace.
@Test
public void testChangeNamespaceIgnoringSpecificNamespace() {
IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("dsls/Brightness.type"), ModelType.Datatype).addFile(getClass().getClassLoader().getResourceAsStream("dsls/Dimmer.type"), ModelType.Datatype).addFile(getClass().getClassLoader().getResourceAsStream("dsls/Color.fbmodel"), ModelType.Functionblock).read();
ChangeSet changeSet = RefactoringTask.from(workspace).toNamespaceForAllModels("private.vorto.alex", "org.eclipse.vorto").execute();
assertEquals(3, changeSet.get().size());
assertEquals(2, changeSet.getChanges().size());
FunctionblockModel color = (FunctionblockModel) changeSet.get().stream().filter(m -> m.getName().equals("Color")).findFirst().get();
assertEquals("org.eclipse.vorto", color.getNamespace());
}
use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.
the class RefactoringWorkspaceTest method testChangeNamespaceWithoutReferences.
@Test
public void testChangeNamespaceWithoutReferences() {
IModelWorkspace workspace = IModelWorkspace.newReader().addFile(getClass().getClassLoader().getResourceAsStream("dsls/Brightness.type"), ModelType.Datatype).read();
ChangeSet changeSet = RefactoringTask.from(workspace).toNamespaceForAllModels("private.vorto.alex").execute();
assertEquals(1, changeSet.get().size());
assertEquals(1, changeSet.getChanges().size());
assertEquals("private.vorto.alex.iot", changeSet.get().get(0).getNamespace());
}
use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.
the class VortoModelImporter method refactor.
private FileUpload refactor(FileUpload fileUpload, String targetNamespace) {
IModelWorkspace workspace = IModelWorkspace.newReader().addFile(new ByteArrayInputStream(fileUpload.getContent()), ModelType.fromFileName(fileUpload.getFileName())).read();
ChangeSet changeSet = RefactoringTask.from(workspace).toNamespaceForAllModels(targetNamespace).execute();
ModelResource resource = new ModelResource(changeSet.get().get(0));
return FileUpload.create(fileUpload.getFileName(), resource.toDSL());
}
use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.
the class VortoModelImporter method preValidation.
/**
* changes the namespace of the uploaded vorto model(s) , if target namespace is specified
*/
@Override
protected FileUpload preValidation(FileUpload fileUpload, Context context) {
if (context.getTargetNamespace().isPresent()) {
if (fileUpload.getFileExtension().endsWith(EXTENSION_ZIP)) {
ModelWorkspaceReader reader = IModelWorkspace.newReader();
getUploadedFilesFromZip(fileUpload.getContent()).stream().filter(this::isSupported).forEach(extractedFile -> {
reader.addFile(new ByteArrayInputStream(addVortolangIfMissing(extractedFile).getContent()), ModelType.fromFileName(extractedFile.getFileExtension()));
});
IModelWorkspace workspace = reader.read();
ChangeSet changeSet = RefactoringTask.from(workspace).toNamespaceForAllModels(context.getTargetNamespace().get()).execute();
ZipUploadFile zipFile = new ZipUploadFile(fileUpload.getFileName());
for (Model model : changeSet.get()) {
ModelResource resource = new ModelResource(model);
zipFile.addToZip(FileUpload.create(resource.getId().getPrettyFormat().replace("\\.", "_") + resource.getType().getExtension(), resource.toDSL()));
}
return zipFile.getFileUpload();
} else {
return refactor(addVortolangIfMissing(fileUpload), context.getTargetNamespace().get());
}
} else {
return addVortolangIfMissing(fileUpload);
}
}
use of org.eclipse.vorto.utilities.reader.IModelWorkspace in project vorto by eclipse.
the class EclipseDittoGeneratorTest method inheritanceFunctionBlockProvider.
public InformationModel inheritanceFunctionBlockProvider(String rootFunctionBlockName, String... functionBlocks) {
ModelWorkspaceReader mwr = IModelWorkspace.newReader();
for (String parentFb : functionBlocks) {
mwr.addFile(getClass().getClassLoader().getResourceAsStream(folderPath + parentFb), ModelType.Functionblock);
}
IModelWorkspace workspace = mwr.read();
FunctionblockModel fb = (FunctionblockModel) workspace.get().stream().filter(p -> p.getName().equals(rootFunctionBlockName)).findAny().get();
return Utils.toInformationModel(fb);
}
Aggregations