Search in sources :

Example 16 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project linuxtools by eclipse.

the class SystemTapLaunchConfigurationDelegate method finishLaunch.

private void finishLaunch(ILaunch launch, ILaunchConfiguration config, IProgressMonitor monitor) {
    try {
        // Check for cancellation
        if (monitor.isCanceled() || launch == null) {
            return;
        }
        monitor.worked(1);
        // set the default source locator if required
        setDefaultSourceLocator(launch, config);
        /*
             * Fetch a parser
             */
        String parserClass = config.getAttribute(LaunchConfigurationConstants.PARSER_CLASS, LaunchConfigurationConstants.DEFAULT_PARSER_CLASS);
        IExtensionRegistry reg = Platform.getExtensionRegistry();
        IConfigurationElement[] extensions = reg.getConfigurationElementsFor(PluginConstants.PARSER_RESOURCE, PluginConstants.PARSER_NAME, parserClass);
        if (extensions == null || extensions.length < 1) {
            SystemTapUIErrorMessages mess = new // $NON-NLS-1$
            SystemTapUIErrorMessages(// $NON-NLS-1$
            Messages.getString("SystemTapLaunchConfigurationDelegate.InvalidParser1"), // $NON-NLS-1$
            Messages.getString("SystemTapLaunchConfigurationDelegate.InvalidParser1"), // $NON-NLS-1$
            Messages.getString("SystemTapLaunchConfigurationDelegate.InvalidParser2") + Messages.getString("SystemTapLaunchConfigurationDelegate.InvalidParser3") + // $NON-NLS-1$
            parserClass);
            mess.schedule();
            return;
        }
        IConfigurationElement element = extensions[0];
        SystemTapParser parser = (SystemTapParser) element.createExecutableExtension(PluginConstants.ATTR_CLASS);
        // Set parser options
        parser.setViewID(config.getAttribute(LaunchConfigurationConstants.VIEW_CLASS, LaunchConfigurationConstants.VIEW_CLASS));
        parser.setSourcePath(outputPath);
        parser.setMonitor(SubMonitor.convert(monitor));
        parser.setDone(false);
        parser.setSecondaryID(config.getAttribute(LaunchConfigurationConstants.SECONDARY_VIEW_ID, LaunchConfigurationConstants.DEFAULT_SECONDARY_VIEW_ID));
        parser.setKillButtonEnabled(true);
        monitor.worked(1);
        /*
             * Launch
             */
        File workDir = getWorkingDirectory(config);
        if (workDir == null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            workDir = new File(System.getProperty("user.home", "."));
        }
        // Put command into a shell script
        String cmd = generateCommand();
        // $NON-NLS-1$ //$NON-NLS-2$
        File script = File.createTempFile("org.eclipse.linuxtools.profiling.launch" + System.currentTimeMillis(), ".sh");
        // $NON-NLS-1$
        String data = "#!/bin/sh\nexec " + cmd;
        try (FileOutputStream out = new FileOutputStream(script)) {
            out.write(data.getBytes());
        }
        // $NON-NLS-1$
        String[] commandArray = new String[] { "sh", script.getAbsolutePath() };
        Process subProcess = CdtSpawnerProcessFactory.getFactory().exec(commandArray, getEnvironment(config), workDir, true);
        IProcess process = DebugPlugin.newProcess(launch, subProcess, renderProcessLabel(commandArray[0]));
        // set the command line used
        process.setAttribute(IProcess.ATTR_CMDLINE, cmd);
        monitor.worked(1);
        StreamListener s = new StreamListener();
        process.getStreamsProxy().getErrorStreamMonitor().addListener(s);
        while (!process.isTerminated()) {
            Thread.sleep(100);
            if ((monitor != null && monitor.isCanceled()) || parser.isDone()) {
                parser.cancelJob();
                process.terminate();
                return;
            }
        }
        Thread.sleep(100);
        s.close();
        parser.setKillButtonEnabled(false);
        if (process.getExitValue() != 0) {
            parser.cancelJob();
            // exit code for command not found
            if (process.getExitValue() == 127) {
                SystemTapUIErrorMessages errorDialog = new SystemTapUIErrorMessages(// $NON-NLS-1$
                Messages.getString("SystemTapLaunchConfigurationDelegate.CallGraphGenericError"), // $NON-NLS-1$
                Messages.getString("SystemTapLaunchConfigurationDelegate.CallGraphGenericError"), // $NON-NLS-1$
                Messages.getString("SystemTapLaunchConfigurationDelegate.stapNotFound"));
                errorDialog.schedule();
            } else {
                SystemTapErrorHandler errorHandler = new SystemTapErrorHandler();
                // Prepare stap information
                // $NON-NLS-1$
                errorHandler.appendToLog(config.getName() + Messages.getString("SystemTapLaunchConfigurationDelegate.stap_command") + cmd + PluginConstants.NEW_LINE + PluginConstants.NEW_LINE);
                // Handle error from TEMP_ERROR_OUTPUT
                errorHandler.handle(monitor, new FileReader(TEMP_ERROR_OUTPUT));
                if ((monitor != null && monitor.isCanceled())) {
                    return;
                }
                errorHandler.finishHandling();
                if (errorHandler.isErrorRecognized()) {
                    SystemTapUIErrorMessages errorDialog = new SystemTapUIErrorMessages(// $NON-NLS-1$
                    Messages.getString("SystemTapLaunchConfigurationDelegate.CallGraphGenericError"), // $NON-NLS-1$
                    Messages.getString("SystemTapLaunchConfigurationDelegate.CallGraphGenericError"), errorHandler.getErrorMessage());
                    errorDialog.schedule();
                }
            }
            return;
        }
        if (element.getAttribute(PluginConstants.ATTR_REALTIME).equals(PluginConstants.VAL_TRUE)) {
            parser.setRealTime(true);
        }
        parser.schedule();
        monitor.worked(1);
        String message = generateErrorMessage(config.getName(), binaryArguments);
        DocWriter dw = new // $NON-NLS-1$
        DocWriter(// $NON-NLS-1$
        Messages.getString("SystemTapLaunchConfigurationDelegate.DocWriterName"), (Helper.getConsoleByName(config.getName())), message);
        dw.schedule();
    } catch (IOException | InterruptedException | CoreException e) {
        e.printStackTrace();
    } finally {
        monitor.done();
    }
}
Also used : SystemTapUIErrorMessages(org.eclipse.linuxtools.internal.callgraph.core.SystemTapUIErrorMessages) IProcess(org.eclipse.debug.core.model.IProcess) IOException(java.io.IOException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) DocWriter(org.eclipse.linuxtools.internal.callgraph.core.DocWriter) SystemTapErrorHandler(org.eclipse.linuxtools.internal.callgraph.core.SystemTapErrorHandler) SystemTapParser(org.eclipse.linuxtools.internal.callgraph.core.SystemTapParser) CoreException(org.eclipse.core.runtime.CoreException) FileOutputStream(java.io.FileOutputStream) FileReader(java.io.FileReader) File(java.io.File) IProcess(org.eclipse.debug.core.model.IProcess) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) IStreamListener(org.eclipse.debug.core.IStreamListener)

