Search in sources :

Example 36 with Location

use of org.eclipse.osgi.service.datalocation.Location in project rt.equinox.framework by eclipse.

the class BasicLocationTests method doAllTestLocationDataArea.

private void doAllTestLocationDataArea(Location location, String dataAreaPrefix) {
    doTestLocateDataArea(location, dataAreaPrefix, getName());
    doTestLocateDataArea(location, dataAreaPrefix, "");
    doTestLocateDataArea(location, dataAreaPrefix, "test/multiple/paths");
    doTestLocateDataArea(location, dataAreaPrefix, "test/multiple/../paths");
    doTestLocateDataArea(location, dataAreaPrefix, "test\\multiple\\paths");
    doTestLocateDataArea(location, dataAreaPrefix, "/test/begin/slash");
    File testLocationFile = OSGiTestsActivator.getContext().getDataFile("testLocations/" + getName());
    Location createdLocation = location.createLocation(null, null, false);
    try {
        createdLocation.set(testLocationFile.toURL(), false);
    } catch (Exception e) {
        fail("Failed to set location", e);
    }
    doTestLocateDataArea(createdLocation, dataAreaPrefix, getName());
    doTestLocateDataArea(createdLocation, dataAreaPrefix, "");
    doTestLocateDataArea(createdLocation, dataAreaPrefix, "test/multiple/paths");
    doTestLocateDataArea(createdLocation, dataAreaPrefix, "test/multiple/../paths");
    doTestLocateDataArea(location, dataAreaPrefix, "test\\multiple\\paths");
    doTestLocateDataArea(location, dataAreaPrefix, "/test/begin/slash");
    createdLocation = location.createLocation(null, null, false);
    try {
        createdLocation.getDataArea("shouldFail");
        fail("expected failure when location is not set");
    } catch (IOException e) {
    // expected;
    }
}
Also used : Location(org.eclipse.osgi.service.datalocation.Location)

Example 37 with Location

use of org.eclipse.osgi.service.datalocation.Location in project knime-core by knime.

the class DefaultRepositoryView method init.

/**
 * {@inheritDoc}
 */
@Override
public void init(final IViewSite site) throws PartInitException {
    super.init(site);
    m_manager = null;
    Location loc = Platform.getInstallLocation();
    if (loc == null) {
        LOGGER.error("Cannot detected KNIME installation directory");
        return;
    } else if (!loc.getURL().getProtocol().equals("file")) {
        LOGGER.error("KNIME installation directory is not local");
        return;
    }
    File instDir = new File(loc.getURL().getPath());
    File customDefinition = new File(instDir, DEFINITION_FILE);
    if (customDefinition.exists()) {
        try {
            m_manager = new CustomRepositoryManager(customDefinition);
            setPartName(m_manager.getCustomName());
        } catch (Exception ex) {
            throw new PartInitException("Could not load custom repository content", ex);
        }
    }
}
Also used : PartInitException(org.eclipse.ui.PartInitException) File(java.io.File) CustomRepositoryManager(org.knime.workbench.repository.model.CustomRepositoryManager) PartInitException(org.eclipse.ui.PartInitException) Location(org.eclipse.osgi.service.datalocation.Location)

Example 38 with Location

use of org.eclipse.osgi.service.datalocation.Location in project knime-core by knime.

the class KNIMESplashHandler method readSplashExtensions.

