예제 #1
0
  void doDebug(IProgressMonitor monitor) throws InterruptedException {
    monitor.setTaskName(
        "Connecting debugger "
            + session.getName()
            + " to "
            + session.getHost()
            + ":"
            + session.getJdb());

    Map<String, String> parameters = new HashMap<String, String>();
    parameters.put("hostname", session.getHost());
    parameters.put("port", session.getJdb() + "");
    parameters.put("timeout", session.getTimeout() + "");
    IVMConnector connector = JavaRuntime.getDefaultVMConnector();

    while (!monitor.isCanceled()) {

      try {
        connector.connect(parameters, monitor, launch);
        break;
      } catch (Exception e) {
        Thread.sleep(500);
      }
    }
  }
  /**
   * 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();
    }
  }