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