Procházet zdrojové kódy

fix #1660. showing dialog if a simulation with a broken model is started. the started simulation is automatically terminated to prevent further unexpected behaviour. (#1661)

Robert Rudi před 8 roky
rodič
revize
b19694398b

+ 21 - 15
plugins/org.yakindu.sct.simulation.core.sexec/src/org/yakindu/sct/simulation/core/sexec/container/AbstractExecutionFlowSimulationEngine.java

@@ -24,6 +24,7 @@ import org.yakindu.sct.model.sruntime.ExecutionContext;
 import org.yakindu.sct.simulation.core.SimulationCoreActivator;
 import org.yakindu.sct.simulation.core.engine.IExecutionControl;
 import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
+import org.yakindu.sct.simulation.core.launch.AbstractSCTLaunchConfigurationDelegate.InitializationException;
 import org.yakindu.sct.simulation.core.sexec.interpreter.IExecutionFlowInterpreter;
 import org.yakindu.sct.simulation.core.sexec.scheduling.ITimeTaskScheduler;
 
@@ -61,23 +62,28 @@ public class AbstractExecutionFlowSimulationEngine extends AbstractSimulationEng
 
 	@Override
 	public void init() {
-		ListBasedValidationIssueAcceptor acceptor = new ListBasedValidationIssueAcceptor();
-		ExecutionFlow flow = sequencer.transform(statechart, acceptor);
-		if (acceptor.getTraces(Severity.ERROR).size() > 0) {
-			Status errorStatus = new Status(Status.ERROR, SimulationCoreActivator.PLUGIN_ID, ERROR_DURING_SIMULATION,
-					acceptor.getTraces(Severity.ERROR).iterator().next().toString(), null);
-			IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(errorStatus);
-			try {
-				statusHandler.handleStatus(errorStatus, getDebugTarget());
-			} catch (CoreException e) {
-				e.printStackTrace();
+		try {
+			ListBasedValidationIssueAcceptor acceptor = new ListBasedValidationIssueAcceptor();
+			ExecutionFlow flow = sequencer.transform(statechart, acceptor);
+			if (acceptor.getTraces(Severity.ERROR).size() > 0) {
+				Status errorStatus = new Status(Status.ERROR, SimulationCoreActivator.PLUGIN_ID,
+						ERROR_DURING_SIMULATION, acceptor.getTraces(Severity.ERROR).iterator().next().toString(), null);
+				IStatusHandler statusHandler = DebugPlugin.getDefault().getStatusHandler(errorStatus);
+				try {
+					statusHandler.handleStatus(errorStatus, getDebugTarget());
+				} catch (CoreException e) {
+					e.printStackTrace();
+				}
 			}
-		}
 
-		if (!context.isSnapshot()) {
-			contextInitializer.initialize(context, flow);
+			if (!context.isSnapshot()) {
+				contextInitializer.initialize(context, flow);
+			}
+			interpreter.initialize(flow, context, useInternalEventQueue());
+		} catch (Exception ex) {
+			handleException(ex);
+			throw new InitializationException(ex.getMessage());
 		}
-		interpreter.initialize(flow, context, useInternalEventQueue());
 	}
 
 	public void start() {
@@ -143,7 +149,7 @@ public class AbstractExecutionFlowSimulationEngine extends AbstractSimulationEng
 	protected boolean useInternalEventQueue() {
 		return false;
 	}
-	
+
 	public Statechart getStatechart() {
 		return statechart;
 	}

+ 104 - 94
plugins/org.yakindu.sct.simulation.core/src/org/yakindu/sct/simulation/core/launch/AbstractSCTLaunchConfigurationDelegate.java

@@ -1,94 +1,104 @@
-/**
- * Copyright (c) 2013 committers of YAKINDU and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * Contributors:
- * 	committers of YAKINDU - initial API and implementation
- * 
- */
-package org.yakindu.sct.simulation.core.launch;
-
-import java.util.Collections;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.debug.core.ILaunch;
-import org.eclipse.debug.core.ILaunchConfiguration;
-import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
-import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.resource.URIConverter;
-import org.yakindu.sct.model.sgraph.Statechart;
-import org.yakindu.sct.simulation.core.debugmodel.SCTDebugTarget;
-import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
-import org.yakindu.sct.simulation.core.util.ResourceUtil;
-
-/**
- * 
- * @author andreas muelder - Initial contribution and API
- * 
- */
-public abstract class AbstractSCTLaunchConfigurationDelegate extends LaunchConfigurationDelegate implements
-			ILaunchConfigurationDelegate {
-
-	public String FILE_NAME = "filename";
-	public String DEFAULT_FILE_NAME = "";
-
-	protected abstract ISimulationEngine createExecutionContainer(ILaunch launch, Statechart statechart);
-
-	@Override
-	public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
-			throws CoreException {
-		String filename = configuration.getAttribute(FILE_NAME, DEFAULT_FILE_NAME);
-		URI uri = URI.createPlatformResourceURI(filename, true);
-		if (!URIConverter.INSTANCE.exists(uri, Collections.emptyMap()))
-			return false;
-		return super.preLaunchCheck(configuration, mode, monitor);
-	}
-
-	public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
-			throws CoreException {
-		String filename = configuration.getAttribute(FILE_NAME, DEFAULT_FILE_NAME);
-		Statechart statechart = loadStatechart(filename);
-		SCTDebugTarget target = createDebugTarget(launch, statechart);
-		launch.addDebugTarget(target);
-		target.init();
-		target.start();
-	}
-
-	protected SCTDebugTarget createDebugTarget(ILaunch launch, Statechart statechart) throws CoreException {
-		Assert.isNotNull(statechart);
-		return new SCTDebugTarget(launch, statechart, createExecutionContainer(launch, statechart));
-	}
-
-	protected Statechart loadStatechart(String filename) {
-		return ResourceUtil.loadStatechart(filename);
-	}
-
-	@Override
-	protected IProject[] getProjectsForProblemSearch(ILaunchConfiguration configuration, String mode)
-			throws CoreException {
-		String filename = configuration.getAttribute(FILE_NAME, "");
-		IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(filename);
-		return new IProject[] { resource.getProject() };
-
-	}
-
-	@Override
-	public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
-			throws CoreException {
-		// Never build the workspace before simulation
-		return false;
-	}
-
-	@Override
-	protected IProject[] getBuildOrder(ILaunchConfiguration configuration, String mode) throws CoreException {
-		return getProjectsForProblemSearch(configuration, mode);
-	}
-}
+/**
+ * Copyright (c) 2013 committers of YAKINDU and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ * Contributors:
+ * 	committers of YAKINDU - initial API and implementation
+ * 
+ */
+package org.yakindu.sct.simulation.core.launch;
+
+import java.util.Collections;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.debug.core.model.ILaunchConfigurationDelegate;
+import org.eclipse.debug.core.model.LaunchConfigurationDelegate;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.resource.URIConverter;
+import org.yakindu.sct.model.sgraph.Statechart;
+import org.yakindu.sct.simulation.core.debugmodel.SCTDebugTarget;
+import org.yakindu.sct.simulation.core.engine.ISimulationEngine;
+import org.yakindu.sct.simulation.core.util.ResourceUtil;
+
+/**
+ * 
+ * @author andreas muelder - Initial contribution and API
+ * 
+ */
+public abstract class AbstractSCTLaunchConfigurationDelegate extends LaunchConfigurationDelegate
+		implements
+			ILaunchConfigurationDelegate {
+
+	public String FILE_NAME = "filename";
+	public String DEFAULT_FILE_NAME = "";
+
+	protected abstract ISimulationEngine createExecutionContainer(ILaunch launch, Statechart statechart);
+
+	@Override
+	public boolean preLaunchCheck(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
+			throws CoreException {
+		String filename = configuration.getAttribute(FILE_NAME, DEFAULT_FILE_NAME);
+		URI uri = URI.createPlatformResourceURI(filename, true);
+		if (!URIConverter.INSTANCE.exists(uri, Collections.emptyMap()))
+			return false;
+		return super.preLaunchCheck(configuration, mode, monitor);
+	}
+
+	public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
+			throws CoreException {
+		String filename = configuration.getAttribute(FILE_NAME, DEFAULT_FILE_NAME);
+		Statechart statechart = loadStatechart(filename);
+		SCTDebugTarget target = createDebugTarget(launch, statechart);
+		launch.addDebugTarget(target);
+		try {
+			target.init();
+			target.start();
+		} catch (InitializationException e) {
+			// handled in AbstractExecutionFlowSimulationEngine
+		}
+	}
+
+	protected SCTDebugTarget createDebugTarget(ILaunch launch, Statechart statechart) throws CoreException {
+		Assert.isNotNull(statechart);
+		return new SCTDebugTarget(launch, statechart, createExecutionContainer(launch, statechart));
+	}
+
+	protected Statechart loadStatechart(String filename) {
+		return ResourceUtil.loadStatechart(filename);
+	}
+
+	@Override
+	protected IProject[] getProjectsForProblemSearch(ILaunchConfiguration configuration, String mode)
+			throws CoreException {
+		String filename = configuration.getAttribute(FILE_NAME, "");
+		IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(filename);
+		return new IProject[]{resource.getProject()};
+
+	}
+
+	@Override
+	public boolean buildForLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
+			throws CoreException {
+		// Never build the workspace before simulation
+		return false;
+	}
+
+	public static class InitializationException extends RuntimeException {
+
+		private static final long serialVersionUID = 1L;
+
+		public InitializationException(String msg) {
+			super(msg);
+		}
+	}
+
+}