use of org.eclipse.core.resources.IPathVariableManager in project usbdm-eclipse-plugins by podonoghue.
the class KSDKLibraryImportWizardPage method createControl.
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
URI kdsPath = null;
try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPathVariableManager pathMan = workspace.getPathVariableManager();
kdsPath = pathMan.getURIValue(UsbdmSharedConstants.USBDM_KSDK_PATH);
} catch (Exception e) {
try {
kdsPath = new URI("C:/Apps/Freescale/KSDK_1.1.0");
} catch (URISyntaxException e1) {
e1.printStackTrace();
}
}
if (kdsPath == null) {
Label label = new Label(parent, SWT.NONE);
label.setText("Path to Kinetis SDK installation is invalid\n" + "Please set path on USBDM configuration page");
setControl(label);
return;
}
IDialogSettings dialogSettings = getDialogSettings();
if (dialogSettings == null) {
System.err.println("UsbdmProjectOptionsPage.createControl() dialogSettings == null!");
}
try {
fKSDKLibraryImportOptionsPanel = new KSDKLibraryImportOptionsPanel(parent, SWT.NONE);
fKSDKLibraryImportOptionsPanel.addListener(SWT.CHANGED, new Listener() {
@Override
public void handleEvent(Event event) {
validate();
}
});
setControl(fKSDKLibraryImportOptionsPanel);
} catch (Exception e) {
Label label = new Label(parent, SWT.NONE);
label.setText("Exception while creating page\n" + "Reason: " + e.getMessage());
setControl(label);
e.printStackTrace();
return;
}
validate();
}
use of org.eclipse.core.resources.IPathVariableManager in project usbdm-eclipse-plugins by podonoghue.
the class KSDKImporter method importKDSLibrary.
private static void importKDSLibrary(IProgressMonitor monitor) throws Exception {
URI kdsPath = null;
try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPathVariableManager pathMan = workspace.getPathVariableManager();
kdsPath = pathMan.getURIValue(UsbdmSharedConstants.USBDM_KSDK_PATH);
} catch (Exception e) {
kdsPath = new URI("file:/C:/Apps/Freescale/KSDK_1.1.0");
}
java.nio.file.Path sourcePath = java.nio.file.Paths.get(kdsPath).resolve("lib/ksdk_platform_lib/kds");
DirectoryStream<java.nio.file.Path> stream;
try {
stream = Files.newDirectoryStream(sourcePath);
for (java.nio.file.Path entry : stream) {
importProject(entry, monitor);
}
} catch (IOException e) {
e.printStackTrace();
} catch (CoreException e) {
e.printStackTrace();
}
}
use of org.eclipse.core.resources.IPathVariableManager in project usbdm-eclipse-plugins by podonoghue.
the class AddTargetFiles method resolvePath.
/**
* Resolves a path containing Path variables
*
* @param sourcePath
*
* @return Modified path
*
* @throws URISyntaxException
*/
Path resolvePath(Path sourcePath) throws URISyntaxException {
IPathVariableManager pathMan;
try {
IWorkspace workspace = ResourcesPlugin.getWorkspace();
pathMan = workspace.getPathVariableManager();
} catch (Exception e) {
return sourcePath;
}
URI sourceURI = URIUtil.fromString("file:" + sourcePath.toString());
// System.err.println(String.format("AddTargetFiles.resolvePath() sourceURI.a = \'%s\'", sourceURI.toASCIIString()));
// System.err.println(String.format("AddTargetFiles.resolvePath() sourceURI.p = \'%s\'", sourceURI.getPath()));
// System.err.println(String.format("AddTargetFiles.resolvePath() Absolute? = \'%s\'\n", sourceURI.isAbsolute()?"True":"False"));
sourceURI = pathMan.resolveURI(sourceURI);
// System.err.println(String.format("AddTargetFiles.resolvePath() resolved URI.a = \'%s\'", sourceURI.toASCIIString()));
// System.err.println(String.format("AddTargetFiles.resolvePath() resolved URI.p = \'%s\'", sourceURI.getPath()));
// System.err.println(String.format("AddTargetFiles.resolvePath() Absolute? = \'%s\'\n", sourceURI.isAbsolute()?"True":"False"));
String source = sourceURI.getPath().replaceFirst("/([a-zA-Z]:.*)", "$1");
sourcePath = Paths.get(source);
// System.err.println(String.format("AddTargetFiles.resolvePath() sourcePath = \'%s\'", sourcePath));
return sourcePath;
}
use of org.eclipse.core.resources.IPathVariableManager in project usbdm-eclipse-plugins by podonoghue.
the class AddTargetFiles method createLink.
/**
* Create link to file.
* Attempts to make it relative to usbdm_resource_path or usbdm_kds_path path variables
*
* @param sourcePath Path of source. May start with path variable
* @param target
* @param projectHandle
* @param monitor
*
* @throws Exception
*/
private void createLink(Path sourcePath, String target, IProject projectHandle, IProgressMonitor monitor) throws Exception {
SubMonitor subMonitor = SubMonitor.convert(monitor);
subMonitor.beginTask("Create Link", 100);
URI sourceURI = URIUtil.fromString("file:" + sourcePath.toString());
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPathVariableManager pathMan = workspace.getPathVariableManager();
sourceURI = pathMan.convertToRelative(sourceURI, false, UsbdmSharedConstants.USBDM_APPLICATION_PATH_VAR);
sourceURI = pathMan.convertToRelative(sourceURI, false, UsbdmSharedConstants.USBDM_KSDK_PATH);
sourcePath = resolvePath(sourcePath);
if (sourcePath.toFile().isDirectory()) {
IFolder iFolder = projectHandle.getFolder(target);
if (!iFolder.getParent().exists()) {
// Create parent directories if necessary
ProjectUtilities.createFolder(projectHandle, iFolder.getParent().getProjectRelativePath().toString(), subMonitor.newChild(50));
}
iFolder.createLink(sourceURI, IResource.ALLOW_MISSING_LOCAL, subMonitor.newChild(50));
} else {
IFile iFile = projectHandle.getFile(target);
if (!iFile.getParent().exists()) {
// Create parent directories if necessary
ProjectUtilities.createFolder(projectHandle, iFile.getParent().getProjectRelativePath().toString(), subMonitor.newChild(50));
}
iFile.createLink(sourceURI, IResource.ALLOW_MISSING_LOCAL, subMonitor.newChild(50));
}
}
use of org.eclipse.core.resources.IPathVariableManager in project dsl-devkit by dsldevkit.
the class DeployJob method deployCheckConfiguration.
/**
* Creates a new instance of {@link DeployJob}.
*
* @throws DeployException
* a general deployment exception.
*/
private void deployCheckConfiguration() throws DeployException {
List<IFile> checkCfgFiles = getCheckConfigurationFiles();
if (checkCfgFiles.isEmpty()) {
return;
}
if (checkCfgFiles.size() != 1) {
showTooManyCheckConfigurationDialog();
return;
}
IFile file = checkCfgFiles.get(0);
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IPathVariableManager pathMan = workspace.getPathVariableManager();
if (pathMan.validateName(CheckCfgConstants.CHECK_CFG_VAR_NAME).isOK() && pathMan.validateValue(file.getFullPath()).isOK()) {
try {
pathMan.setURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME, file.getLocationURI());
} catch (CoreException e) {
LOGGER.error(NLS.bind(Messages.DeployJob_CouldNotSetPathVariable, CheckCfgConstants.CHECK_CFG_VAR_NAME));
throw new DeployException(e);
}
} else {
LOGGER.error(NLS.bind(Messages.DeployJob_CouldNotSetPathVariable, CheckCfgConstants.CHECK_CFG_VAR_NAME));
throw new DeployException();
}
XtextResourceSet rs = new XtextResourceSet();
String uriString = pathMan.getURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME).toString();
URI uri = URI.createURI(uriString, true);
Resource resource = rs.createResource(uri);
try {
resource.load(new FileInputStream(new File(pathMan.getURIValue(CheckCfgConstants.CHECK_CFG_VAR_NAME))), rs.getLoadOptions());
rs.getURIResourceMap().put(uri, resource);
EcoreUtil.resolveAll(resource);
CheckConfiguration checkConfig = (CheckConfiguration) resource.getContents().get(0);
assert checkConfig != null;
} catch (IOException e) {
LOGGER.error(NLS.bind(Messages.DeployJob_ExceptionWhileReadingTheCheckConfigurationFile, uriString), e);
throw new DeployException(e);
}
}
Aggregations