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;
}
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);
}
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() - ============================================");
}
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);
}
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;
}
Aggregations