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;
}
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;
}
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;
}
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;
});
});
}
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;
}
Aggregations