Example 17 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project linuxtools by eclipse.

the class SystemTapOptionsTab method createParserOption.

private void createParserOption(Composite parserTop) {
    Composite browseTop = new Composite(parserTop, SWT.NONE);
    browseTop.setLayout(new GridLayout(1, false));
    GridData browseData = new GridData(GridData.FILL_HORIZONTAL);
    browseTop.setLayoutData(browseData);
    Label suppFileLabel = new Label(browseTop, SWT.NONE);
    // $NON-NLS-1$
    suppFileLabel.setText("Parser");
    parser = new Text(browseTop, SWT.BORDER);
    parser.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    parser.addModifyListener(modifyListener);
    Button parserButton = createPushButton(browseTop, "Find parsers", // $NON-NLS-1$
    null);
    parserButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new ListLabelProvider());
        // $NON-NLS-1$
        dialog.setTitle("Select parser");
        // $NON-NLS-1$
        dialog.setMessage("Select parser to use.");
        IExtensionRegistry reg = Platform.getExtensionRegistry();
        IConfigurationElement[] extensions = reg.getConfigurationElementsFor(PluginConstants.PARSER_RESOURCE, PluginConstants.PARSER_NAME);
        dialog.setElements(extensions);
        if (dialog.open() == IDialogConstants.OK_ID) {
            String arg = getUsefulLabel(dialog.getFirstResult());
            parser.setText(arg);
        }
    }));
    viewer = new Text(browseTop, SWT.BORDER);
    viewer.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    viewer.addModifyListener(modifyListener);
    Button viewerButton = createPushButton(browseTop, "Find viewers", // $NON-NLS-1$
    null);
    viewerButton.addSelectionListener(SelectionListener.widgetSelectedAdapter(e -> {
        ElementListSelectionDialog dialog = new ElementListSelectionDialog(getShell(), new ListLabelProvider());
        // $NON-NLS-1$
        dialog.setTitle("Select viewer");
        // $NON-NLS-1$
        dialog.setMessage("Select viewer to use.");
        IExtensionRegistry reg = Platform.getExtensionRegistry();
        IConfigurationElement[] extensions = reg.getConfigurationElementsFor(PluginConstants.VIEW_RESOURCE, PluginConstants.VIEW_NAME);
        ArrayList<IConfigurationElement> ext = new ArrayList<>();
        for (IConfigurationElement el : extensions) {
            if (// $NON-NLS-1$
            !el.getNamespaceIdentifier().contains("org.eclipse.linuxtools"))
                continue;
            // org.eclipse.linuxtools, then see if the class extends SystemTapView
            try {
                if (el.createExecutableExtension(PluginConstants.ATTR_CLASS) instanceof SystemTapView) {
                    ext.add(el);
                }
            } catch (CoreException e1) {
            }
        }
        dialog.setElements(ext.toArray());
        if (dialog.open() == IDialogConstants.OK_ID) {
            String arg = getUsefulLabel(dialog.getFirstResult());
            viewer.setText(arg);
        }
    }));
}
Also used : CLaunchConfigurationTab(org.eclipse.cdt.launch.ui.CLaunchConfigurationTab) LaunchConfigurationConstants(org.eclipse.linuxtools.internal.callgraph.core.LaunchConfigurationConstants) CoreException(org.eclipse.core.runtime.CoreException) IDialogConstants(org.eclipse.jface.dialogs.IDialogConstants) ILaunchConfiguration(org.eclipse.debug.core.ILaunchConfiguration) IPath(org.eclipse.core.runtime.IPath) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) Composite(org.eclipse.swt.widgets.Composite) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IExtension(org.eclipse.core.runtime.IExtension) SystemTapView(org.eclipse.linuxtools.internal.callgraph.core.SystemTapView) CDebugUtils(org.eclipse.cdt.debug.core.CDebugUtils) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) PlatformUI(org.eclipse.ui.PlatformUI) ICElement(org.eclipse.cdt.core.model.ICElement) IBinary(org.eclipse.cdt.core.model.IBinary) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Window(org.eclipse.jface.window.Window) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) PluginConstants(org.eclipse.linuxtools.internal.callgraph.core.PluginConstants) SelectionListener(org.eclipse.swt.events.SelectionListener) WorkbenchContentProvider(org.eclipse.ui.model.WorkbenchContentProvider) TabFolder(org.eclipse.swt.widgets.TabFolder) ResourcesPlugin(org.eclipse.core.resources.ResourcesPlugin) Image(org.eclipse.swt.graphics.Image) Spinner(org.eclipse.swt.widgets.Spinner) FocusListener(org.eclipse.swt.events.FocusListener) ArrayList(java.util.ArrayList) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) TwoPaneElementSelector(org.eclipse.ui.dialogs.TwoPaneElementSelector) IWorkspace(org.eclipse.core.resources.IWorkspace) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) GridData(org.eclipse.swt.layout.GridData) ICProject(org.eclipse.cdt.core.model.ICProject) WorkbenchLabelProvider(org.eclipse.ui.model.WorkbenchLabelProvider) TabItem(org.eclipse.swt.widgets.TabItem) Shell(org.eclipse.swt.widgets.Shell) FileDialog(org.eclipse.swt.widgets.FileDialog) ResourceComparator(org.eclipse.ui.views.navigator.ResourceComparator) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) File(java.io.File) CElementLabelProvider(org.eclipse.cdt.ui.CElementLabelProvider) ICDTLaunchConfigurationConstants(org.eclipse.cdt.debug.core.ICDTLaunchConfigurationConstants) ModifyListener(org.eclipse.swt.events.ModifyListener) IResource(org.eclipse.core.resources.IResource) Platform(org.eclipse.core.runtime.Platform) LabelProvider(org.eclipse.jface.viewers.LabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) SystemTapView(org.eclipse.linuxtools.internal.callgraph.core.SystemTapView) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) Text(org.eclipse.swt.widgets.Text) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) GridLayout(org.eclipse.swt.layout.GridLayout) CoreException(org.eclipse.core.runtime.CoreException) Button(org.eclipse.swt.widgets.Button) ElementListSelectionDialog(org.eclipse.ui.dialogs.ElementListSelectionDialog) GridData(org.eclipse.swt.layout.GridData) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 18 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project knime-core by knime.

