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);
}
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;
}
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;
}
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);
}
Aggregations