Exemplo n.º 1
0
 @Override
 protected IStatus run(IProgressMonitor monitor) {
   try {
     if (astManager != null) {
       String pythonpath = pythonPathNature.getOnlyProjectPythonPathStr(true);
       PythonPathHelper pythonPathHelper =
           (PythonPathHelper) astManager.getModulesManager().getPythonPathHelper();
       // If it doesn't match, rebuid the pythonpath!
       if (!new HashSet<String>(PythonPathHelper.parsePythonPathFromStr(pythonpath, null))
           .equals(new HashSet<String>(pythonPathHelper.getPythonpath()))) {
         rebuildPath();
       }
     }
   } catch (CoreException e) {
     Log.log(e);
   }
   return Status.OK_STATUS;
 }
Exemplo n.º 2
0
  /**
   * Initializes the python nature if it still has not been for this session.
   *
   * <p>Actions includes restoring the dump from the code completion cache
   *
   * @param projectPythonpath this is the project python path to be used (may be null) -- if not
   *     null, this nature is being created
   * @param version this is the version (project type) to be used (may be null) -- if not null, this
   *     nature is being created
   * @param monitor
   * @param interpreter
   */
  @SuppressWarnings("unchecked")
  private void init(
      String version,
      String projectPythonpath,
      String externalProjectPythonpath,
      IProgressMonitor monitor,
      String interpreter,
      Map<String, String> variableSubstitution) {

    // if some information is passed, restore it (even if it was already initialized)
    boolean updatePaths =
        version != null
            || projectPythonpath != null
            || externalProjectPythonpath != null
            || variableSubstitution != null
            || interpreter != null;

    if (updatePaths) {
      this.getStore().startInit();
      try {
        if (variableSubstitution != null) {
          this.getPythonPathNature().setVariableSubstitution(variableSubstitution);
        }
        if (projectPythonpath != null) {
          this.getPythonPathNature().setProjectSourcePath(projectPythonpath);
        }
        if (externalProjectPythonpath != null) {
          this.getPythonPathNature().setProjectExternalSourcePath(externalProjectPythonpath);
        }
        if (version != null || interpreter != null) {
          this.setVersion(version, interpreter);
        }
      } catch (CoreException e) {
        Log.log(e);
      } finally {
        this.getStore().endInit();
      }
    } else {
      // Change: 1.3.10: it could be reloaded more than once... (when it shouldn't)
      if (astManager != null) {
        return; // already initialized...
      }
    }

    synchronized (initLock) {
      if (initialized && !updatePaths) {
        return;
      }
      initialized = true;
    }

    if (updatePaths) {
      // If updating the paths, rebuild and return (don't try to load an existing ast manager
      // and restore anything already there)
      rebuildPath();
      return;
    }

    if (monitor.isCanceled()) {
      checkPythonPathHelperPathsJob.schedule(500);
      return;
    }

    // Change: 1.3.10: no longer in a Job... should already be called in a job if that's needed.

    try {
      File astOutputFile = getAstOutputFile();
      if (astOutputFile == null) {
        Log.log(
            IStatus.INFO,
            "Not saving ast manager for: " + this.project + ". No write area available.",
            null);
        return; // The project was deleted
      }
      astManager = ASTManager.loadFromFile(astOutputFile);
      if (astManager != null) {
        synchronized (astManager.getLock()) {
          astManager.setProject(
              getProject(),
              this,
              true); // this is the project related to it, restore the deltas (we may have some
                     // crash)

          // just a little validation so that we restore the needed info if we did not get the
          // modules
          if (astManager.getModulesManager().getOnlyDirectModules().length < 15) {
            astManager = null;
          }

          if (astManager != null) {
            List<IInterpreterObserver> participants =
                ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_INTERPRETER_OBSERVER);
            for (IInterpreterObserver observer : participants) {
              try {
                observer.notifyNatureRecreated(this, monitor);
              } catch (Exception e) {
                // let's not fail because of other plugins
                Log.log(e);
              }
            }
          }
        }
      }
    } catch (Exception e) {
      // Log.logInfo("Info: Rebuilding internal caches for: "+this.project, e);
      astManager = null;
    }

    // errors can happen when restoring it
    if (astManager == null) {
      try {
        rebuildPath();
      } catch (Exception e) {
        Log.log(e);
      }
    } else {
      checkPythonPathHelperPathsJob.schedule(500);
    }
  }