Search in sources :

Example 1 with MisconfigurationException

use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.

the class AnalysisBuilderRunnableForRemove method removeInfoForModule.

/**
 * @param moduleName this is the module name
 * @param nature this is the nature
 */
public static void removeInfoForModule(String moduleName, IPythonNature nature, boolean isFullBuild) {
    if (moduleName != null && nature != null) {
        AbstractAdditionalDependencyInfo info;
        try {
            info = AdditionalProjectInterpreterInfo.getAdditionalInfoForProject(nature);
        } catch (MisconfigurationException e) {
            Log.log(e);
            return;
        }
        boolean generateDelta;
        if (isFullBuild) {
            generateDelta = false;
        } else {
            generateDelta = true;
        }
        info.removeInfoFromModule(moduleName, generateDelta);
    } else {
        if (DebugSettings.DEBUG_ANALYSIS_REQUESTS) {
            org.python.pydev.shared_core.log.ToLogFile.toLogFile("Unable to remove info. name: " + moduleName + " or nature:" + nature + " is null.", AnalysisBuilderRunnableForRemove.class);
        }
    }
}
Also used : MisconfigurationException(org.python.pydev.core.MisconfigurationException) AbstractAdditionalDependencyInfo(com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo)

Example 2 with MisconfigurationException

use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.

the class AnalysisBuilderVisitor method visitChangedResource.

public void visitChangedResource(final IResource resource, final ICallback0<IDocument> document, final IProgressMonitor monitor, boolean forceAnalysis) {
    // we may need to 'force' the analysis when a module is renamed, because the first message we receive is
    // a 'delete' and after that an 'add' -- which is later mapped to this method, so, if we don't have info
    // on the module we should analyze it because it is 'probably' a rename.
    final PythonNature nature = getPythonNature(resource);
    if (nature == null) {
        return;
    }
    // Put things from the memo to final variables as we might need them later on and we cannot get them from
    // the memo later.
    final String moduleName;
    final SourceModule[] module = new SourceModule[] { null };
    final IDocument doc;
    doc = document.call();
    if (doc == null) {
        return;
    }
    try {
        moduleName = getModuleName(resource, nature);
    } catch (MisconfigurationException e) {
        Log.log(e);
        return;
    }
    // depending on the level of analysis we have to do, we'll decide whether we want
    // to make the full parse (slower) or the definitions parse (faster but only with info
    // related to the definitions)
    ICallback<IModule, Integer> moduleCallback = new ICallback<IModule, Integer>() {

        @Override
        public IModule call(Integer arg) {
            if (arg == IAnalysisBuilderRunnable.FULL_MODULE) {
                if (module[0] != null) {
                    return module[0];
                } else {
                    try {
                        module[0] = getSourceModule(resource, doc, nature);
                    } catch (MisconfigurationException e1) {
                        throw new RuntimeException(e1);
                    }
                    if (module[0] != null) {
                        return module[0];
                    }
                    try {
                        module[0] = createSoureModule(resource, doc, moduleName);
                    } catch (MisconfigurationException e) {
                        throw new RuntimeException(e);
                    }
                    return module[0];
                }
            } else if (arg == IAnalysisBuilderRunnable.DEFINITIONS_MODULE) {
                if (DebugSettings.DEBUG_ANALYSIS_REQUESTS) {
                    org.python.pydev.shared_core.log.ToLogFile.toLogFile(this, "PyDevBuilderPrefPage.getAnalyzeOnlyActiveEditor()");
                }
                IFile f = (IFile) resource;
                IPath location = f.getLocation();
                if (location != null) {
                    String file = location.toOSString();
                    File f2 = new File(file);
                    return new SourceModule(moduleName, f2, FastDefinitionsParser.parse(doc.get(), moduleName, f2), null, nature);
                }
                return null;
            } else {
                throw new RuntimeException("Unexpected parameter: " + arg);
            }
        }
    };
    long documentTime = this.getDocumentTime();
    if (documentTime == -1) {
        Log.log("Warning: The document time in the visitor is -1. Changing for current time.");
        documentTime = System.currentTimeMillis();
    }
    doVisitChangedResource(nature, resource, doc, moduleCallback, null, monitor, forceAnalysis, AnalysisBuilderRunnable.ANALYSIS_CAUSE_BUILDER, documentTime, false);
}
Also used : SourceModule(org.python.pydev.ast.codecompletion.revisited.modules.SourceModule) IModule(org.python.pydev.core.IModule) IFile(org.eclipse.core.resources.IFile) IPythonNature(org.python.pydev.core.IPythonNature) PythonNature(org.python.pydev.plugin.nature.PythonNature) IPath(org.eclipse.core.runtime.IPath) MisconfigurationException(org.python.pydev.core.MisconfigurationException) ICallback(org.python.pydev.shared_core.callbacks.ICallback) File(java.io.File) IFile(org.eclipse.core.resources.IFile) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with MisconfigurationException

use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.

the class AbstractAdditionalDependencyInfo method load.

/**
 * actually does the load
 * @return true if it was successfully loaded and false otherwise
 */
protected boolean load() {
    Throwable errorFound = null;
    synchronized (lock) {
        File file;
        try {
            file = getPersistingLocation();
        } catch (MisconfigurationException e) {
            Log.log("Unable to restore previous info... (persisting location not available).", e);
            return false;
        }
        if (file.exists() && file.isFile()) {
            try {
                return loadContentsFromFile(file, getNature()) != null;
            } catch (Throwable e) {
                errorFound = new RuntimeException("Unable to read: " + file, e);
            }
        }
    }
    try {
        String msg = "Info: Rebuilding internal caches: " + this.getPersistingLocation();
        if (errorFound == null) {
            msg += " (Expected error to be provided and got no error!)";
            Log.log(IStatus.ERROR, msg, errorFound);
        } else {
            Log.log(IStatus.INFO, msg, errorFound);
        }
    } catch (Exception e1) {
        Log.log("Rebuilding internal caches (error getting persisting location).");
    }
    return false;
}
Also used : MisconfigurationException(org.python.pydev.core.MisconfigurationException) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) MisconfigurationException(org.python.pydev.core.MisconfigurationException)

