private static ILaunchConfiguration createLaunchConfigurationForProject(IJavaProject javaProject)
      throws CoreException {

    DebugPlugin plugin = DebugPlugin.getDefault();
    ILaunchManager manager = plugin.getLaunchManager();

    ILaunchConfigurationType javaAppType =
        manager.getLaunchConfigurationType(IJavaLaunchConfigurationConstants.ID_JAVA_APPLICATION);
    ILaunchConfigurationWorkingCopy wc = javaAppType.newInstance(null, "temp-config");

    wc.setAttribute(
        IJavaLaunchConfigurationConstants.ATTR_PROJECT_NAME, javaProject.getElementName());
    return wc;
  }
Example #2
0
  /** @return a map with the env variables for the system */
  @SuppressWarnings("unchecked")
  private static Map<String, String> getDefaultSystemEnv(
      DebugPlugin defaultPlugin, IPythonNature nature) throws CoreException {
    if (defaultPlugin != null) {
      ILaunchManager launchManager = defaultPlugin.getLaunchManager();

      // build base environment
      Map<String, String> env = new HashMap<String, String>();
      env.putAll(launchManager.getNativeEnvironment());

      // Add variables from config
      boolean win32 = PlatformUtils.isWindowsPlatform();
      for (Iterator iter = env.entrySet().iterator(); iter.hasNext(); ) {
        Map.Entry entry = (Map.Entry) iter.next();
        String key = (String) entry.getKey();
        if (win32) {
          // Win32 vars are case insensitive. Uppercase everything so
          // that (for example) "pAtH" will correctly replace "PATH"
          key = key.toUpperCase();
        }
        String value = (String) entry.getValue();
        // translate any string substitution variables
        String translated = value;
        try {
          StringSubstitution stringSubstitution = new StringSubstitution(nature);
          translated = stringSubstitution.performStringSubstitution(value, false);
        } catch (Exception e) {
          Log.log(e);
        }
        env.put(key, translated);
      }

      // Always remove PYTHONHOME from the default system env, as it doesn't work well with multiple
      // interpreters.
      env.remove("PYTHONHOME");
      return env;
    }
    return null;
  }