Java Code Examples for org.eclipse.core.variables.IStringVariableManager
The following examples show how to use
org.eclipse.core.variables.IStringVariableManager. These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xds-ide Source File: SpellingPreferenceBlock.java License: Eclipse Public License 1.0 | 6 votes |
private void validateAbsoluteFilePath() { MyStatus ms = new MyStatus(IStatus.OK, XdsEditorsPlugin.PLUGIN_ID, null); String path = fDictionaryPath == null ? "" : fDictionaryPath.getText().trim(); //$NON-NLS-1$ if (!path.isEmpty()) { IStringVariableManager variableManager= VariablesPlugin.getDefault().getStringVariableManager(); try { path= variableManager.performStringSubstitution(path); if (path.length() > 0) { final File file= new File(path); if (!file.exists() || !file.isFile() || !file.isAbsolute() || !file.canRead()) { ms = new MyStatus(IStatus.ERROR, XdsEditorsPlugin.PLUGIN_ID, Messages.SpellingPreferenceBlock_BadDictFile); } else if (!file.getParentFile().canWrite() || !file.canWrite()) { ms = new MyStatus(IStatus.ERROR, XdsEditorsPlugin.PLUGIN_ID, Messages.SpellingPreferenceBlock_RWAccessRequired); } } } catch (CoreException e) { ms = new MyStatus(IStatus.ERROR, XdsEditorsPlugin.PLUGIN_ID, e.getLocalizedMessage()); } } if (ms.matches(IStatus.ERROR) || fFileStatus.matches(IStatus.ERROR)) { fFileStatus = ms; updateStatus(); } }
Example 2
Source Project: EasyShell Source File: ActionDelegate.java License: Eclipse Public License 2.0 | 6 votes |
private String[] getCommandResolved(IStringVariableManager variableManager) throws CoreException { String[] commandArray = null; switch(commandTokenizer) { case commandTokenizerSpaces: commandArray = Utils.splitSpaces(commandValue); break; case commandTokenizerSpacesAndQuotes: commandArray = Utils.splitSpacesAndQuotes(commandValue, false); break; case commandTokenizerSpacesAndQuotesSkip: commandArray = Utils.splitSpacesAndQuotes(commandValue, true); break; case commandTokenizerDisabled: commandArray = new String[1]; commandArray[0] = commandValue; break; default: throw new IllegalArgumentException(); } // resolve the variables for (int i=0;i<commandArray.length;i++) { commandArray[i] = variableManager.performStringSubstitution(commandArray[i], false); Activator.logDebug("exc" + i + ":>" + commandArray[i]+ "<"); } return commandArray; }
Example 3
Source Project: EasyShell Source File: ActionDelegate.java License: Eclipse Public License 2.0 | 6 votes |
private void handleExec(IStringVariableManager variableManager) throws CoreException, IOException { Activator.logDebug("exc:>---"); // get working directory File workingDirectory = getWorkingDirectoryResolved(variableManager); // get command String[] command = getCommandResolved(variableManager); // create process builder with command and ... ProcessBuilder pb = new ProcessBuilder(command); // ... set working directory and redirect error stream if (workingDirectory != null) { pb.directory(workingDirectory); } Activator.logDebug("exc:<---"); // get passed system environment //Map<String, String> env = pb.environment(); // add own variables pb.start(); }
Example 4
Source Project: Eclipse-Postfix-Code-Completion Source File: SpellingConfigurationBlock.java License: Eclipse Public License 1.0 | 6 votes |
/** * Validates that the file with the specified absolute path exists and can * be opened. * * @param path * The path of the file to validate * @return a status without error if the path is valid */ protected static IStatus validateAbsoluteFilePath(String path) { final StatusInfo status= new StatusInfo(); IStringVariableManager variableManager= VariablesPlugin.getDefault().getStringVariableManager(); try { path= variableManager.performStringSubstitution(path); if (path.length() > 0) { final File file= new File(path); if (!file.exists() && (!file.isAbsolute() || !file.getParentFile().canWrite())) status.setError(PreferencesMessages.SpellingPreferencePage_dictionary_error); else if (file.exists() && (!file.isFile() || !file.isAbsolute() || !file.canRead() || !file.canWrite())) status.setError(PreferencesMessages.SpellingPreferencePage_dictionary_error); } } catch (CoreException e) { status.setError(e.getLocalizedMessage()); } return status; }
Example 5
Source Project: birt Source File: HiveSelectionPageHelper.java License: Eclipse Public License 1.0 | 6 votes |
private void setDefaultMessage( String odaDesignerID ) { String msgExpr = Messages.getMessage( "datasource.page.title" ); // "Define ${odadesignerid.ds.displayname} Data Source"; String dsMsgExpr = msgExpr.replace( "odadesignerid", odaDesignerID ); //$NON-NLS-1$ IStringVariableManager varMgr = org.eclipse.core.variables.VariablesPlugin.getDefault( ) .getStringVariableManager( ); try { DEFAULT_MESSAGE = varMgr.performStringSubstitution( dsMsgExpr, false ); } catch ( CoreException ex ) { // TODO Auto-generated catch block } }
Example 6
Source Project: birt Source File: ReportPlugin.java License: Eclipse Public License 1.0 | 6 votes |
/** * Return default template preference * * @return String The string of default template preference */ public String getTemplatePreference( ) { String temp = PreferenceFactory.getInstance( ) .getPreferences( this, UIUtil.getCurrentProject( ) ) .getString( TEMPLATE_PREFERENCE ); String str = temp; try { IStringVariableManager mgr = VariablesPlugin.getDefault( ) .getStringVariableManager( ); str = mgr.performStringSubstitution( temp ); } catch ( CoreException e ) { str = temp; } return str; }
Example 7
Source Project: Pydev Source File: InterpreterInfo.java License: Eclipse Public License 1.0 | 6 votes |
public static void fillMapWithEnv(String[] env, Map<String, String> hashMap, Set<String> keysThatShouldNotBeUpdated, IStringVariableManager manager) { if (env == null || env.length == 0) { // nothing to do return; } if (keysThatShouldNotBeUpdated == null) { keysThatShouldNotBeUpdated = Collections.emptySet(); } for (String s : env) { Tuple<String, String> sp = StringUtils.splitOnFirst(s, '='); if (sp.o1.length() != 0 && sp.o2.length() != 0 && !keysThatShouldNotBeUpdated.contains(sp.o1)) { String value = sp.o2; if (manager != null) { try { value = manager.performStringSubstitution(value, false); } catch (CoreException e) { // Unreachable as false passed to reportUndefinedVariables above } } hashMap.put(sp.o1, value); } } }
Example 8
Source Project: Pydev Source File: PydevConsole.java License: Eclipse Public License 1.0 | 6 votes |
/** * @return the initial commands set in the preferences */ @Override public String getInitialCommands() { String str = PydevDebugPlugin.getDefault().getPreferenceStore() .getString(PydevConsoleConstants.INITIAL_INTERPRETER_CMDS); try { // Expand any eclipse variables in the GUI IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); str = manager.performStringSubstitution(str, false); } catch (CoreException e) { // Unreachable as false passed to reportUndefinedVariables above Log.log(e); } if (!str.endsWith("\n")) { str += "\n"; } if (additionalInitialComands != null) { str += additionalInitialComands; } return str; }
Example 9
Source Project: Pydev Source File: LaunchConfigurationCreator.java License: Eclipse Public License 1.0 | 6 votes |
/** * Builds a value of a location attribute used in launch configurations. * * @param file an array of resources * @param makeRelative {@code true} to produce path relative to workspace location * @return default string for the location field */ public static String getDefaultLocation(FileOrResource[] file, boolean makeRelative) { StringBuffer buffer = new StringBuffer(); for (FileOrResource r : file) { if (buffer.length() > 0) { buffer.append('|'); } String loc; if (r.resource != null) { if (makeRelative) { IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager(); loc = makeFileRelativeToWorkspace(r.resource, varManager); } else { loc = r.resource.getLocation().toOSString(); } } else { loc = FileUtils.getFileAbsolutePath(r.file.getAbsolutePath()); } buffer.append(loc); } return buffer.toString(); }
Example 10
Source Project: aCute Source File: DotnetRunDelegate.java License: Eclipse Public License 2.0 | 5 votes |
private File locationToFile(String location) { if (location.matches("^.*\\$\\{.*\\}.*$")) { //$NON-NLS-1$ IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); try { location = manager.performStringSubstitution(location, false); } catch (CoreException e) { return null; } } return new File(location); }
Example 11
Source Project: corrosion Source File: CorrosionPreferencePage.java License: Eclipse Public License 2.0 | 5 votes |
private static String varParse(String unparsedString) { IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); try { return manager.performStringSubstitution(unparsedString); } catch (CoreException e) { return unparsedString; } }
Example 12
Source Project: workspacemechanic Source File: VariableManagerStringParser.java License: Eclipse Public License 1.0 | 5 votes |
public String apply(String input) { try { IStringVariableManager stringManager = VariablesPlugin.getDefault().getStringVariableManager(); return stringManager.performStringSubstitution(input); } catch (CoreException e) { return ""; } }
Example 13
Source Project: xds-ide Source File: VariableUtils.java License: Eclipse Public License 1.0 | 5 votes |
public static String performStringSubstitution(Sdk context, String line, boolean isReportUndefinedVariables) throws CoreException { IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); if (context != null) { line = line.replaceAll(String.format(Pattern.quote("${%s}"), XDS_HOME_VAR), StringUtils.replaceChars( context.getSdkHomePath(), '\\', '/')); } line = manager.performStringSubstitution(line, isReportUndefinedVariables); return line; }
Example 14
Source Project: cppcheclipse Source File: PathMacroReplacer.java License: Apache License 2.0 | 5 votes |
public static String performMacroSubstitution(String input) { String ret = input; IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); try { ret = manager.performStringSubstitution(ret, false); } catch (CoreException e) { // in case of a issue, keep the path as it is and log error CppcheclipsePlugin.logError("Path macro subsitution failed", e); //$NON-NLS-1$ } return ret; }
Example 15
Source Project: gwt-eclipse-plugin Source File: GwtSdk.java License: Eclipse Public License 1.0 | 5 votes |
/** * Returns the value of the gwt_devjar variable or <code>null</code> if the variable is not defined. */ private IPath computeGwtDevJarVariableValue() { IStringVariableManager variableManager = VariablesPlugin.getDefault().getStringVariableManager(); IValueVariable valueVariable = variableManager.getValueVariable("gwt_devjar"); if (valueVariable != null) { String value = valueVariable.getValue(); if (value != null) { IPath path = new Path(value); return path.removeLastSegments(1); } } return null; }
Example 16
Source Project: EasyShell Source File: ActionDelegate.java License: Eclipse Public License 2.0 | 5 votes |
private File getWorkingDirectoryResolved(IStringVariableManager variableManager) throws CoreException { // working directory if (commandWorkingDir != null && !commandWorkingDir.isEmpty()) { variableManager.validateStringVariables(commandWorkingDir); Activator.logDebug("cwd: >" + commandWorkingDir + "<"); return new File(variableManager.performStringSubstitution(commandWorkingDir, false)); } return null; }
Example 17
Source Project: birt Source File: ScriptDebugUtil.java License: Eclipse Public License 1.0 | 5 votes |
/** * @param text * @return * @throws CoreException */ public static String getSubstitutedString(String text) throws CoreException { if (text == null) return ""; //$NON-NLS-1$ IStringVariableManager mgr = VariablesPlugin.getDefault().getStringVariableManager(); return mgr.performStringSubstitution(text); }
Example 18
Source Project: Pydev Source File: InterpreterInfo.java License: Eclipse Public License 1.0 | 5 votes |
private IStringVariableManager getStringVariableManager() { if (SharedCorePlugin.inTestMode()) { return stringVariableManagerForTests; } VariablesPlugin variablesPlugin = VariablesPlugin.getDefault(); return variablesPlugin.getStringVariableManager(); }
Example 19
Source Project: Pydev Source File: WorkingDirectoryBlock.java License: Eclipse Public License 1.0 | 5 votes |
@Override public boolean isValid(ILaunchConfiguration launchConfig) { setErrorMessage(null); setMessage(null); // if variables are present, we cannot resolve the directory String workingDirPath = getWorkingDirectoryText(); if (workingDirPath.indexOf("${") >= 0) { //$NON-NLS-1$ IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); try { manager.validateStringVariables(workingDirPath); } catch (CoreException e) { setErrorMessage(e.getMessage()); return false; } } else if (workingDirPath.length() > 0) { IContainer container = getContainer(); if (container == null) { File dir = new File(workingDirPath); if (dir.isDirectory()) { return true; } setErrorMessage("Only directories can be selected"); return false; } } else if (workingDirPath.length() == 0) { setErrorMessage("A non-empty directory must be selected"); return false; } return true; }
Example 20
Source Project: Pydev Source File: LaunchConfigurationCreator.java License: Eclipse Public License 1.0 | 5 votes |
private static String makeFileRelativeToWorkspace(FileOrResource[] resource, IStringVariableManager varManager) { FastStringBuffer moduleFile = new FastStringBuffer(80 * resource.length); for (FileOrResource r : resource) { if (moduleFile.length() > 0) { moduleFile.append("|"); } if (r.resource != null) { moduleFile.append(makeFileRelativeToWorkspace(r.resource, varManager)); } else { moduleFile.append(FileUtils.getFileAbsolutePath(r.file)); } } return moduleFile.toString(); }
Example 21
Source Project: goclipse Source File: StringSubstitutionEngine.java License: Eclipse Public License 1.0 | 5 votes |
/** * Performs recursive string substitution and returns the resulting string. * * @param expression expression to resolve * @param reportUndefinedVariables whether to report undefined variables as an error * @param resolveVariables if the variables should be resolved during the substitution * @param manager registry of variables * @return the resulting string with all variables recursively * substituted * @exception CoreException if unable to resolve a referenced variable or if a cycle exists * in referenced variables */ public String performStringSubstitution(String expression, boolean reportUndefinedVariables, boolean resolveVariables, IStringVariableManager manager) throws CoreException { substitute(expression, reportUndefinedVariables, resolveVariables, manager); List<HashSet<String>> resolvedVariableSets = new ArrayList<HashSet<String>>(); while (fSubs) { HashSet<String> resolved = substitute(fResult.toString(), reportUndefinedVariables, true, manager); for(int i=resolvedVariableSets.size()-1; i>=0; i--) { HashSet<String> prevSet = resolvedVariableSets.get(i); if (prevSet.equals(resolved)) { HashSet<String> conflictingSet = new HashSet<String>(); for (; i<resolvedVariableSets.size(); i++) { conflictingSet.addAll(resolvedVariableSets.get(i)); } StringBuffer problemVariableList = new StringBuffer(); for (String string : conflictingSet) { problemVariableList.append(string); problemVariableList.append(", "); //$NON-NLS-1$ } problemVariableList.setLength(problemVariableList.length()-2); //truncate the last ", " throw new CoreException(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.REFERENCE_CYCLE_ERROR, NLS.bind(VariablesMessages.StringSubstitutionEngine_4, new String[]{problemVariableList.toString()}), null)); } } resolvedVariableSets.add(resolved); } return fResult.toString(); }
Example 22
Source Project: corrosion Source File: RustLaunchDelegateTools.java License: Eclipse Public License 2.0 | 4 votes |
public static String performVariableSubstitution(String string) throws CoreException { IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); return manager.performStringSubstitution(string); }
Example 23
Source Project: google-cloud-eclipse Source File: LocalAppEngineServerLaunchConfigurationDelegate.java License: Apache License 2.0 | 4 votes |
/** * Create a CloudSdk RunConfiguration corresponding to the launch configuration and server * defaults. Details are pulled from {@link ILaunchConfiguration#getAttributes() launch * attributes} and {@link IServer server settings and attributes}. * @param runnables */ @VisibleForTesting RunConfiguration generateServerRunConfiguration(ILaunchConfiguration configuration, IServer server, String mode, List<Path> services) throws CoreException { RunConfiguration.Builder builder = RunConfiguration.builder(services); // Iterate through our different configurable parameters // TODO: storage-related paths, including storage_path and the {blob,data,*search*,logs} paths // TODO: allow setting host from launch config if (server.getHost() != null) { builder.host(server.getHost()); } int serverPort = getPortAttribute(LocalAppEngineServerBehaviour.SERVER_PORT_ATTRIBUTE_NAME, LocalAppEngineServerBehaviour.DEFAULT_SERVER_PORT, configuration, server); if (serverPort >= 0) { builder.port(serverPort); } // only restart server on on-disk changes detected when in RUN mode builder.automaticRestart(ILaunchManager.RUN_MODE.equals(mode)); // vmArguments is exactly as supplied by the user in the dialog box String vmArgumentString = getVMArguments(configuration); List<String> vmArguments = Arrays.asList(DebugPlugin.parseArguments(vmArgumentString)); if (!vmArguments.isEmpty()) { builder.jvmFlags(vmArguments); } // programArguments is exactly as supplied by the user in the dialog box String programArgumentString = getProgramArguments(configuration); List<String> programArguments = Arrays.asList(DebugPlugin.parseArguments(programArgumentString)); if (!programArguments.isEmpty()) { builder.additionalArguments(programArguments); } boolean environmentAppend = configuration.getAttribute(ILaunchManager.ATTR_APPEND_ENVIRONMENT_VARIABLES, true); if (!environmentAppend) { // not externalized as this may change due to // https://github.com/GoogleCloudPlatform/appengine-plugins-core/issues/446 throw new CoreException( StatusUtil.error(this, "'Environment > Replace environment' not yet supported")); //$NON-NLS-1$ } // Could use getEnvironment(), but it does `append` processing and joins as key-value pairs Map<String, String> environment = configuration.getAttribute( ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, Collections.<String, String>emptyMap()); Map<String, String> expanded = new HashMap<>(); IStringVariableManager variableEngine = VariablesPlugin.getDefault().getStringVariableManager(); for (Map.Entry<String, String> entry : environment.entrySet()) { // expand any variable references expanded.put(entry.getKey(), variableEngine.performStringSubstitution(entry.getValue())); } builder.environment(expanded); return builder.build(); }
Example 24
Source Project: xds-ide Source File: VariableUtils.java License: Eclipse Public License 1.0 | 4 votes |
public static String performStringSubstitution(String line, boolean isReportUndefinedVariables) throws CoreException { IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager(); return manager.performStringSubstitution(line, isReportUndefinedVariables); }
Example 25
Source Project: typescript.java Source File: TypeScriptCompilerLaunchConfigurationDelegate.java License: MIT License | 4 votes |
private static IStringVariableManager getStringVariableManager() { return VariablesPlugin.getDefault().getStringVariableManager(); }
Example 26
Source Project: gwt-eclipse-plugin Source File: GWTProjectsRuntime.java License: Eclipse Public License 1.0 | 4 votes |
private IStringVariableManager getVariableManager() { return VariablesPlugin.getDefault().getStringVariableManager(); }
Example 27
Source Project: birt Source File: ReportPlugin.java License: Eclipse Public License 1.0 | 4 votes |
/** * @param project * @param parentPath * @return */ public String getResourceFolder( IProject project, String parentPath ) { String resourceFolder = ReportPlugin.getDefault( ) .getResourcePreference( project ); if ( resourceFolder == null || resourceFolder.equals( "" ) ) //$NON-NLS-1$ { resourceFolder = parentPath; } if ( resourceFolder == null ) { resourceFolder = "";//$NON-NLS-1$ } String str = resourceFolder; try { IStringVariableManager mgr = VariablesPlugin.getDefault( ) .getStringVariableManager( ); str = mgr.performStringSubstitution( resourceFolder ); } catch ( CoreException e ) { str = resourceFolder; } resourceFolder = str; File file = new File( resourceFolder ); if ( !file.isAbsolute( ) ) { if ( project != null && project.getLocation( ) != null ) { resourceFolder = project.getLocation( ) .append( resourceFolder ) .toOSString( ); } else { if ( resourceFolder != null && !resourceFolder.startsWith( File.separator ) ) { resourceFolder = File.separator + resourceFolder; } resourceFolder = parentPath + resourceFolder; } } return resourceFolder; }
Example 28
Source Project: Pydev Source File: LaunchConfigurationCreator.java License: Eclipse Public License 1.0 | 4 votes |
/** * @param resource only used if captureOutput is true! * @param location only used if captureOutput is false! * @param captureOutput determines if the output should be captured or not (if captured a console will be * shown to it by default) */ private static ILaunchConfigurationWorkingCopy createDefaultLaunchConfiguration(FileOrResource[] resource, String launchConfigurationType, String location, IInterpreterManager pythonInterpreterManager, String projName, String vmargs, String programArguments, boolean captureOutput) throws CoreException { ILaunchManager manager = org.eclipse.debug.core.DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType type = manager.getLaunchConfigurationType(launchConfigurationType); if (type == null) { throw new CoreException(PydevDebugPlugin.makeStatus(IStatus.ERROR, "Python launch configuration not found", null)); } IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager(); String name; String baseDirectory; String moduleFile; int resourceType; if (captureOutput) { StringBuffer buffer = new StringBuffer(projName); buffer.append(" "); StringBuffer resourceNames = new StringBuffer(); for (FileOrResource r : resource) { if (resourceNames.length() > 0) { resourceNames.append(" - "); } if (r.resource != null) { resourceNames.append(r.resource.getName()); } else { resourceNames.append(r.file.getName()); } } buffer.append(resourceNames); name = buffer.toString().trim(); if (resource[0].resource != null) { // Build the working directory to a path relative to the workspace_loc baseDirectory = resource[0].resource.getFullPath().removeLastSegments(1).makeRelative().toString(); baseDirectory = varManager.generateVariableExpression("workspace_loc", baseDirectory); // Build the location to a path relative to the workspace_loc moduleFile = makeFileRelativeToWorkspace(resource, varManager); resourceType = resource[0].resource.getType(); } else { baseDirectory = FileUtils.getFileAbsolutePath(resource[0].file.getParentFile()); // Build the location to a path relative to the workspace_loc moduleFile = FileUtils.getFileAbsolutePath(resource[0].file); resourceType = IResource.FILE; } } else { captureOutput = true; name = location; baseDirectory = new File(location).getParent(); moduleFile = location; resourceType = IResource.FILE; } name = manager.generateLaunchConfigurationName(name); ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, name); // Python Main Tab Arguments workingCopy.setAttribute(Constants.ATTR_PROJECT, projName); workingCopy.setAttribute(Constants.ATTR_RESOURCE_TYPE, resourceType); workingCopy.setAttribute(Constants.ATTR_INTERPRETER, Constants.ATTR_INTERPRETER_DEFAULT); workingCopy.setAttribute(Constants.ATTR_LOCATION, moduleFile); workingCopy.setAttribute(Constants.ATTR_WORKING_DIRECTORY, baseDirectory); workingCopy.setAttribute(Constants.ATTR_PROGRAM_ARGUMENTS, programArguments); workingCopy.setAttribute(Constants.ATTR_VM_ARGUMENTS, vmargs); workingCopy.setAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, captureOutput); workingCopy.setAttribute(DebugPlugin.ATTR_CAPTURE_OUTPUT, captureOutput); if (resource[0].resource != null) { workingCopy.setMappedResources(FileOrResource.createIResourceArray(resource)); } return workingCopy; }
Example 29
Source Project: Pydev Source File: LaunchConfigurationCreator.java License: Eclipse Public License 1.0 | 4 votes |
private static String makeFileRelativeToWorkspace(IResource r, IStringVariableManager varManager) { String m = r.getFullPath().makeRelative().toString(); m = varManager.generateVariableExpression("workspace_loc", m); return m; }
Example 30
Source Project: Pydev Source File: PythonRunnerConfigTestWorkbench.java License: Eclipse Public License 1.0 | 4 votes |
public void testPythonCommandLine() throws Exception { PythonNature nature = PythonNature.getPythonNature(mod1); // Create a temporary variable for testing IStringVariableManager variableManager = VariablesPlugin.getDefault().getStringVariableManager(); IValueVariable myCustomVariable = variableManager.newValueVariable("pydev_python_runner_config_test_var", "", true, "my_custom_value"); variableManager.addVariables(new IValueVariable[] { myCustomVariable }); try { IInterpreterManager manager = InterpreterManagersAPI.getPythonInterpreterManager(true); InterpreterInfo info = (InterpreterInfo) manager.getDefaultInterpreterInfo(false); info.setEnvVariables(new String[] { "MY_CUSTOM_VAR_FOR_TEST=FOO", "MY_CUSTOM_VAR_FOR_TEST2=FOO2", "MY_CUSTOM_VAR_WITH_VAR=${pydev_python_runner_config_test_var}" }); // Make sure variable hasn't been expanded too early assertTrue(arrayContains(info.getEnvVariables(), "MY_CUSTOM_VAR_WITH_VAR=${pydev_python_runner_config_test_var}")); PythonRunnerConfig runnerConfig = createConfig(); assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST=FOO")); assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST2=FOO2")); assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_WITH_VAR=my_custom_value")); String[] argv = runnerConfig.getCommandLine(false); assertFalse(arrayContains(argv, PythonRunnerConfig.getRunFilesScript())); assertTrue(arrayContains(argv, mod1.getLocation().toOSString())); nature.setVersion(IPythonNature.Versions.PYTHON_VERSION_LATEST, IPythonNature.DEFAULT_INTERPRETER); assertEquals(manager.getDefaultInterpreterInfo(false).getExecutableOrJar(), nature.getProjectInterpreter() .getExecutableOrJar()); runnerConfig = createConfig(); argv = runnerConfig.getCommandLine(false); assertEquals(manager.getDefaultInterpreterInfo(false).getExecutableOrJar(), argv[0]); IInterpreterManager interpreterManager = nature.getRelatedInterpreterManager(); InterpreterInfo info2 = new InterpreterInfo(IPythonNature.PYTHON_VERSION_2_6, "c:\\interpreter\\py25.exe", new ArrayList<String>()); interpreterManager.setInfos(new IInterpreterInfo[] { info, info2 }, null, null); nature.setVersion(IPythonNature.Versions.PYTHON_VERSION_LATEST, "c:\\interpreter\\py25.exe"); assertEquals("c:\\interpreter\\py25.exe", nature.getProjectInterpreter().getExecutableOrJar()); runnerConfig = createConfig(); argv = runnerConfig.getCommandLine(false); assertEquals("c:\\interpreter\\py25.exe", argv[0]); nature.setVersion(IPythonNature.Versions.PYTHON_VERSION_LATEST, IPythonNature.DEFAULT_INTERPRETER); ILaunchConfiguration config; config = new LaunchShortcut().createDefaultLaunchConfiguration(FileOrResource .createArray(new IResource[] { mod1 })); ILaunchConfigurationWorkingCopy workingCopy = config.getWorkingCopy(); HashMap<String, String> map = new HashMap<String, String>(); map.put("VAR_SPECIFIED_IN_LAUNCH", "BAR"); map.put("MY_CUSTOM_VAR_FOR_TEST2", "BAR2"); //The one in the launch configuration always has preference. workingCopy.setAttribute(ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, map); config = workingCopy.doSave(); runnerConfig = new PythonRunnerConfig(config, ILaunchManager.RUN_MODE, PythonRunnerConfig.RUN_REGULAR); assertTrue(arrayContains(runnerConfig.envp, "VAR_SPECIFIED_IN_LAUNCH=BAR")); assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST=FOO")); assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_FOR_TEST2=BAR2")); assertTrue(arrayContains(runnerConfig.envp, "MY_CUSTOM_VAR_WITH_VAR=my_custom_value")); } catch (Throwable e) { e.printStackTrace(); throw new RuntimeException(e); } finally { //restore the default! nature.setVersion(IPythonNature.Versions.PYTHON_VERSION_LATEST, IPythonNature.DEFAULT_INTERPRETER); variableManager.removeVariables(new IValueVariable[] { myCustomVariable }); } }