PageRenderTime 70ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 1ms

/plugins/org.python.pydev/src/org/python/pydev/ui/pythonpathconf/InterpreterInfo.java

https://github.com/rdenadai/Pydev
Java | 1409 lines | 1043 code | 157 blank | 209 comment | 147 complexity | 9bf144bfdc6e48fb32be57f38055477c MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, EPL-1.0, GPL-2.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. /**
  2. * Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved.
  3. * Licensed under the terms of the Eclipse Public License (EPL).
  4. * Please see the license.txt included with this distribution for details.
  5. * Any modifications to this file must keep this entire header intact.
  6. */
  7. /*
  8. * Created on May 11, 2005
  9. *
  10. * @author Fabio Zadrozny
  11. */
  12. package org.python.pydev.ui.pythonpathconf;
  13. import java.io.File;
  14. import java.io.FilenameFilter;
  15. import java.util.ArrayList;
  16. import java.util.Arrays;
  17. import java.util.Collection;
  18. import java.util.Collections;
  19. import java.util.HashMap;
  20. import java.util.HashSet;
  21. import java.util.Iterator;
  22. import java.util.List;
  23. import java.util.Map;
  24. import java.util.Map.Entry;
  25. import java.util.Properties;
  26. import java.util.Set;
  27. import java.util.TreeSet;
  28. import java.util.zip.ZipFile;
  29. import org.eclipse.core.runtime.IProgressMonitor;
  30. import org.eclipse.core.runtime.IStatus;
  31. import org.eclipse.swt.SWT;
  32. import org.eclipse.swt.widgets.MessageBox;
  33. import org.python.pydev.core.ExtensionHelper;
  34. import org.python.pydev.core.IInterpreterInfo;
  35. import org.python.pydev.core.IInterpreterManager;
  36. import org.python.pydev.core.ISystemModulesManager;
  37. import org.python.pydev.core.PropertiesHelper;
  38. import org.python.pydev.core.REF;
  39. import org.python.pydev.core.Tuple;
  40. import org.python.pydev.core.callbacks.ICallback;
  41. import org.python.pydev.core.docutils.StringUtils;
  42. import org.python.pydev.core.log.Log;
  43. import org.python.pydev.core.structure.FastStringBuffer;
  44. import org.python.pydev.core.uiutils.RunInUiThread;
  45. import org.python.pydev.editor.actions.PyAction;
  46. import org.python.pydev.editor.codecompletion.revisited.ProjectModulesManager;
  47. import org.python.pydev.editor.codecompletion.revisited.SystemModulesManager;
  48. import org.python.pydev.plugin.nature.PythonNature;
  49. public class InterpreterInfo implements IInterpreterInfo{
  50. //We want to force some libraries to be analyzed as source (e.g.: django)
  51. private static String[] LIBRARIES_TO_IGNORE_AS_FORCED_BUILTINS = new String[]{"django"};
  52. /**
  53. * For jython, this is the jython.jar
  54. *
  55. * For python, this is the path to the python executable
  56. */
  57. public volatile String executableOrJar;
  58. public String getExecutableOrJar() {
  59. return executableOrJar;
  60. }
  61. /**
  62. * Folders or zip files: they should be passed to the pythonpath
  63. */
  64. public final java.util.List<String> libs = new ArrayList<String>();
  65. /**
  66. * __builtin__, os, math, etc for python
  67. *
  68. * check sys.builtin_module_names and others that should
  69. * be forced to use code completion as builtins, such os, math, etc.
  70. */
  71. private final Set<String> forcedLibs = new TreeSet<String>();
  72. /**
  73. * This is the cache for the builtins (that's the same thing as the forcedLibs, but in a different format,
  74. * so, whenever the forcedLibs change, this should be changed too).
  75. */
  76. private String[] builtinsCache;
  77. private Map<String, File> predefinedBuiltinsCache;
  78. /**
  79. * module management for the system is always binded to an interpreter (binded in this class)
  80. *
  81. * The modules manager is no longer persisted. It is restored from a separate file, because we do
  82. * not want to keep it in the 'configuration', as a giant Base64 string.
  83. */
  84. private final ISystemModulesManager modulesManager;
  85. /**
  86. * This callback is only used in tests, to configure the paths that should be chosen after the interpreter is selected.
  87. */
  88. public static ICallback<Boolean, Tuple<List<String>, List<String>>> configurePathsCallback = null;
  89. /**
  90. * This is the version for the python interpreter (it is regarded as a String with Major and Minor version
  91. * for python in the format '2.5' or '2.4'.
  92. */
  93. private final String version;
  94. /**
  95. * This are the environment variables that should be used when this interpreter is specified.
  96. * May be null if no env. variables are specified.
  97. */
  98. private String[] envVariables;
  99. private Properties stringSubstitutionVariables;
  100. private final Set<String> predefinedCompletionsPath = new TreeSet<String>();
  101. /**
  102. * This is the way that the interpreter should be referred. Can be null (in which case the executable is
  103. * used as the name)
  104. */
  105. private String name;
  106. public ISystemModulesManager getModulesManager() {
  107. return modulesManager;
  108. }
  109. /**
  110. * @return the pythonpath to be used (only the folders)
  111. */
  112. public List<String> getPythonPath() {
  113. ArrayList<String> ret = new ArrayList<String>();
  114. ret.addAll(libs);
  115. return ret;
  116. }
  117. public InterpreterInfo(String version, String exe, Collection<String> libs0){
  118. this.executableOrJar = exe;
  119. this.version = version;
  120. ISystemModulesManager modulesManager = new SystemModulesManager(this);
  121. this.modulesManager = modulesManager;
  122. libs.addAll(libs0);
  123. }
  124. /*default*/ InterpreterInfo(String version, String exe, Collection<String> libs0, Collection<String> dlls){
  125. this(version, exe, libs0);
  126. }
  127. /*default*/ InterpreterInfo(String version, String exe, List<String> libs0, List<String> dlls, List<String> forced) {
  128. this(version, exe, libs0, dlls, forced, null, null);
  129. }
  130. /*default*/ InterpreterInfo(
  131. String version,
  132. String exe,
  133. List<String> libs0,
  134. List<String> dlls,
  135. List<String> forced,
  136. List<String> envVars,
  137. Properties stringSubstitution
  138. ){
  139. this(version, exe, libs0, dlls);
  140. for(String s:forced){
  141. if(!isForcedLibToIgnore(s)){
  142. forcedLibs.add(s);
  143. }
  144. }
  145. if(envVars == null){
  146. this.setEnvVariables(null);
  147. }else{
  148. this.setEnvVariables(envVars.toArray(new String[envVars.size()]));
  149. }
  150. this.setStringSubstitutionVariables(stringSubstitution);
  151. this.clearBuiltinsCache(); //force cache recreation
  152. }
  153. /**
  154. * @see java.lang.Object#equals(java.lang.Object)
  155. */
  156. public boolean equals(Object o) {
  157. if (!(o instanceof InterpreterInfo)){
  158. return false;
  159. }
  160. InterpreterInfo info = (InterpreterInfo) o;
  161. if(info.executableOrJar.equals(this.executableOrJar) == false){
  162. return false;
  163. }
  164. if(info.libs.equals(this.libs) == false){
  165. return false;
  166. }
  167. if (info.forcedLibs.equals(this.forcedLibs) == false){
  168. return false;
  169. }
  170. if(info.predefinedCompletionsPath.equals(this.predefinedCompletionsPath) == false){
  171. return false;
  172. }
  173. if(this.envVariables != null){
  174. if(info.envVariables == null){
  175. return false;
  176. }
  177. //both not null
  178. if(!Arrays.equals(this.envVariables, info.envVariables)){
  179. return false;
  180. }
  181. }else{
  182. //env is null -- the other must be too
  183. if(info.envVariables != null){
  184. return false;
  185. }
  186. }
  187. if(this.stringSubstitutionVariables != null){
  188. if(info.stringSubstitutionVariables == null){
  189. return false;
  190. }
  191. //both not null
  192. if(!this.stringSubstitutionVariables.equals(info.stringSubstitutionVariables)){
  193. return false;
  194. }
  195. }else{
  196. //ours is null -- the other must be too
  197. if(info.stringSubstitutionVariables != null){
  198. return false;
  199. }
  200. }
  201. return true;
  202. }
  203. /**
  204. * Format we receive should be:
  205. *
  206. * Executable:python.exe|lib1|lib2|lib3@dll1|dll2|dll3$forcedBuitin1|forcedBuiltin2^envVar1|envVar2@PYDEV_STRING_SUBST_VARS@PropertiesObjectAsString
  207. *
  208. * or
  209. *
  210. * Version2.5Executable:python.exe|lib1|lib2|lib3@dll1|dll2|dll3$forcedBuitin1|forcedBuiltin2^envVar1|envVar2@PYDEV_STRING_SUBST_VARS@PropertiesObjectAsString
  211. * (added only when version 2.5 was added, so, if the string does not have it, it is regarded as 2.4)
  212. *
  213. * or
  214. *
  215. * Name:MyInterpreter:EndName:Version2.5Executable:python.exe|lib1|lib2|lib3@dll1|dll2|dll3$forcedBuitin1|forcedBuiltin2^envVar1|envVar2@PYDEV_STRING_SUBST_VARS@PropertiesObjectAsString
  216. *
  217. * Symbols ': @ $'
  218. */
  219. public static InterpreterInfo fromString(String received, boolean askUserInOutPath) {
  220. if(received.toLowerCase().indexOf("executable") == -1){
  221. throw new RuntimeException("Unable to recreate the Interpreter info (Its format changed. Please, re-create your Interpreter information).Contents found:"+received);
  222. }
  223. Tuple<String, String> predefCompsPath = StringUtils.splitOnFirst(received, "@PYDEV_PREDEF_COMPS_PATHS@");
  224. received = predefCompsPath.o1;
  225. //Note that the new lines are important for the string substitution, so, we must remove it before removing new lines
  226. Tuple<String, String> stringSubstitutionVarsSplit = StringUtils.splitOnFirst(received, "@PYDEV_STRING_SUBST_VARS@");
  227. received = stringSubstitutionVarsSplit.o1;
  228. received = received.replaceAll("\n", "").replaceAll("\r", "");
  229. String name=null;
  230. if(received.startsWith("Name:")){
  231. int endNameIndex = received.indexOf(":EndName:");
  232. if(endNameIndex != -1){
  233. name = received.substring("Name:".length(), endNameIndex);
  234. received = received.substring(endNameIndex+":EndName:".length());
  235. }
  236. }
  237. Tuple<String, String> envVarsSplit = StringUtils.splitOnFirst(received, '^');
  238. Tuple<String, String> forcedSplit = StringUtils.splitOnFirst(envVarsSplit.o1, '$');
  239. Tuple<String, String> libsSplit = StringUtils.splitOnFirst(forcedSplit.o1, '@');
  240. String exeAndLibs = libsSplit.o1;
  241. String version = "2.4"; //if not found in the string, the grammar version is regarded as 2.4
  242. String[] exeAndLibs1 = exeAndLibs.split("\\|");
  243. String exeAndVersion = exeAndLibs1[0];
  244. String lowerExeAndVersion = exeAndVersion.toLowerCase();
  245. if(lowerExeAndVersion.startsWith("version")){
  246. int execut = lowerExeAndVersion.indexOf("executable");
  247. version = exeAndVersion.substring(0,execut).substring(7);
  248. exeAndVersion = exeAndVersion.substring(7+version.length());
  249. }
  250. String executable = exeAndVersion.substring(exeAndVersion.indexOf(":")+1, exeAndVersion.length());
  251. List<String> selection = new ArrayList<String>();
  252. List<String> toAsk = new ArrayList<String>();
  253. for (int i = 1; i < exeAndLibs1.length; i++) { //start at 1 (0 is exe)
  254. String trimmed = exeAndLibs1[i].trim();
  255. if(trimmed.length() > 0){
  256. if(trimmed.endsWith("OUT_PATH")){
  257. trimmed = trimmed.substring(0, trimmed.length()-8);
  258. if(askUserInOutPath){
  259. toAsk.add(trimmed);
  260. }else{
  261. //Change 2.0.1: if not asked, it's included by default!
  262. selection.add(trimmed);
  263. }
  264. }else if(trimmed.endsWith("INS_PATH")){
  265. trimmed = trimmed.substring(0, trimmed.length()-8);
  266. if(askUserInOutPath){
  267. toAsk.add(trimmed);
  268. selection.add(trimmed);
  269. }else{
  270. selection.add(trimmed);
  271. }
  272. }else{
  273. selection.add(trimmed);
  274. }
  275. }
  276. }
  277. boolean result = true;//true == OK, false == CANCELLED
  278. if(ProjectModulesManager.IN_TESTS){
  279. if(InterpreterInfo.configurePathsCallback != null){
  280. InterpreterInfo.configurePathsCallback.call(new Tuple<List<String>, List<String>>(toAsk, selection));
  281. }
  282. }else{
  283. if(toAsk.size() > 0){
  284. PythonSelectionLibrariesDialog runnable = new PythonSelectionLibrariesDialog(selection, toAsk, true);
  285. try{
  286. RunInUiThread.sync(runnable);
  287. }catch(NoClassDefFoundError e){
  288. }catch(UnsatisfiedLinkError e){
  289. //this means that we're running unit-tests, so, we don't have to do anything about it
  290. //as 'l' is already ok.
  291. }
  292. result = runnable.getOkResult();
  293. if(result == false){
  294. //Canceled by the user
  295. return null;
  296. }
  297. selection = runnable.getSelection();
  298. }
  299. }
  300. ArrayList<String> l1 = new ArrayList<String>();
  301. if(libsSplit.o2.length() > 1){
  302. fillList(libsSplit, l1);
  303. }
  304. ArrayList<String> l2 = new ArrayList<String>();
  305. if(forcedSplit.o2.length() > 1){
  306. fillList(forcedSplit, l2);
  307. }
  308. ArrayList<String> l3 = new ArrayList<String>();
  309. if(envVarsSplit.o2.length() > 1){
  310. fillList(envVarsSplit, l3);
  311. }
  312. Properties p4 = null;
  313. if(stringSubstitutionVarsSplit.o2.length() > 1){
  314. p4 = PropertiesHelper.createPropertiesFromString(stringSubstitutionVarsSplit.o2);
  315. }
  316. InterpreterInfo info = new InterpreterInfo(version, executable, selection, l1, l2, l3, p4);
  317. if(predefCompsPath.o2.length() > 1){
  318. List<String> split = StringUtils.split(predefCompsPath.o2, '|');
  319. for(String s:split){
  320. s = s.trim();
  321. if(s.length() > 0){
  322. info.addPredefinedCompletionsPath(s);
  323. }
  324. }
  325. }
  326. info.setName(name);
  327. return info;
  328. }
  329. private static void fillList(Tuple<String, String> forcedSplit, ArrayList<String> l2) {
  330. String forcedLibs = forcedSplit.o2;
  331. for (String trimmed:StringUtils.splitAndRemoveEmptyTrimmed(forcedLibs, '|')) {
  332. trimmed = trimmed.trim();
  333. if(trimmed.length() > 0){
  334. l2.add(trimmed);
  335. }
  336. }
  337. }
  338. /**
  339. * @see java.lang.Object#toString()
  340. */
  341. public String toString() {
  342. FastStringBuffer buffer = new FastStringBuffer();
  343. if(this.name != null){
  344. buffer.append("Name:");
  345. buffer.append(this.name);
  346. buffer.append(":EndName:");
  347. }
  348. buffer.append("Version");
  349. buffer.append(version);
  350. buffer.append("Executable:");
  351. buffer.append(executableOrJar);
  352. for (Iterator<String> iter = libs.iterator(); iter.hasNext();) {
  353. buffer.append("|");
  354. buffer.append(iter.next().toString());
  355. }
  356. buffer.append("@");
  357. buffer.append("$");
  358. if(forcedLibs.size() > 0){
  359. for (Iterator<String> iter = forcedLibs.iterator(); iter.hasNext();) {
  360. buffer.append("|");
  361. buffer.append(iter.next().toString());
  362. }
  363. }
  364. if(this.envVariables != null){
  365. buffer.append("^");
  366. for(String s:envVariables){
  367. buffer.append(s);
  368. buffer.append("|");
  369. }
  370. }
  371. if(this.stringSubstitutionVariables != null && this.stringSubstitutionVariables.size() > 0){
  372. buffer.append("@PYDEV_STRING_SUBST_VARS@");
  373. buffer.append(PropertiesHelper.createStringFromProperties(this.stringSubstitutionVariables));
  374. }
  375. if(this.predefinedCompletionsPath.size() > 0){
  376. buffer.append("@PYDEV_PREDEF_COMPS_PATHS@");
  377. for(String s:this.predefinedCompletionsPath){
  378. buffer.append("|");
  379. buffer.append(s);
  380. }
  381. }
  382. return buffer.toString();
  383. }
  384. /**
  385. * Adds the compiled libs (dlls)
  386. */
  387. public void restoreCompiledLibs(IProgressMonitor monitor) {
  388. //the compiled with the interpreter should be already gotten.
  389. for(String lib:this.libs){
  390. addForcedLibsFor(lib);
  391. }
  392. //we have it in source, but want to interpret it, source info (ast) does not give us much
  393. forcedLibs.add("os");
  394. //we also need to add this submodule (because even though it's documented as such, it's not really
  395. //implemented that way with a separate file -- there's black magic to put it there)
  396. forcedLibs.add("os.path");
  397. //as it is a set, there is no problem to add it twice
  398. if(this.version.startsWith("2") || this.version.startsWith("1")){
  399. //don't add it for 3.0 onwards.
  400. forcedLibs.add("__builtin__"); //jython bug: __builtin__ is not added
  401. }
  402. forcedLibs.add("sys"); //jython bug: sys is not added
  403. forcedLibs.add("email"); //email has some lazy imports that pydev cannot handle through the source
  404. forcedLibs.add("hashlib"); //depending on the Python version, hashlib cannot find md5, so, let's always leave it there.
  405. forcedLibs.add("pytest"); //yeap, pytest does have a structure that's pretty hard to analyze.
  406. int interpreterType = getInterpreterType();
  407. switch(interpreterType){
  408. case IInterpreterManager.INTERPRETER_TYPE_JYTHON:
  409. //by default, we don't want to force anything to python.
  410. forcedLibs.add("StringIO"); //jython bug: StringIO is not added
  411. forcedLibs.add("re"); //re is very strange in Jython (while it's OK in Python)
  412. forcedLibs.add("com.ziclix.python.sql"); //bultin to jython but not reported.
  413. break;
  414. case IInterpreterManager.INTERPRETER_TYPE_PYTHON:
  415. //those are sources, but we want to get runtime info on them.
  416. forcedLibs.add("OpenGL");
  417. forcedLibs.add("wxPython");
  418. forcedLibs.add("wx");
  419. forcedLibs.add("numpy");
  420. forcedLibs.add("scipy");
  421. forcedLibs.add("Image"); //for PIL
  422. //these are the builtins -- apparently sys.builtin_module_names is not ok in linux.
  423. forcedLibs.add("_ast");
  424. forcedLibs.add("_bisect");
  425. forcedLibs.add("_bytesio");
  426. forcedLibs.add("_codecs");
  427. forcedLibs.add("_codecs_cn");
  428. forcedLibs.add("_codecs_hk");
  429. forcedLibs.add("_codecs_iso2022");
  430. forcedLibs.add("_codecs_jp");
  431. forcedLibs.add("_codecs_kr");
  432. forcedLibs.add("_codecs_tw");
  433. forcedLibs.add("_collections");
  434. forcedLibs.add("_csv");
  435. forcedLibs.add("_fileio");
  436. forcedLibs.add("_functools");
  437. forcedLibs.add("_heapq");
  438. forcedLibs.add("_hotshot");
  439. forcedLibs.add("_json");
  440. forcedLibs.add("_locale");
  441. forcedLibs.add("_lsprof");
  442. forcedLibs.add("_md5");
  443. forcedLibs.add("_multibytecodec");
  444. forcedLibs.add("_random");
  445. forcedLibs.add("_sha");
  446. forcedLibs.add("_sha256");
  447. forcedLibs.add("_sha512");
  448. forcedLibs.add("_sre");
  449. forcedLibs.add("_struct");
  450. forcedLibs.add("_subprocess");
  451. forcedLibs.add("_symtable");
  452. forcedLibs.add("_warnings");
  453. forcedLibs.add("_weakref");
  454. forcedLibs.add("_winreg");
  455. forcedLibs.add("array");
  456. forcedLibs.add("audioop");
  457. forcedLibs.add("binascii");
  458. forcedLibs.add("cPickle");
  459. forcedLibs.add("cStringIO");
  460. forcedLibs.add("cmath");
  461. forcedLibs.add("datetime");
  462. forcedLibs.add("errno");
  463. forcedLibs.add("exceptions");
  464. forcedLibs.add("future_builtins");
  465. forcedLibs.add("gc");
  466. forcedLibs.add("imageop");
  467. forcedLibs.add("imp");
  468. forcedLibs.add("itertools");
  469. forcedLibs.add("marshal");
  470. forcedLibs.add("math");
  471. forcedLibs.add("mmap");
  472. forcedLibs.add("msvcrt");
  473. forcedLibs.add("nt");
  474. forcedLibs.add("operator");
  475. forcedLibs.add("parser");
  476. forcedLibs.add("signal");
  477. forcedLibs.add("socket"); //socket seems to have issues on linux
  478. forcedLibs.add("strop");
  479. forcedLibs.add("sys");
  480. forcedLibs.add("thread");
  481. forcedLibs.add("time");
  482. forcedLibs.add("xxsubtype");
  483. forcedLibs.add("zipimport");
  484. forcedLibs.add("zlib");
  485. break;
  486. case IInterpreterManager.INTERPRETER_TYPE_IRONPYTHON:
  487. //base namespaces
  488. forcedLibs.add("System");
  489. forcedLibs.add("Microsoft");
  490. forcedLibs.add("clr");
  491. //other namespaces (from http://msdn.microsoft.com/en-us/library/ms229335.aspx)
  492. forcedLibs.add("IEHost.Execute");
  493. forcedLibs.add("Microsoft.Aspnet.Snapin");
  494. forcedLibs.add("Microsoft.Build.BuildEngine");
  495. forcedLibs.add("Microsoft.Build.Conversion");
  496. forcedLibs.add("Microsoft.Build.Framework");
  497. forcedLibs.add("Microsoft.Build.Tasks");
  498. forcedLibs.add("Microsoft.Build.Tasks.Deployment.Bootstrapper");
  499. forcedLibs.add("Microsoft.Build.Tasks.Deployment.ManifestUtilities");
  500. forcedLibs.add("Microsoft.Build.Tasks.Hosting");
  501. forcedLibs.add("Microsoft.Build.Tasks.Windows");
  502. forcedLibs.add("Microsoft.Build.Utilities");
  503. forcedLibs.add("Microsoft.CLRAdmin");
  504. forcedLibs.add("Microsoft.CSharp");
  505. forcedLibs.add("Microsoft.Data.Entity.Build.Tasks");
  506. forcedLibs.add("Microsoft.IE");
  507. forcedLibs.add("Microsoft.Ink");
  508. forcedLibs.add("Microsoft.Ink.TextInput");
  509. forcedLibs.add("Microsoft.JScript");
  510. forcedLibs.add("Microsoft.JScript.Vsa");
  511. forcedLibs.add("Microsoft.ManagementConsole");
  512. forcedLibs.add("Microsoft.ManagementConsole.Advanced");
  513. forcedLibs.add("Microsoft.ManagementConsole.Internal");
  514. forcedLibs.add("Microsoft.ServiceModel.Channels.Mail");
  515. forcedLibs.add("Microsoft.ServiceModel.Channels.Mail.ExchangeWebService");
  516. forcedLibs.add("Microsoft.ServiceModel.Channels.Mail.ExchangeWebService.Exchange2007");
  517. forcedLibs.add("Microsoft.ServiceModel.Channels.Mail.WindowsMobile");
  518. forcedLibs.add("Microsoft.SqlServer.Server");
  519. forcedLibs.add("Microsoft.StylusInput");
  520. forcedLibs.add("Microsoft.StylusInput.PluginData");
  521. forcedLibs.add("Microsoft.VisualBasic");
  522. forcedLibs.add("Microsoft.VisualBasic.ApplicationServices");
  523. forcedLibs.add("Microsoft.VisualBasic.Compatibility.VB6");
  524. forcedLibs.add("Microsoft.VisualBasic.CompilerServices");
  525. forcedLibs.add("Microsoft.VisualBasic.Devices");
  526. forcedLibs.add("Microsoft.VisualBasic.FileIO");
  527. forcedLibs.add("Microsoft.VisualBasic.Logging");
  528. forcedLibs.add("Microsoft.VisualBasic.MyServices");
  529. forcedLibs.add("Microsoft.VisualBasic.MyServices.Internal");
  530. forcedLibs.add("Microsoft.VisualBasic.Vsa");
  531. forcedLibs.add("Microsoft.VisualC");
  532. forcedLibs.add("Microsoft.VisualC.StlClr");
  533. forcedLibs.add("Microsoft.VisualC.StlClr.Generic");
  534. forcedLibs.add("Microsoft.Vsa");
  535. forcedLibs.add("Microsoft.Vsa.Vb.CodeDOM");
  536. forcedLibs.add("Microsoft.Win32");
  537. forcedLibs.add("Microsoft.Win32.SafeHandles");
  538. forcedLibs.add("Microsoft.Windows.Themes");
  539. forcedLibs.add("Microsoft.WindowsCE.Forms");
  540. forcedLibs.add("Microsoft.WindowsMobile.DirectX");
  541. forcedLibs.add("Microsoft.WindowsMobile.DirectX.Direct3D");
  542. forcedLibs.add("Microsoft_VsaVb");
  543. forcedLibs.add("RegCode");
  544. forcedLibs.add("System");
  545. forcedLibs.add("System.AddIn");
  546. forcedLibs.add("System.AddIn.Contract");
  547. forcedLibs.add("System.AddIn.Contract.Automation");
  548. forcedLibs.add("System.AddIn.Contract.Collections");
  549. forcedLibs.add("System.AddIn.Hosting");
  550. forcedLibs.add("System.AddIn.Pipeline");
  551. forcedLibs.add("System.CodeDom");
  552. forcedLibs.add("System.CodeDom.Compiler");
  553. forcedLibs.add("System.Collections");
  554. forcedLibs.add("System.Collections.Generic");
  555. forcedLibs.add("System.Collections.ObjectModel");
  556. forcedLibs.add("System.Collections.Specialized");
  557. forcedLibs.add("System.ComponentModel");
  558. forcedLibs.add("System.ComponentModel.DataAnnotations");
  559. forcedLibs.add("System.ComponentModel.Design");
  560. forcedLibs.add("System.ComponentModel.Design.Data");
  561. forcedLibs.add("System.ComponentModel.Design.Serialization");
  562. forcedLibs.add("System.Configuration");
  563. forcedLibs.add("System.Configuration.Assemblies");
  564. forcedLibs.add("System.Configuration.Install");
  565. forcedLibs.add("System.Configuration.Internal");
  566. forcedLibs.add("System.Configuration.Provider");
  567. forcedLibs.add("System.Data");
  568. forcedLibs.add("System.Data.Common");
  569. forcedLibs.add("System.Data.Common.CommandTrees");
  570. forcedLibs.add("System.Data.Design");
  571. forcedLibs.add("System.Data.Entity.Design");
  572. forcedLibs.add("System.Data.Entity.Design.AspNet");
  573. forcedLibs.add("System.Data.EntityClient");
  574. forcedLibs.add("System.Data.Linq");
  575. forcedLibs.add("System.Data.Linq.Mapping");
  576. forcedLibs.add("System.Data.Linq.SqlClient");
  577. forcedLibs.add("System.Data.Linq.SqlClient.Implementation");
  578. forcedLibs.add("System.Data.Mapping");
  579. forcedLibs.add("System.Data.Metadata.Edm");
  580. forcedLibs.add("System.Data.Objects");
  581. forcedLibs.add("System.Data.Objects.DataClasses");
  582. forcedLibs.add("System.Data.Odbc");
  583. forcedLibs.add("System.Data.OleDb");
  584. forcedLibs.add("System.Data.OracleClient");
  585. forcedLibs.add("System.Data.Services");
  586. forcedLibs.add("System.Data.Services.Client");
  587. forcedLibs.add("System.Data.Services.Common");
  588. forcedLibs.add("System.Data.Services.Design");
  589. forcedLibs.add("System.Data.Services.Internal");
  590. forcedLibs.add("System.Data.Sql");
  591. forcedLibs.add("System.Data.SqlClient");
  592. forcedLibs.add("System.Data.SqlTypes");
  593. forcedLibs.add("System.Deployment.Application");
  594. forcedLibs.add("System.Deployment.Internal");
  595. forcedLibs.add("System.Diagnostics");
  596. forcedLibs.add("System.Diagnostics.CodeAnalysis");
  597. forcedLibs.add("System.Diagnostics.Design");
  598. forcedLibs.add("System.Diagnostics.Eventing");
  599. forcedLibs.add("System.Diagnostics.Eventing.Reader");
  600. forcedLibs.add("System.Diagnostics.PerformanceData");
  601. forcedLibs.add("System.Diagnostics.SymbolStore");
  602. forcedLibs.add("System.DirectoryServices");
  603. forcedLibs.add("System.DirectoryServices.AccountManagement");
  604. forcedLibs.add("System.DirectoryServices.ActiveDirectory");
  605. forcedLibs.add("System.DirectoryServices.Protocols");
  606. forcedLibs.add("System.Drawing");
  607. forcedLibs.add("System.Drawing.Design");
  608. forcedLibs.add("System.Drawing.Drawing2D");
  609. forcedLibs.add("System.Drawing.Imaging");
  610. forcedLibs.add("System.Drawing.Printing");
  611. forcedLibs.add("System.Drawing.Text");
  612. forcedLibs.add("System.EnterpriseServices");
  613. forcedLibs.add("System.EnterpriseServices.CompensatingResourceManager");
  614. forcedLibs.add("System.EnterpriseServices.Internal");
  615. forcedLibs.add("System.Globalization");
  616. forcedLibs.add("System.IdentityModel.Claims");
  617. forcedLibs.add("System.IdentityModel.Policy");
  618. forcedLibs.add("System.IdentityModel.Selectors");
  619. forcedLibs.add("System.IdentityModel.Tokens");
  620. forcedLibs.add("System.IO");
  621. forcedLibs.add("System.IO.Compression");
  622. forcedLibs.add("System.IO.IsolatedStorage");
  623. forcedLibs.add("System.IO.Log");
  624. forcedLibs.add("System.IO.Packaging");
  625. forcedLibs.add("System.IO.Pipes");
  626. forcedLibs.add("System.IO.Ports");
  627. forcedLibs.add("System.Linq");
  628. forcedLibs.add("System.Linq.Expressions");
  629. forcedLibs.add("System.Management");
  630. forcedLibs.add("System.Management.Instrumentation");
  631. forcedLibs.add("System.Media");
  632. forcedLibs.add("System.Messaging");
  633. forcedLibs.add("System.Messaging.Design");
  634. forcedLibs.add("System.Net");
  635. forcedLibs.add("System.Net.Cache");
  636. forcedLibs.add("System.Net.Configuration");
  637. forcedLibs.add("System.Net.Mail");
  638. forcedLibs.add("System.Net.Mime");
  639. forcedLibs.add("System.Net.NetworkInformation");
  640. forcedLibs.add("System.Net.PeerToPeer");
  641. forcedLibs.add("System.Net.PeerToPeer.Collaboration");
  642. forcedLibs.add("System.Net.Security");
  643. forcedLibs.add("System.Net.Sockets");
  644. forcedLibs.add("System.Printing");
  645. forcedLibs.add("System.Printing.IndexedProperties");
  646. forcedLibs.add("System.Printing.Interop");
  647. forcedLibs.add("System.Reflection");
  648. forcedLibs.add("System.Reflection.Emit");
  649. forcedLibs.add("System.Resources");
  650. forcedLibs.add("System.Resources.Tools");
  651. forcedLibs.add("System.Runtime");
  652. forcedLibs.add("System.Runtime.CompilerServices");
  653. forcedLibs.add("System.Runtime.ConstrainedExecution");
  654. forcedLibs.add("System.Runtime.Hosting");
  655. forcedLibs.add("System.Runtime.InteropServices");
  656. forcedLibs.add("System.Runtime.InteropServices.ComTypes");
  657. forcedLibs.add("System.Runtime.InteropServices.CustomMarshalers");
  658. forcedLibs.add("System.Runtime.InteropServices.Expando");
  659. forcedLibs.add("System.Runtime.Remoting");
  660. forcedLibs.add("System.Runtime.Remoting.Activation");
  661. forcedLibs.add("System.Runtime.Remoting.Channels");
  662. forcedLibs.add("System.Runtime.Remoting.Channels.Http");
  663. forcedLibs.add("System.Runtime.Remoting.Channels.Ipc");
  664. forcedLibs.add("System.Runtime.Remoting.Channels.Tcp");
  665. forcedLibs.add("System.Runtime.Remoting.Contexts");
  666. forcedLibs.add("System.Runtime.Remoting.Lifetime");
  667. forcedLibs.add("System.Runtime.Remoting.Messaging");
  668. forcedLibs.add("System.Runtime.Remoting.Metadata");
  669. forcedLibs.add("System.Runtime.Remoting.MetadataServices");
  670. forcedLibs.add("System.Runtime.Remoting.Proxies");
  671. forcedLibs.add("System.Runtime.Remoting.Services");
  672. forcedLibs.add("System.Runtime.Serialization");
  673. forcedLibs.add("System.Runtime.Serialization.Configuration");
  674. forcedLibs.add("System.Runtime.Serialization.Formatters");
  675. forcedLibs.add("System.Runtime.Serialization.Formatters.Binary");
  676. forcedLibs.add("System.Runtime.Serialization.Formatters.Soap");
  677. forcedLibs.add("System.Runtime.Serialization.Json");
  678. forcedLibs.add("System.Runtime.Versioning");
  679. forcedLibs.add("System.Security");
  680. forcedLibs.add("System.Security.AccessControl");
  681. forcedLibs.add("System.Security.Authentication");
  682. forcedLibs.add("System.Security.Authentication.ExtendedProtection");
  683. forcedLibs.add("System.Security.Authentication.ExtendedProtection.Configuration");
  684. forcedLibs.add("System.Security.Cryptography");
  685. forcedLibs.add("System.Security.Cryptography.Pkcs");
  686. forcedLibs.add("System.Security.Cryptography.X509Certificates");
  687. forcedLibs.add("System.Security.Cryptography.Xml");
  688. forcedLibs.add("System.Security.Permissions");
  689. forcedLibs.add("System.Security.Policy");
  690. forcedLibs.add("System.Security.Principal");
  691. forcedLibs.add("System.Security.RightsManagement");
  692. forcedLibs.add("System.ServiceModel");
  693. forcedLibs.add("System.ServiceModel.Activation");
  694. forcedLibs.add("System.ServiceModel.Activation.Configuration");
  695. forcedLibs.add("System.ServiceModel.Channels");
  696. forcedLibs.add("System.ServiceModel.ComIntegration");
  697. forcedLibs.add("System.ServiceModel.Configuration");
  698. forcedLibs.add("System.ServiceModel.Description");
  699. forcedLibs.add("System.ServiceModel.Diagnostics");
  700. forcedLibs.add("System.ServiceModel.Dispatcher");
  701. forcedLibs.add("System.ServiceModel.Install.Configuration");
  702. forcedLibs.add("System.ServiceModel.Internal");
  703. forcedLibs.add("System.ServiceModel.MsmqIntegration");
  704. forcedLibs.add("System.ServiceModel.PeerResolvers");
  705. forcedLibs.add("System.ServiceModel.Persistence");
  706. forcedLibs.add("System.ServiceModel.Security");
  707. forcedLibs.add("System.ServiceModel.Security.Tokens");
  708. forcedLibs.add("System.ServiceModel.Syndication");
  709. forcedLibs.add("System.ServiceModel.Web");
  710. forcedLibs.add("System.ServiceProcess");
  711. forcedLibs.add("System.ServiceProcess.Design");
  712. forcedLibs.add("System.Speech.AudioFormat");
  713. forcedLibs.add("System.Speech.Recognition");
  714. forcedLibs.add("System.Speech.Recognition.SrgsGrammar");
  715. forcedLibs.add("System.Speech.Synthesis");
  716. forcedLibs.add("System.Speech.Synthesis.TtsEngine");
  717. forcedLibs.add("System.Text");
  718. forcedLibs.add("System.Text.RegularExpressions");
  719. forcedLibs.add("System.Threading");
  720. forcedLibs.add("System.Timers");
  721. forcedLibs.add("System.Transactions");
  722. forcedLibs.add("System.Transactions.Configuration");
  723. forcedLibs.add("System.Web");
  724. forcedLibs.add("System.Web.ApplicationServices");
  725. forcedLibs.add("System.Web.Caching");
  726. forcedLibs.add("System.Web.ClientServices");
  727. forcedLibs.add("System.Web.ClientServices.Providers");
  728. forcedLibs.add("System.Web.Compilation");
  729. forcedLibs.add("System.Web.Configuration");
  730. forcedLibs.add("System.Web.Configuration.Internal");
  731. forcedLibs.add("System.Web.DynamicData");
  732. forcedLibs.add("System.Web.DynamicData.Design");
  733. forcedLibs.add("System.Web.DynamicData.ModelProviders");
  734. forcedLibs.add("System.Web.Handlers");
  735. forcedLibs.add("System.Web.Hosting");
  736. forcedLibs.add("System.Web.Mail");
  737. forcedLibs.add("System.Web.Management");
  738. forcedLibs.add("System.Web.Mobile");
  739. forcedLibs.add("System.Web.Profile");
  740. forcedLibs.add("System.Web.Query.Dynamic");
  741. forcedLibs.add("System.Web.RegularExpressions");
  742. forcedLibs.add("System.Web.Routing");
  743. forcedLibs.add("System.Web.Script.Serialization");
  744. forcedLibs.add("System.Web.Script.Services");
  745. forcedLibs.add("System.Web.Security");
  746. forcedLibs.add("System.Web.Services");
  747. forcedLibs.add("System.Web.Services.Configuration");
  748. forcedLibs.add("System.Web.Services.Description");
  749. forcedLibs.add("System.Web.Services.Discovery");
  750. forcedLibs.add("System.Web.Services.Protocols");
  751. forcedLibs.add("System.Web.SessionState");
  752. forcedLibs.add("System.Web.UI");
  753. forcedLibs.add("System.Web.UI.Adapters");
  754. forcedLibs.add("System.Web.UI.Design");
  755. forcedLibs.add("System.Web.UI.Design.MobileControls");
  756. forcedLibs.add("System.Web.UI.Design.MobileControls.Converters");
  757. forcedLibs.add("System.Web.UI.Design.WebControls");
  758. forcedLibs.add("System.Web.UI.Design.WebControls.WebParts");
  759. forcedLibs.add("System.Web.UI.MobileControls");
  760. forcedLibs.add("System.Web.UI.MobileControls.Adapters");
  761. forcedLibs.add("System.Web.UI.MobileControls.Adapters.XhtmlAdapters");
  762. forcedLibs.add("System.Web.UI.WebControls");
  763. forcedLibs.add("System.Web.UI.WebControls.Adapters");
  764. forcedLibs.add("System.Web.UI.WebControls.WebParts");
  765. forcedLibs.add("System.Web.Util");
  766. forcedLibs.add("System.Windows");
  767. forcedLibs.add("System.Windows.Annotations");
  768. forcedLibs.add("System.Windows.Annotations.Storage");
  769. forcedLibs.add("System.Windows.Automation");
  770. forcedLibs.add("System.Windows.Automation.Peers");
  771. forcedLibs.add("System.Windows.Automation.Provider");
  772. forcedLibs.add("System.Windows.Automation.Text");
  773. forcedLibs.add("System.Windows.Controls");
  774. forcedLibs.add("System.Windows.Controls.Primitives");
  775. forcedLibs.add("System.Windows.Converters");
  776. forcedLibs.add("System.Windows.Data");
  777. forcedLibs.add("System.Windows.Documents");
  778. forcedLibs.add("System.Windows.Documents.Serialization");
  779. forcedLibs.add("System.Windows.Forms");
  780. forcedLibs.add("System.Windows.Forms.ComponentModel.Com2Interop");
  781. forcedLibs.add("System.Windows.Forms.Design");
  782. forcedLibs.add("System.Windows.Forms.Design.Behavior");
  783. forcedLibs.add("System.Windows.Forms.Integration");
  784. forcedLibs.add("System.Windows.Forms.Layout");
  785. forcedLibs.add("System.Windows.Forms.PropertyGridInternal");
  786. forcedLibs.add("System.Windows.Forms.VisualStyles");
  787. forcedLibs.add("System.Windows.Ink");
  788. forcedLibs.add("System.Windows.Ink.AnalysisCore");
  789. forcedLibs.add("System.Windows.Input");
  790. forcedLibs.add("System.Windows.Input.StylusPlugIns");
  791. forcedLibs.add("System.Windows.Interop");
  792. forcedLibs.add("System.Windows.Markup");
  793. forcedLibs.add("System.Windows.Markup.Localizer");
  794. forcedLibs.add("System.Windows.Markup.Primitives");
  795. forcedLibs.add("System.Windows.Media");
  796. forcedLibs.add("System.Windows.Media.Animation");
  797. forcedLibs.add("System.Windows.Media.Converters");
  798. forcedLibs.add("System.Windows.Media.Effects");
  799. forcedLibs.add("System.Windows.Media.Imaging");
  800. forcedLibs.add("System.Windows.Media.Media3D");
  801. forcedLibs.add("System.Windows.Media.Media3D.Converters");
  802. forcedLibs.add("System.Windows.Media.TextFormatting");
  803. forcedLibs.add("System.Windows.Navigation");
  804. forcedLibs.add("System.Windows.Resources");
  805. forcedLibs.add("System.Windows.Shapes");
  806. forcedLibs.add("System.Windows.Threading");
  807. forcedLibs.add("System.Windows.Xps");
  808. forcedLibs.add("System.Windows.Xps.Packaging");
  809. forcedLibs.add("System.Windows.Xps.Serialization");
  810. forcedLibs.add("System.Workflow.Activities");
  811. forcedLibs.add("System.Workflow.Activities.Configuration");
  812. forcedLibs.add("System.Workflow.Activities.Rules");
  813. forcedLibs.add("System.Workflow.Activities.Rules.Design");
  814. forcedLibs.add("System.Workflow.ComponentModel");
  815. forcedLibs.add("System.Workflow.ComponentModel.Compiler");
  816. forcedLibs.add("System.Workflow.ComponentModel.Design");
  817. forcedLibs.add("System.Workflow.ComponentModel.Serialization");
  818. forcedLibs.add("System.Workflow.Runtime");
  819. forcedLibs.add("System.Workflow.Runtime.Configuration");
  820. forcedLibs.add("System.Workflow.Runtime.DebugEngine");
  821. forcedLibs.add("System.Workflow.Runtime.Hosting");
  822. forcedLibs.add("System.Workflow.Runtime.Tracking");
  823. forcedLibs.add("System.Xml");
  824. forcedLibs.add("System.Xml.Linq");
  825. forcedLibs.add("System.Xml.Schema");
  826. forcedLibs.add("System.Xml.Serialization");
  827. forcedLibs.add("System.Xml.Serialization.Advanced");
  828. forcedLibs.add("System.Xml.Serialization.Configuration");
  829. forcedLibs.add("System.Xml.XPath");
  830. forcedLibs.add("System.Xml.Xsl");
  831. forcedLibs.add("System.Xml.Xsl.Runtime");
  832. forcedLibs.add("UIAutomationClientsideProviders");
  833. break;
  834. default:
  835. throw new RuntimeException("Don't know how to treat: "+interpreterType);
  836. }
  837. this.clearBuiltinsCache(); //force cache recreation
  838. }
  839. private void addForcedLibsFor(String lib) {
  840. //For now only adds "werkzeug", but this is meant as an extension place.
  841. File file = new File(lib);
  842. if(file.exists()){
  843. if(file.isDirectory()){
  844. //check as dir (if it has a werkzeug folder)
  845. File werkzeug = new File(file, "werkzeug");
  846. if(werkzeug.isDirectory()){
  847. forcedLibs.add("werkzeug");
  848. }
  849. }else{
  850. //check as zip (if it has a werkzeug entry -- note that we have to check the __init__
  851. //because an entry just with the folder doesn't really exist)
  852. try {
  853. ZipFile zipFile = new ZipFile(file);
  854. if(zipFile.getEntry("werkzeug/__init__.py") != null){
  855. forcedLibs.add("werkzeug");
  856. }
  857. } catch (Exception e) {
  858. //ignore (not zip file)
  859. }
  860. }
  861. }
  862. }
  863. // Initially I thought werkzeug would need to add all the contents, so, this was a prototype to
  864. // analyze it and add what's needed (but it turns out that just adding werkzeug is ok.
  865. // protected void handleWerkzeug(File initWerkzeug) {
  866. // String fileContents = REF.getFileContents(initWerkzeug);
  867. // Tuple<SimpleNode, Throwable> parse = PyParser.reparseDocument(
  868. // new PyParser.ParserInfo(new Document(fileContents), false, this.getGrammarVersion()));
  869. // Module o1 = (Module) parse.o1;
  870. // forcedLibs.add("werkzeug");
  871. // for(stmtType stmt:o1.body){
  872. // if(stmt instanceof Assign){
  873. // Assign assign = (Assign) stmt;
  874. // if(assign.targets.length == 1){
  875. // if(assign.value instanceof Dict){
  876. // String rep = NodeUtils.getRepresentationString(assign.targets[0]);
  877. // if("all_by_module".equals(rep)){
  878. // Dict dict = (Dict) assign.value;
  879. // for(exprType key:dict.keys){
  880. // if(key instanceof Str){
  881. // Str str = (Str) key;
  882. // forcedLibs.add(str.s);
  883. // }
  884. // }
  885. // }
  886. // }else if(assign.value instanceof Call){
  887. // String rep = NodeUtils.getRepresentationString(assign.targets[0]);
  888. // if("attribute_modules".equals(rep)){
  889. // Call call = (Call) assign.value;
  890. // rep = NodeUtils.getRepresentationString(call.func);
  891. // if("fromkeys".equals(rep)){
  892. // if(call.args.length == 1){
  893. // if(call.args[0] instanceof org.python.pydev.parser.jython.ast.List){
  894. // org.python.pydev.parser.jython.ast.List list = (org.python.pydev.parser.jython.ast.List) call.args[0];
  895. // for(exprType elt:list.elts){
  896. // if(elt instanceof Str){
  897. // Str str = (Str) elt;
  898. // forcedLibs.add("werkzeug."+str.s);
  899. // }
  900. // }
  901. //
  902. // }
  903. // }
  904. // }
  905. // }
  906. // }
  907. // }
  908. // }
  909. // }
  910. // }
  911. private void clearBuiltinsCache(){
  912. this.builtinsCache = null; //force cache recreation
  913. this.predefinedBuiltinsCache = null;
  914. }
  915. /**
  916. * Restores the path given non-standard libraries
  917. * @param path
  918. */
  919. private void restorePythonpath(String path, IProgressMonitor monitor) {
  920. //no managers involved here...
  921. getModulesManager().changePythonPath(path, null, monitor);
  922. }
  923. /**
  924. * Restores the path with the discovered libs
  925. * @param path
  926. */
  927. public void restorePythonpath(IProgressMonitor monitor) {
  928. FastStringBuffer buffer = new FastStringBuffer();
  929. for (Iterator<String> iter = libs.iterator(); iter.hasNext();) {
  930. String folder = (String) iter.next();
  931. buffer.append(folder);
  932. buffer.append("|");
  933. }
  934. restorePythonpath(buffer.toString(), monitor);
  935. }
  936. public int getInterpreterType(){
  937. if(isJythonExecutable(executableOrJar)){
  938. return IInterpreterManager.INTERPRETER_TYPE_JYTHON;
  939. }else if(isIronpythonExecutable(executableOrJar)){
  940. return IInterpreterManager.INTERPRETER_TYPE_IRONPYTHON;
  941. }
  942. //neither one: it's python.
  943. return IInterpreterManager.INTERPRETER_TYPE_PYTHON;
  944. }
  945. /**
  946. * @param executable the executable we want to know about
  947. * @return if the executable is the jython jar.
  948. */
  949. public static boolean isJythonExecutable(String executable) {
  950. if (executable.endsWith("\"")) {
  951. return executable.endsWith(".jar\"");
  952. }
  953. return executable.endsWith(".jar");
  954. }
  955. /**
  956. * @param executable the executable we want to know about
  957. * @return if the executable is the ironpython executable.
  958. */
  959. public static boolean isIronpythonExecutable(String executable) {
  960. File file = new File(executable);
  961. return file.getName().startsWith("ipy");
  962. }
  963. public static String getExeAsFileSystemValidPath(String executableOrJar) {
  964. return "v1_"+StringUtils.md5(executableOrJar);
  965. }
  966. public String getExeAsFileSystemValidPath() {
  967. return getExeAsFileSystemValidPath(executableOrJar);
  968. }
  969. public String getVersion() {
  970. return version;
  971. }
  972. public int getGrammarVersion() {
  973. return PythonNature.getGrammarVersionFromStr(version);
  974. }
  975. //START: Things related to the builtins (forcedLibs) ---------------------------------------------------------------
  976. public String[] getBuiltins() {
  977. if(this.builtinsCache == null){
  978. Set<String> set = new HashSet<String>(forcedLibs);
  979. this.builtinsCache = set.toArray(new String[0]);
  980. }
  981. return this.builtinsCache;
  982. }
  983. public void addForcedLib(String forcedLib) {
  984. if(isForcedLibToIgnore(forcedLib)){
  985. return;
  986. }
  987. this.forcedLibs.add(forcedLib);
  988. this.clearBuiltinsCache();
  989. }
  990. /**
  991. * @return true if the passed forced lib should not be added to the forced builtins.
  992. */
  993. private boolean isForcedLibToIgnore(String forcedLib){
  994. if(forcedLib == null){
  995. return true;
  996. }
  997. //We want django to be always analyzed as source
  998. for(String s:LIBRARIES_TO_IGNORE_AS_FORCED_BUILTINS){
  999. if(forcedLib.equals(s) || forcedLib.startsWith(s+".")){
  1000. return true;
  1001. }
  1002. }
  1003. return false;
  1004. }
  1005. public void removeForcedLib(String forcedLib) {
  1006. this.forcedLibs.remove(forcedLib);
  1007. this.clearBuiltinsCache();
  1008. }
  1009. public Iterator<String> forcedLibsIterator() {
  1010. return forcedLibs.iterator();
  1011. }
  1012. //END: Things related to the builtins (forcedLibs) ---------------------------------------------------------------…

Large files files are truncated, but you can click here to view the full file