Search code examples
eclipseeclipse-pluginexternal-tools

how to use the variables from eclipse


I'm developing an Eclipse plugin (Eclipse preferencePage), and I need to know how to use the variables from eclipse (workspace_loc ,project_loc,.... ), because my path on the preference page will be set with them. (that's my first question, let me know if you no understand)


Solution

  • Use the IStringVariableManager interface to access the manager for these variables:

    IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
    

    You will need to add the org.eclipse.core.variables plugin to your plugin's dependencies.

    The interface has various methods for accessing expressions containing variables, one of the main ones is:

    public String performStringSubstitution(String expression, boolean reportUndefinedVariables) throws CoreException;
    

    You can pass this a string containing things like ${workspace_loc} and it returns the resolved result.