Search in sources :

Example 1 with ProjectConfigError

use of org.python.pydev.navigator.elements.ProjectConfigError in project Pydev by fabioz.

the class ProjectInfoForPackageExplorer method getConfigErrorsAndInfo.

/**
 * @return a list of configuration errors and the interpreter info for the project (the interpreter info can be null)
 * @throws PythonNatureWithoutProjectException
 */
public Tuple<List<ProjectConfigError>, IInterpreterInfo> getConfigErrorsAndInfo(IPythonNature nature, final IProject relatedToProject) throws PythonNatureWithoutProjectException {
    if (PythonNature.IN_TESTS) {
        return new Tuple<List<ProjectConfigError>, IInterpreterInfo>(new ArrayList<ProjectConfigError>(), null);
    }
    ArrayList<ProjectConfigError> lst = new ArrayList<ProjectConfigError>();
    if (nature.getProject() == null) {
        lst.add(new ProjectConfigError(relatedToProject, "The configured nature has no associated project."));
    }
    IInterpreterInfo info = null;
    try {
        info = nature.getProjectInterpreter();
        String executableOrJar = info.getExecutableOrJar();
        // interpreterInfo.py output.
        if (executableOrJar.contains("/") || executableOrJar.contains("\\")) {
            if (!FileUtils.enhancedIsFile(new File(executableOrJar))) {
                lst.add(new ProjectConfigError(relatedToProject, "The interpreter configured does not exist in the filesystem: " + executableOrJar));
            }
        }
        List<String> projectSourcePathSet = new ArrayList<String>(nature.getPythonPathNature().getProjectSourcePathSet(true));
        Collections.sort(projectSourcePathSet);
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        for (String path : projectSourcePathSet) {
            if (path.trim().length() > 0) {
                IPath p = new Path(path);
                IResource resource = root.findMember(p);
                if (resource == null) {
                    relatedToProject.refreshLocal(p.segmentCount(), null);
                    // 2nd attempt (after refresh)
                    resource = root.findMember(p);
                }
                if (resource == null || !resource.exists()) {
                    lst.add(new ProjectConfigError(relatedToProject, "Source folder: " + path + " not found"));
                }
            }
        }
        List<String> externalPaths = nature.getPythonPathNature().getProjectExternalSourcePathAsList(true);
        Collections.sort(externalPaths);
        for (String path : externalPaths) {
            if (!new File(path).exists()) {
                lst.add(new ProjectConfigError(relatedToProject, "Invalid external source folder specified: " + path));
            }
        }
        Tuple<String, String> versionAndError = nature.getVersionAndError(true);
        if (versionAndError.o2 != null) {
            lst.add(new ProjectConfigError(relatedToProject, org.python.pydev.shared_core.string.StringUtils.replaceNewLines(versionAndError.o2, " ")));
        }
    } catch (MisconfigurationException e) {
        lst.add(new ProjectConfigError(relatedToProject, org.python.pydev.shared_core.string.StringUtils.replaceNewLines(e.getMessage(), " ")));
    } catch (Throwable e) {
        lst.add(new ProjectConfigError(relatedToProject, org.python.pydev.shared_core.string.StringUtils.replaceNewLines("Unexpected error:" + e.getMessage(), " ")));
    }
    return new Tuple<List<ProjectConfigError>, IInterpreterInfo>(lst, info);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) MisconfigurationException(org.python.pydev.core.MisconfigurationException) ProjectConfigError(org.python.pydev.navigator.elements.ProjectConfigError) ArrayList(java.util.ArrayList) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) File(java.io.File) Tuple(org.python.pydev.shared_core.structure.Tuple) IResource(org.eclipse.core.resources.IResource)

Example 2 with ProjectConfigError

use of org.python.pydev.navigator.elements.ProjectConfigError in project Pydev by fabioz.

the class ProjectInfoForPackageExplorer method getConfigErrorsAndInfo.

/**
 * Never returns null.
 *
 * This method should only be called through recreateInfo.
 */
