public void handleDebugEvents(DebugEvent[] events) {
      if (events != null && project != null) {
        int size = events.length;
        for (int i = 0; i < size; i++) {
          for (IProcess process : processes) {
            if (process != null
                && process.equals(events[i].getSource())
                && events[i].getKind() == DebugEvent.TERMINATE) {

              DebugPlugin.getDefault().removeDebugEventListener(this);
              terminateForked();
              Job job =
                  new Job("refresh project") {

                    @Override
                    protected IStatus run(IProgressMonitor monitor) {
                      try {
                        project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
                      } catch (CoreException e) {
                      }
                      GrailsCoreActivator.getDefault().notifyCommandFinish(project);
                      return Status.OK_STATUS;
                    }
                  };
              job.setSystem(true);
              job.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule());
              job.setPriority(Job.INTERACTIVE);
              job.schedule();
            }
          }
        }
      }
    }
Ejemplo n.º 2
0
 /*
  * (non-Javadoc)
  *
  * @see
  * org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextListener
  * #contextEvent
  * (org.eclipse.debug.internal.ui.contexts.provisional.DebugContextEvent)
  */
 public void debugContextChanged(final DebugContextEvent event) {
   if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) {
     IProcess process = getProcess();
     if (fView != null && process != null && process.equals(DebugUITools.getCurrentProcess())) {
       fView.display(fConsole);
     }
   }
 }
  @Override
  public boolean finalLaunchCheck(
      ILaunchConfiguration configuration, String mode, IProgressMonitor monitor)
      throws CoreException {
    // Check for existing launches of same resource
    BndPreferences prefs = new BndPreferences();
    if (prefs.getWarnExistingLaunches()) {
      IResource launchResource = LaunchUtils.getTargetResource(configuration);
      if (launchResource == null)
        throw new CoreException(
            new Status(
                IStatus.ERROR,
                Plugin.PLUGIN_ID,
                0,
                "Bnd launch target was not specified or does not exist.",
                null));

      int processCount = 0;
      for (ILaunch l : DebugPlugin.getDefault().getLaunchManager().getLaunches()) {
        // ... is it the same launch resource?
        ILaunchConfiguration launchConfig = l.getLaunchConfiguration();
        if (launchConfig == null) {
          continue;
        }
        if (launchResource.equals(LaunchUtils.getTargetResource(launchConfig))) {
          // Iterate existing processes
          for (IProcess process : l.getProcesses()) {
            if (!process.isTerminated()) processCount++;
          }
        }
      }

      // Warn if existing processes running
      if (processCount > 0) {
        Status status =
            new Status(
                IStatus.WARNING,
                Plugin.PLUGIN_ID,
                0,
                "One or more OSGi Frameworks have already been launched for this configuration. Additional framework instances may interfere with each other due to the shared storage directory.",
                null);
        IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(status);
        if (prompter != null) {
          boolean okay = (Boolean) prompter.handleStatus(status, launchResource);
          if (!okay) return okay;
        }
      }
    }

    IStatus launchStatus = getLauncherStatus();

    IStatusHandler prompter = DebugPlugin.getDefault().getStatusHandler(launchStatus);
    if (prompter != null) return (Boolean) prompter.handleStatus(launchStatus, model);
    return true;
  }
Ejemplo n.º 4
0
  public boolean isPVSRunning() {
    ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
    IProcess[] processes = manager.getProcesses();
    for (IProcess p : processes) {
      if (Activator.name.equals(p.getLabel())) {
        return !p.isTerminated();
      }
    }
    return false;
    // TODO: this should later be replaced by:
    // return mode != PVSMode.OFF;

  }
