use of org.osate.aadl2.instance.SystemInstance in project AGREE by loonwerks.
the class VerifyHandler method getSysInstance.
protected SystemInstance getSysInstance(ComponentImplementation ci, EphemeralImplementationUtil implUtil) {
try {
AnalysisErrorReporterManager errorManager = new AnalysisErrorReporterManager(QueuingAnalysisErrorReporter.factory);
SystemInstance result = implUtil.generateEphemeralCompInstanceFromImplementation(ci);
QueuingAnalysisErrorReporter errorReporter = (QueuingAnalysisErrorReporter) errorManager.getReporter(result.eResource());
StringBuilder stringBuilder = new StringBuilder();
List<Message> instantiationMarkers = errorReporter.getErrors();
if (!instantiationMarkers.isEmpty()) {
instantiationMarkers.stream().forEach(marker -> {
stringBuilder.append(marker.message);
});
throw new AgreeException(stringBuilder.toString());
}
return result;
} catch (Exception e) {
Dialog.showError("Model Instantiate", "Error while re-instantiating the model: " + e.getMessage());
throw new AgreeException("Error Instantiating model");
}
}
use of org.osate.aadl2.instance.SystemInstance in project AGREE by loonwerks.
the class MATLABFunctionHandler method runJob.
@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
Classifier classifier = getOutermostClassifier(root);
if (!(classifier instanceof ComponentType)) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Must select an AADL Component Type");
}
ComponentType ct = (ComponentType) classifier;
ComponentImplementation ci = null;
EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
try {
SystemInstance si = implUtil.generateEphemeralCompInstanceFromType(ct);
ComponentType sysType = AgreeUtils.getInstanceType(si);
EList<AnnexSubclause> annexSubClauses = AnnexUtil.getAllAnnexSubclauses(sysType, AgreePackage.eINSTANCE.getAgreeContractSubclause());
if (annexSubClauses.size() == 0) {
throw new AgreeException("There is not an AGREE annex in the '" + sysType.getName() + "' system type.");
}
// Get Agree program
AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
if (agreeProgram.containsRealTimePatterns) {
throw new AgreeException("'" + sysType.getName() + "' system type contains AGREE Real Time Patterns." + " Export of AGREE Real Time Patterns NOT Supported - they are considered scheduling properties" + " of components and can be decomposed further.");
}
// Translate Agree Node to Lustre Node with pre-statement flatten, helper nodes inlined,
// and variable declarations sorted so they are declared before use
Node lustreNode = AgreeNodeToLustreContract.translate(agreeProgram.topNode, agreeProgram);
// Translate Lustre Node to MATLAB Function AST
MATLABPrimaryFunction matlabFunction = LustreToMATLABTranslator.translate(lustreNode, agreeProgram);
ModelInfo info = getModelInfo(ct);
if (info == null) {
// return;
return Status.CANCEL_STATUS;
}
String dirStr = info.outputDirPath;
if (dirStr == null || dirStr.isEmpty()) {
// return;
return Status.CANCEL_STATUS;
}
boolean exportContractsPressed = info.exportPressed;
boolean genImplPressed = info.generatePressed;
boolean genVerificationPressed = info.updatePressed;
boolean verifySubsysPressed = info.verifyPressed;
String matlabFuncScriptName = matlabFunction.name + ".m";
if (genImplPressed) {
// Write MATLAB script to generate subsystem in the selected
// output folder
String subsysName = "";
if (info.subsystemName.equals("")) {
subsysName = sysType.getName();
} else {
subsysName = info.subsystemName;
}
MdlScriptCreator implMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, subsysName, matlabFunction.ports, matlabFuncScriptName, true, info.verifyPressed);
String implMdlScriptName = "generate_" + subsysName + ".m";
// generate the script to create the impl model file into the path specified for the model
File implMdlFile = new File(info.implMdlPath);
String implMdlDir = implMdlFile.getParent();
if (implMdlDir != null) {
Path implMdlScriptPath = Paths.get(implMdlDir, implMdlScriptName);
writeToFile(implMdlScriptPath, implMdlScript.toString());
}
}
if (exportContractsPressed || genVerificationPressed || verifySubsysPressed) {
Path matlabFuncScriptPath = Paths.get(dirStr, matlabFuncScriptName);
// Write MATLAB function code into the specified file in the
// selected output folder
writeToFile(matlabFuncScriptPath, matlabFunction.toString());
if (genVerificationPressed || verifySubsysPressed) {
// Create Simulink Model Update script into the output
// folder
MdlScriptCreator verifMdlScript = new MdlScriptCreator(dirStr, info.implMdlPath, info.verifyMdlName, info.subsystemName, matlabFunction.ports, matlabFuncScriptName, false, info.verifyPressed);
String verifMdlScriptName = matlabFunction.name + "_Observer.m";
Path verifMdlScriptPath = Paths.get(dirStr, verifMdlScriptName);
writeToFile(verifMdlScriptPath, verifMdlScript.toString());
}
}
// return;
return Status.OK_STATUS;
} catch (Throwable e) {
String messages = getNestedMessages(e);
e.printStackTrace();
Dialog.showError("AGREE Error", e.toString());
// return;
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
} finally {
if (ci != null) {
ci.eResource().getContents().remove(ci);
}
implUtil.cleanup();
}
}
use of org.osate.aadl2.instance.SystemInstance in project AGREE by loonwerks.
the class SimulationLaunchConfigurationDelegate method launch.
@Override
public void launch(final ILaunchConfiguration configuration, final String mode, final ILaunch launch, final IProgressMonitor monitor) throws CoreException {
SimulationService simulationService = null;
try {
simulationService = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()).get(SimulationService.class);
Objects.requireNonNull(configuration, "configuration must not be null");
// Find the component implementation
final String componentImplementationName = configuration.getAttribute(SimulationLaunchConfigurationAttributes.COMPONENT_IMPLEMENTATION_NAME, (String) null);
final String projectName = configuration.getAttribute(SimulationLaunchConfigurationAttributes.PROJECT_NAME, (String) null);
final IProject project = projectName == null ? null : findProject(projectName);
final EObject obj = componentImplementationName == null ? null : findComponentImplementation(project, componentImplementationName);
if (obj instanceof ComponentImplementation) {
// Refresh the component implementation
final ComponentImplementation ci = refreshComponentImplementation((ComponentImplementation) obj);
// (Re)instantiate the model
final SystemInstance systemInstance = InstantiateModel.buildInstanceModelFile(ci);
// Get the selected simulation engine type.
final String selectedEngineTypeId = Objects.requireNonNull(configuration.getAttribute(SimulationLaunchConfigurationAttributes.ENGINE_TYPE_ID, (String) null), "Simulation Engine must be specified");
final EngineType engineType = Objects.requireNonNull(simulationService.getEngineTypeById(selectedEngineTypeId), "Unable to find specified simulation engine");
final SimulationEngine newEngine = simulationService.createEngine(engineType, systemInstance);
final SimulationService simService = simulationService;
simulationService.addSimulationEngineChangeListener(new SimulationEngineChangeListener() {
@Override
public void onSimulationEngineCreated(final SimulationEngine engine) {
}
@Override
public void onSimulationEngineDisposed(final SimulationEngine engine) {
if (engine == newEngine) {
DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
simService.removeSimulationEngineChangeListener(this);
}
}
});
if (launch instanceof SimulationLaunch) {
((SimulationLaunch) launch).setSimulationEngine(newEngine);
}
} else {
simulationService.getExceptionHandler().handleException(new CoreException(new Status(IStatus.ERROR, FrameworkUtil.getBundle(getClass()).getSymbolicName(), "Unable to find Component Implementation.")));
}
} catch (final Exception e) {
DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
if (simulationService == null) {
throw new RuntimeException(e);
} else {
simulationService.getExceptionHandler().handleException(e);
}
}
}
use of org.osate.aadl2.instance.SystemInstance in project AMASE by loonwerks.
the class GenMCSHandler method runJob.
@Override
protected IStatus runJob(Element root, IProgressMonitor monitor) {
EphemeralImplementationUtil implUtil = new EphemeralImplementationUtil(monitor);
// this flag is set by the rerun handler to prevent clearing the advice map
if (!calledFromRerun) {
rerunAdviceMap.clear();
}
calledFromRerun = false;
disableRerunHandler();
handlerService = getWindow().getService(IHandlerService.class);
try {
// Make sure the user selected a component implementation
ComponentImplementation ci = getComponentImplementation(root, implUtil);
SystemInstance si = getSysInstance(ci, implUtil);
AnalysisResult result;
CompositeAnalysisResult wrapper = new CompositeAnalysisResult("");
// SystemType sysType = si.getSystemImplementation().getType();
ComponentType sysType = AgreeUtils.getInstanceType(si);
EList<AnnexSubclause> annexSubClauses = AnnexUtil.getAllAnnexSubclauses(sysType, AgreePackage.eINSTANCE.getAgreeContractSubclause());
if (annexSubClauses.size() == 0) {
throw new AgreeException("There is not an AGREE annex in the '" + sysType.getName() + "' system type.");
}
if (isRecursive()) {
if (AgreeUtils.usingKind2()) {
throw new AgreeException("Kind2 only supports monolithic verification");
}
result = buildAnalysisResult(((NamedElement) root).getName(), si);
wrapper.addChild(result);
result = wrapper;
} else if (isRealizability()) {
AgreeProgram agreeProgram = new AgreeASTBuilder().getAgreeProgram(si, false);
Program program = LustreAstBuilder.getRealizabilityLustreProgram(agreeProgram);
wrapper.addChild(createVerification("Realizability Check", si, program, agreeProgram, AnalysisType.Realizability));
result = wrapper;
} else {
wrapVerificationResult(si, wrapper);
result = wrapper;
}
showView(result, linker);
return doAnalysis(root, monitor, result, linker);
} catch (Throwable e) {
String messages = getNestedMessages(e);
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, messages, e);
} finally {
implUtil.cleanup();
}
}
use of org.osate.aadl2.instance.SystemInstance in project osate2 by osate.
the class ComponentInstanceHandler method getCanonicalReference.
@Override
public CanonicalBusinessObjectReference getCanonicalReference(final ReferenceContext ctx) {
final ComponentInstance bo = ctx.getBusinessObject(ComponentInstance.class).get();
final String systemInstanceKey = AadlReferenceUtil.getSystemInstanceKey(bo);
if (bo instanceof SystemInstance) {
return AadlReferenceUtil.getCanonicalBusinessObjectReferenceForSystemInstance(systemInstanceKey);
} else {
return new CanonicalBusinessObjectReference(AadlReferenceUtil.INSTANCE_ID, AadlReferenceUtil.COMPONENT_INSTANCE_KEY, systemInstanceKey, bo.getInstanceObjectPath());
}
}
Aggregations