Search in sources :

Example 16 with IPathVariableManager

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;
}
Also used : IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) VariableNotFoundException(org.eclipse.titan.common.utils.environment.EnvironmentVariableResolver.VariableNotFoundException) URI(java.net.URI)

Example 17 with IPathVariableManager

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);
    }
}
Also used : IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) URI(java.net.URI)

Aggregations

IPathVariableManager (org.eclipse.core.resources.IPathVariableManager)17 URI (java.net.URI)10 IWorkspace (org.eclipse.core.resources.IWorkspace)9 CoreException (org.eclipse.core.runtime.CoreException)5 URISyntaxException (java.net.URISyntaxException)4 IPath (org.eclipse.core.runtime.IPath)4 IOException (java.io.IOException)3 Path (org.eclipse.core.runtime.Path)3 OtpErlangList (com.ericsson.otp.erlang.OtpErlangList)2 OtpErlangTuple (com.ericsson.otp.erlang.OtpErlangTuple)2 ArrayList (java.util.ArrayList)2 IFile (org.eclipse.core.resources.IFile)2 IFolder (org.eclipse.core.resources.IFolder)2 CheckConfiguration (com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration)1 OtpErlangObject (com.ericsson.otp.erlang.OtpErlangObject)1 OtpErlangString (com.ericsson.otp.erlang.OtpErlangString)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IProject (org.eclipse.core.resources.IProject)1