private static void execute(String commandLine, String[] expectedArgs, String expectedRendered)
      throws Exception {
    String[] arguments = DebugPlugin.parseArguments(commandLine);
    assertEquals(
        "unexpected parseArguments result;", //$NON-NLS-1$
        Arrays.asList(expectedArgs).toString(),
        Arrays.asList(arguments).toString());

    runCommandLine(commandLine, arguments);

    String rendered = DebugPlugin.renderArguments(arguments, null);
    assertEquals("unexpected renderArguments result;", expectedRendered, rendered); // $NON-NLS-1$

    if (!commandLine.equals(rendered)) {
      String[] arguments2 = DebugPlugin.parseArguments(rendered);
      assertEquals(
          "parsing rendered command line doesn't yield original arguments;", //$NON-NLS-1$
          Arrays.asList(expectedArgs).toString(),
          Arrays.asList(arguments2).toString());
    }

    String[] splitArguments = DebugPlugin.splitArguments(commandLine);
    assertEquals(expectedArgs.length, splitArguments.length);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < splitArguments.length; i++) {
      if (i > 0) {
        sb.append(" "); // $NON-NLS-1$
      }
      sb.append(splitArguments[i]);
    }
    assertEquals(commandLine, sb.toString());
  }
  @Override
  public void setupLaunchConfiguration(
      ILaunchConfigurationWorkingCopy workingCopy, IProgressMonitor monitor) throws CoreException {

    super.setupLaunchConfiguration(workingCopy, monitor);

    workingCopy.setAttribute(DebugPlugin.ATTR_CONSOLE_ENCODING, "UTF-8"); // $NON-NLS-1$

    String existingVMArgs =
        workingCopy.getAttribute(
            IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, (String) null);

    if (null != existingVMArgs) {
      String[] parsedVMArgs = DebugPlugin.parseArguments(existingVMArgs);

      List<String> memoryArgs = new ArrayList<String>();

      if (!CoreUtil.isNullOrEmpty(parsedVMArgs)) {
        for (String pArg : parsedVMArgs) {
          if (pArg.startsWith("-Xm") || pArg.startsWith("-XX:")) // $NON-NLS-1$ //$NON-NLS-2$
          {
            memoryArgs.add(pArg);
          }
        }
      }

      String argsWithoutMem =
          mergeArguments(
              existingVMArgs, getRuntimeVMArguments(), memoryArgs.toArray(new String[0]), false);
      String fixedArgs = mergeArguments(argsWithoutMem, getRuntimeVMArguments(), null, false);

      workingCopy.setAttribute(IJavaLaunchConfigurationConstants.ATTR_VM_ARGUMENTS, fixedArgs);
    }
  }
 public String[] getProgramArguments() throws CoreException {
   return DebugPlugin.parseArguments(programArguments);
 }
Пример #4
0
  /**
   * Try to get the war output path from server launch config.
   *
   * @param server is the server launcher
   * @param serverLaunchConfig server launcher config
   * @return string path to the output war
   */
  private String getLauncherDirFromServerLaunchConfigAttributes(
      IServer server, ILaunchConfiguration serverLaunchConfig) {
    if (server == null || serverLaunchConfig == null) {
      return null;
    }

    // First get wtp.deploy from the server attributes
    Map<String, Object> launchConfigAttributes = null;
    try {
      launchConfigAttributes = serverLaunchConfig.getAttributes();
    } catch (CoreException e) {
      logError(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: can't find launcher directory in ATTR_VM_ARGUMENTS.",
          e);
    }

    // Get the vm arguments in the launch configs vm args
    String vmArgsString =
        (String) launchConfigAttributes.get("org.eclipse.jdt.launching.VM_ARGUMENTS");
    if (vmArgsString == null || vmArgsString.isEmpty()) {
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: can't get org.eclipse.jdt.launching.VM_ARGUMENTS from the launch config.");
      return null;
    }

    // Create an array from the vm args string
    String[] vmArgsArray = DebugPlugin.parseArguments(vmArgsString);
    if (vmArgsArray == null || vmArgsString.isEmpty()) {
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: can't parse vm args into an array.");
      return null;
    }

    String wtpDeployArg = null;
    for (int i = 0; i < vmArgsArray.length; i++) {
      String arg = vmArgsArray[i];
      if (arg != null && arg.startsWith("-Dwtp.deploy")) {
        wtpDeployArg = arg.replaceFirst("-Dwtp.deploy=", "");
        wtpDeployArg = wtpDeployArg.replace("\"", "").trim();
        break;
      }
    }

    if (wtpDeployArg == null || wtpDeployArg.isEmpty()) {
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: can't get \"-Dwtp.deploy=\" (w/no spaces) arg from vm args list.");
      return null;
    }

    // Next get the server project deploy name or deploy context relative path
    String launcherDir = null;
    String deployName = null;
    IModule[] modules = server.getModules();
    if (modules != null && modules.length > 0) {
      if (modules.length > 0) {
        logMessage(
            "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: launcherDir will use the first module for the deploy path.");
      }
      IModule2 module = (IModule2) modules[0];
      deployName = module.getProperty(IModule2.PROP_DEPLOY_NAME);
      if (deployName == null) {
        logMessage(
            "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: Couldn't get the deploy path for the module.");
      } else {
        launcherDir = wtpDeployArg + File.separator + deployName;
      }
    } else {
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: the modules are empty, add a wtp module.");
    }

    if (launcherDir == null) {
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: couldn't construct the launcherDir Path from server launch config.");
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: wtpDeployArg="
              + wtpDeployArg);
      logMessage(
          "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: wtpDeployArg="
              + deployName);
    }

    logMessage(
        "posiblyLaunchGwtSuperDevModeCodeServer > getLauncherDirFromServerLaunchConfigAttributes: Success, found the launcherDir="
            + launcherDir);

    return launcherDir;
  }