protected boolean containsDebugOption(EnvironmentVariable var) {
   return var != null
       && var.getValue() != null
       && JAVA_OPTS.equals(var.getVariable())
       && (var.getValue().contains("-Xdebug")
           || var.getValue().contains("-Xrunjdwp")); // $NON-NLS-1$ //$NON-NLS-2$
 }
 protected EnvironmentVariable getDebugEnvironment(ApplicationDeploymentInfo info) {
   List<EnvironmentVariable> vars = info.getEnvVariables();
   for (EnvironmentVariable var : vars) {
     if (JAVA_OPTS.equals(var.getVariable())) {
       return var;
     }
   }
   return null;
 }
  protected void setEnvironmentVariable(
      CloudFoundryApplicationModule appModule,
      CloudFoundryServer cloudServer,
      int remoteDebugPort,
      IProgressMonitor monitor)
      throws CoreException {

    ApplicationDeploymentInfo info = appModule.getDeploymentInfo();
    List<EnvironmentVariable> vars = info.getEnvVariables();
    EnvironmentVariable javaOpts = getDebugEnvironment(info);

    IModule[] mod = new IModule[] {appModule.getLocalModule()};

    boolean restart = CloudFoundryProperties.isModuleStopped.testProperty(mod, cloudServer);

    if (!containsDebugOption(javaOpts)) {

      if (javaOpts == null) {
        javaOpts = new EnvironmentVariable();
        javaOpts.setVariable(JAVA_OPTS);
        vars.add(javaOpts);
      }

      String debugOpts =
          "-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address="
              + remoteDebugPort //$NON-NLS-1$
              + ",suspend=n"; //$NON-NLS-1$
      javaOpts.setValue(debugOpts);

      cloudServer
          .getBehaviour()
          .operations()
          .environmentVariablesUpdate(
              appModule.getLocalModule(), appModule.getDeployedApplicationName(), vars)
          .run(monitor);

      restart = true;
    }

    if (restart) {
      printToConsole(
          appModule,
          cloudServer,
          NLS.bind(
              Messages.SshDebugLaunchConfigDelegate_RESTARTING_APP,
              appModule.getDeployedApplicationName()),
          false);

      cloudServer
          .getBehaviour()
          .operations()
          .applicationDeployment(mod, ApplicationAction.START, false)
          .run(monitor);
    }
  }