Search in sources :

Example 11 with IPathVariableManager

use of org.eclipse.core.resources.IPathVariableManager in project titan.EclipsePlug-ins by eclipse.

the class TpdImporter method loadPathVariables.

/**
 * Load the information on path variables.
 *
 * @param rootNode
 *            the node to load from.
 * @param projectName
 *            the name of the project to be used on the user interface.
 *
 * @return true if the import was successful, false otherwise.
 */
private boolean loadPathVariables(final Node rootNode, final String projectName) {
    final IPathVariableManager pathVariableManager = ResourcesPlugin.getWorkspace().getPathVariableManager();
    NodeList variableNodes = rootNode.getChildNodes();
    for (int i = 0, size = variableNodes.getLength(); i < size; i++) {
        Node variable = variableNodes.item(i);
        if (variable.getNodeType() != Node.ELEMENT_NODE) {
            continue;
        }
        NamedNodeMap attributeMap = variable.getAttributes();
        if (attributeMap == null) {
            continue;
        }
        Node nameNode = attributeMap.getNamedItem("name");
        Node valueNode = attributeMap.getNamedItem("value");
        if (nameNode == null || valueNode == null) {
            displayError("Import failed", "Error while importing project " + projectName + " some attributes of a path variable are missing");
            return false;
        }
        final String variableName = nameNode.getTextContent();
        final String variableValue = valueNode.getTextContent();
        if (headless || shell == null) {
            try {
                pathVariableManager.setURIValue(variableName, convertPathOrUriStringToURI(variableValue));
            } catch (CoreException e) {
                ErrorReporter.logExceptionStackTrace("While setting path variable `" + variableName + "' in headless mode", e);
            } catch (URISyntaxException e) {
                ErrorReporter.logExceptionStackTrace("While setting path variable `" + variableName + "' in headless mode", e);
            }
        } else {
            Display.getDefault().syncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        final URI variableValueURI = convertPathOrUriStringToURI(variableValue);
                        final String variableValue1 = variableValueURI.toString();
                        if (pathVariableManager.isDefined(variableName)) {
                            URI uri = pathVariableManager.getURIValue(variableName);
                            if (!variableValue1.equals(uri.toString())) {
                                EditPathVariableDialog dialog = new EditPathVariableDialog(shell, variableName, uri, variableValueURI);
                                if (Window.OK == dialog.open()) {
                                    URI actualValue = dialog.getActualValue();
                                    pathVariableManager.setURIValue(variableName, actualValue);
                                }
                            }
                        } else {
                            // Modification dialog has been removed
                            pathVariableManager.setURIValue(variableName, variableValueURI);
                        }
                    } catch (CoreException e) {
                        ErrorReporter.logExceptionStackTrace("While setting path variable `" + variableName + "' in GUI mode", e);
                    } catch (URISyntaxException e) {
                        ErrorReporter.logExceptionStackTrace("While setting path variable `" + variableName + "' in GUI mode", e);
                    }
                }
            });
        }
    }
    return true;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) CoreException(org.eclipse.core.runtime.CoreException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Example 12 with IPathVariableManager

use of org.eclipse.core.resources.IPathVariableManager in project dsl-devkit by dsldevkit.

the class UndeployJob method undeployCheckConfiguration.

/**
 * Undeploys the check configuration.
 *
 * @throws CoreException
 *           core exception.
 */
public static void undeployCheckConfiguration() throws CoreException {
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IPathVariableManager pathMan = workspace.getPathVariableManager();
    if (pathMan.getURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME) == null) {
        return;
    }
    pathMan.setURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME, null);
}
Also used : IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 13 with IPathVariableManager

use of org.eclipse.core.resources.IPathVariableManager in project usbdm-eclipse-plugins by podonoghue.

the class Activator method loadUsbdmPaths.

