Exemplo n.º 1
0
    @SuppressWarnings("unchecked")
    protected IStatus run(IProgressMonitor monitorArg) {

      String paths;
      paths = submittedPaths;

      try {
        final JobProgressComunicator jobProgressComunicator =
            new JobProgressComunicator(
                monitorArg, "Rebuilding modules", IProgressMonitor.UNKNOWN, this);
        final PythonNature nature = PythonNature.this;
        try {
          ICodeCompletionASTManager tempAstManager = astManager;
          if (tempAstManager == null) {
            tempAstManager = new ASTManager();
          }
          synchronized (tempAstManager.getLock()) {
            astManager = tempAstManager;
            tempAstManager.setProject(
                getProject(), nature, false); // it is a new manager, so, remove all deltas

            // begins task automatically
            tempAstManager.changePythonPath(paths, project, jobProgressComunicator);
            saveAstManager();

            List<IInterpreterObserver> participants =
                ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_INTERPRETER_OBSERVER);
            for (IInterpreterObserver observer : participants) {
              try {
                observer.notifyProjectPythonpathRestored(nature, jobProgressComunicator);
              } catch (Exception e) {
                // let's keep it safe
                PydevPlugin.log(e);
              }
            }
          }
        } catch (Throwable e) {
          PydevPlugin.log(e);
        }

        PythonNatureListenersManager.notifyPythonPathRebuilt(project, nature);
        // end task
        jobProgressComunicator.done();
      } catch (Exception 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);
    }
  }