private Tuple<List<ProjectConfigError>, IInterpreterInfo> getConfigErrorsAndInfo(IProject project) {
    if (project == null || !project.isOpen()) {
        return new Tuple<List<ProjectConfigError>, IInterpreterInfo>(new ArrayList<ProjectConfigError>(), null);
    }
    PythonNature nature = PythonNature.getPythonNature(project);
    if (nature == null) {
        return new Tuple<List<ProjectConfigError>, IInterpreterInfo>(new ArrayList<ProjectConfigError>(), null);
    }
    // If the info is not readily available, we try to get some more times... after that, if still not available,
    // we just return as if it's all OK.
    Tuple<List<ProjectConfigError>, IInterpreterInfo> configErrorsAndInfo = null;
    boolean goodToGo = false;
    for (int i = 0; i < 10 && !goodToGo; i++) {
        try {
            configErrorsAndInfo = getConfigErrorsAndInfo(nature, project);
            goodToGo = true;
        } catch (PythonNatureWithoutProjectException e1) {
            goodToGo = false;
            synchronized (this) {
                try {
                    wait(100);
                } catch (InterruptedException e) {
                }
            }
        }
    }
    if (configErrorsAndInfo == null) {
        return new Tuple<List<ProjectConfigError>, IInterpreterInfo>(new ArrayList<ProjectConfigError>(), null);
    }
    if (nature != null) {
        synchronized (lock) {
            UpdatePydevPackageExplorerProblemMarkers job = projectToJob.get(project);
            if (job == null) {
                job = new UpdatePydevPackageExplorerProblemMarkers("Update pydev package explorer markers for: " + project);
                projectToJob.put(project, job);
            }
            job.setInfo(project, configErrorsAndInfo.o1.toArray(new ProjectConfigError[configErrorsAndInfo.o1.size()]));
            job.schedule();
        }
    }
    return configErrorsAndInfo;
}
Also used : IPythonNature(org.python.pydev.core.IPythonNature) PythonNature(org.python.pydev.plugin.nature.PythonNature) IInterpreterInfo(org.python.pydev.core.IInterpreterInfo) ProjectConfigError(org.python.pydev.navigator.elements.ProjectConfigError) PythonNatureWithoutProjectException(org.python.pydev.core.PythonNatureWithoutProjectException) ArrayList(java.util.ArrayList) List(java.util.List) Tuple(org.python.pydev.shared_core.structure.Tuple)

Example 3 with ProjectConfigError

use of org.python.pydev.navigator.elements.ProjectConfigError in project Pydev by fabioz.

the class PythonLabelProvider method getImage.

/**
 * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
 */
@Override
public Image getImage(Object element) {
    if (element instanceof PythonProjectSourceFolder) {
        return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.PROJECT_SOURCE_FOLDER_ICON));
    }
    if (element instanceof PythonSourceFolder) {
        return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.SOURCE_FOLDER_ICON));
    }
    if (element instanceof PythonFolder) {
        PythonFolder folder = (PythonFolder) element;
        IFolder actualObject = folder.getActualObject();
        if (actualObject != null) {
            if (checkIfValidPackageFolder(folder)) {
                return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.FOLDER_PACKAGE_ICON));
            }
        }
        return provider.getImage(actualObject);
    }
    if (element instanceof PythonNode) {
        PythonNode node = (PythonNode) element;
        return node.entry.getImage();
    }
    if (element instanceof IWrappedResource) {
        IWrappedResource resource = (IWrappedResource) element;
        Object actualObject = resource.getActualObject();
        if (actualObject instanceof IFile) {
            IFile iFile = (IFile) actualObject;
            final String name = iFile.getName();
            if (name.indexOf('.') == -1) {
                try {
                    if (CorePlugin.markAsPyDevFileIfDetected(iFile)) {
                        if (FileTypesPreferences.isCythonFile(name)) {
                            return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.CYTHON_FILE_ICON));
                        }
                        return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.PY_FILE_ICON));
                    }
                } catch (Exception e) {
                // Ignore
                }
            }
            if (FileTypesPreferences.isCythonFile(name)) {
                return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.CYTHON_FILE_ICON));
            }
            if (name.startsWith("__init__.") && PythonPathHelper.isValidSourceFile(name)) {
                return ImageCache.asImage(PyTitlePreferencesPage.getInitIcon());
            } else {
                IProject project = iFile.getProject();
                try {
                    if (project.hasNature(PythonNature.DJANGO_NATURE_ID)) {
                        String djangoModulesHandling = PyTitlePreferencesPage.getDjangoModulesHandling();
                        if (djangoModulesHandling == PyTitlePreferencesPage.TITLE_EDITOR_DJANGO_MODULES_SHOW_PARENT_AND_DECORATE || djangoModulesHandling == PyTitlePreferencesPage.TITLE_EDITOR_DJANGO_MODULES_DECORATE) {
                            if (PyTitlePreferencesPage.isDjangoModuleToDecorate(name)) {
                                return ImageCache.asImage(PyTitlePreferencesPage.getDjangoModuleIcon(name));
                            }
                        }
                    }
                } catch (CoreException e) {
                    Log.log(e);
                }
            }
        }
        return provider.getImage(actualObject);
    }
    if (element instanceof ProjectConfigError) {
        return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.ERROR));
    }
    if (element instanceof TreeNode<?>) {
        TreeNode<?> treeNode = (TreeNode<?>) element;
        LabelAndImage data = (LabelAndImage) treeNode.getData();
        return ImageCache.asImage(data.image);
    }
    if (element instanceof IFile) {
        IFile iFile = (IFile) element;
        String name = iFile.getName();
        if (FileTypesPreferences.isCythonFile(name)) {
            return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.CYTHON_FILE_ICON));
        }
    }
    if (element instanceof IProject) {
        IProject project = (IProject) element;
        if (!project.isOpen()) {
            return null;
        }
        IMarker[] markers;
        try {
            markers = project.findMarkers(PythonBaseModelProvider.PYDEV_PACKAGE_EXPORER_PROBLEM_MARKER, true, 0);
        } catch (CoreException e1) {
            Log.log(e1);
            return null;
        }
        if (markers == null || markers.length == 0) {
            return null;
        }
        // We have errors: make them explicit.
        if (projectWithError == null) {
            synchronized (lock) {
                // the other enters the lock, it does not need to recalculated).
                if (projectWithError == null) {
                    // Note on double-checked locking idiom: http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html.
                    // (would not work as expected on java 1.4)
                    Image image = provider.getImage(element);
                    try {
                        DecorationOverlayIcon decorationOverlayIcon = new DecorationOverlayIcon(image, ImageCache.asImageDescriptor(SharedUiPlugin.getImageCache().getDescriptor(UIConstants.ERROR_SMALL)), IDecoration.BOTTOM_LEFT);
                        projectWithError = decorationOverlayIcon.createImage();
                    } catch (Exception e) {
                        Log.log("Unable to create error decoration for project icon.", e);
                        projectWithError = image;
                    }
                }
            }
        }
        return projectWithError;
    }
    if (element instanceof IWorkingSet) {
        return ImageCache.asImage(SharedUiPlugin.getImageCache().get(UIConstants.WORKING_SET));
    }
    return null;
}
Also used : DecorationOverlayIcon(org.eclipse.jface.viewers.DecorationOverlayIcon) IFile(org.eclipse.core.resources.IFile) PythonNode(org.python.pydev.navigator.elements.PythonNode) PythonFolder(org.python.pydev.navigator.elements.PythonFolder) ProjectConfigError(org.python.pydev.navigator.elements.ProjectConfigError) PythonProjectSourceFolder(org.python.pydev.navigator.elements.PythonProjectSourceFolder) Image(org.eclipse.swt.graphics.Image) PythonSourceFolder(org.python.pydev.navigator.elements.PythonSourceFolder) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) TreeNode(org.python.pydev.shared_core.structure.TreeNode) IMarker(org.eclipse.core.resources.IMarker) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource) IWorkingSet(org.eclipse.ui.IWorkingSet) IFolder(org.eclipse.core.resources.IFolder)