the class PortTypeRegistry method availablePortTypes.

/**
 * Returns a collection with all known data types (that registered at the extension point
 * <tt>org.knime.core.DataType</tt>. The returned collection is not sorted in any particular order.
 *
 * @return a (possibly empty) collection with data types
 */
public synchronized Collection<PortType> availablePortTypes() {
    // perform lazy initialization
    if (!m_allPortTypesRead) {
        IExtensionRegistry registry = Platform.getExtensionRegistry();
        IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
        Stream.of(point.getExtensions()).flatMap(ext -> Stream.of(ext.getConfigurationElements())).filter(e -> getObjectClass(e.getAttribute("objectClass")).isPresent()).forEach(e -> createPortTypes(e));
        m_allPortTypesRead = true;
    }
    return m_allPortTypes.values();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SerializerMethodLoader(org.knime.core.internal.SerializerMethodLoader) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) PortObjectSpecSerializer(org.knime.core.node.port.PortObjectSpec.PortObjectSpecSerializer) BufferedDataTable(org.knime.core.node.BufferedDataTable) Stream(java.util.stream.Stream) PortObjectSerializer(org.knime.core.node.port.PortObject.PortObjectSerializer) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) NodeLogger(org.knime.core.node.NodeLogger) Map(java.util.Map) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) Optional(java.util.Optional) Platform(org.eclipse.core.runtime.Platform) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) GlobalClassCreator(org.knime.core.eclipseUtil.GlobalClassCreator) DataCell(org.knime.core.data.DataCell) DataType(org.knime.core.data.DataType) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 19 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project knime-core by knime.

