org.eclipse.core.variables.IStringVariableManager Java Examples

The following examples show how to use org.eclipse.core.variables.IStringVariableManager. 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: LaunchConfigurationCreator.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #2
Source File: PydevConsole.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @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 #3
Source File: InterpreterInfo.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
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 #4
Source File: SpellingPreferenceBlock.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
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 #5
Source File: ReportPlugin.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #6
Source File: HiveSelectionPageHelper.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
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 #7
Source File: SpellingConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 #8
Source File: ActionDelegate.java    From EasyShell with Eclipse Public License 2.0 6 votes vote down vote up
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 #9
Source File: ActionDelegate.java    From EasyShell with Eclipse Public License 2.0 6 votes vote down vote up
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 #10
Source File: LaunchConfigurationCreator.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
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 #11
Source File: WorkingDirectoryBlock.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@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 #12
Source File: InterpreterInfo.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
private IStringVariableManager getStringVariableManager() {
    if (SharedCorePlugin.inTestMode()) {
        return stringVariableManagerForTests;
    }
    VariablesPlugin variablesPlugin = VariablesPlugin.getDefault();
    return variablesPlugin.getStringVariableManager();
}
 
Example #13
Source File: ScriptDebugUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @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 #14
Source File: ActionDelegate.java    From EasyShell with Eclipse Public License 2.0 5 votes vote down vote up
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 #15
Source File: GwtSdk.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 File: PathMacroReplacer.java    From cppcheclipse with Apache License 2.0 5 votes vote down vote up
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 #17
Source File: VariableUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
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 #18
Source File: StringSubstitutionEngine.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 #19
Source File: VariableManagerStringParser.java    From workspacemechanic with Eclipse Public License 1.0 5 votes vote down vote up
public String apply(String input) {
  try {
    IStringVariableManager stringManager =
        VariablesPlugin.getDefault().getStringVariableManager();
    return stringManager.performStringSubstitution(input);
  } catch (CoreException e) {
    return "";
  }
}
 
Example #20
Source File: CorrosionPreferencePage.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
private static String varParse(String unparsedString) {
	IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
	try {
		return manager.performStringSubstitution(unparsedString);
	} catch (CoreException e) {
		return unparsedString;
	}
}
 
Example #21
Source File: DotnetRunDelegate.java    From aCute with Eclipse Public License 2.0 5 votes vote down vote up
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 #22
Source File: PythonRunnerConfigTestWorkbench.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
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 #23
Source File: LangLaunchConfigurationDelegate.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
protected IStringVariableManager getVariableManager() {
	return VariablesPlugin.getDefault().getStringVariableManager();
}
 
Example #24
Source File: VariablesResolver.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public VariablesResolver(IStringVariableManager parentVarMgr) {
	this.parentVarMgr = assertNotNull(parentVarMgr);
	this.varMgr = new OverlayVariableManager(parentVarMgr);
}
 
Example #25
Source File: VariablesResolver.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public OverlayVariableManager(IStringVariableManager parentVarMgr) {
	super(parentVarMgr);
}
 
Example #26
Source File: LaunchConfigurationCreator.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
private static String makeFileRelativeToWorkspace(IResource r, IStringVariableManager varManager) {
    String m = r.getFullPath().makeRelative().toString();
    m = varManager.generateVariableExpression("workspace_loc", m);
    return m;
}
 
Example #27
Source File: StringSubstitutionEngine.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * 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 #28
Source File: ForwardingVariableManager.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public ForwardingVariableManager(IStringVariableManager parentVarMgr) {
	this.parentVarMgr = assertNotNull(parentVarMgr);
}
 
Example #29
Source File: LaunchConfigurationCreator.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @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 #30
Source File: ReportPlugin.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @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;
}