From 1da519376d7ec758a20e0f603ac1644bb2b893b5 Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Sat, 21 Sep 2024 10:55:16 -0300 Subject: [PATCH] To define whether folders are by default in the project, don't just check workspace, actually resolve the pythonpath from projects. --- .../AdditionalProjectInterpreterInfo.java | 2 +- .../pydev/analysis/mypy/MypyAnalysis.java | 4 +- .../tdd/TddQuickFixParticipant.java | 3 +- .../python/pydev/ast/builder/VisitorMemo.java | 6 +- .../revisited/ProjectModulesManager.java | 33 +++---- .../DefaultPathsForInterpreterInfo.java | 33 ++++++- .../pydev/plugin/nature/PythonNature.java | 6 +- .../pydev/plugin/nature/PythonPathNature.java | 27 ++++-- .../plugin/nature/SystemPythonNature.java | 2 +- .../python/pydev/core/IPythonPathNature.java | 32 +++---- .../core/docutils/StringSubstitution.java | 89 ++++++++++--------- .../core/docutils/StringSubstitutionTest.java | 2 +- .../django/debug/ui/actions/DjangoWar.java | 3 +- .../pydev/navigator/PythonPathNatureStub.java | 2 +- 14 files changed, 144 insertions(+), 100 deletions(-) diff --git a/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/additionalinfo/AdditionalProjectInterpreterInfo.java b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/additionalinfo/AdditionalProjectInterpreterInfo.java index 7371325314..5d0d0a8536 100644 --- a/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/additionalinfo/AdditionalProjectInterpreterInfo.java +++ b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/additionalinfo/AdditionalProjectInterpreterInfo.java @@ -125,7 +125,7 @@ protected Set getPythonPathFolders() { IPythonPathNature pythonPathNature = pythonNature.getPythonPathNature(); Set ret = new HashSet<>(); try { - ret.addAll(StringUtils.split(pythonPathNature.getOnlyProjectPythonPathStr(true), "|")); + ret.addAll(pythonPathNature.getOnlyProjectPythonPathStr(true)); } catch (CoreException e) { Log.log(e); } diff --git a/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/mypy/MypyAnalysis.java b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/mypy/MypyAnalysis.java index 52abc6a294..c56a883b6b 100644 --- a/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/mypy/MypyAnalysis.java +++ b/plugins/com.python.pydev.analysis/src/com/python/pydev/analysis/mypy/MypyAnalysis.java @@ -196,9 +196,7 @@ void createMypyProcess(IExternalCodeAnalysisStream out) Collection addToMypyPath = new HashSet(); IModulesManager[] managersInvolved = nature.getAstManager().getModulesManager().getManagersInvolved(false); for (IModulesManager iModulesManager : managersInvolved) { - for (String s : StringUtils - .split(iModulesManager.getNature().getPythonPathNature().getOnlyProjectPythonPathStr(true), - "|")) { + for (String s : iModulesManager.getNature().getPythonPathNature().getOnlyProjectPythonPathStr(true)) { if (!s.isEmpty()) { addToMypyPath.add(s); } diff --git a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddQuickFixParticipant.java b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddQuickFixParticipant.java index 11df8fcc02..21e45c8679 100644 --- a/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddQuickFixParticipant.java +++ b/plugins/com.python.pydev.refactoring/src/com/python/pydev/refactoring/tdd/TddQuickFixParticipant.java @@ -271,8 +271,7 @@ public void addProps(MarkerAnnotationAndPosition markerAnnotation, IAnalysisPref //Discover the source folder where we should create the structure. File editorFile = edit.getEditorFile(); - String onlyProjectPythonPathStr = nature.getPythonPathNature().getOnlyProjectPythonPathStr(false); - List split = StringUtils.splitAndRemoveEmptyTrimmed(onlyProjectPythonPathStr, '|'); + List split = nature.getPythonPathNature().getOnlyProjectPythonPathStr(false); for (int i = 0; i < split.size(); i++) { String fullPath = FileUtils.getFileAbsolutePath(split.get(i)); fullPath = PythonPathHelper.getDefaultPathStr(fullPath); diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/builder/VisitorMemo.java b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/builder/VisitorMemo.java index 2fae16e13b..3f107c3d85 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/builder/VisitorMemo.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/builder/VisitorMemo.java @@ -7,7 +7,6 @@ import org.eclipse.core.runtime.CoreException; import org.python.pydev.core.IPythonNature; -import org.python.pydev.shared_core.string.StringUtils; import org.python.pydev.shared_core.structure.Tuple3; @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -46,9 +45,8 @@ public List getOnlyProjectPythonPathStr(IPythonNature nature, boolean ad lst = onlyProjectPythonPathStrNonExternal; } if (lst == null) { - String onlyProjectPythonPathStr = nature.getPythonPathNature().getOnlyProjectPythonPathStr(addExternal); - HashSet projectSourcePath = new HashSet(StringUtils.splitAndRemoveEmptyTrimmed( - onlyProjectPythonPathStr, '|')); + HashSet projectSourcePath = new HashSet( + nature.getPythonPathNature().getOnlyProjectPythonPathStr(addExternal)); lst = new ArrayList(projectSourcePath); if (addExternal) { onlyProjectPythonPathStrExternal = lst; diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/ProjectModulesManager.java b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/ProjectModulesManager.java index 6e8d540d45..913234ba9f 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/ProjectModulesManager.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/codecompletion/revisited/ProjectModulesManager.java @@ -41,7 +41,6 @@ import org.python.pydev.plugin.nature.PythonNature; import org.python.pydev.shared_core.callbacks.ICallback; import org.python.pydev.shared_core.io.FileUtils; -import org.python.pydev.shared_core.string.StringUtils; import org.python.pydev.shared_core.structure.Tuple; /** @@ -254,8 +253,7 @@ protected String getResolveModuleErr(IResource member) { } public String resolveModuleOnlyInProjectSources(String fileAbsolutePath, boolean addExternal) throws CoreException { - String onlyProjectPythonPathStr = this.nature.getPythonPathNature().getOnlyProjectPythonPathStr(addExternal); - List pathItems = StringUtils.splitAndRemoveEmptyTrimmed(onlyProjectPythonPathStr, '|'); + List pathItems = this.nature.getPythonPathNature().getOnlyProjectPythonPathStr(addExternal); List filteredPathItems = filterDuplicatesPreservingOrder(pathItems); return this.pythonPathHelper.resolveModule(fileAbsolutePath, false, filteredPathItems, project); } @@ -516,7 +514,7 @@ public List getCompletePythonPath(IInterpreterInfo interpreter, IInterpr boolean forceCheck = false; ProjectModulesManager m2 = null; - String onlyProjectPythonPathStr = null; + IPythonPathNature pythonPathNature = null; if (m instanceof ProjectModulesManager) { long currentTimeMillis = System.currentTimeMillis(); m2 = (ProjectModulesManager) m; @@ -526,9 +524,8 @@ public List getCompletePythonPath(IInterpreterInfo interpreter, IInterpr try { IPythonNature n = m.getNature(); if (n != null) { - IPythonPathNature pythonPathNature = n.getPythonPathNature(); + pythonPathNature = n.getPythonPathNature(); if (pythonPathNature != null) { - onlyProjectPythonPathStr = pythonPathNature.getOnlyProjectPythonPathStr(true); m2.checkedPythonpathConsistency = currentTimeMillis; forceCheck = true; } @@ -541,16 +538,22 @@ public List getCompletePythonPath(IInterpreterInfo interpreter, IInterpr if (forceCheck) { //Check if it's actually correct and auto-fix if it's not. - List parsed = PythonPathHelper.parsePythonPathFromStr(onlyProjectPythonPathStr, null); - if (m2.nature != null && !new HashSet(parsed).equals(new HashSet(pythonpath))) { - // Make it right at this moment (so any other place that calls it before the restore - //takes place has the proper version). - h.setPythonPath(parsed); - - // Force a rebuild as the PythonPathHelper paths are not up to date. - m2.nature.rebuildPath(); + List parsed; + try { + parsed = pythonPathNature.getOnlyProjectPythonPathStr(true); + if (m2.nature != null + && !new HashSet(parsed).equals(new HashSet(pythonpath))) { + // Make it right at this moment (so any other place that calls it before the restore + //takes place has the proper version). + h.setPythonPath(parsed); + + // Force a rebuild as the PythonPathHelper paths are not up to date. + m2.nature.rebuildPath(); + } + l.addAll(parsed); //add the proper paths + } catch (Exception e) { + Log.log(e); } - l.addAll(parsed); //add the proper paths } else { l.addAll(pythonpath); } diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/interpreter_managers/DefaultPathsForInterpreterInfo.java b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/interpreter_managers/DefaultPathsForInterpreterInfo.java index 34ef986117..9ac88445b4 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/ast/interpreter_managers/DefaultPathsForInterpreterInfo.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/ast/interpreter_managers/DefaultPathsForInterpreterInfo.java @@ -12,14 +12,20 @@ package org.python.pydev.ast.interpreter_managers; import java.io.File; +import java.io.IOException; +import java.nio.file.Files; import java.util.HashSet; +import java.util.List; import java.util.Set; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; +import org.python.pydev.core.log.Log; +import org.python.pydev.plugin.nature.PythonNature; import org.python.pydev.shared_core.SharedCorePlugin; import org.python.pydev.shared_core.io.FileUtils; @@ -48,10 +54,19 @@ public boolean exists(String data) { */ public static boolean isChildOfRootPath(String data, Set rootPaths) { IPath path = Path.fromOSString(data); + java.nio.file.Path nativePath = new File(data).toPath(); + for (IPath p : rootPaths) { if (FileUtils.isPrefixOf(p, path)) { return true; } + try { + if (Files.isSameFile(nativePath, p.toFile().toPath())) { + return true; + } + } catch (IOException e) { + Log.log(e); + } } return false; } @@ -75,8 +90,22 @@ public static HashSet getRootPaths() { IPath location = iProject.getLocation(); if (location != null) { IPath abs = location.makeAbsolute(); - if (!FileUtils.isPrefixOf(rootLocation, abs)) { - rootPaths.add(abs); + rootPaths.add(abs); + } + + PythonNature nature = PythonNature.getPythonNature(iProject); + if (nature != null) { + try { + List splitted = nature.getPythonPathNature().getOnlyProjectPythonPathStr(true); + for (String s : splitted) { + try { + rootPaths.add(Path.fromOSString(FileUtils.getFileAbsolutePath(s))); + } catch (Exception e) { + Log.log(e); + } + } + } catch (CoreException e) { + Log.log(e); } } } diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/plugin/nature/PythonNature.java b/plugins/org.python.pydev.ast/src/org/python/pydev/plugin/nature/PythonNature.java index f35ab1a3b0..5d43fed63f 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/plugin/nature/PythonNature.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/plugin/nature/PythonNature.java @@ -135,7 +135,7 @@ protected RebuildPythonNatureModules() { protected IStatus run(IProgressMonitor monitor) { String paths; try { - paths = pythonPathNature.getOnlyProjectPythonPathStr(true); + paths = StringUtils.join("|", pythonPathNature.getOnlyProjectPythonPathStr(true)); } catch (CoreException e1) { Log.log(e1); return Status.OK_STATUS; @@ -671,11 +671,11 @@ private void init(String version, String projectPythonpath, String externalProje protected IStatus run(IProgressMonitor monitor) { try { if (astManager != null) { - String pythonpath = pythonPathNature.getOnlyProjectPythonPathStr(true); + List pythonpath = pythonPathNature.getOnlyProjectPythonPathStr(true); PythonPathHelper pythonPathHelper = (PythonPathHelper) astManager.getModulesManager() .getPythonPathHelper(); //If it doesn't match, rebuid the pythonpath! - if (!new HashSet(PythonPathHelper.parsePythonPathFromStr(pythonpath, null)) + if (!new HashSet(pythonpath) .equals(new HashSet(pythonPathHelper.getPythonpath()))) { rebuildPath(); } diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/plugin/nature/PythonPathNature.java b/plugins/org.python.pydev.ast/src/org/python/pydev/plugin/nature/PythonPathNature.java index f424697791..75b4d380f7 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/plugin/nature/PythonPathNature.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/plugin/nature/PythonPathNature.java @@ -11,6 +11,7 @@ */ package org.python.pydev.plugin.nature; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -25,6 +26,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.QualifiedName; +import org.python.pydev.ast.codecompletion.revisited.PythonPathHelper; import org.python.pydev.core.ExtensionHelper; import org.python.pydev.core.ICodeCompletionASTManager; import org.python.pydev.core.IInterpreterInfo; @@ -33,6 +35,7 @@ import org.python.pydev.core.IPythonNature; import org.python.pydev.core.IPythonPathNature; import org.python.pydev.core.MisconfigurationException; +import org.python.pydev.core.ProjectMisconfiguredException; import org.python.pydev.core.PropertiesHelper; import org.python.pydev.core.PythonNatureWithoutProjectException; import org.python.pydev.core.docutils.StringSubstitution; @@ -151,7 +154,7 @@ private IModulesManager getProjectModulesManager() { * @return the project pythonpath with complete paths in the filesystem. */ @Override - public String getOnlyProjectPythonPathStr(boolean addExternal) throws CoreException { + public List getOnlyProjectPythonPathStr(boolean addExternal) throws CoreException { String source = null; String external = null; String contributed = null; @@ -159,7 +162,7 @@ public String getOnlyProjectPythonPathStr(boolean addExternal) throws CoreExcept PythonNature nature = fNature; if (project == null || nature == null) { - return ""; + return new ArrayList<>(); } //Substitute with variables! @@ -215,7 +218,8 @@ public String getOnlyProjectPythonPathStr(boolean addExternal) throws CoreExcept if (external == null) { external = ""; } - return buf.append("|").append(external).append("|").append(contributed).toString(); + return PythonPathHelper.parsePythonPathFromStr( + buf.append("|").append(external).append("|").append(contributed).toString(), null); } /** @@ -517,12 +521,19 @@ public Map getVariableSubstitution(boolean addInterpreterInfoSub Map variableSubstitution; if (addInterpreterInfoSubstitutions) { - IInterpreterInfo info = nature.getProjectInterpreter(); - Properties stringSubstitutionVariables = info.getStringSubstitutionVariables(true); - if (stringSubstitutionVariables == null) { + try { + IInterpreterInfo info = nature.getProjectInterpreter(); + Properties stringSubstitutionVariables = info.getStringSubstitutionVariables(true); + if (stringSubstitutionVariables == null) { + variableSubstitution = new HashMap(); + } else { + variableSubstitution = PropertiesHelper.createMapFromProperties(stringSubstitutionVariables); + } + } catch (ProjectMisconfiguredException e) { + Log.logInfo( + "Interpreter info still not fully configured (interpreter substitutions won't be available).", + e); variableSubstitution = new HashMap(); - } else { - variableSubstitution = PropertiesHelper.createMapFromProperties(stringSubstitutionVariables); } } else { variableSubstitution = new HashMap(); diff --git a/plugins/org.python.pydev.ast/src/org/python/pydev/plugin/nature/SystemPythonNature.java b/plugins/org.python.pydev.ast/src/org/python/pydev/plugin/nature/SystemPythonNature.java index b1c74d5911..6b662be03e 100644 --- a/plugins/org.python.pydev.ast/src/org/python/pydev/plugin/nature/SystemPythonNature.java +++ b/plugins/org.python.pydev.ast/src/org/python/pydev/plugin/nature/SystemPythonNature.java @@ -107,7 +107,7 @@ public String getProjectExternalSourcePath(boolean replaceVariables) throws Core } @Override - public String getOnlyProjectPythonPathStr(boolean addExternal) throws CoreException { + public List getOnlyProjectPythonPathStr(boolean addExternal) throws CoreException { throw new RuntimeException("Not implemented"); } diff --git a/plugins/org.python.pydev.core/src/org/python/pydev/core/IPythonPathNature.java b/plugins/org.python.pydev.core/src/org/python/pydev/core/IPythonPathNature.java index 45533d2d9e..600e154662 100644 --- a/plugins/org.python.pydev.core/src/org/python/pydev/core/IPythonPathNature.java +++ b/plugins/org.python.pydev.core/src/org/python/pydev/core/IPythonPathNature.java @@ -6,7 +6,7 @@ */ /* * Created on Jun 2, 2005 - * + * * @author Fabio Zadrozny */ package org.python.pydev.core; @@ -34,29 +34,29 @@ public interface IPythonPathNature { /** * @param interpreter: this is the interpreter that should be used for getting the pythonpathString interpreter * (if it is null, the default interpreter is used) - * + * * @param manager this is the interpreter manager that contains the interpreter passed. It's needed so that we * can get the actual pythonpath for the interpreter passed (needed for the system pythonpath info). - * + * * @return the pythonpath (source and externals) for the project as a list of strings (always as paths * in the filesystem properly substituted) */ public List getCompleteProjectPythonPath(IInterpreterInfo interpreter, IInterpreterManager info); /** - * @param addExternal if true, the external libraries will also be added (and not only the project + * @param addExternal if true, the external libraries will also be added (and not only the project * source folders) - * + * * @return the pythonpath (source and externals) as a string (paths separated by | ), and always as * complete paths in the filesystem. * @throws CoreException */ - public String getOnlyProjectPythonPathStr(boolean addExternal) throws CoreException; + public List getOnlyProjectPythonPathStr(boolean addExternal) throws CoreException; /** - * Sets the project source path (paths are relative to the project location and are separated by | ) + * Sets the project source path (paths are relative to the project location and are separated by | ) * It can contain variables to be substituted. - * + * * @param newSourcePath * @throws CoreException */ @@ -65,14 +65,14 @@ public interface IPythonPathNature { /** * Sets the project external source paths (those are full-paths for mapping to a file in the filesystem, separated by | ). * It can contain variables to be substituted. - * + * * @param newExternalSourcePath * @throws CoreException */ public void setProjectExternalSourcePath(String newExternalSourcePath) throws CoreException; /** - * @param replaceVariables if true, any variables must be substituted (note that the return should still be always + * @param replaceVariables if true, any variables must be substituted (note that the return should still be always * interpreted relative to the project location) * @return only the project source paths (paths are relative to the project location and are separated by | ) * @throws CoreException @@ -89,7 +89,7 @@ public interface IPythonPathNature { public List getProjectExternalSourcePathAsList(boolean replaceVariables) throws CoreException; /** - * @param replaceVariables if true, any variables must be substituted (note that the return should still be always + * @param replaceVariables if true, any variables must be substituted (note that the return should still be always * interpreted relative to the project location) * @return only the project source paths as a list of strings (paths are relative to the project location) * @throws CoreException @@ -99,7 +99,7 @@ public interface IPythonPathNature { /** * This is a method akin to getProjectSourcePathSet, but it will return an ordered map where * we map the version with variables resolved to the version without variables resolved. - * + * * It should be used when doing some PYTHONPATH manipulation based on the current values, so, * we can keep the values with the variables when doing some operation while being able to check * for the resolved paths to check if some item should be actually added or not. @@ -112,15 +112,15 @@ public interface IPythonPathNature { public void clearCaches(); /** - * This method sets a variable substitution so that the source folders (project and external) can be set + * This method sets a variable substitution so that the source folders (project and external) can be set * based on those variables. - * + * * E.g.: If a variable PLATFORM maps to win32, setting a source folder as /libs/${PLATFORM}/dlls, it will be * resolved in the project as /libs/win32/dlls. - * + * * Another example would be creating a varible MY_APP that maps to d:\bin\my_app, so, ${MY_APP}/libs would point to * d:\bin\my_app/libs - * + * * Note that this variables are set at the project level and are resolved later than at the system level, so, * when performing the substitution, it should get the variables from the interpreter and override those with * the project variables before actually resolving anything. diff --git a/plugins/org.python.pydev.core/src/org/python/pydev/core/docutils/StringSubstitution.java b/plugins/org.python.pydev.core/src/org/python/pydev/core/docutils/StringSubstitution.java index d4fff845e6..58e35f8234 100644 --- a/plugins/org.python.pydev.core/src/org/python/pydev/core/docutils/StringSubstitution.java +++ b/plugins/org.python.pydev.core/src/org/python/pydev/core/docutils/StringSubstitution.java @@ -58,62 +58,69 @@ public StringSubstitution(IPythonNature nature) { try { IPythonPathNature pythonPathNature = nature.getPythonPathNature(); IProject project = nature.getProject(); //note: project can be null when creating a new project and receiving a system nature. - variableSubstitution = pythonPathNature.getVariableSubstitution(); + initialize(pythonPathNature, project); + } catch (Exception e) { + Log.log(e); + } + } + } + public void initialize(IPythonPathNature pythonPathNature, IProject project) { + try { + try { + variableSubstitution = pythonPathNature.getVariableSubstitution(); + IPathVariableManager projectPathVarManager = null; try { - IPathVariableManager projectPathVarManager = null; - try { - if (project != null) { - projectPathVarManager = project.getPathVariableManager(); - } - } catch (Throwable e1) { - //Ignore: getPathVariableManager not available on earlier Eclipse versions. + if (project != null) { + projectPathVarManager = project.getPathVariableManager(); } - String[] pathVarNames = null; - if (projectPathVarManager != null) { - pathVarNames = projectPathVarManager.getPathVariableNames(); - } - //The usual path var names are: + } catch (Throwable e1) { + //Ignore: getPathVariableManager not available on earlier Eclipse versions. + } + String[] pathVarNames = null; + if (projectPathVarManager != null) { + pathVarNames = projectPathVarManager.getPathVariableNames(); + } + //The usual path var names are: - //ECLIPSE_HOME, PARENT_LOC, WORKSPACE_LOC, PROJECT_LOC - //Other possible variables may be defined in General > Workspace > Linked Resources. + //ECLIPSE_HOME, PARENT_LOC, WORKSPACE_LOC, PROJECT_LOC + //Other possible variables may be defined in General > Workspace > Linked Resources. - //We also add PROJECT_DIR_NAME (so, we can define a source folder with /${PROJECT_DIR_NAME} - if (project != null && !variableSubstitution.containsKey("PROJECT_DIR_NAME")) { - IPath location = project.getFullPath(); - if (location != null) { - variableSubstitution.put("PROJECT_DIR_NAME", location.lastSegment()); - } + //We also add PROJECT_DIR_NAME (so, we can define a source folder with /${PROJECT_DIR_NAME} + if (project != null && !variableSubstitution.containsKey("PROJECT_DIR_NAME")) { + IPath location = project.getFullPath(); + if (location != null) { + variableSubstitution.put("PROJECT_DIR_NAME", location.lastSegment()); } + } - if (pathVarNames != null) { - URI uri = null; - String var = null; - String path = null; - for (int i = 0; i < pathVarNames.length; i++) { - try { - var = pathVarNames[i]; - uri = projectPathVarManager.getURIValue(var); - if (uri != null) { - String scheme = uri.getScheme(); - if (scheme != null && scheme.equalsIgnoreCase("file")) { - path = uri.getPath(); - if (path != null && !variableSubstitution.containsKey(var)) { - variableSubstitution.put(var, new File(uri).toString()); - } + if (pathVarNames != null) { + URI uri = null; + String var = null; + String path = null; + for (int i = 0; i < pathVarNames.length; i++) { + try { + var = pathVarNames[i]; + uri = projectPathVarManager.getURIValue(var); + if (uri != null) { + String scheme = uri.getScheme(); + if (scheme != null && scheme.equalsIgnoreCase("file")) { + path = uri.getPath(); + if (path != null && !variableSubstitution.containsKey(var)) { + variableSubstitution.put(var, new File(uri).toString()); } } - } catch (Exception e) { - Log.log(e); } + } catch (Exception e) { + Log.log(e); } } - } catch (Throwable e) { - Log.log(e); } - } catch (Exception e) { + } catch (Throwable e) { Log.log(e); } + } catch (Exception e) { + Log.log(e); } } diff --git a/plugins/org.python.pydev.core/tests/org/python/pydev/core/docutils/StringSubstitutionTest.java b/plugins/org.python.pydev.core/tests/org/python/pydev/core/docutils/StringSubstitutionTest.java index a26da3cc0d..9b97415b1a 100644 --- a/plugins/org.python.pydev.core/tests/org/python/pydev/core/docutils/StringSubstitutionTest.java +++ b/plugins/org.python.pydev.core/tests/org/python/pydev/core/docutils/StringSubstitutionTest.java @@ -194,7 +194,7 @@ public List getProjectExternalSourcePathAsList(boolean replaceVariables) } @Override - public String getOnlyProjectPythonPathStr(boolean b) throws CoreException { + public List getOnlyProjectPythonPathStr(boolean b) throws CoreException { throw new RuntimeException("Not implemented"); } diff --git a/plugins/org.python.pydev.django/src/org/python/pydev/django/debug/ui/actions/DjangoWar.java b/plugins/org.python.pydev.django/src/org/python/pydev/django/debug/ui/actions/DjangoWar.java index d0720af55c..c75384d11c 100644 --- a/plugins/org.python.pydev.django/src/org/python/pydev/django/debug/ui/actions/DjangoWar.java +++ b/plugins/org.python.pydev.django/src/org/python/pydev/django/debug/ui/actions/DjangoWar.java @@ -23,9 +23,8 @@ public void run(IAction action) { "Creation of WAR packages is only supported on Jython"); return; } - String projectPythonPath = nature.getPythonPathNature().getOnlyProjectPythonPathStr(true); String javaLibs = null; - for (String path : projectPythonPath.split("\\|")) { + for (String path : nature.getPythonPathNature().getOnlyProjectPythonPathStr(true)) { if (path.endsWith(".jar")) { if (javaLibs == null) { javaLibs = path; diff --git a/plugins/org.python.pydev/tests_navigator/org/python/pydev/navigator/PythonPathNatureStub.java b/plugins/org.python.pydev/tests_navigator/org/python/pydev/navigator/PythonPathNatureStub.java index f7d1fcfc70..48d08e8f94 100644 --- a/plugins/org.python.pydev/tests_navigator/org/python/pydev/navigator/PythonPathNatureStub.java +++ b/plugins/org.python.pydev/tests_navigator/org/python/pydev/navigator/PythonPathNatureStub.java @@ -35,7 +35,7 @@ public List getCompleteProjectPythonPath(IInterpreterInfo interpreter, I } @Override - public String getOnlyProjectPythonPathStr(boolean b) throws CoreException { + public List getOnlyProjectPythonPathStr(boolean b) throws CoreException { throw new RuntimeException("Not impl"); }