protected void loadUsbdmPaths() {
    String appPathName = UsbdmSharedConstants.USBDM_APPLICATION_PATH_VAR;
    String resPathName = UsbdmSharedConstants.USBDM_RESOURCE_PATH_VAR;
    String kdsPathName = UsbdmSharedConstants.USBDM_KSDK_PATH;
    System.err.println("loadUsbdmPaths()");
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    UsbdmSharedSettings settings = UsbdmSharedSettings.getSharedSettings();
    IPath kdsPath = new Path(settings.get(kdsPathName, "Not Set"));
    IPath usbdmApplicationPath = Usbdm.getApplicationPath();
    IPath usbdmResourcePath = Usbdm.getResourcePath();
    IPathVariableManager pathMan = workspace.getPathVariableManager();
    if (!pathMan.validateValue(usbdmApplicationPath).isOK()) {
        usbdmApplicationPath = new Path("USBDM APPLICATION PATH NOT FOUND");
        System.err.println("loadUsbdmPath() - setting USBDM Application path variable");
    }
    if (!pathMan.validateValue(usbdmResourcePath).isOK()) {
        usbdmResourcePath = new Path("USBDM RESOURCE PATH NOT FOUND");
        System.err.println("loadUsbdmPath() - setting USBDM Resource path variable");
    }
    if (!pathMan.validateValue(kdsPath).isOK()) {
        kdsPath = new Path("");
        System.err.println("loadUsbdmPath() - KDS path is invalid or not set = " + kdsPath);
    }
    if (pathMan.validateValue(usbdmApplicationPath).isOK()) {
        try {
            pathMan.setURIValue(appPathName, usbdmApplicationPath.toFile().toURI());
        } catch (Exception e) {
            System.err.println("loadUsbdmPath() - Failed to set USBDM path variables, Exception = " + e.getMessage());
        }
    } else {
        System.err.println("loadUsbdmPath() - Failed to set USBDM path variables");
    }
    if (pathMan.validateValue(usbdmResourcePath).isOK()) {
        try {
            pathMan.setURIValue(resPathName, usbdmResourcePath.toFile().toURI());
        } catch (Exception e) {
            System.err.println("loadUsbdmPath() - Failed to set USBDM path variables, Exception = " + e.getMessage());
        }
    } else {
        System.err.println("loadUsbdmPath() - Failed to set USBDM path variables");
    }
    if (pathMan.validateValue(kdsPath).isOK()) {
        try {
            pathMan.setURIValue(kdsPathName, kdsPath.toFile().toURI());
        } catch (Exception e) {
            System.err.println("loadUsbdmPath() - Failed to set kdsPath path variables, Exception = " + e.getMessage());
        }
    } else {
        System.err.println("loadUsbdmPath() - Failed to set kdsPath path variables");
    }
// System.err.println("loadUsbdmPath() - Path names =================================");
// String[] names = pathMan.getPathVariableNames();
// for (String s:names) {
// System.err.println(String.format("loadUsbdmPath() \'%s\' => \'%s\'", s, pathMan.getURIValue(s)));
// }
// System.err.println("loadUsbdmPath() - ============================================");
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) IWorkspace(org.eclipse.core.resources.IWorkspace)

Example 14 with IPathVariableManager

use of org.eclipse.core.resources.IPathVariableManager in project usbdm-eclipse-plugins by podonoghue.

the class KSDKImporter method importProject.

private static void importProject(final java.nio.file.Path targetPath, final IProgressMonitor monitor) throws Exception {
    monitor.subTask("Importing project " + targetPath.getFileName());
    IPath targetIPath = new Path(targetPath.toAbsolutePath().toString());
    System.err.println(String.format("importProject()  targetIPath = \'%s\'", targetIPath));
    URI targetURI = targetIPath.toFile().toURI();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IPathVariableManager pathMan = workspace.getPathVariableManager();
    targetURI = pathMan.convertToRelative(targetURI, false, UsbdmSharedConstants.USBDM_KSDK_PATH);
    final IProjectDescription externalProjectDescription = workspace.loadProjectDescription(targetIPath.append(".project"));
    externalProjectDescription.setLocationURI(targetURI);
    final IProject project = workspace.getRoot().getProject(externalProjectDescription.getName());
    try {
        if (!project.exists()) {
            // Only create the project if necessary
            project.create(externalProjectDescription, IProject.NONE, monitor);
        }
        project.open(monitor);
        project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
        project.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
        // The KDS project don't have the RefreshPolicy set correctly
        project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
    } catch (CoreException e) {
        e.printStackTrace();
        System.err.println("Unable to process project \'" + targetPath.toAbsolutePath() + "\'");
    }
    monitor.worked(1);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IProjectDescription(org.eclipse.core.resources.IProjectDescription) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject)

Example 15 with IPathVariableManager

use of org.eclipse.core.resources.IPathVariableManager in project titan.EclipsePlug-ins by eclipse.

the class TITANResourceLocatorFieldEditor method doCheckState.

@Override
protected boolean doCheckState() {
    if (isNullOrEmpty(target)) {
        return isEmptyStringAllowed();
    }
    final Map<?, ?> envVariables = DebugPlugin.getDefault().getLaunchManager().getNativeEnvironmentCasePreserved();
    String result;
    try {
        result = EnvironmentVariableResolver.eclipseStyle().resolve(target, envVariables);
        result = EnvironmentVariableResolver.unixStyle().resolve(result, envVariables);
    } catch (EnvironmentVariableResolver.VariableNotFoundException e) {
        setErrorMessage(e.getMessage());
        return false;
    }
    final IPathVariableManager pathVariableManager = ResourcesPlugin.getWorkspace().getPathVariableManager();
    final URI uri = URIUtil.toURI(result);
    final URI resolvedURI = pathVariableManager.resolveURI(uri);
    if (rootPath != null && !resolvedURI.isAbsolute()) {
        final URI root = URIUtil.toURI(rootPath);
        final URI absoluteURI = root.resolve(resolvedURI);
        if (absoluteURI != null && !absoluteURI.isAbsolute()) {
            setErrorMessage("Could not be resolved to an absolute path");
            return false;
        }
    }
    return true;
}
Also used : EnvironmentVariableResolver(org.eclipse.titan.common.utils.environment.EnvironmentVariableResolver) IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) 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