protected void onBeforeStartJob() {
    // Get the console
    final MessageConsole console = Utils.findConsole("ocarina");
    console.addPatternMatchListener(new AadlFilenamePatternMatchListener());
    console.clearConsole();

    if (automaticallyShowConsole) {
      showConsole();
    }

    // Create and configure streams
    this.out = console.newMessageStream();
    this.err = console.newMessageStream();
    this.err.setColor(new Color(Display.getCurrent(), 255, 0, 0));
  }
  @Override
  public void launch(
      ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
      throws CoreException {
    try {
      this.launch = launch;
      cleanup();

      final MitraLaunchConfigurationAdapter configAdapter =
          new MitraLaunchConfigurationAdapter(configuration);

      String consoleName = "Mitra Interpreter [" + configAdapter.getName() + "] " + mode;
      console = findConsole(consoleName);
      console.activate();
      initConsoleStream();

      clearConsole();

      final StandaloneExecutor executor =
          MitraStandaloneLaunchFactory.createExecutor(configAdapter);
      executor.getProjectContext().setMessageAcceptor(new ConsoleMessageAcceptor(console));

      console.addPatternMatchListener(new MitraConsoleTracker(executor.getProjectContext()));

      executor.getProjectContext().out = new PrintStream(createMessageStream(SWT.COLOR_BLACK));

      PrintStream err = new PrintStream(createMessageStream(SWT.COLOR_RED));
      executor.getProjectContext().err = err;

      executor.getProjectContext().log = new PrintStream(createMessageStream(SWT.COLOR_BLUE));

      try {
        executor.prepareInterpreter();
      } catch (Exception ex) {
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                MitraDebugPlugin.PLUGIN_ID,
                "Error preparing Mitra interpreter: " + ex.getMessage(),
                ex));
      }

      executor
          .getDebugable()
          .addInterpreterListener(
              new IDebugableListener() {

                @Override
                public void terminated() {

                  out("Mitra interpreter terminated.");
                  try {
                    for (String fileName : configAdapter.getOutputModelFilenames().values()) {
                      URI uri = URI.createFileURI(fileName);
                      refreshPath(uri);
                    }
                    for (String fileName : configAdapter.getInputModelFilenames().values()) {
                      URI uri = URI.createFileURI(fileName);
                      refreshPath(uri);
                    }
                    if (configAdapter.isSaveTraces()) {
                      URI uri = URI.createFileURI(configAdapter.getTraceModelFilename());
                      refreshPath(uri);
                    }
                  } catch (CoreException ex) {
                    out("Error refreshing project path: " + ex);
                  }
                }

                @Override
                public void processDebugableEvent(DebugEventType eventType) {
                  // not interested in
                }

                @Override
                public void suspended() {
                  // not interested in
                }
              });

      ResourceSet rs = executor.getProjectContext().getResourceSet();
      int errorCount = 0;
      int warningCount = 0;
      int moduleCount = 0;
      // iterate over copy, as new resources may be
      // added while resolving proxies
      List<Resource> resources = new ArrayList<Resource>(rs.getResources());
      for (Resource resource : resources) {
        errorCount += resource.getErrors().size();
        warningCount += resource.getWarnings().size();

        if (resource.getContents().size() > 0) {
          for (EObject model : resource.getContents()) {

            if (model instanceof Module) {
              moduleCount++;
            }
            Diagnostic diagnostic = Diagnostician.INSTANCE.validate(model);
            for (Diagnostic child : diagnostic.getChildren()) {
              switch (child.getSeverity()) {
                case Diagnostic.ERROR:
                  if (!(model instanceof Module)) {
                    err.println(model.eResource().getURI() + ": " + child.getMessage());
                  }
                  errorCount++;
                  break;
                case Diagnostic.WARNING:
                  warningCount++;
              }
            }
          }
        }
      }

      MessageFormat form = new MessageFormat("Loaded {0}{1}, {2}.");
      double[] limits = {0, 1, 2};
      String[] moduleparts = {"no module", "1 module", "{0,number} modules"};
      ChoiceFormat moduleform = new ChoiceFormat(limits, moduleparts);
      form.setFormatByArgumentIndex(0, moduleform);
      String[] errorparts = {" successfully: 0 errors", ": 1 error", ": {1,number} errors"};
      ChoiceFormat errorform = new ChoiceFormat(limits, errorparts);
      form.setFormatByArgumentIndex(1, errorform);
      String[] warningparts = {"0 warnings", "1 warning", "{2,number} warnings"};
      ChoiceFormat warningform = new ChoiceFormat(limits, warningparts);
      form.setFormatByArgumentIndex(2, warningform);

      String msg = form.format(new Object[] {moduleCount, errorCount, warningCount});
      if (errorCount > 0) {
        msg += " Cannot start Mitra intpreter.";
      }
      out(msg);
      if (errorCount > 0 || moduleCount == 0) {
        throw new CoreException(new Status(IStatus.ERROR, MitraDebugPlugin.PLUGIN_ID, msg));
      }

      IDebuggable debugable = executor.getDebugable(); // debugable
      // supports
      // listeners!

      if (debugable == null) {
        throw new CoreException(
            new Status(
                IStatus.ERROR, MitraDebugPlugin.PLUGIN_ID, "No debuggable interpreter prepared."));
      }

      RuleDeclaration decl = debugable.getCalledRule();

      if (decl == null) {
        throw new CoreException(
            new Status(IStatus.ERROR, MitraDebugPlugin.PLUGIN_ID, "No rule selected."));
      }
      IDebugTarget debugTarget =
          new MitraDebugTarget(
              launch, new MitraDebugProxy(debugable), decl.eResource().getURI().toFileString());

      Display display = Display.getCurrent();
      if (display == null) { // start in normal thread
        if (log.isLoggable(Level.INFO)) {
          log.info("Start mitra interpreter via new thread");
        }
        out("Start Mitra interpreter on new thread");

        Thread interpreterThread = new Thread(debugable);
        if (mode.equals(ILaunchManager.DEBUG_MODE)) {
          debugable.enableDebug(true);
          interpreterThread.setName("MitraInterpreter");
          interpreterThread.start();
          launch.addDebugTarget(debugTarget);
        } else {
          interpreterThread.start();
        }
      } else { // start via display
        if (log.isLoggable(Level.INFO)) {
          log.info("Start mitra interpreter via display.asyncExec");
        }
        out("Start Mitra interpreter on display thread");

        if (mode.equals(ILaunchManager.DEBUG_MODE)) {
          debugable.enableDebug(true);
          display.asyncExec(debugable);
          // interpreterThread.setName("MitraInterpreter");
          // interpreterThread.start();
          launch.addDebugTarget(debugTarget);
        } else {
          display.asyncExec(debugable);
        }
      }
      out("Interpreter running...");
    } finally {
      console = null;
    }
  }