Java Code Examples for org.eclipse.core.variables.IStringVariableManager#performStringSubstitution()

The following examples show how to use org.eclipse.core.variables.IStringVariableManager#performStringSubstitution() . 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: 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 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: 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 5
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 6
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 7
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 8
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 9
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 10
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 11
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 12
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 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: 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 15
Source File: VariableUtils.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public static String performStringSubstitution(String line, boolean isReportUndefinedVariables) throws CoreException {
	IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
	return manager.performStringSubstitution(line, isReportUndefinedVariables);
}
 
Example 16
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;
}
 
Example 17
Source File: RustLaunchDelegateTools.java    From corrosion with Eclipse Public License 2.0 4 votes vote down vote up
public static String performVariableSubstitution(String string) throws CoreException {
	IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
	return manager.performStringSubstitution(string);
}
 
Example 18
Source File: AbstractMainTab.java    From typescript.java with MIT License 2 votes vote down vote up
/**
 * Validates the value of the given string to determine if any/all variables
 * are valid
 *
 * @param expression
 *            expression with variables
 * @return whether the expression contained any variable values
 * @exception CoreException
 *                if variable resolution fails
 */
private String getValue(String expression) throws CoreException {
	IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
	return manager.performStringSubstitution(expression);
}