the class DatabaseDriverLoader method loadDriversFromExtensionPoint.

/**
 * Loads all JDBC driver registered via the extension point.
 */
private static void loadDriversFromExtensionPoint() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    if (point == null) {
        throw new IllegalStateException("Invalid extension point id: " + EXT_POINT_ID);
    }
    for (IExtension ext : point.getExtensions()) {
        IConfigurationElement[] elements = ext.getConfigurationElements();
        for (IConfigurationElement e : elements) {
            String path = e.getAttribute("jarFile");
            String bundleId = e.getDeclaringExtension().getNamespaceIdentifier();
            Bundle bundle = Platform.getBundle(bundleId);
            URL jdbcUrl = FileLocator.find(bundle, new Path(path), null);
            if (jdbcUrl != null) {
                ClassLoader bundleClassLoader = bundle.adapt(BundleWiring.class).getClassLoader();
                try {
                    loadDriver(new File(FileLocator.toFileURL(jdbcUrl).getPath()), bundleClassLoader, false);
                } catch (IOException ex) {
                    LOGGER.error("Could not load JDBC driver '" + path + "': " + ex.getMessage(), ex);
                }
            } else {
                LOGGER.error("Could not find JDBC driver file '" + path + "' from plug-in '" + bundleId + "'");
            }
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) Bundle(org.osgi.framework.Bundle) BundleWiring(org.osgi.framework.wiring.BundleWiring) IOException(java.io.IOException) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) URL(java.net.URL) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) URLClassLoader(java.net.URLClassLoader) File(java.io.File) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Example 20 with IExtensionRegistry