Example 4 with ProjectConfigError

use of org.python.pydev.navigator.elements.ProjectConfigError in project Pydev by fabioz.

the class PythonLabelProvider method getText.

/**
 * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
 */
@Override
public String getText(Object element) {
    if (element instanceof PythonNode) {
        PythonNode node = (PythonNode) element;
        return node.entry.toString();
    }
    if (element instanceof PythonSourceFolder) {
        PythonSourceFolder sourceFolder = (PythonSourceFolder) element;
        return provider.getText(sourceFolder.container);
    }
    if (element instanceof IWrappedResource) {
        IWrappedResource resource = (IWrappedResource) element;
        return provider.getText(resource.getActualObject());
    }
    if (element instanceof TreeNode<?>) {
        TreeNode<?> treeNode = (TreeNode<?>) element;
        LabelAndImage data = (LabelAndImage) treeNode.getData();
        return data.label;
    }
    if (element instanceof ProjectConfigError) {
        return ((ProjectConfigError) element).getLabel();
    }
    return provider.getText(element);
}
Also used : TreeNode(org.python.pydev.shared_core.structure.TreeNode) PythonNode(org.python.pydev.navigator.elements.PythonNode) ProjectConfigError(org.python.pydev.navigator.elements.ProjectConfigError) PythonSourceFolder(org.python.pydev.navigator.elements.PythonSourceFolder) IWrappedResource(org.python.pydev.navigator.elements.IWrappedResource)

Aggregations

ProjectConfigError (org.python.pydev.navigator.elements.ProjectConfigError)4 ArrayList (java.util.ArrayList)2 IInterpreterInfo (org.python.pydev.core.IInterpreterInfo)2 IWrappedResource (org.python.pydev.navigator.elements.IWrappedResource)2 PythonNode (org.python.pydev.navigator.elements.PythonNode)2 PythonSourceFolder (org.python.pydev.navigator.elements.PythonSourceFolder)2 TreeNode (org.python.pydev.shared_core.structure.TreeNode)2 Tuple (org.python.pydev.shared_core.structure.Tuple)2 File (java.io.File)1 List (java.util.List)1 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IMarker (org.eclipse.core.resources.IMarker)1 IProject (org.eclipse.core.resources.IProject)1 IResource (org.eclipse.core.resources.IResource)1 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 DecorationOverlayIcon (org.eclipse.jface.viewers.DecorationOverlayIcon)1