Example #1
0
  @Override
  public void terminate() {
    if (terminated.getAndSet(true)) return;

    if (sproxy != null) sproxy.close();

    try {
      launcher.cancel();
    } catch (Exception e) {
      // ignore
    } finally {
      fireTerminateEvent();
    }
    IDebugTarget[] debugTargets = launch.getDebugTargets();
    for (int i = 0; i < debugTargets.length; i++) {
      IDebugTarget target = debugTargets[i];
      if (target.canDisconnect()) {
        try {
          target.disconnect();
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
 protected Object getDebugTarget() {
   IDebugTarget[] debugTargets = DebugPlugin.getDefault().getLaunchManager().getDebugTargets();
   for (IDebugTarget iDebugTarget : debugTargets) {
     if (iDebugTarget.isTerminated()) continue;
     if (iDebugTarget.getAdapter(ISimulationEngine.class) == this) return iDebugTarget;
   }
   return null;
 }
  private void abortContinueDialog(final IDebugTarget target) {
    // do not report errors for snippet editor targets
    // that do not support HCR. HCR is simulated by using
    // a new class loader for each evaluation
    // final ILaunch launch = target.getLaunch();
    // if (launch.getAttribute(ScrapbookLauncher.SCRAPBOOK_LAUNCH) != null)
    // {
    // if (!target.supportsHotCodeReplace()) {
    // return;
    // }
    // }
    final Display display = ErlideUIPlugin.getStandardDisplay();
    if (display.isDisposed()) {
      return;
    }

    String name = null;
    try {
      name = target.getName();
    } catch (final DebugException e) {
      name = ""; // never happens, ErlangDebugTarget doesn't throw this...
    }
    final String vmName = name;
    final ILaunchConfiguration config = target.getLaunch().getLaunchConfiguration();
    final String launchName = config != null ? config.getName() : "<unknown>";
    final IStatus status =
        new Status(IStatus.ERROR, ErlangCore.PLUGIN_ID, IStatus.ERROR, "Can't replace code", null);
    final String title = "Code Replace Failed";
    final String message =
        MessageFormat.format(
            "Some code changes cannot be replaced when being debugged.",
            new Object[] {vmName, launchName});
    display.asyncExec(
        new Runnable() {
          @Override
          public void run() {
            if (display.isDisposed()) {
              return;
            }
            final Shell shell = ErlideUIPlugin.getActiveWorkbenchShell();
            final HotCodeReplaceErrorDialog dialog =
                new HotCodeReplaceErrorDialog(shell, title, message, status, target);
            dialog.setBlockOnOpen(false);
            dialog.open();
          }
        });
  }
Example #4
0
  /**
   * Notification the target has resumed for the given reason
   *
   * @param detail reason for the resume
   */
  public void resumed(int detail) {
    thread.setSuspended(false);
    thread.resumedByVM();

    thread.fireResumeEvent(detail);

    for (IDebugTarget target : this.getLaunch().getDebugTargets()) {
      if (target != this) {
        try {
          target.resume();
        } catch (DebugException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      }
    }
  }
 /*
  * (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);
 }
  /**
   * Create debugging target similar to a remote debugging session would and add them to the launch.
   * This is to support debugging of 'forked mode' run-app and test-app processes. These are
   * processes spun-off by Grails in new JVM.
   *
   * @param port the remote launch will be listening on for forked process to connect to.
   */
  private void launchRemote(
      int port,
      ILaunchConfiguration configuration,
      String mode,
      ILaunch launch,
      IProgressMonitor monitor)
      throws CoreException {
    if (port < 0) {
      return;
    }
    if (monitor == null) {
      monitor = new NullProgressMonitor();
    }

    monitor.beginTask(
        NLS.bind(
            LaunchingMessages
                .JavaRemoteApplicationLaunchConfigurationDelegate_Attaching_to__0_____1,
            new String[] {configuration.getName()}),
        3);
    // check for cancellation
    if (monitor.isCanceled()) {
      return;
    }
    try {
      monitor.subTask(
          LaunchingMessages
              .JavaRemoteApplicationLaunchConfigurationDelegate_Verifying_launch_attributes____1);

      String connectorId =
          "org.eclipse.jdt.launching.socketListenConnector"; // getVMConnectorId(configuration);
      IVMConnector connector = JavaRuntime.getVMConnector(connectorId);
      if (connector == null) {
        abort(
            LaunchingMessages
                .JavaRemoteApplicationLaunchConfigurationDelegate_Connector_not_specified_2,
            null,
            IJavaLaunchConfigurationConstants.ERR_CONNECTOR_NOT_AVAILABLE);
      }

      Map<String, String> argMap = new HashMap<String, String>();

      //	        int connectTimeout = Platform.getPreferencesService().getInt(
      //	        		LaunchingPlugin.ID_PLUGIN,
      //	        		JavaRuntime.PREF_CONNECT_TIMEOUT,
      //	        		JavaRuntime.DEF_CONNECT_TIMEOUT,
      //	        		null);
      argMap.put(
          "timeout",
          "120000"); // Give grails run-app command enough time to build the app and kick off a
                     // forked process.
      argMap.put("port", "" + port);

      // check for cancellation
      if (monitor.isCanceled()) {
        return;
      }

      monitor.worked(1);

      // Don't think we need to set source location since the main launch method already does this.

      //
      //	monitor.subTask(LaunchingMessages.JavaRemoteApplicationLaunchConfigurationDelegate_Creating_source_locator____2);
      //			// set the default source locator if required
      //			setDefaultSourceLocator(launch, configuration);
      //			monitor.worked(1);

      // connect to remote VM
      connector.connect(argMap, monitor, launch);

      // check for cancellation
      if (monitor.isCanceled()) {
        IDebugTarget[] debugTargets = launch.getDebugTargets();
        for (int i = 0; i < debugTargets.length; i++) {
          IDebugTarget target = debugTargets[i];
          if (target.canDisconnect()) {
            target.disconnect();
          }
        }
        return;
      }
    } finally {
      monitor.done();
    }
  }