use of org.eclipse.core.runtime.IExtensionRegistry in project knime-core by knime.

the class TableStoreFormatRegistry method createInstance.

private static TableStoreFormatRegistry createInstance() {
    IExtensionRegistry registry = Platform.getExtensionRegistry();
    IExtensionPoint point = registry.getExtensionPoint(EXT_POINT_ID);
    List<TableStoreFormat> formatList = Stream.of(point.getExtensions()).flatMap(ext -> Stream.of(ext.getConfigurationElements())).map(cfe -> readFormat(cfe)).filter(f -> f != null).sorted(Comparator.comparing(f -> f.getClass().getSimpleName(), (a, b) -> {
        // sort formats so that the "KNIME standard" format comes first.
        if (Objects.equals(a, b)) {
            return 0;
        } else if (DefaultTableStoreFormat.class.getName().equals(a)) {
            return -1;
        } else if (DefaultTableStoreFormat.class.getName().equals(b)) {
            return +1;
        } else {
            return a.compareTo(b);
        }
    })).collect(Collectors.toList());
    boolean hasFallback = formatList.stream().anyMatch(f -> f.getClass().equals(DefaultTableStoreFormat.class));
    CheckUtils.checkState(hasFallback, "No fallback table format registered, expected '%s' but not present in '%s'", DefaultTableStoreFormat.class.getName(), StringUtils.join(formatList.stream().map(f -> f.getClass().getName()).iterator(), ", "));
    return new TableStoreFormatRegistry(formatList);
}
Also used : KNIMEConstants(org.knime.core.node.KNIMEConstants) DataTableSpec(org.knime.core.data.DataTableSpec) CoreException(org.eclipse.core.runtime.CoreException) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) DefaultTableStoreFormat(org.knime.core.data.container.DefaultTableStoreFormat) Objects(java.util.Objects) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) List(java.util.List) Stream(java.util.stream.Stream) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry) NodeLogger(org.knime.core.node.NodeLogger) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) IEclipsePreferences(org.eclipse.core.runtime.preferences.IEclipsePreferences) Optional(java.util.Optional) Platform(org.eclipse.core.runtime.Platform) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) Comparator(java.util.Comparator) CheckUtils(org.knime.core.node.util.CheckUtils) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) DefaultTableStoreFormat(org.knime.core.data.container.DefaultTableStoreFormat) DefaultTableStoreFormat(org.knime.core.data.container.DefaultTableStoreFormat) IExtensionRegistry(org.eclipse.core.runtime.IExtensionRegistry)

Aggregations

IExtensionRegistry (org.eclipse.core.runtime.IExtensionRegistry)55 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)50 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)33 CoreException (org.eclipse.core.runtime.CoreException)25 IExtension (org.eclipse.core.runtime.IExtension)20 ArrayList (java.util.ArrayList)13 HashMap (java.util.HashMap)11 Platform (org.eclipse.core.runtime.Platform)9 Map (java.util.Map)8 Optional (java.util.Optional)8 Stream (java.util.stream.Stream)8 NodeLogger (org.knime.core.node.NodeLogger)8 Collection (java.util.Collection)7 List (java.util.List)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 DataTableSpec (org.knime.core.data.DataTableSpec)5 GlobalClassCreator (org.knime.core.eclipseUtil.GlobalClassCreator)5 SerializerMethodLoader (org.knime.core.internal.SerializerMethodLoader)5 File (java.io.File)4 Collections (java.util.Collections)4