Merge pull request #386 fix conflict
authorElizaveta Shashkova <Elizaveta.Shashkova@jetbrains.com>
Wed, 11 May 2016 11:48:01 +0000 (14:48 +0300)
committerElizaveta Shashkova <Elizaveta.Shashkova@jetbrains.com>
Wed, 11 May 2016 11:48:01 +0000 (14:48 +0300)
1  2 
python/src/com/jetbrains/python/debugger/PyDebugRunner.java

index 9792c06af3a5c486a593a3e6fcc65e6f7a02ca00,69322272a41569b8b58513189030902e5344255b..24c225e838a42f2fbc3c851b94cf743b2298bebe
@@@ -28,7 -28,6 +28,7 @@@ import com.intellij.execution.ui.RunCon
  import com.intellij.openapi.application.ApplicationManager;
  import com.intellij.openapi.fileEditor.FileDocumentManager;
  import com.intellij.openapi.project.Project;
 +import com.intellij.openapi.projectRoots.Sdk;
  import com.intellij.openapi.roots.OrderRootType;
  import com.intellij.openapi.roots.ProjectRootManager;
  import com.intellij.openapi.util.text.StringUtil;
@@@ -54,6 -53,7 +54,7 @@@ import org.jetbrains.annotations.Nullab
  import java.io.File;
  import java.net.ServerSocket;
  import java.util.List;
+ import java.util.Map;
  
  /**
   * @author yole
@@@ -289,20 -289,8 +290,8 @@@ public class PyDebugRunner extends Gene
  
      configureDebugParameters(project, debugParams, pyState, cmd);
  
-     if (PyDebuggerOptionsProvider.getInstance(project).isSupportGeventDebugging()) {
-       cmd.getEnvironment().put(GEVENT_SUPPORT, "True");
-     }
-     PyDebuggerSettings debuggerSettings = PyDebuggerSettings.getInstance();
-     if (debuggerSettings.isSteppingFiltersEnabled()) {
-       cmd.getEnvironment().put(PYDEVD_FILTERS, debuggerSettings.getSteppingFiltersForProject(project));
-     }
-     if (debuggerSettings.isLibrariesFilterEnabled()) {
-       cmd.getEnvironment().put(PYDEVD_FILTER_LIBRARIES, "True");
-     }
  
-     addProjectRootsToEnv(project, cmd);
-     addSdkRootsToEnv(project, cmd);
+     configureDebugEnvironment(project, cmd.getEnvironment());
  
      final String[] debuggerArgs = new String[]{
        CLIENT_PARAM, "127.0.0.1",
      }
    }
  
+   public static void configureDebugEnvironment(@NotNull Project project, Map<String, String> environment) {
+     if (PyDebuggerOptionsProvider.getInstance(project).isSupportGeventDebugging()) {
+       environment.put(GEVENT_SUPPORT, "True");
+     }
+     PyDebuggerSettings debuggerSettings = PyDebuggerSettings.getInstance();
+     if (debuggerSettings.isSteppingFiltersEnabled()) {
+       environment.put(PYDEVD_FILTERS, debuggerSettings.getSteppingFiltersForProject(project));
+     }
+     if (debuggerSettings.isLibrariesFilterEnabled()) {
+       environment.put(PYDEVD_FILTER_LIBRARIES, "True");
+     }
+     addProjectRootsToEnv(project, environment);
+     addSdkRootsToEnv(project, environment);
+   }
    protected void configureDebugParameters(@NotNull Project project,
                                          @NotNull ParamsGroup debugParams,
                                          @NotNull PythonCommandLineState pyState,
      }
    }
  
-   private static void addProjectRootsToEnv(@NotNull Project project, @NotNull GeneralCommandLine commandLine) {
+   private static void addProjectRootsToEnv(@NotNull Project project, @NotNull Map<String, String> environment) {
  
      List<String> roots = Lists.newArrayList();
      for (VirtualFile contentRoot : ProjectRootManager.getInstance(project).getContentRoots()) {
        roots.add(contentRoot.getPath());
      }
  
-     commandLine.getEnvironment().put(IDE_PROJECT_ROOTS, StringUtil.join(roots, File.pathSeparator));
+     environment.put(IDE_PROJECT_ROOTS, StringUtil.join(roots, File.pathSeparator));
    }
  
-   private static void addSdkRootsToEnv(@NotNull Project project, @NotNull GeneralCommandLine commandLine) {
+   private static void addSdkRootsToEnv(@NotNull Project project, @NotNull Map<String, String> environment) {
      final RunManager runManager = RunManager.getInstance(project);
      final RunnerAndConfigurationSettings selectedConfiguration = runManager.getSelectedConfiguration();
      if (selectedConfiguration != null) {
        final RunConfiguration configuration = selectedConfiguration.getConfiguration();
        if (configuration instanceof AbstractPythonRunConfiguration) {
          AbstractPythonRunConfiguration runConfiguration = (AbstractPythonRunConfiguration)configuration;
 -        List<String> roots = Lists.newArrayList();
 -        for (VirtualFile contentRoot : runConfiguration.getSdk().getSdkModificator().getRoots(OrderRootType.CLASSES)) {
 -          roots.add(contentRoot.getPath());
 +        final Sdk sdk = runConfiguration.getSdk();
 +        if (sdk != null) {
 +          List<String> roots = Lists.newArrayList();
 +          for (VirtualFile contentRoot : sdk.getSdkModificator().getRoots(OrderRootType.CLASSES)) {
 +            roots.add(contentRoot.getPath());
 +          }
-           commandLine.getEnvironment().put(LIBRARY_ROOTS, StringUtil.join(roots, File.pathSeparator));
++          environment.put(LIBRARY_ROOTS, StringUtil.join(roots, File.pathSeparator));
          }
 -        environment.put(LIBRARY_ROOTS, StringUtil.join(roots, File.pathSeparator));
        }
      }
    }