Search in sources :

Example 6 with IPathVariableManager

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();
}
Also used : Listener(org.eclipse.swt.widgets.Listener) IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) IDialogSettings(org.eclipse.jface.dialogs.IDialogSettings) IWorkspace(org.eclipse.core.resources.IWorkspace) Label(org.eclipse.swt.widgets.Label) Event(org.eclipse.swt.widgets.Event) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException)

Example 7 with IPathVariableManager

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();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IOException(java.io.IOException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 8 with IPathVariableManager

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;
}
Also used : IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) IWorkspace(org.eclipse.core.resources.IWorkspace) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

Example 9 with IPathVariableManager

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));
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) IWorkspace(org.eclipse.core.resources.IWorkspace) SubMonitor(org.eclipse.core.runtime.SubMonitor) URI(java.net.URI) IFolder(org.eclipse.core.resources.IFolder)

Example 10 with IPathVariableManager

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);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IResource(org.eclipse.core.resources.IResource) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) FileInputStream(java.io.FileInputStream) CheckConfiguration(com.avaloq.tools.ddk.checkcfg.checkcfg.CheckConfiguration) IPathVariableManager(org.eclipse.core.resources.IPathVariableManager) CoreException(org.eclipse.core.runtime.CoreException) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) IWorkspace(org.eclipse.core.resources.IWorkspace) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

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