示例#1
0
 /* (non-Javadoc)
  * @see org.eclipse.jdt.launching.IVMInstall#getVMRunner(java.lang.String)
  */
 public IVMRunner getVMRunner(String mode) {
   if (ILaunchManager.RUN_MODE.equals(mode)) {
     return new StandardVMRunner(this);
   } else if (ILaunchManager.DEBUG_MODE.equals(mode)) {
     return new StandardVMDebugger(this);
   }
   return null;
 }
示例#2
0
  public LSLTestInteractor(
      String launchMode,
      TestManager manager,
      String testDescriptor,
      InputStream in,
      OutputStream out) {
    reader = new BufferedReader(new InputStreamReader(in));
    writer = new PrintStream(out);

    this.testDescriptor = testDescriptor;
    this.manager = manager;
    this.debugMode = ILaunchManager.DEBUG_MODE.equals(launchMode);
  }
  /** @return <code>true</code> iff the runtime VM of this test session is still alive */
  public boolean isKeptAlive() {
    if (fTestRunnerClient != null
        && fLaunch != null
        && fTestRunnerClient.isRunning()
        && ILaunchManager.DEBUG_MODE.equals(fLaunch.getLaunchMode())) {
      ILaunchConfiguration config = fLaunch.getLaunchConfiguration();
      try {
        return config != null && config.getAttribute(DLTKTestingConstants.ATTR_KEEPRUNNING, false);
      } catch (CoreException e) {
        return false;
      }

    } else {
      return false;
    }
  }
 /**
  * Helper function to add system properties that tell Grails to debug run-app or test-app in as a
  * forked process in debugging mode.
  *
  * <p>These properties are added only if applicable. I.e. recent enough graisl version and this is
  * a debug-mode launch.
  *
  * <p>In the process of adding the arguments, we will pick a free port.
  *
  * @return Chosen debug port or -1 if not launching in forked debug mode.
  */
 private int addForkedModeDebuggingArgs(ILaunchConfiguration conf, String mode, List<String> args)
     throws IOException {
   // TODO Auto-generated method stub
   if (!ILaunchManager.DEBUG_MODE.equals(mode)) {
     return -1;
   }
   GrailsVersion version = GrailsLaunchArgumentUtils.getGrailsVersion(conf);
   if (GrailsVersion.V_2_3_.compareTo(version) > 0) {
     return -1; // Disable this feature for pre Grails 2.3.
   }
   int debugPort = portFinder.findUniqueFreePort();
   args.add("-Dgrails.project.fork.run.debug=true");
   args.add("-Dgrails.project.fork.test.debug=true");
   String debugArgs = "-Xrunjdwp:transport=dt_socket,server=n,suspend=y,address=" + debugPort;
   args.add("-Dgrails.project.fork.run.debugArgs=" + debugArgs);
   args.add("-Dgrails.project.fork.test.debugArgs=" + debugArgs);
   return debugPort;
 }
  @SuppressWarnings("unchecked")
  public void launch(
      ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
      throws CoreException {

    try {

      GrailsVersion version = GrailsLaunchArgumentUtils.getGrailsVersion(configuration);
      IProgressMonitor subMonitor = new SubProgressMonitor(monitor, 5);
      checkCancelled(subMonitor);
      subMonitor.beginTask("Starting Grails", 5);
      subMonitor.worked(1);
      checkCancelled(subMonitor);
      subMonitor.subTask("Configuring launch parameters...");

      // FIXKDV FIXADE Copies of this code exist in
      // GrailsLaunchArgumentUtils.prepareClasspath()
      // and GrailsLaunchConfigurationDelegate.launch()
      // consider refactoring to combine

      IVMRunner runner;
      IVMInstall vm = verifyVMInstall(configuration);
      if (GrailsVersion.V_2_3_.compareTo(version) <= 0) {
        // We'll be debugging the forked process, not the run-app command.
        runner = vm.getVMRunner(ILaunchManager.RUN_MODE);
      } else {
        runner = vm.getVMRunner(mode);
      }
      if (runner == null) {
        runner = vm.getVMRunner(ILaunchManager.RUN_MODE);
      }

      String projectName =
          configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, "");
      IProject project = null;
      if (!"".equals(projectName)) {
        project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
      }

      String grailsHome = GrailsLaunchArgumentUtils.getGrailsHome(configuration);
      String baseDir =
          configuration.getAttribute(GrailsLaunchArgumentUtils.PROJECT_DIR_LAUNCH_ATTR, "");
      if (baseDir.equals("")) {
        baseDir = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString();
      }
      String script = getScript(configuration);

      File workingDir = verifyWorkingDirectory(configuration);
      String workingDirName = null;
      if (workingDir != null) {
        workingDirName = workingDir.getAbsolutePath();
      } else {
        workingDirName = baseDir;
      }

      List<String> programArguments = new ArrayList<String>();
      programArguments.add("--conf");
      programArguments.add(grailsHome + "conf" + File.separatorChar + "groovy-starter.conf");
      programArguments.add("--main");
      programArguments.add("org.codehaus.groovy.grails.cli.GrailsScriptRunner");

      StringBuilder grailsCommand = new StringBuilder();
      String grailsWorkDir =
          configuration.getAttribute(GrailsLaunchArgumentUtils.GRAILS_WORK_DIR_LAUNCH_ATTR, "");
      if (!grailsWorkDir.equals("")) {
        grailsCommand.append("-Dgrails.work.dir=" + grailsWorkDir + " ");
      }
      grailsCommand.append(script + " ");
      programArguments.add(grailsCommand.toString().trim());

      List<String> vmArgs = new ArrayList<String>();
      // vmArgs.add("-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8123");

      // add manual configured vm options to the argument list
      String existingVmArgs = getVMArguments(configuration);
      boolean launchConfHasVMArgs = false;
      if (existingVmArgs != null && existingVmArgs.length() > 0) {
        launchConfHasVMArgs = true;
        StringTokenizer additionalArguments = new StringTokenizer(existingVmArgs, " ");
        while (additionalArguments.hasMoreTokens()) {
          vmArgs.add(additionalArguments.nextToken());
        }
      }

      Map<String, String> systemProps =
          GrailsCoreActivator.getDefault().getLaunchSystemProperties();
      GrailsLaunchArgumentUtils.setMaybe(systemProps, "base.dir", baseDir);
      GrailsLaunchArgumentUtils.setMaybe(systemProps, "grails.home", grailsHome);
      for (Map.Entry<String, String> prop : systemProps.entrySet()) {
        vmArgs.add("-D" + prop.getKey() + "=" + prop.getValue());
      }
      int forkedProcessDebugPort = addForkedModeDebuggingArgs(configuration, mode, vmArgs);
      ArrayList<Integer> killPorts = addKillPortArg(project, vmArgs);

      if (!launchConfHasVMArgs) {
        // If the user added their own vmargs to the launch config then the 'default' from global
        // prefs should
        // not be used.
        GrailsLaunchArgumentUtils.addUserDefinedJVMArgs(vmArgs);
      }
      // Grails uses some default memory settings that we want to use as well if no others have been
      // configured
      vmArgs = GrailsLaunchArgumentUtils.addMemorySettings(vmArgs);
      vmArgs = GrailsLaunchArgumentUtils.addSpringLoadedArgs(configuration, vmArgs);

      String[] envp = getEnvironment(configuration);
      Map<String, String> extra = new HashMap<String, String>();
      extra.put("JAVA_HOME", vm.getInstallLocation().getAbsolutePath());
      extra.put(
          "GROOVY_PAGE_ADD_LINE_NUMBERS", "true"); // Enables line number info for GSP debugging
      envp = GrailsLaunchArgumentUtils.addToEnvMaybe(envp, extra);

      Map<String, Object> vmAttributesMap = getVMSpecificAttributesMap(configuration);

      String[] classpath = getClasspath(configuration);
      String mainTypeName = verifyMainTypeName(configuration);

      VMRunnerConfiguration runConfiguration = new VMRunnerConfiguration(mainTypeName, classpath);
      runConfiguration.setProgramArguments(
          programArguments.toArray(new String[programArguments.size()]));
      runConfiguration.setVMArguments(vmArgs.toArray(new String[vmArgs.size()]));
      runConfiguration.setWorkingDirectory(workingDirName);
      runConfiguration.setEnvironment(envp);
      runConfiguration.setVMSpecificAttributesMap(vmAttributesMap);

      String[] bootpath = getBootpath(configuration);
      if (bootpath != null && bootpath.length > 0) {
        runConfiguration.setBootClassPath(bootpath);
      }

      subMonitor.worked(1);
      checkCancelled(subMonitor);

      subMonitor.subTask("Setting up source locator...");
      setDefaultSourceLocator(launch, configuration);
      subMonitor.worked(1);
      checkCancelled(subMonitor);

      subMonitor.worked(1);
      checkCancelled(subMonitor);

      subMonitor.subTask("Launching Grails...");

      if (ILaunchManager.DEBUG_MODE.equals(mode)) {
        launchRemote(forkedProcessDebugPort, configuration, mode, launch, subMonitor);
      }
      GrailsCoreActivator.getDefault().notifyCommandStart(project);
      runner.run(runConfiguration, launch, monitor);
      AbstractLaunchProcessListener listener = getLaunchListener(configuration);
      if (listener != null) {
        listener.init(launch.getProcesses()[0]);
      }
      DebugPlugin.getDefault()
          .addDebugEventListener(
              new GrailsProcessListener(launch.getProcesses(), project, killPorts));
      subMonitor.worked(1);
    } catch (Exception e) {
      GrailsCoreActivator.log(e);
    }
  }
  /*
   * (non-Javadoc)
   *
   * @seeorg.eclipse.php.internal.debug.core.debugger.parameters.
   * IDebugParametersInitializer
   * #generateQueryParameters(org.eclipse.debug.core.ILaunch)
   */
  public Hashtable<String, String> getDebugParameters(ILaunch launch) {
    Hashtable<String, String> parameters = new Hashtable<String, String>();
    ILaunchConfiguration launchConfiguration = launch.getLaunchConfiguration();
    parameters.put(START_DEBUG, "1"); // $NON-NLS-1$

    String port = launch.getAttribute(IDebugParametersKeys.PORT);
    if (port != null) {
      parameters.put(DEBUG_PORT, port);
    } else {
      PHPDebugPlugin.logErrorMessage(
          "A port was not defined for the DefaultDebugParametersInitializer."); //$NON-NLS-1$
    }

    if (getBooleanValue(launch.getAttribute(IDebugParametersKeys.PASSIVE_DEBUG))) {
      parameters.put(DEBUG_PASSIVE, "1"); // $NON-NLS-1$
    }

    parameters.put(SEND_SESS_END, "1"); // $NON-NLS-1$

    if (getBooleanValue(launch.getAttribute(IDebugParametersKeys.WEB_SERVER_DEBUGGER))) {
      String debugHosts = PHPDebugPlugin.getDebugHosts();
      // Set up custom server debug hosts if any
      if (launchConfiguration != null) {
        try {
          Server server =
              ServersManager.getServer(
                  launchConfiguration.getAttribute(Server.NAME, "")); // $NON-NLS-1$
          String customHosts = ZendDebuggerSettingsUtil.getDebugHosts(server.getUniqueId());
          if (!customHosts.isEmpty()) debugHosts = customHosts;
        } catch (CoreException ce) {
          Logger.logException(ce);
        }
      }
      parameters.put(DEBUG_HOST, debugHosts);

      parameters.put(DEBUG_NO_CACHE, Long.toString(System.currentTimeMillis()));
    }

    if (ILaunchManager.DEBUG_MODE.equals(launch.getLaunchMode())
        && getBooleanValue(launch.getAttribute(IDebugParametersKeys.FIRST_LINE_BREAKPOINT))) {
      parameters.put(DEBUG_STOP, "1"); // $NON-NLS-1$
    }
    String url = launch.getAttribute(IDebugParametersKeys.ORIGINAL_URL);
    if (url != null) {
      parameters.put(ORIGINAL_URL, url);
    }
    if (launchConfiguration != null) {
      try {
        String sessionSetting =
            launchConfiguration.getAttribute(
                IPHPDebugConstants.DEBUGGING_PAGES, IPHPDebugConstants.DEBUGGING_ALL_PAGES);
        if (IPHPDebugConstants.DEBUGGING_ALL_PAGES.equals(sessionSetting)) {
          parameters.put(DEBUG_ALL_PAGES, "1"); // $NON-NLS-1$
        } else if (IPHPDebugConstants.DEBUGGING_FIRST_PAGE.equals(sessionSetting)) {
          parameters.put(DEBUG_FIRST_PAGE, "1"); // $NON-NLS-1$
        } else if (IPHPDebugConstants.DEBUGGING_START_FROM.equals(sessionSetting)) {
          parameters.put(
              DEBUG_START_URL,
              launchConfiguration.getAttribute(
                  IPHPDebugConstants.DEBUGGING_START_FROM_URL, "")); // $NON-NLS-1$
          if (launchConfiguration.getAttribute(
              IPHPDebugConstants.DEBUGGING_SHOULD_CONTINUE, false)) {
            parameters.put(DEBUG_CONTINUE, "1"); // $NON-NLS-1$
          }
        }
      } catch (CoreException ce) {
        Logger.logException(ce);
      }
    }
    String sessID = launch.getAttribute(IDebugParametersKeys.SESSION_ID);
    if (sessID != null) {
      parameters.put(DEBUG_SESSION_ID, sessID);
    }

    return parameters;
  }