private List<IConfigurationElement> readSplashExtensions() {
    // Get all splash handler extensions
    IExtension[] extensions = Platform.getExtensionRegistry().getExtensionPoint(SPLASH_EXTENSION_ID).getExtensions();
    List<IConfigurationElement> configElements = new ArrayList<IConfigurationElement>();
    // add and check for duplicates
    for (IExtension ext : extensions) {
        for (IConfigurationElement elem : ext.getConfigurationElements()) {
            String id1 = elem.getAttribute("id");
            boolean exists = false;
            if (id1 != null) {
                // check if the same id already exists
                for (IConfigurationElement elem2 : configElements) {
                    String id2 = elem2.getAttribute("id");
                    if (id1.equals(id2)) {
                        exists = true;
                        break;
                    }
                }
            }
            if (!exists) {
                configElements.add(elem);
            }
        }
    }
    // sort splash icons by name or by config file
    Comparator<IConfigurationElement> comparator = new DefaultComparator();
    Location loc = Platform.getInstallLocation();
    if ((loc != null) && "file".equals(loc.getURL().getProtocol())) {
        File instDir = new File(loc.getURL().getPath());
        File splashConfig = new File(instDir, "splash.config");
        if (splashConfig.exists()) {
            try {
                comparator = new ConfiguredComparator(splashConfig);
            } catch (IOException ex) {
                Bundle thisBundle = FrameworkUtil.getBundle(getClass());
                Platform.getLog(thisBundle).log(new Status(IStatus.ERROR, thisBundle.getSymbolicName(), "Error while reading splash config file", ex));
            }
        }
    }
    Collections.sort(configElements, comparator);
    return configElements;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IExtension(org.eclipse.core.runtime.IExtension) File(java.io.File) Location(org.eclipse.osgi.service.datalocation.Location)

Example 39 with Location

use of org.eclipse.osgi.service.datalocation.Location in project knime-core by knime.

the class KNIMEApplication method checkInstanceLocation.

/**
 * Return true if a valid workspace path has been set and false otherwise.
 * Prompt for and set the path if possible and required.
 *
 * @return true if a valid instance location has been set and false
 *         otherwise
 */
private boolean checkInstanceLocation() {
    // -data @none was specified but an ide requires workspace
    Location instanceLoc = Platform.getInstanceLocation();
    if (instanceLoc == null) {
        MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceMandatoryTitle, IDEWorkbenchMessages.IDEApplication_workspaceMandatoryMessage);
        return false;
    }
    // -data "/valid/path", workspace already set
    if (instanceLoc.isSet()) {
        // chosen to overwrite it).
        if (!checkValidWorkspace(instanceLoc.getURL())) {
            return false;
        }
        // metadata version information if successful
        try {
            if (instanceLoc.lock()) {
                writeWorkspaceVersion();
                return true;
            }
            // we failed to create the directory.
            // Two possibilities:
            // 1. directory is already in use
            // 2. directory could not be created
            File workspaceDirectory = new File(instanceLoc.getURL().getFile());
            if (workspaceDirectory.exists()) {
                MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceCannotLockTitle, NLS.bind(IDEWorkbenchMessages.IDEApplication_workspaceCannotLockMessage, workspaceDirectory.getAbsolutePath()));
            } else {
                MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
            }
        } catch (IOException e) {
            MessageDialog.openError(null, IDEWorkbenchMessages.InternalError, e.getMessage());
        }
        return false;
    }
    URL defaultLocation = instanceLoc.getDefault();
    if (Platform.OS_MACOSX.equals(Platform.getOS())) {
        if (defaultLocation.getPath().contains("/Knime.app/")) {
            URL url = Platform.getInstallLocation().getURL();
            try {
                defaultLocation = new URL(url.getProtocol(), url.getHost(), url.getPath() + "/workspace");
            } catch (MalformedURLException ex) {
            // should not happen
            }
        }
    }
    // -data @noDefault or -data not specified, prompt and set
    ChooseWorkspaceData launchData = new ChooseWorkspaceData(defaultLocation);
    boolean force = false;
    while (true) {
        URL workspaceUrl = promptForWorkspace(launchData, force);
        if (workspaceUrl == null) {
            return false;
        }
        // if there is an error with the first selection, then force the
        // dialog to open to give the user a chance to correct
        force = true;
        try {
            // instance data area, so other checking is unneeded
            if (instanceLoc.set(workspaceUrl, true)) {
                launchData.writePersistedData();
                writeWorkspaceVersion();
                return true;
            }
            // by this point it has been determined that the workspace is
            // already in use -- force the user to choose again
            MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceInUseTitle, NLS.bind(IDEWorkbenchMessages.IDEApplication_workspaceInUseMessage, workspaceUrl.getPath()));
        } catch (Exception e) {
            MessageDialog.openError(null, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetTitle, IDEWorkbenchMessages.IDEApplication_workspaceCannotBeSetMessage);
        }
    }
}
Also used : ChooseWorkspaceData(org.eclipse.ui.internal.ide.ChooseWorkspaceData) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) File(java.io.File) URL(java.net.URL) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) SWTException(org.eclipse.swt.SWTException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Location(org.eclipse.osgi.service.datalocation.Location)

Example 40 with Location

use of org.eclipse.osgi.service.datalocation.Location in project knime-core by knime.

the class ExampleWorkflowExtractor method run.

/**
 * {@inheritDoc}
 */
@Override
public void run() {
    Location loc = Platform.getInstallLocation();
    if (loc == null) {
        NodeLogger.getLogger(getClass()).error("Cannot detect KNIME installation directory");
        return;
    } else if (!loc.getURL().getProtocol().equals("file")) {
        NodeLogger.getLogger(getClass()).error("KNIME installation directory is not local");
        return;
    }
    String path = loc.getURL().getPath();
    if (Platform.OS_WIN32.equals(Platform.getOS()) && path.matches("^/[a-zA-Z]:/.*")) {
        // Windows path with drive letter => remove first slash
        path = path.substring(1);
    }
    Path initialWorkspace = Paths.get(path, "knime-workspace.zip");
    if (!Files.exists(initialWorkspace)) {
        NodeLogger.getLogger(getClass()).warn(initialWorkspace.toAbsolutePath() + " not found in installation directory, not creating inital workspace");
        return;
    }
    File workspace = KNIMEPath.getWorkspaceDirPath();
    try (ZipInputStream is = new ZipInputStream(Files.newInputStream(initialWorkspace))) {
        FileUtil.unzip(is, workspace, 0);
    } catch (IOException ex) {
        NodeLogger.getLogger(getClass()).error("Could not extract example workflows: " + ex.getMessage(), ex);
    }
    for (IWorkbenchWindow window : PlatformUI.getWorkbench().getWorkbenchWindows()) {
        for (IWorkbenchPage page : window.getPages()) {
            for (IViewReference ref : page.getViewReferences()) {
                if (ExplorerView.ID.equals(ref.getId())) {
                    final ExplorerView explorer = (ExplorerView) ref.getView(true);
                    final TreeViewer viewer = explorer.getViewer();
                    if (viewer.getControl() != null && viewer.getControl().getDisplay() != null) {
                        viewer.getControl().getDisplay().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                viewer.refresh();
                                viewer.expandAll();
                            }
                        });
                    }
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) KNIMEPath(org.knime.core.internal.KNIMEPath) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ExplorerView(org.knime.workbench.explorer.view.ExplorerView) TreeViewer(org.eclipse.jface.viewers.TreeViewer) IOException(java.io.IOException) ZipInputStream(java.util.zip.ZipInputStream) IViewReference(org.eclipse.ui.IViewReference) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) File(java.io.File) Location(org.eclipse.osgi.service.datalocation.Location)

Aggregations

Location (org.eclipse.osgi.service.datalocation.Location)42 File (java.io.File)14 URL (java.net.URL)13 IOException (java.io.IOException)12 Equinox (org.eclipse.osgi.launch.Equinox)10 MalformedURLException (java.net.MalformedURLException)9 FileNotFoundException (java.io.FileNotFoundException)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 ServiceReference (org.osgi.framework.ServiceReference)4 BufferedReader (java.io.BufferedReader)3 FileReader (java.io.FileReader)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 Bundle (org.osgi.framework.Bundle)3 BundleContext (org.osgi.framework.BundleContext)3 BundleException (org.osgi.framework.BundleException)3 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2