use of org.eclipse.core.resources.IPathVariableManager in project titan.EclipsePlug-ins by eclipse.
the class TITANPathUtilities method resolvePath.
/**
* Resolves the provided uri relative to the provided base uri. Environment
* variables and path variables will be resolved
*
* @param pathToBeResolved
* the path to be resolved.
* @param basePath
* the full path to which the resolvable one might be relative
* to.
*
* @return the resolved uri.
*/
// TODO: call resolvePathURI, it is the same functionality!!!
public static URI resolvePath(final String pathToBeResolved, final URI basePath) {
Map<?, ?> envVariables;
if (DebugPlugin.getDefault() != null) {
envVariables = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironmentCasePreserved();
} else {
envVariables = null;
}
String tmp2 = null;
try {
final String tmp1 = EnvironmentVariableResolver.eclipseStyle().resolve(pathToBeResolved, envVariables);
tmp2 = EnvironmentVariableResolver.unixStyle().resolveIgnoreErrors(tmp1, envVariables);
} catch (VariableNotFoundException e) {
ErrorReporter.logError("There was an error while resolving `" + pathToBeResolved + "'");
return null;
}
final IPathVariableManager pathVariableManager = ResourcesPlugin.getWorkspace().getPathVariableManager();
// the trailing dots are removed but later corrected
URI uri = URIUtil.toURI(tmp2);
uri = pathVariableManager.resolveURI(uri);
if (basePath != null && uri != null && !uri.isAbsolute()) {
final String basePathString = URIUtil.toPath(basePath).toOSString();
final String temp = PathUtil.getAbsolutePath(basePathString, tmp2);
if (temp != null) {
uri = URIUtil.toURI(temp);
}
}
return uri;
}
use of org.eclipse.core.resources.IPathVariableManager in project titan.EclipsePlug-ins by eclipse.
the class TITANProjectExporter method savePathVariableData.
/**
* Saves the path variables with name and value under the provided node.
*
* @param root
* the node to save the data under.
*/
private void savePathVariableData(final Node root) {
IPathVariableManager pathVariableManager = ResourcesPlugin.getWorkspace().getPathVariableManager();
String[] names = pathVariableManager.getPathVariableNames();
if (names.length == 0) {
return;
}
List<String> namesArray = new ArrayList<String>(names.length);
for (String name : names) {
namesArray.add(name);
}
Collections.sort(namesArray);
final Document document = root.getOwnerDocument();
final Element variablesRoot = document.createElement(ProjectFormatConstants.PATH_VARIABLES);
root.appendChild(variablesRoot);
for (String name : namesArray) {
final Element variableRoot = document.createElement(ProjectFormatConstants.PATH_VARIABLE);
variablesRoot.appendChild(variableRoot);
URI value = pathVariableManager.getURIValue(name);
variableRoot.setAttribute("value", value.toString());
variableRoot.setAttribute("name", name);
}
}
Aggregations