⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractinterpretermanager.java

📁 Python Development Environment (Python IDE plugin for Eclipse). Features editor, code completion, re
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	                        public void run() {
	                            ErrorDialog.openError(null, title, msg, new Status(Status.ERROR, PydevPlugin.getPluginID(), 0, reason, null));
	                        }
	                    });
	                } catch (Throwable e) {
	                    // ignore error comunication error
	                }
	    	        throw new RuntimeException(reason);
	    	    }
	        }
	        return info;
    	}
    }

    /**
     * Called when an interpreter should be added.
     * 
     * @see org.python.pydev.core.IInterpreterManager#addInterpreter(java.lang.String)
     */
    public String addInterpreter(String executable, IProgressMonitor monitor) {
        exeToInfo.remove(executable); //always clear it
        InterpreterInfo info = getInterpreterInfo(executable, monitor);
        if(info == null){
            //cancelled on the screen that the user has to choose paths...
            return null;
        }
        return info.executableOrJar;
    }

    private Object lock = new Object();
    //little cache...
    private String persistedCache;
    private String [] persistedCacheRet;
    
    /**
     * @see org.python.pydev.core.IInterpreterManager#getInterpretersFromPersistedString(java.lang.String)
     */
    public String[] getInterpretersFromPersistedString(String persisted) {
    	synchronized(lock){
	        if(persisted == null || persisted.trim().length() == 0){
	            return new String[0];
	        }
	        
	        if(persistedCache == null || persistedCache.equals(persisted) == false){
		        List<String> ret = new ArrayList<String>();
	
		        try {
		            List<InterpreterInfo> list = new ArrayList<InterpreterInfo>();	            
	                String[] strings = persisted.split("&&&&&");
	                
	                //first, get it...
	                for (String string : strings) {
	                    try {
	                        list.add(InterpreterInfo.fromString(string));
	                    } catch (Exception e) {
	                    	//ok, its format might have changed
	                    	String errMsg = "Interpreter storage changed.\r\n" +
	                    	"Please restore it (window > preferences > Pydev > Interpreter)";
	                        PydevPlugin.log(errMsg, e);
	                        
	                        return new String[0];
	                    }
	                }
	                
	                //then, put it in cache
	                for (InterpreterInfo info: list) {
	                    if(info != null && info.executableOrJar != null){
	    	                this.exeToInfo.put(info.executableOrJar, info);
	    	                ret.add(info.executableOrJar);
	                    }
		            }
	                
	                //and at last, restore the system info
		            for (final InterpreterInfo info: list) {
		                try {
	                        SystemModulesManager systemModulesManager = (SystemModulesManager) PydevPlugin.readFromWorkspaceMetadata(info.getExeAsFileSystemValidPath());
                            info.setModulesManager(systemModulesManager);
	                    } catch (Exception e) {
	                        //PydevPlugin.logInfo(e); -- don't log it, that should be 'standard' (something changed in the way we store it).
	                    	
	                    	//if it does not work it (probably) means that the internal storage format changed among versions,
	                        //so, we have to recreate that info.
	                    	final Display def = Display.getDefault();
	                    	def.syncExec(new Runnable(){
	
								public void run() {
									Shell shell = def.getActiveShell();
			                    	ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
			                        dialog.setBlockOnOpen(false);
			                        try {
										dialog.run(false, false, new IRunnableWithProgress(){

											public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
												monitor.beginTask("Updating the interpreter info (internal storage format changed).", 100);
												//ok, maybe its file-format changed... let's re-create it then.
												info.restorePythonpath(monitor);
                                                //after restoring it, let's save it.
                                                PydevPlugin.writeToWorkspaceMetadata(info.getModulesManager(), info.getExeAsFileSystemValidPath());
												monitor.done();
											}}
										);
									} catch (Exception e) {
										throw new RuntimeException(e);
									}
								}
								
	                		});
	                    	System.out.println("Finished restoring information for: "+info.executableOrJar);
	                    }
	                }
	                
	            } catch (Exception e) {
	                PydevPlugin.log(e);
	                
	                //ok, some error happened (maybe it's not configured)
	                return new String[0];
	            }
	            
		        persistedCache = persisted;
		        persistedCacheRet = ret.toArray(new String[0]);
	        }
        }
        return persistedCacheRet;
    }

    /**
     * @see org.python.pydev.core.IInterpreterManager#getStringToPersist(java.lang.String[])
     */
    public String getStringToPersist(String[] executables) {
        StringBuffer buf = new StringBuffer();
        for (String exe : executables) {
            InterpreterInfo info = this.exeToInfo.get(exe);
            if(info!=null){
                buf.append(info.toString());
                buf.append("&&&&&");
            }
        }
        
        return buf.toString();
    }

    String persistedString;
    public String getPersistedString() {
    	if(persistedString == null){
    		persistedString = prefs.getString(getPreferenceName());
    	}
    	return persistedString;
    }
    
    public void setPersistedString(String s) {
    	persistedString = s;
    	prefs.setValue(getPreferenceName(), s);
    }
    
    /**
     * This method persists all the modules managers that are within this interpreter manager
     * (so, all the SystemModulesManagers will be saved -- and can be later restored).
     */
    public void saveInterpretersInfoModulesManager() {
        for(InterpreterInfo info : this.exeToInfo.values()){
            PydevPlugin.writeToWorkspaceMetadata(info.getModulesManager(), info.getExeAsFileSystemValidPath());
        }
    }


    /**
     * @return whether this interpreter manager can be used to get info on the specified nature
     */
    public abstract boolean canGetInfoOnNature(IPythonNature nature);
    
    /**
     * @see org.python.pydev.core.IInterpreterManager#hasInfoOnDefaultInterpreter(IPythonNature)
     */
    public boolean hasInfoOnDefaultInterpreter(IPythonNature nature) {
        if(!canGetInfoOnNature(nature)){
            throw new RuntimeException("Cannot get info on the requested nature");
        }
        
        try {
            InterpreterInfo info = (InterpreterInfo) exeToInfo.get(getDefaultInterpreter());
            return info != null;
            
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * @see org.python.pydev.core.IInterpreterManager#restorePythopathFor(java.lang.String, org.eclipse.core.runtime.IProgressMonitor)
     */
    @SuppressWarnings("unchecked")
	public void restorePythopathFor(String defaultSelectedInterpreter, IProgressMonitor monitor) {
    	synchronized(lock){
	        final InterpreterInfo info = getInterpreterInfo(defaultSelectedInterpreter, monitor);
	        info.restorePythonpath(monitor); //that's it, info.modulesManager contains the SystemModulesManager
	        
	        List<IInterpreterObserver> participants = ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_INTERPRETER_OBSERVER);
	        for (IInterpreterObserver observer : participants) {
	            try {
					observer.notifyDefaultPythonpathRestored(this, defaultSelectedInterpreter, monitor);
				} catch (Exception e) {
					PydevPlugin.log(e);
				}
	        }
	        
	        //update the natures...
	        List<IPythonNature> pythonNatures = PythonNature.getAllPythonNatures();
	        for (IPythonNature nature : pythonNatures) {
	        	try {
	        		//if they have the same type of the interpreter manager.
					if (this.isPython() == nature.isPython() || this.isJython() == nature.isJython()) {
						nature.rebuildPath(defaultSelectedInterpreter, monitor);
					}
				} catch (Throwable e) {
					PydevPlugin.log(e);
				}
	        }
    	}        
    }

	public boolean isConfigured() {
        try {
            String defaultInterpreter = getDefaultInterpreter();
            if(defaultInterpreter == null){
                return false;
            }
            if(defaultInterpreter.length() == 0){
                return false;
            }
        } catch (NotConfiguredInterpreterException e) {
            return false;
        }
        return true;
    }
    
    public int getRelatedId() {
        if(isPython()){
            return IPythonNature.PYTHON_RELATED;
        }else if(isJython()){
            return IPythonNature.JYTHON_RELATED;
        }else{
            throw new RuntimeException("Expected Python or Jython");
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -