示例#1
0
  public void run(ItemPointer p, IProject project) {
    editor = null;
    Object file = p.file;
    String zipFilePath = p.zipFilePath;

    if (zipFilePath != null) {
      // currently, only open zip file
      editor = PyOpenEditor.doOpenEditor((File) file, zipFilePath);

    } else if (file instanceof IFile) {
      IFile f = (IFile) file;
      editor = PyOpenEditor.doOpenEditor(f);

    } else if (file instanceof IPath) {
      IPath path = (IPath) file;
      editor = PyOpenEditor.doOpenEditor(path, project);

    } else if (file instanceof File) {
      String absPath = FileUtils.getFileAbsolutePath((File) file);
      IPath path = Path.fromOSString(absPath);
      editor = PyOpenEditor.doOpenEditor(path, project);
    }

    if (editor instanceof ITextEditor && p.start.line >= 0) {
      EditorUtils.showInEditor((ITextEditor) editor, p.start, p.end);
    }
  }
  /**
   * Create a project with the structure:
   *
   * <p>/pydev_unit_test_project junit.jar <-- set in pythonpath /src <-- set in pythonpath /pack1
   * __init__.py /pack2 __init__.py mod1.py
   *
   * <p>/java_unit_test_project /src <-- set in classpath JavaDefault.java (default package)
   * /javamod1/JavaClass.java /javamod2/JavaClass.java
   *
   * <p>Note: the initialization of the structure will happen only once and will be re-used in all
   * the tests after it.
   */
  @Override
  protected void setUp() throws Exception {
    closeWelcomeView();

    String mod1Contents = "import java.lang.Class\njava.lang.Class";
    if (editor == null) {
      InterpreterInfo.configurePathsCallback =
          new ICallback<Boolean, Tuple<List<String>, List<String>>>() {
            public Boolean call(Tuple<List<String>, List<String>> arg) {
              return Boolean.TRUE;
            }
          };
      PydevPlugin.setJythonInterpreterManager(
          new JythonInterpreterManager(PydevPlugin.getDefault().getPluginPreferences()));
      PydevPlugin.setPythonInterpreterManager(
          new PythonInterpreterManager(PydevPlugin.getDefault().getPluginPreferences()));

      ProjectModulesManager.IN_TESTS = true;
      NullProgressMonitor monitor = new NullProgressMonitor();

      createJythonInterpreterManager(monitor);
      createPythonInterpreterManager(monitor);

      IProject project = createProject(monitor, "pydev_unit_test_project");
      IJavaProject javaProject =
          configureAsJavaProject(createProject(monitor, "java_unit_test_project"), monitor);
      setProjectReference(monitor, project, javaProject);

      createJunitJar(monitor, project);
      createGrinderJar(monitor, project);

      IFolder sourceFolder = createSourceFolder(monitor, project);

      initFile = createPackageStructure(sourceFolder, "pack1.pack2", monitor);

      mod1 = initFile.getParent().getFile(new Path("mod1.py"));

      // OK, structure created, now, let's open mod1.py with a PyEdit so that the tests can begin...

      // create the contents and open the editor
      mod1.create(new ByteArrayInputStream(mod1Contents.getBytes()), true, monitor);

      PythonNature nature = PythonNature.getPythonNature(project);

      waitForNatureToBeRecreated(nature);

      editor = (PyEdit) PyOpenEditor.doOpenEditor(mod1);
    } else {
      setFileContents(mod1Contents); // just make sure that the contents of mod1 are correct.
    }
  }