Ejemplo n.º 5
0
 private void tryConnect() throws RpcException {
   synchronized (connectLock) {
     switch (state) {
       case DISCONNECTED:
         reported = false;
         if (connectRetry()) {
           state = State.CONNECTED;
         } else if (connectOnce) {
           state = State.DOWN;
         } else {
           state = State.DISCONNECTED;
         }
         break;
       case CONNECTED:
         break;
       case DOWN:
         try {
           if (process != null) {
             process.terminate();
           }
         } catch (final DebugException e) {
           ErlLogger.info(e);
         }
         // TODO restart it??
         // process =
         if (!stopped) {
           final String msg = reportRuntimeDown(data.getNodeName());
           throw new RpcException(msg);
         }
     }
   }
 }
 /* (non-Javadoc)
  * @see java.lang.Thread#run()
  */
 public IStatus run(IProgressMonitor mon) {
   try {
     // There is no join on a process available, so we will have to
     // busy wait. Give it 10 seconds in 1/10 second intervals.
     for (int i = 0; !process.isTerminated() && i < 100; i++) {
       try {
         Thread.sleep(100);
       } catch (InterruptedException e) {
       }
     }
     if (!process.isTerminated()) {
       process.terminate();
     }
   } catch (DebugException e) {
   }
   return Status.OK_STATUS;
 }
Ejemplo n.º 7
0
 public void stopPVS() {
   if (iprocess != null) {
     if (iprocess.canTerminate()) {
       try {
         iprocess.terminate();
         iprocess = null;
         process = null;
         for (PVSStateChangeListener l : stateListeners) {
           l.sourceChanged(PVSConstants.PVSRUNNING, PVSConstants.FALSE);
         }
         DebugPlugin.getDefault().removeDebugEventListener(instance);
       } catch (DebugException e) {
         e.printStackTrace();
       }
     }
   }
   mode = PVSMode.OFF;
 }
Ejemplo n.º 8
0
 @Override
 public void selectionChanged(final IAction action, final ISelection selection) {
   fLaunch = null;
   if (selection instanceof IStructuredSelection) {
     final IStructuredSelection ss = (IStructuredSelection) selection;
     for (final Object o : ss.toArray()) {
       if (o instanceof ErlangDebugElement) {
         final ErlangDebugElement d = (ErlangDebugElement) o;
         fLaunch = d.getLaunch();
       } else if (o instanceof ILaunch) {
         fLaunch = (ILaunch) o;
       } else if (o instanceof IProcess) {
         final IProcess p = (IProcess) o;
         fLaunch = p.getLaunch();
       }
     }
   }
 }
Ejemplo n.º 9
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);
  }
Ejemplo n.º 10
0
  private void registerProcess(
      ILaunch launch,
      SDBGLaunchConfigWrapper launchConfig,
      IProcess process,
      String processDescription) {
    launch.setAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, "UTF-8");
    launch.addProcess(process);

    if (processDescription != null) {
      process.setAttribute(IProcess.ATTR_CMDLINE, processDescription);
    }
  }
 private void terminateForked() {
   if (killPorts != null) {
     for (int killPort : killPorts) {
       try {
         URI killUrl = new URI("http://localhost:" + killPort);
         HttpUtil.ping(killUrl);
       } catch (Throwable e) {
       }
     }
   }
   if (processes != null && processes.length > 1) {
     // Make sure all processes are terminated
     for (IProcess process : processes) {
       try {
         if (process.canTerminate() && !process.isTerminated()) {
           process.terminate();
         }
       } catch (Throwable e) {
         GrailsCoreActivator.log(e);
       }
     }
     processes = null;
   }
 }
Ejemplo n.º 12
0
 /*
  * (non-Javadoc)
  *
  * @see org.eclipse.ui.part.IShowInSource#getShowInContext()
  */
 public ShowInContext getShowInContext() {
   IProcess process = getProcess();
   if (process == null) {
     return null;
   }
   IDebugTarget target = (IDebugTarget) process.getAdapter(IDebugTarget.class);
   ISelection selection = null;
   if (target == null) {
     selection =
         new TreeSelection(
             new TreePath(
                 new Object[] {
                   DebugPlugin.getDefault().getLaunchManager(), process.getLaunch(), process
                 }));
   } else {
     selection =
         new TreeSelection(
             new TreePath(
                 new Object[] {
                   DebugPlugin.getDefault().getLaunchManager(), target.getLaunch(), target
                 }));
   }
   return new ShowInContext(null, selection);
 }
