org.eclipse.core.variables.VariablesPlugin Java Examples
The following examples show how to use
org.eclipse.core.variables.VariablesPlugin.
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 File: HiveTab.java From neoscada with Eclipse Public License 1.0 | 6 votes |
protected void chooseWorkspace () { final ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog ( getShell (), new WorkbenchLabelProvider (), new WorkbenchContentProvider () ); dialog.setTitle ( "Select driver exporter configuration file" ); dialog.setMessage ( "Choose a driver exporter file for the configuration" ); dialog.setInput ( ResourcesPlugin.getWorkspace ().getRoot () ); dialog.setComparator ( new ResourceComparator ( ResourceComparator.NAME ) ); dialog.setAllowMultiple ( true ); dialog.setDialogBoundsSettings ( getDialogBoundsSettings ( HiveTab.WORKSPACE_SELECTION_DIALOG ), Dialog.DIALOG_PERSISTSIZE ); if ( dialog.open () == IDialogConstants.OK_ID ) { final IResource resource = (IResource)dialog.getFirstResult (); if ( resource != null ) { final String arg = resource.getFullPath ().toString (); final String fileLoc = VariablesPlugin.getDefault ().getStringVariableManager ().generateVariableExpression ( "workspace_loc", arg ); //$NON-NLS-1$ this.fileText.setText ( fileLoc ); makeDirty (); } } }
Example #2
Source File: SpellingPreferenceBlock.java From xds-ide with 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 #3
Source File: PydevConsole.java From Pydev with 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 #4
Source File: ReportPlugin.java From birt with 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 #5
Source File: EclipseProcessLauncher.java From goclipse with Eclipse Public License 1.0 | 6 votes |
protected IProcess launchProcess(final ILaunch launch) throws CoreException, CommonException { if(workingDir != null && !workingDir.toFile().exists()) { fail(LaunchMessages.errWorkingDirectoryDoesntExist, workingDir); } if(!programFileLocation.toFile().exists()) { fail(LaunchMessages.errExecutableFileDoesntExist, programFileLocation); } CommandInvocation programInvocation = unresolvedProgramInvocation.getResolvedCommandInvocation( new VariablesResolver(VariablesPlugin.getDefault().getStringVariableManager())); Indexable<String> cmdLine = programInvocation.parseCommandLineArguments(); Process sp = newSystemProcess(programInvocation); return newEclipseProcessWithLabelUpdater(launch, cmdLine, sp); }
Example #6
Source File: SpellingConfigurationBlock.java From Eclipse-Postfix-Code-Completion with 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 #7
Source File: WarArgumentProcessor.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
public static WarParser parse(List<String> args, IJavaProject javaProject) { // Get the WAR dir index (either after the "-war" arg or the last arg) int unverifiedWarDirIndex = getUnverifiedWarDirIndex(args); // Get the arg at the index String unverifiedWarDir = LaunchConfigurationProcessorUtilities.getArgValue(args, unverifiedWarDirIndex); String resolvedUnverifiedWarDir = unverifiedWarDir; try { resolvedUnverifiedWarDir = unverifiedWarDir != null ? VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution(unverifiedWarDir) : null; } catch (CoreException e) { GdtPlugin.getLogger().logWarning(e, "Could not resolve any variables in the WAR directory."); } // Check if the WAR dir is valid boolean isWarDirValid = resolvedUnverifiedWarDir != null ? isWarDirValid(resolvedUnverifiedWarDir) : false; // Check if it is specified with the "-war" arg boolean isSpecifiedWithWarArg = unverifiedWarDirIndex != -1 ? isSpecifiedWithWarArg(unverifiedWarDirIndex, args) : false; return new WarParser(unverifiedWarDirIndex, isWarDirValid, isSpecifiedWithWarArg, unverifiedWarDir, resolvedUnverifiedWarDir); }
Example #8
Source File: LaunchConfigurationCreator.java From Pydev with 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 #9
Source File: PathMacroReplacer.java From cppcheclipse with 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 #10
Source File: StringSubstitution.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Resolve and return the value of the given variable reference, * possibly <code>null</code>. * * @param var * @param resolveVariables whether to resolve the variables value or just to validate that this variable is valid * @param variableSubstitution variable registry * @return variable value, possibly <code>null</code> * @exception CoreException if unable to resolve a value */ private String resolve(VariableReference var, boolean resolveVariables, Map<String, String> variableSubstitution) throws CoreException { String text = var.getText(); int pos = text.indexOf(VARIABLE_ARG); String name = null; String arg = null; if (pos > 0) { name = text.substring(0, pos); pos++; if (pos < text.length()) { arg = text.substring(pos); } } else { name = text; } String valueVariable = variableSubstitution.get(name); if (valueVariable == null) { //leave as is return getOriginalVarText(var); } if (arg == null) { if (resolveVariables) { fSubs = true; return valueVariable; } //leave as is return getOriginalVarText(var); } // error - an argument specified for a value variable throw new CoreException(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR, "Error substituting: " + name + " var: " + valueVariable, null)); }
Example #11
Source File: StringSubstitution.java From Pydev with 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 variableSubstitution 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 resolveVariables, Map<String, String> variableSubstitution) throws CoreException { substitute(expression, resolveVariables, variableSubstitution); List<HashSet<String>> resolvedVariableSets = new ArrayList<HashSet<String>>(); while (fSubs) { HashSet<String> resolved = substitute(fResult.toString(), true, variableSubstitution); 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 (Iterator<?> it = conflictingSet.iterator(); it.hasNext();) { problemVariableList.append(it.next().toString()); 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, StringUtils.format("Cycle error on:", problemVariableList.toString()), null)); } } resolvedVariableSets.add(resolved); } return fResult.toString(); }
Example #12
Source File: InterpreterInfo.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private IStringVariableManager getStringVariableManager() { if (SharedCorePlugin.inTestMode()) { return stringVariableManagerForTests; } VariablesPlugin variablesPlugin = VariablesPlugin.getDefault(); return variablesPlugin.getStringVariableManager(); }
Example #13
Source File: StringVariableSelectionDialog.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Constructs a new string substitution variable selection dialog. * * @param parent * parent shell */ public StringVariableSelectionDialog( Shell parent ) { super( parent, new StringVariableLabelProvider( ) ); setHelpAvailable( false ); setShellStyle( getShellStyle( ) | SWT.RESIZE ); setTitle( TITLE ); setMessage( MESSAGE ); setMultipleSelection( false ); setElements( VariablesPlugin.getDefault( ) .getStringVariableManager( ) .getVariables( ) ); }
Example #14
Source File: ScriptDebugUtil.java From birt with 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 #15
Source File: WorkingDirectoryBlock.java From Pydev with 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 #16
Source File: GwtSdk.java From gwt-eclipse-plugin with 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 #17
Source File: GWTCompileRunner.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Computes the command line arguments required to invoke the GWT compiler for * this project. */ private static List<String> computeCompilerCommandLine( IJavaProject javaProject, IPath warLocation, GWTCompileSettings settings) throws CoreException { List<String> commandLine = new ArrayList<String>(); // add the fully qualified path to java String javaExecutable = ProcessUtilities.computeJavaExecutableFullyQualifiedPath(javaProject); commandLine.add(javaExecutable); commandLine.addAll(GWTLaunchConfiguration.computeCompileDynamicVMArgsAsList( javaProject)); commandLine.addAll(splitArgs(VariablesPlugin.getDefault().getStringVariableManager().performStringSubstitution( settings.getVmArgs()))); // add the classpath commandLine.add("-cp"); commandLine.add(ClasspathUtilities.flattenToClasspathString(computeClasspath(javaProject))); // add the GWT compiler class name commandLine.add(COMPILER_NAME); // add the GWT compiler options commandLine.addAll(computeCompilerOptions(warLocation, settings)); // add the startup modules commandLine.addAll(settings.getEntryPointModules()); return commandLine; }
Example #18
Source File: VariableUtils.java From xds-ide with 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 #19
Source File: StringSubstitutionEngine.java From goclipse with 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 #20
Source File: VariableManagerStringParser.java From workspacemechanic with 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 #21
Source File: CorrosionPreferencePage.java From corrosion with 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 #22
Source File: DotnetRunDelegate.java From aCute with 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 #23
Source File: LaunchShortcut.java From neoscada with Eclipse Public License 1.0 | 5 votes |
protected Collection<ILaunchConfiguration> findConfigurations ( final IResource resource ) throws CoreException, IOException { if ( resource == null ) { return Collections.emptyList (); } final Collection<ILaunchConfiguration> result = new LinkedList<> (); final File sourceFile = resource.getLocation ().toFile ().getCanonicalFile (); final ILaunchConfiguration[] cfgs = DebugPlugin.getDefault ().getLaunchManager ().getLaunchConfigurations ( getConfigurationType () ); for ( final ILaunchConfiguration cfg : cfgs ) { final Map<?, ?> envs = cfg.getAttribute ( ATTR_ENV_VARS, Collections.<String, String> emptyMap () ); if ( envs != null ) { final Object profile = envs.get ( "SCADA_PROFILE" ); //$NON-NLS-1$ if ( profile instanceof String ) { String profileString = (String)profile; profileString = VariablesPlugin.getDefault ().getStringVariableManager ().performStringSubstitution ( profileString ); final File other = new File ( profileString ); try { if ( sourceFile.equals ( other.getCanonicalFile () ) ) { result.add ( cfg ); } } catch ( final IOException e ) { // ignore this one } } } } return result; }
Example #24
Source File: ForwardingVariableManager.java From goclipse with Eclipse Public License 1.0 | 4 votes |
public ForwardingVariableManager() { this(VariablesPlugin.getDefault().getStringVariableManager()); }
Example #25
Source File: LaunchConfigurationCreator.java From Pydev with 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 #26
Source File: PythonRunnerConfigTestWorkbench.java From Pydev with 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 }); } }
Example #27
Source File: LangLaunchConfigurationDelegate.java From goclipse with Eclipse Public License 1.0 | 4 votes |
protected IStringVariableManager getVariableManager() { return VariablesPlugin.getDefault().getStringVariableManager(); }
Example #28
Source File: StringSubstitutionEngine.java From goclipse with Eclipse Public License 1.0 | 4 votes |
/** * Resolve and return the value of the given variable reference, * possibly <code>null</code>. * * @param var the {@link VariableReference} to try and resolve * @param reportUndefinedVariables whether to report undefined variables as * an error * @param resolveVariables whether to resolve the variables value or just to validate that this variable is valid * @param manager variable registry * @return variable value, possibly <code>null</code> * @exception CoreException if unable to resolve a value */ private String resolve(VariableReference var, boolean reportUndefinedVariables, boolean resolveVariables, IStringVariableManager manager) throws CoreException { String text = var.getText(); int pos = text.indexOf(VARIABLE_ARG); String name = null; String arg = null; if (pos > 0) { name = text.substring(0, pos); pos++; if (pos < text.length()) { arg = text.substring(pos); } } else { name = text; } IValueVariable valueVariable = manager.getValueVariable(name); if (valueVariable == null) { IDynamicVariable dynamicVariable = manager.getDynamicVariable(name); if (dynamicVariable == null) { // no variables with the given name if (reportUndefinedVariables) { throw new CoreException(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR, NLS.bind(VariablesMessages.StringSubstitutionEngine_3, new String[]{name}), null)); } // leave as is return getOriginalVarText(var); } if (resolveVariables) { fSubs = true; return dynamicVariable.getValue(arg); } //leave as is return getOriginalVarText(var); } if (arg == null) { if (resolveVariables) { fSubs = true; return valueVariable.getValue(); } //leave as is return getOriginalVarText(var); } // error - an argument specified for a value variable throw new CoreException(new Status(IStatus.ERROR, VariablesPlugin.getUniqueIdentifier(), VariablesPlugin.INTERNAL_ERROR, NLS.bind(VariablesMessages.StringSubstitutionEngine_4, new String[]{valueVariable.getName()}), null)); }
Example #29
Source File: ReportPlugin.java From birt with 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 #30
Source File: GWTProjectsRuntime.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 4 votes |
private IStringVariableManager getVariableManager() { return VariablesPlugin.getDefault().getStringVariableManager(); }