示例#1
0
  private void processSdmCodeServerLauncher(DebugEvent event) {
    RuntimeProcess runtimeProcess = (RuntimeProcess) event.getSource();
    final ILaunch launch = runtimeProcess.getLaunch();
    IProcess[] processes = launch.getProcesses();
    final IProcess process = processes[0];

    // Look for the links in the sdm console output
    consoleStreamListener =
        new IStreamListener() {
          @Override
          public void streamAppended(String text, IStreamMonitor monitor) {
            displayCodeServerUrlInDevMode(launch, text);
          }
        };

    // Listen to Console output
    streamMonitor = process.getStreamsProxy().getOutputStreamMonitor();
    streamMonitor.addListener(consoleStreamListener);
  }
  public void execute(IProgressMonitor monitor) throws Exception {

    /*
     * use the ExecutePomAction directly.
     */
    // ExecutePomAction exePomAction = new ExecutePomAction();
    // exePomAction.setInitializationData(null, null, MavenConstants.GOAL_COMPILE);
    // exePomAction.launch(new StructuredSelection(launcherPomFile), ILaunchManager.RUN_MODE);

    /*
     * use launch way
     */

    // try{

    ILaunchConfiguration launchConfiguration = createLaunchConfiguration();
    if (launchConfiguration == null) {
      throw new Exception("Can't create maven command launcher.");
    }
    // if (launchConfiguration instanceof ILaunchConfigurationWorkingCopy) {
    // ILaunchConfigurationWorkingCopy copiedConfig = (ILaunchConfigurationWorkingCopy)
    // launchConfiguration;
    // }
    TalendLauncherWaiter talendWaiter = new TalendLauncherWaiter(launchConfiguration);

    final ILaunch launch = buildAndLaunch(launchConfiguration, launcherMode, monitor);
    talendWaiter.waitFinish(launch);
    StringBuffer errors = new StringBuffer();
    for (IProcess process : launch.getProcesses()) {
      String log = process.getStreamsProxy().getOutputStreamMonitor().getContents();

      if (!isCaptureOutputInConsoleView()) {
        // specially for commandline. if studio, when debug model, will log it in console view, so
        // no need this.
        TalendDebugHandler.debug(
            "\n------------------ Talend Maven Launcher log START -----------------------\n");
        TalendDebugHandler.debug(log);
        TalendDebugHandler.debug(
            "\n------------------ Talend Maven Launcher log END -----------------------\n");
      }
      for (String line : log.split("\n")) { // $NON-NLS-1$
        if (line.startsWith("[ERROR]")) { // $NON-NLS-1$
          errors.append(line + "\n"); // $NON-NLS-1$
        }
      }
    }
    if (errors.length() > 0) {
      if (getGoals() != null
          && getGoals()
              .matches(
                  "(.*)\\b"
                      + TalendMavenConstants.GOAL_TEST
                      + "\\b(.*)")) { //$NON-NLS-1$//$NON-NLS-2$
        ExceptionHandler.process(new Exception(errors.toString()));
      } else {
        throw new Exception(errors.toString());
      }
    }

    // }finally{
    // if (launch != null) {
    // if remove, after execute launch, will remove the console also. so shouldn't remove it.
    // DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
    // }
    // }
  }
示例#3
0
  /**
   * the command has been executed, so extract extract the needed information from the application
   * context.
   */
  public Object execute(ExecutionEvent event) throws ExecutionException {
    log.fine("Message to start PVS was received");
    window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
    if (PVSExecutionManager.INST().isPVSRunning()) {
      MessageDialog.openInformation(
          window.getShell(), "PVS Running", "An instance of PVS is already running.");
    } else {
      try {
        final PVSConsole console = PVSConsole.getConsole();
        console.activate();
        console.clearConsole();
        final IOConsoleOutputStream outStream = console.newOutputStream();
        Map<String, String> attributes = new HashMap<String, String>();
        attributes.put(IProcess.ATTR_CMDLINE, PVSExecutionManager.INST().getPVSStartingCommand());
        ILaunch launch = new Launch(null, ILaunchManager.RUN_MODE, null);
        IProcess process =
            DebugPlugin.newProcess(
                launch, PVSExecutionManager.INST().startPVS(), Activator.name, attributes);
        PVSExecutionManager.INST().setIProcess(process);
        DebugPlugin.getDefault().getLaunchManager().addLaunch(launch);
        DebugPlugin.getDefault().addDebugEventListener(PVSExecutionManager.INST());
        PVSJsonWrapper.init();
        PVSExecutionManager.INST().removeRespondListeners();
        PVSExecutionManager.INST()
            .addListener(
                new PVSRespondListener() {

                  @Override
                  public void onMessageReceived(String message) {
                    log.log(Level.INFO, "Message received: {0}", message);
                    try {
                      outStream.write(message);
                    } catch (IOException e) {
                      e.printStackTrace();
                    }
                  }

                  @Override
                  public void onMessageReceived(JSONObject message) {
                    log.log(Level.INFO, "JSON received: {0}", message);
                    PVSJsonWrapper.INST().addToJSONQueue(message);
                  }

                  @Override
                  public void onPromptReceived(List<String> previousLines, String prompt) {
                    log.log(Level.INFO, "Prompt received: {0}", prompt);
                    try {
                      outStream.write(prompt);
                    } catch (IOException e) {
                      e.printStackTrace();
                    }
                    PVSPromptProcessor.processPrompt(previousLines, prompt);
                  }
                });
        IStreamsProxy streamProxy = process.getStreamsProxy();
        IStreamMonitor outMonitor = streamProxy.getOutputStreamMonitor();
        outMonitor.addListener(new PVSStreamListener(EclipsePluginUtil.getLispType()));

        IOConsoleKeyboardReader.init(console);
        IOConsoleKeyboardReader.INST()
            .addListener(
                new IOConsoleKeyboardReader.IOConsoleKeyboardReaderListener() {
                  public void onTextReceived(String text) {
                    PVSExecutionManager.INST().writeToPVS(text);
                  }
                });
        IOConsoleKeyboardReader.INST().start();
        Thread.sleep(500);
        restorePVSContext();
      } catch (IOException e) {
        log.severe("Failed to start PVS");
        MessageDialog.openInformation(window.getShell(), "Error", "Failed to start PVS");
      } catch (InterruptedException e) {
        log.severe("Failed to restore PVS context");
        MessageDialog.openInformation(
            window.getShell(), "Error", "Failed to restore the PVS context");
      } catch (PVSException e) {
        log.severe("Failed to restore PVS context");
        MessageDialog.openInformation(
            window.getShell(), "Error", "Failed to restore the PVS context");
      }
    }
    return null;
  }