Example 4 with MisconfigurationException

use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.

the class IOUtils method save.

/**
 * this can be used to save the file
 */
public void save() {
    File persistingLocation;
    try {
        persistingLocation = getPersistingLocation();
    } catch (MisconfigurationException e) {
        Log.log("Error. Unable to get persisting location for additional interprer info. Configuration may be corrupted.", e);
        return;
    }
    if (DEBUG_ADDITIONAL_INFO) {
        System.out.println("Saving to " + persistingLocation);
    }
    save(persistingLocation);
}
Also used : MisconfigurationException(org.python.pydev.core.MisconfigurationException) File(java.io.File)

Example 5 with MisconfigurationException

use of org.python.pydev.core.MisconfigurationException in project Pydev by fabioz.

the class AdditionalProjectInterpreterInfo method getAdditionalInfoAndNature.

public static List<Tuple<AbstractAdditionalTokensInfo, IPythonNature>> getAdditionalInfoAndNature(IPythonNature nature, boolean addSystemInfo, boolean addReferencingProjects, boolean addReferencedProjects) throws MisconfigurationException {
    List<Tuple<AbstractAdditionalTokensInfo, IPythonNature>> ret = new ArrayList<Tuple<AbstractAdditionalTokensInfo, IPythonNature>>();
    IProject project = nature.getProject();
    // get for the system info
    if (addSystemInfo) {
        AbstractAdditionalTokensInfo systemInfo;
        try {
            systemInfo = AdditionalSystemInterpreterInfo.getAdditionalSystemInfo(InterpreterManagersAPI.getInterpreterManager(nature), nature.getProjectInterpreter().getExecutableOrJar());
        } catch (MisconfigurationException e) {
            throw e;
        } catch (PythonNatureWithoutProjectException e) {
            throw new RuntimeException(e);
        }
        ret.add(new Tuple<AbstractAdditionalTokensInfo, IPythonNature>(systemInfo, new SystemPythonNature(nature.getRelatedInterpreterManager())));
    }
    // get for the current project
    if (project != null) {
        AbstractAdditionalTokensInfo additionalInfoForProject = getAdditionalInfoForProject(nature);
        if (additionalInfoForProject != null) {
            ret.add(new Tuple<AbstractAdditionalTokensInfo, IPythonNature>(additionalInfoForProject, nature));
        }
        try {
            if (addReferencedProjects) {
                // get for the referenced projects
                Set<IProject> referencedProjects = ProjectModulesManager.getReferencedProjects(project);
                for (IProject refProject : referencedProjects) {
                    additionalInfoForProject = getAdditionalInfoForProject(PythonNature.getPythonNature(refProject));
                    if (additionalInfoForProject != null) {
                        ret.add(new Tuple<AbstractAdditionalTokensInfo, IPythonNature>(additionalInfoForProject, PythonNature.getPythonNature(refProject)));
                    }
                }
            }
            if (addReferencingProjects) {
                Set<IProject> referencingProjects = ProjectModulesManager.getReferencingProjects(project);
                for (IProject refProject : referencingProjects) {
                    additionalInfoForProject = getAdditionalInfoForProject(PythonNature.getPythonNature(refProject));
                    if (additionalInfoForProject != null) {
                        ret.add(new Tuple<AbstractAdditionalTokensInfo, IPythonNature>(additionalInfoForProject, PythonNature.getPythonNature(refProject)));
                    }
                }
            }
        } catch (Exception e) {
            Log.log(e);
        }
    }
    return ret;
}
Also used : MisconfigurationException(org.python.pydev.core.MisconfigurationException) ArrayList(java.util.ArrayList) IPythonNature(org.python.pydev.core.IPythonNature) SystemPythonNature(org.python.pydev.plugin.nature.SystemPythonNature) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) PythonNatureWithoutProjectException(org.python.pydev.core.PythonNatureWithoutProjectException) MisconfigurationException(org.python.pydev.core.MisconfigurationException) PythonNatureWithoutProjectException(org.python.pydev.core.PythonNatureWithoutProjectException) Tuple(org.python.pydev.shared_core.structure.Tuple)

Aggregations

MisconfigurationException (org.python.pydev.core.MisconfigurationException)99 IPythonNature (org.python.pydev.core.IPythonNature)28 ArrayList (java.util.ArrayList)23 File (java.io.File)21 CoreException (org.eclipse.core.runtime.CoreException)18 IOException (java.io.IOException)14 SourceModule (org.python.pydev.ast.codecompletion.revisited.modules.SourceModule)14 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)13 IDocument (org.eclipse.jface.text.IDocument)13 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)13 IInterpreterManager (org.python.pydev.core.IInterpreterManager)12 PythonNatureWithoutProjectException (org.python.pydev.core.PythonNatureWithoutProjectException)12 HashSet (java.util.HashSet)11 IModule (org.python.pydev.core.IModule)11 BadLocationException (org.eclipse.jface.text.BadLocationException)10 SimpleNode (org.python.pydev.parser.jython.SimpleNode)10 AbstractAdditionalDependencyInfo (com.python.pydev.analysis.additionalinfo.AbstractAdditionalDependencyInfo)9 IFile (org.eclipse.core.resources.IFile)9 IGrammarVersionProvider (org.python.pydev.core.IGrammarVersionProvider)9 TokensList (org.python.pydev.core.TokensList)9