Search in sources :

Example 61 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.

the class SmfVisitor method getAllPackages.

private HashSet<SecModelLibrary> getAllPackages(Element root) {
    HashSet<SecModelLibrary> secLibs = new HashSet<SecModelLibrary>();
    // no need of seen set as the circular imports are not allowed
    HashSet<ModelUnit> seens = new HashSet();
    PackageSection ps = AadlUtil.getContainingPackageSection(((SystemInstance) root).getComponentClassifier());
    EList<ComponentImplementation> ais = AadlUtil.getAllComponentImpl();
    Set<ModelUnit> aps = ais.stream().flatMap(it -> AadlUtil.getContainingPackage(it).getPublicSection().getImportedUnits().stream()).collect(Collectors.toSet());
    Set<ModelUnit> worklist = aps;
    try {
        for (ModelUnit head : worklist) {
            seens.add(head);
            if (head != null && head instanceof AadlPackage) {
                secLibs.addAll(AnnexUtil.getAllActualAnnexLibraries((AadlPackage) head, SecMFPackage.eINSTANCE.getSecModelLibrary()).stream().map(al -> (SecModelLibrary) al).collect(Collectors.toList()));
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return secLibs;
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) SmfTypeDef(org.sireum.aadl.osate.securitymodel.secMF.SmfTypeDef) AnnexUtil(org.osate.annexsupport.AnnexUtil) Element(org.osate.aadl2.Element) SMFDeclassification(org.sireum.aadl.osate.securitymodel.secMF.SMFDeclassification) ComponentImplementation(org.osate.aadl2.ComponentImplementation) Name(org.sireum.hamr.ir.Name) SecMFPackage(org.sireum.aadl.osate.securitymodel.secMF.SecMFPackage) HashSet(java.util.HashSet) AnnexLib(org.sireum.hamr.ir.AnnexLib) SmfDeclass(org.sireum.hamr.ir.SmfDeclass) Classifier(org.osate.aadl2.Classifier) Annex(org.sireum.hamr.ir.Annex) SmfClassification(org.sireum.hamr.ir.SmfClassification) SystemInstance(org.osate.aadl2.instance.SystemInstance) AadlUtil(org.osate.aadl2.modelsupport.util.AadlUtil) SecModelLibrary(org.sireum.aadl.osate.securitymodel.secMF.SecModelLibrary) SecModelSubclause(org.sireum.aadl.osate.securitymodel.secMF.SecModelSubclause) PackageSection(org.osate.aadl2.PackageSection) Set(java.util.Set) AadlPackage(org.osate.aadl2.AadlPackage) SMFClassification(org.sireum.aadl.osate.securitymodel.secMF.SMFClassification) Collectors(java.util.stream.Collectors) EList(org.eclipse.emf.common.util.EList) List(java.util.List) ModelUnit(org.osate.aadl2.ModelUnit) SmfType(org.sireum.hamr.ir.SmfType) AnnexSubclause(org.osate.aadl2.AnnexSubclause) NamedElement(org.osate.aadl2.NamedElement) AadlPackage(org.osate.aadl2.AadlPackage) SecModelLibrary(org.sireum.aadl.osate.securitymodel.secMF.SecModelLibrary) PackageSection(org.osate.aadl2.PackageSection) ModelUnit(org.osate.aadl2.ModelUnit) HashSet(java.util.HashSet)

Example 62 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.

the class Phantom method getSystemInstance.

SystemInstance getSystemInstance(AadlSystem system, ResourceSet rset) {
    try {
        populateResourceSet(system.projects, rset);
        org.sireum.aadl.osate.PreferenceValues.setPROCESS_BA_OPT(true);
        SystemImplementation sysImpl = null;
        if (!system.systemFileContainer.isPresent()) {
            if (!system.isSystemNameQualified()) {
                addError("The " + AadlSystem.KEY_SYSTEM_IMPL + " property '" + system.systemImplementationName + "' must be fully qualified or the " + AadlSystem.KEY_SYSTEM_IMPL_FILE + " property must also be provided");
                return null;
            }
            for (Resource rs : rset.getResources()) {
                if (!rs.getContents().isEmpty() && rs.getContents().get(0) instanceof AadlPackage) {
                    AadlPackage candidate = (AadlPackage) rs.getContents().get(0);
                    if (candidate.getOwnedPublicSection() != null && candidate.getOwnedPublicSection().getOwnedClassifiers() != null) {
                        Classifier classCand = AadlProjectUtil.getResourceByName(system.systemImplementationName, candidate.getOwnedPublicSection().getOwnedClassifiers());
                        if (classCand != null) {
                            if (classCand instanceof SystemImplementation) {
                                sysImpl = (SystemImplementation) classCand;
                                break;
                            } else {
                                addError(system.systemImplementationName + " is a " + classCand.getClass().getSimpleName() + " rather than a system implementation");
                                return null;
                            }
                        }
                    }
                }
            }
        } else {
            Resource sysImplResource = null;
            String candURI = "platform:/resource/" + system.systemFileContainer.get().proj.projectName + "/" + system.systemFileContainer.get().getProjectRelativeURI();
            for (Resource rs : rset.getResources()) {
                if (debugging) {
                    System.out.println("rs.getURI: " + rs.getURI().toString());
                    System.out.println("  candURI: " + candURI);
                    System.out.println();
                }
                if (rs.getURI().toString().equals(candURI)) {
                    sysImplResource = rs;
                    break;
                }
            }
            if (sysImplResource == null || sysImplResource.getContents().isEmpty() || !(sysImplResource.getContents().get(0) instanceof AadlPackage)) {
                addError("Couldn't find an AadlPackage in " + system.systemFileContainer.get().systemImplementationFile);
                return null;
            }
            AadlPackage pkg = (AadlPackage) (sysImplResource.getContents().get(0));
            if (pkg.getOwnedPublicSection() == null || pkg.getOwnedPublicSection().getOwnedClassifiers() == null) {
                addError("Couldn't find public classifiers in " + pkg.getQualifiedName());
                return null;
            }
            Classifier cand = AadlProjectUtil.getResourceByName(system.systemImplementationName, pkg.getOwnedPublicSection().getOwnedClassifiers());
            if (cand == null || !(cand instanceof SystemImplementation)) {
                addError(system.systemImplementationName + " not found in package " + pkg.getQualifiedName() + " or it isn't a system implementation");
                return null;
            }
            sysImpl = (SystemImplementation) cand;
        }
        if (sysImpl != null) {
            addInfo("Processing: " + system.systemImplementationName);
            return InstantiateModel.instantiate(sysImpl);
        } else {
            String msg = "Unable to find a system implementation named " + system.systemImplementationName + (system.systemFileContainer.isPresent() ? " in file " + system.systemFileContainer.get().systemImplementationFile : "");
            addError(msg);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) SystemImplementation(org.osate.aadl2.SystemImplementation) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Classifier(org.osate.aadl2.Classifier) IOException(java.io.IOException)

Example 63 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.

the class Phantom method phantom.

int phantom(SireumHamrPhantomOption po, ResourceSet rs) {
    boolean userProvided = po.getProjects().nonEmpty() && po.getMain().nonEmpty() && po.getImpl().nonEmpty();
    if (// XOR, only one should be true
    (userProvided == po.getArgs().nonEmpty()) || (po.getArgs().nonEmpty() && (po.getProjects().nonEmpty() || po.getMain().nonEmpty() || po.getImpl().nonEmpty()))) {
        addError("Either point to a directory or supply the required options\n");
        printUsage("hamr", "phantom", "-h");
        return 1;
    }
    AadlSystem system = null;
    if (userProvided) {
        File mainPackageFile = new File(po.getMain().get().string());
        List<File> projRoots = VisitorUtil.isz2IList(po.getProjects()).stream().map(m -> new File(m.string())).collect(Collectors.toList());
        for (File projectRoot : projRoots) {
            if (!projectRoot.exists() || !projectRoot.isDirectory()) {
                addError(projectRoot + " does not exist or is not a directory");
                return 1;
            }
        }
        List<AadlProject> projects = projRoots.stream().map(m -> AadlProjectUtil.createAadlProject(m)).collect(Collectors.toList());
        String sysImplName = po.getImpl().get().string();
        system = AadlSystem.makeAadlSystem(sysImplName, Optional.of(mainPackageFile), projects, null);
    } else {
        File root = new File(po.getArgs().apply(z(0)).string()).getAbsoluteFile();
        if (!root.exists() || !root.isDirectory()) {
            addError(root + " is not a directory\n");
            // printUsage();
            return 1;
        }
        List<AadlSystem> systems = AadlProjectUtil.findSystems(root);
        if (systems.size() != 1) {
            addError("Found " + systems.size() + " AADL projects. " + "Point to a directory that contains a single .project file " + "or a .system file\n");
            // printUsage();
            return 1;
        }
        system = systems.get(0);
    }
    File outputFile = po.getOutput().nonEmpty() ? new File(po.getOutput().get().string()) : null;
    String ext = ".json";
    SerializerType st = null;
    switch(po.getMode().name()) {
        case "Json":
            st = SerializerType.JSON;
            break;
        case "Json_compact":
            st = SerializerType.JSON_COMPACT;
            break;
        case "Msgpack":
            st = SerializerType.MSG_PACK;
            ext = ".msgpack";
            break;
        default:
            addError("Invalid serializer type: " + po.getMode().name());
            return 1;
    }
    SystemInstance instance = getSystemInstance(system, rs);
    if (instance != null) {
        Aadl model = Util.getAir(instance, true);
        if (model != null) {
            String air = Util.serialize(model, st);
            if (outputFile == null) {
                String instanceFilename = Util.toIFile(instance.eResource().getURI()).getName();
                String fname = instanceFilename.substring(0, instanceFilename.lastIndexOf(".")) + ext;
                File slangDir = new File(system.projects.get(0).rootDirectory, ".slang");
                outputFile = new File(slangDir, fname);
            }
            IOUtils.writeFile(outputFile, air);
            return IApplication.EXIT_OK;
        }
    }
    addError("Could not generate AIR");
    return 1;
}
Also used : Arrays(java.util.Arrays) SireumTopOption(org.sireum.Cli.SireumTopOption) URL(java.net.URL) VisitorUtil(org.sireum.aadl.osate.architecture.VisitorUtil) Reporter(org.sireum.message.Reporter) SireumHamrCodegenOption(org.sireum.Cli.SireumHamrCodegenOption) Classifier(org.osate.aadl2.Classifier) Map(java.util.Map) InstancePackage(org.osate.aadl2.instance.InstancePackage) SystemInstance(org.osate.aadl2.instance.SystemInstance) HelpOption(org.sireum.Cli.HelpOption) Aadl2ResourceFactoryImpl(org.osate.aadl2.util.Aadl2ResourceFactoryImpl) AadlPackage(org.osate.aadl2.AadlPackage) AadlProject(org.sireum.aadl.osate.util.AadlProjectUtil.AadlProject) Collectors(java.util.stream.Collectors) List(java.util.List) Aadl2StandaloneSetup(org.osate.xtext.aadl2.Aadl2StandaloneSetup) Resource(org.eclipse.emf.ecore.resource.Resource) Optional(java.util.Optional) AadlSystem(org.sireum.aadl.osate.util.AadlProjectUtil.AadlSystem) IApplicationContext(org.eclipse.equinox.app.IApplicationContext) PluginSupportUtil(org.osate.pluginsupport.PluginSupportUtil) SireumHamrPhantomOption(org.sireum.Cli.SireumHamrPhantomOption) EcorePlugin(org.eclipse.emf.ecore.plugin.EcorePlugin) CheckMode(org.eclipse.xtext.validation.CheckMode) URI(org.eclipse.emf.common.util.URI) Option(org.sireum.Option) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) SystemImplementation(org.osate.aadl2.SystemImplementation) CancelIndicator(org.eclipse.xtext.util.CancelIndicator) IApplication(org.eclipse.equinox.app.IApplication) SireumApi(org.sireum.SireumApi) XtextResource(org.eclipse.xtext.resource.XtextResource) AadlProjectUtil(org.sireum.aadl.osate.util.AadlProjectUtil) Aadl(org.sireum.hamr.ir.Aadl) InstantiateModel(org.osate.aadl2.instantiation.InstantiateModel) IResourceValidator(org.eclipse.xtext.validation.IResourceValidator) IOException(java.io.IOException) ApiUtil(org.sireum.aadl.osate.util.ApiUtil) IOUtils(org.sireum.aadl.osate.util.IOUtils) File(java.io.File) ErrorModelStandaloneSetup(org.osate.xtext.aadl2.errormodel.ErrorModelStandaloneSetup) SerializerType(org.sireum.aadl.osate.util.Util.SerializerType) Injector(com.google.inject.Injector) Util(org.sireum.aadl.osate.util.Util) Issue(org.eclipse.xtext.validation.Issue) Platform(org.eclipse.core.runtime.Platform) Collections(java.util.Collections) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) InputStream(java.io.InputStream) SystemInstance(org.osate.aadl2.instance.SystemInstance) Aadl(org.sireum.hamr.ir.Aadl) AadlProject(org.sireum.aadl.osate.util.AadlProjectUtil.AadlProject) AadlSystem(org.sireum.aadl.osate.util.AadlProjectUtil.AadlSystem) File(java.io.File) SerializerType(org.sireum.aadl.osate.util.Util.SerializerType)

Example 64 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.

the class AwasServerHandler method clearInstanceDiagram.

@SuppressWarnings("restriction")
public static void clearInstanceDiagram(Set<URI> iUri, SystemInstance root) {
    display.syncExec(() -> {
        Set<DiagramElement> des = new HashSet<DiagramElement>();
        AwasUtil.getAllDiagramElements(ade.getDiagram()).forEach(de -> des.add(de));
        des.forEach(de -> {
            URI hUri = new EObjectURIWrapper((EObject) de.getBusinessObject()).getUri();
            if (de.getBusinessObject() instanceof EObject && iUri.contains(hUri)) {
                de.setStyle(Style.DEFAULT);
            }
        });
        ade.getActionExecutor().execute("highlight diagram", ExecutionMode.NORMAL, () -> {
            ade.updateNowIfModelHasChanged();
            ade.updateDiagram();
            ade.getGefDiagram().refreshDiagramStyles();
            ade.doSave(new NullProgressMonitor());
            return null;
        });
    });
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) EObjectURIWrapper(org.osate.aadl2.modelsupport.EObjectURIWrapper) EObject(org.eclipse.emf.ecore.EObject) URI(org.eclipse.emf.common.util.URI) HashSet(java.util.HashSet)

Example 65 with SystemInstance

use of org.osate.aadl2.instance.SystemInstance in project osate-plugin by sireum.

the class ReachBackwardHandler method execute.

@SuppressWarnings("restriction")
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Boolean isImplDiagram = false;
    IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
    List<DiagramElement> des = SelectionUtil.getSelectedDiagramElements(SelectionHelper.getDiagramSelection(), // getSelectedDiagramElem(event)
    true);
    List<InstanceObject> ios = des.stream().flatMap(de -> {
        Object bo = de.getBusinessObject();
        List<InstanceObject> io = new ArrayList<InstanceObject>();
        if (bo != null && bo instanceof InstanceObject) {
            io.add(((InstanceObject) bo));
        }
        return io.stream();
    }).collect(Collectors.toList());
    List<String> criterions = ios.stream().map(io -> io.getInstanceObjectPath()).collect(Collectors.toList());
    if (!ios.isEmpty()) {
        MessageConsole console = displayConsole("Awas Console");
        try {
            Aadl model = Util.getAir(ios.get(0).getSystemInstance(), true, console);
            Model awasModel = org.sireum.awas.slang.Aadl2Awas$.MODULE$.apply(model);
            SymbolTable st = org.sireum.awas.symbol.SymbolTable$.MODULE$.apply(awasModel, new ConsoleTagReporter());
            FlowGraph<FlowNode, FlowEdge<FlowNode>> graph = org.sireum.awas.flow.FlowGraph$.MODULE$.apply(awasModel, st, false);
            AwasGraph awasgraph = new AwasGraphImpl(graph, st);
            String query = "t = reach backward " + "{" + String.join(",", criterions) + "}";
            Map<String, Collector> qres = awasgraph.queryEvaluator(query);
            if (qres.isEmpty()) {
                MessageDialog.openError(window.getShell(), "Sireum", "Empty result");
            } else {
                final DiagramService diagramService = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(DiagramService.class);
                SystemInstance si = ios.get(0).getSystemInstance();
                Resource resource = si.eResource();
                List<Collector> lc = new ArrayList<Collector>(qres.values());
                Set<AgeEditor> ads = AwasUtil.awasGraphUri2AgeDiagramEditor(lc.get(0).getGraph(), isImplDiagram, st, resource, diagramService);
                AwasUtil.highlightDiagrams(ads, lc.get(0), isImplDiagram, st, resource);
            }
        } catch (URISyntaxException e1) {
            // // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (Exception e3) {
            e3.printStackTrace();
            String m2 = "Could not invoke visualizer.  Please make sure Awas is configured correctly.\n\n" + e3.getLocalizedMessage();
            MessageDialog.openError(window.getShell(), "Sireum", m2);
        }
    } else {
        String m3 = "Please select a component or port from the instance diagram";
        MessageDialog.openError(window.getShell(), "Sireum", m3);
    }
    return null;
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) Element(org.osate.aadl2.Element) AbstractSireumHandler(org.sireum.aadl.osate.handlers.AbstractSireumHandler) URISyntaxException(java.net.URISyntaxException) AwasGraphImpl(org.sireum.awas.awasfacade.AwasGraphImpl) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ArrayList(java.util.ArrayList) HandlerUtil(org.eclipse.ui.handlers.HandlerUtil) AgeEditor(org.osate.ge.gef.ui.editor.AgeEditor) IStatus(org.eclipse.core.runtime.IStatus) SelectionHelper(org.sireum.aadl.osate.util.SelectionHelper) Map(java.util.Map) Collector(org.sireum.awas.awasfacade.Collector) FlowGraph(org.sireum.awas.flow.FlowGraph) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) AwasUtil(org.sireum.aadl.osate.awas.util.AwasUtil) SystemInstance(org.osate.aadl2.instance.SystemInstance) Shell(org.eclipse.swt.widgets.Shell) PlatformUI(org.eclipse.ui.PlatformUI) DiagramService(org.osate.ge.internal.services.DiagramService) Aadl(org.sireum.hamr.ir.Aadl) SelectionUtil(org.osate.ge.internal.ui.util.SelectionUtil) SymbolTable(org.sireum.awas.symbol.SymbolTable) Set(java.util.Set) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) MessageConsole(org.eclipse.ui.console.MessageConsole) Model(org.sireum.awas.ast.Model) Collectors(java.util.stream.Collectors) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) FlowEdge(org.sireum.awas.flow.FlowEdge) FlowNode(org.sireum.awas.flow.FlowNode) List(java.util.List) Util(org.sireum.aadl.osate.util.Util) Resource(org.eclipse.emf.ecore.resource.Resource) ConsoleTagReporter(org.sireum.util.ConsoleTagReporter) AwasGraph(org.sireum.awas.awasfacade.AwasGraph) InstanceObject(org.osate.aadl2.instance.InstanceObject) AwasGraph(org.sireum.awas.awasfacade.AwasGraph) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) ConsoleTagReporter(org.sireum.util.ConsoleTagReporter) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) InstanceObject(org.osate.aadl2.instance.InstanceObject) AwasGraphImpl(org.sireum.awas.awasfacade.AwasGraphImpl) Shell(org.eclipse.swt.widgets.Shell) AgeEditor(org.osate.ge.gef.ui.editor.AgeEditor) SystemInstance(org.osate.aadl2.instance.SystemInstance) Aadl(org.sireum.hamr.ir.Aadl) Collector(org.sireum.awas.awasfacade.Collector) ArrayList(java.util.ArrayList) List(java.util.List) FlowEdge(org.sireum.awas.flow.FlowEdge) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) MessageConsole(org.eclipse.ui.console.MessageConsole) Resource(org.eclipse.emf.ecore.resource.Resource) SymbolTable(org.sireum.awas.symbol.SymbolTable) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ExecutionException(org.eclipse.core.commands.ExecutionException) Model(org.sireum.awas.ast.Model) InstanceObject(org.osate.aadl2.instance.InstanceObject) DiagramService(org.osate.ge.internal.services.DiagramService) FlowNode(org.sireum.awas.flow.FlowNode)

Aggregations

SystemInstance (org.osate.aadl2.instance.SystemInstance)100 ComponentInstance (org.osate.aadl2.instance.ComponentInstance)52 InstanceObject (org.osate.aadl2.instance.InstanceObject)26 ComponentImplementation (org.osate.aadl2.ComponentImplementation)25 Element (org.osate.aadl2.Element)25 SystemOperationMode (org.osate.aadl2.instance.SystemOperationMode)22 ConnectionInstance (org.osate.aadl2.instance.ConnectionInstance)21 Classifier (org.osate.aadl2.Classifier)18 ForAllElement (org.osate.aadl2.modelsupport.modeltraversal.ForAllElement)18 ComponentCategory (org.osate.aadl2.ComponentCategory)17 NamedElement (org.osate.aadl2.NamedElement)16 List (java.util.List)14 Resource (org.eclipse.emf.ecore.resource.Resource)14 AadlPackage (org.osate.aadl2.AadlPackage)14 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)14 ArrayList (java.util.ArrayList)13 EList (org.eclipse.emf.common.util.EList)13 IOException (java.io.IOException)12 IStatus (org.eclipse.core.runtime.IStatus)12 Optional (java.util.Optional)10