Ejemplo n.º 13
0
  @Override
  protected void init() {
    super.init();

    if (process.isTerminated()) {
      if (shellConnection != null) {
        try {
          shellConnection.disconnect();
        } catch (final IOException e) {
          KarafUIPluginActivator.getLogger().error("Unable to disconnect from SSH server", e);
        }
      }
    } else {
      DebugPlugin.getDefault().addDebugEventListener(this);
    }
  }
Ejemplo n.º 14
0
  /**
   * Computes and returns the current name of this console.
   *
   * @return a name for this console
   */
  protected String computeName() {
    String label = null;
    final IProcess process = getProcess();
    final ILaunchConfiguration config = process.getLaunch().getLaunchConfiguration();

    label = process.getAttribute(IProcess.ATTR_PROCESS_LABEL);
    if (label == null) {
      if (config == null) {
        label = process.getLabel();
      } else {
        // check if PRIVATE config
        if (DebugUITools.isPrivate(config)) {
          label = process.getLabel();
        } else {
          String type = null;
          try {
            type = config.getType().getName();
          } catch (final CoreException e) {
          }
          final StringBuffer buffer = new StringBuffer();
          buffer.append("Remote shell connection to: ");
          buffer.append(config.getName());
          if (type != null) {
            buffer.append(" ["); // $NON-NLS-1$
            buffer.append(type);
            buffer.append("] "); // $NON-NLS-1$
          }
          buffer.append(process.getLabel());
          label = buffer.toString();
        }
      }
    }

    if (process.isTerminated()) {
      return MessageFormat.format("<disconnected> {0}", (Object[]) new String[] {label});
    }
    return label;
  }
  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);
    // }
    // }
  }
  /** When a console page is initialized, */
  public void init(IPageBookViewPage page, final IConsole console) {
    if (!(console instanceof ProcessConsole)) {
      return;
    }
    ProcessConsole processConsole = (ProcessConsole) console;
    IProcess process = processConsole.getProcess();
    if (process == null) {
      return;
    }
    if (!PyCodeCompletionPreferencesPage.useCodeCompletion()
        || !PyCodeCompletionPreferencesPage.useCodeCompletionOnDebug()) {
      return;
    }
    String attribute = process.getAttribute(Constants.PYDEV_DEBUG_IPROCESS_ATTR);
    if (!Constants.PYDEV_DEBUG_IPROCESS_ATTR_TRUE.equals(attribute)) {
      // Only provide code-completion for pydev debug processes.
      return;
    }
    Control control = page.getControl();
    if (page instanceof IOConsolePage) {

      // Note that completions on "all letters and '_'" are already activated just by installing
      // the content assist, but the completions on the default keybinding is not, so, we have to
      // call it ourselves here.
      control.addKeyListener(
          new KeyListener() {
            public void keyPressed(KeyEvent e) {

              if (KeyBindingHelper.matchesContentAssistKeybinding(e)) {
                contentAssist.showPossibleCompletions();
              }
            }

            public void keyReleased(KeyEvent e) {}
          });

      IOConsolePage consolePage = (IOConsolePage) page;
      TextConsoleViewer viewer = consolePage.getViewer();

      contentAssist =
          new PyContentAssistant() {
            public String showPossibleCompletions() {
              // Only show completions if we're in a suspended console.
              if (getCurrentSuspendedPyStackFrame(console) == null) {
                return null;
              }
              return super.showPossibleCompletions();
            };
          };
      contentAssist.setInformationControlCreator(
          PyContentAssistant.createInformationControlCreator(viewer));
      ILaunch launch = process.getLaunch();
      IDebugTarget debugTarget = launch.getDebugTarget();
      IInterpreterInfo projectInterpreter = null;
      if (debugTarget instanceof PyDebugTarget) {
        PyDebugTarget pyDebugTarget = (PyDebugTarget) debugTarget;
        PythonNature nature = PythonNature.getPythonNature(pyDebugTarget.project);
        if (nature != null) {
          try {
            projectInterpreter = nature.getProjectInterpreter();
          } catch (Throwable e1) {
            Log.log(e1);
          }
        }
      }
      contentAssist.install(new ScriptConsoleViewerWrapper(viewer, projectInterpreter));

      PydevConsoleInterpreter interpreter = new PydevConsoleInterpreter();
      interpreter.setConsoleCommunication(new GetCompletionsInDebug());

      IContentAssistProcessor processor =
          new PydevConsoleCompletionProcessor(interpreter, contentAssist);
      contentAssist.setContentAssistProcessor(processor, IOConsolePartition.INPUT_PARTITION_TYPE);
      contentAssist.setContentAssistProcessor(processor, IOConsolePartition.OUTPUT_PARTITION_TYPE);

      contentAssist.enableAutoActivation(true);
      contentAssist.enableAutoInsert(false);
      contentAssist.setAutoActivationDelay(PyCodeCompletionPreferencesPage.getAutocompleteDelay());
    }
  }
Ejemplo n.º 17
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;
  }
Ejemplo n.º 18
0
  public KarafRemoteConsole(
      final IProcess process,
      final KarafSshConnectionUrl connectionUrl,
      final KarafSshShellConnection.Credentials credentials,
      final IConsoleColorProvider colorProvider,
      final String name,
      final String encoding) {
    super(
        name,
        KARAF_REMOTE_CONSOLE_TYPE,
        KarafUIPluginActivator.getDefault()
            .getImageRegistry()
            .getDescriptor(KarafUIPluginActivator.LOGO_16X16_IMG),
        encoding,
        true);

    this.process = process;
    this.inputStream = getInputStream();
    this.colorProvider = colorProvider;

    final Color color = this.colorProvider.getColor(IDebugUIConstants.ID_STANDARD_INPUT_STREAM);
    this.inputStream.setColor(color);

    final InputStream noAvailableInputStream =
        new FilterInputStream(inputStream) {
          @Override
          public int available() throws IOException {
            return 0;
          }
        };

    setName(computeName());
    final IOConsoleOutputStream outputStream = newOutputStream();

    boolean remoteShellEnabled = false;
    try {
      final ILaunchConfiguration configuration = process.getLaunch().getLaunchConfiguration();
      remoteShellEnabled =
          configuration.getAttribute(
              KarafLaunchConfigurationConstants.KARAF_LAUNCH_START_REMOTE_CONSOLE, false);
    } catch (final CoreException e) {
      return;
    }

    if (remoteShellEnabled) {
      shellConnection =
          new KarafSshShellConnection(
              connectionUrl, credentials, noAvailableInputStream, outputStream, outputStream);

      final KarafRemoteShellConnectJob job = new KarafRemoteShellConnectJob(name, shellConnection);
      job.addJobChangeListener(
          new JobChangeAdapter() {
            @Override
            public void done(final IJobChangeEvent event) {
              if (!event.getResult().isOK()) {
                final Throwable t = event.getResult().getException();
                writeTo(
                    outputStream,
                    "Unable to connect to SSH server: "
                        + (t != null ? t.getLocalizedMessage() : "Unknown error"));
              }
            }
          });

      DebugPlugin.getDefault()
          .addDebugEventListener(
              new IDebugEventSetListener() {

                @Override
                public void handleDebugEvents(final DebugEvent[] events) {

                  for (final DebugEvent event : events) {
                    if (process != null
                        && process.equals(event.getSource())
                        && event.getKind() == DebugEvent.TERMINATE) {
                      job.cancel();
                    }
                  }
                }
              });

      job.schedule(15 * 1000);
    } else {
      writeTo(
          outputStream,
          "The Karaf remote shell is disabled. Enable it in the launch configuration dialog.");
    }
  }