org.eclipse.core.runtime.RegistryFactory Java Examples
The following examples show how to use
org.eclipse.core.runtime.RegistryFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RunnerRegistry.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Reads information from extensions defined in plugin.xml files. */ private void initialize() { if (isInitialized) throw new IllegalStateException("may invoke method initialize() only once"); isInitialized = true; final IExtensionRegistry registry = RegistryFactory.getRegistry(); if (registry != null) { final IConfigurationElement[] configElems = registry .getConfigurationElementsFor(RUNNERS_EXTENSION_POINT_ID); for (IConfigurationElement elem : configElems) { try { final EclipseRunnerDescriptor descriptor = new EclipseRunnerDescriptor(elem); injector.injectMembers(descriptor); register(descriptor); } catch (Exception ex) { log.error("Error while reading extensions for extension point " + RUNNERS_EXTENSION_POINT_ID, ex); } } } }
Example #2
Source File: BasicResourceManager.java From textuml with Eclipse Public License 1.0 | 6 votes |
protected Collection<FeatureProvider> createFeatureProviders() throws ResourceException { IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint(BasicResource.PLUGIN_ID, "features"); Collection<FeatureProvider> providers = new HashSet<FeatureProvider>(); providers.add(resourceProvider); Set<Class<?>> knownFeatures = new HashSet<Class<?>>(); IConfigurationElement[] configurationElements = point.getConfigurationElements(); for (int i = 0; i < configurationElements.length; i++) { try { FeatureProvider currentFeatureProvider = (FeatureProvider) configurationElements[i] .createExecutableExtension("provider"); if (!currentFeatureProvider.isEnabled()) continue; Set<Class<?>> provided = new HashSet<Class<?>>(Arrays.asList(currentFeatureProvider .getProvidedFeatureTypes())); provided.retainAll(knownFeatures); if (!provided.isEmpty()) throw new ResourceException("Provider " + currentFeatureProvider.getClass().getSimpleName() + " provides redundant features: " + provided); knownFeatures.addAll(Arrays.asList(currentFeatureProvider.getProvidedFeatureTypes())); providers.add(currentFeatureProvider); } catch (CoreException e) { throw new ResourceException(e); } } return providers; }
Example #3
Source File: BundleUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 6 votes |
/** * Returns <code>true</code> if this bundle implements the extension point * with the given <code>extensionPointId</code>. * * @param bundle the bundle to test * @param extensionSimpleId the simple id of the extension point * @param extensionPointId extension id to search for * * @return <code>true</code> if this bundle implements the extension point * with the given <code>extensionPointId</code> */ public static boolean contributesToExtensionPoint(Bundle bundle, String extensionSimpleId, String extensionPointId) { IExtensionRegistry registry = RegistryFactory.getRegistry(); IContributor contributor = ContributorFactoryOSGi.createContributor(bundle); for (IExtension extension : registry.getExtensions(contributor.getName())) { if (extension.getExtensionPointUniqueIdentifier().equals(extensionPointId)) { if (extensionSimpleId != null && !extensionSimpleId.equals(extension.getSimpleIdentifier())) { continue; } return true; } } return false; }
Example #4
Source File: ExtensionRegistryMock.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Unmocks the extension registry. */ @SuppressWarnings("restriction") // for accessing RegistryProviderFactory public static void unMockRegistry() { configurationElements.clear(); configurationAnswers.clear(); registrySpy = null; org.eclipse.core.internal.registry.RegistryProviderFactory.releaseDefault(); // restricted try { RegistryFactory.setDefaultRegistryProvider(() -> { return registry; }); } catch (CoreException e) { // This shouldn't happen as the default was released. throw new WrappedException(e); } }
Example #5
Source File: ExtensionRegistryMock.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Mocks the extension registry. * * @throws CoreException */ @SuppressWarnings("restriction") // for accessing RegistryProviderFactory public static synchronized void mockRegistry() { if (registrySpy == null) { registry = RegistryFactory.getRegistry(); registrySpy = spy(registry); org.eclipse.core.internal.registry.RegistryProviderFactory.releaseDefault(); try { RegistryFactory.setDefaultRegistryProvider(() -> { return registrySpy; }); } catch (CoreException e) { // This shouldn't happen as the default was released. throw new WrappedException(e); } } }
Example #6
Source File: BasePluginXmlTest.java From google-cloud-eclipse with Apache License 2.0 | 6 votes |
@Test public final void testValidExtensionPoints() { NodeList extensions = getDocument().getElementsByTagName("extension"); Assert.assertTrue( "plugin.xml must contain at least one extension point", extensions.getLength() > 0); IExtensionRegistry registry = RegistryFactory.getRegistry(); Assert.assertNotNull("Make sure you're running this as a plugin test", registry); for (int i = 0; i < extensions.getLength(); i++) { Element extension = (Element) extensions.item(i); String point = extension.getAttribute("point"); Assert.assertNotNull("Could not load " + extension.getAttribute("id"), point); IExtensionPoint extensionPoint = registry.getExtensionPoint(point); Assert.assertNotNull("Could not load " + extension.getAttribute("id"), extensionPoint); } }
Example #7
Source File: TesterRegistry.java From n4js with Eclipse Public License 1.0 | 6 votes |
/** * Reads information from extensions defined in plugin.xml files. */ private void initialize() { if (isInitialized) throw new IllegalStateException("may invoke method initialize() only once"); isInitialized = true; final IExtensionRegistry registry = RegistryFactory.getRegistry(); if (registry != null) { final IConfigurationElement[] configElems = registry .getConfigurationElementsFor(TESTERS_EXTENSION_POINT_ID); for (IConfigurationElement elem : configElems) { try { final EclipseTesterDescriptor descriptor = new EclipseTesterDescriptor(elem); injector.injectMembers(descriptor); register(descriptor); } catch (Exception ex) { log.error("Error while reading extensions for extension point " + TESTERS_EXTENSION_POINT_ID, ex); } } } }
Example #8
Source File: JSONExtensionRegistry.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Creates a list of executable extensions of type {@code extensionClass} from all registered extension class for * the given extension point IDs. * * Returns an empty list if {@link IExtensionRegistry} is no available (platform not running). * * @param extensionPointId * The extension point ID. * @param extensionClass * The expected extension class. */ private <T> List<T> createExecutableExtensions(String extensionPointId, Class<T> extensionClass) { final IExtensionRegistry registry = RegistryFactory.getRegistry(); if (registry == null) { return Collections.emptyList(); } final IExtension[] extensions = registry.getExtensionPoint(extensionPointId) .getExtensions(); final List<T> executableExtensions = new ArrayList<>(); for (IExtension extension : extensions) { final IConfigurationElement[] configElems = extension.getConfigurationElements(); for (IConfigurationElement elem : configElems) { try { final Object executableExtension = elem .createExecutableExtension(JSON_EXTENSIONS_POINT_CLASS_PROPERTY); executableExtensions.add(extensionClass.cast(executableExtension)); } catch (Exception ex) { LOGGER.error("Error while reading extensions for extension point " + JSON_VALIDATORS_EXTENSIONS_POINT_ID, ex); } } } return executableExtensions; }
Example #9
Source File: UrlLinkTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
@Before public void setUp() { IExtensionRegistry registry = RegistryFactory.getRegistry(); IExtension extension = registry.getExtension("org.eclipse.ui.console.consolePatternMatchListeners", "com.google.cloud.tools.eclipse.appengine.localserver.urlLinker"); assertNotNull("URL linking extension not found", extension); assertEquals("Should only have a single URL linker", 1, extension.getConfigurationElements().length); IConfigurationElement definition = extension.getConfigurationElements()[0]; assertEquals("consolePatternMatchListener", definition.getName()); assertNotNull(definition.getAttribute("regex")); regexp = Pattern.compile(".*(" + definition.getAttribute("regex") + ").*"); }
Example #10
Source File: SubGeneratorRegistry.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Read information from extensions defined in plugin.xml files */ private synchronized void initialize() { if (isInitialized) { return; } try { final IExtensionRegistry registry = RegistryFactory.getRegistry(); if (registry != null) { final IExtension[] extensions = registry.getExtensionPoint(SUBGENERATORS_EXTENSIONS_POINT_ID) .getExtensions(); for (IExtension extension : extensions) { final IConfigurationElement[] configElems = extension.getConfigurationElements(); for (IConfigurationElement elem : configElems) { try { String fileExtensions = elem.getAttribute(ATT_FILE_EXTENSIONS); List<String> fileExtensionList = Splitter.on(',').trimResults().omitEmptyStrings() .splitToList(fileExtensions); ISubGenerator generator = (ISubGenerator) elem .createExecutableExtension(ATT_SUB_GENERATOR_CLASS); for (String fileExtension : fileExtensionList) { register(generator, fileExtension); } } catch (Exception ex) { LOGGER.error( "Error while reading extensions for extension point " + SUBGENERATORS_EXTENSIONS_POINT_ID, ex); } } } } } finally { isInitialized = true; } }
Example #11
Source File: JSONUiExtensionRegistry.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Creates a list of executable extensions of type {@code extensionClass} from * all registered extension class for the given extension point IDs. * * Returns an empty list if {@link IExtensionRegistry} is no available (platform * not running). * * @param extensionPointId * The extension point ID. * @param extensionClass * The expected extension class. */ private <T> List<T> createExecutableExtensions(String extensionPointId, Class<T> extensionClass) { final IExtensionRegistry registry = RegistryFactory.getRegistry(); if (registry == null) { return Collections.emptyList(); } final IExtension[] extensions = registry.getExtensionPoint(extensionPointId).getExtensions(); final List<T> executableExtensions = new ArrayList<>(); for (IExtension extension : extensions) { final IConfigurationElement[] configElems = extension.getConfigurationElements(); for (IConfigurationElement elem : configElems) { try { final Object executableExtension = elem .createExecutableExtension(JSON_EXTENSIONS_POINT_CLASS_PROPERTY); executableExtensions.add(extensionClass.cast(executableExtension)); } catch (Exception ex) { LOGGER.error("Error while reading extensions for extension point " + JSON_QUICKFIXPROVIDER_EXTENSIONS_POINT_ID, ex); } } } return executableExtensions; }
Example #12
Source File: FileExtensionsRegistry.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Read information from extensions defined in plugin.xml files */ protected synchronized void initialize() { if (isInitialized) { throw new IllegalStateException("may invoke method initialize() only once"); } isInitialized = true; final IExtensionRegistry registry = RegistryFactory.getRegistry(); if (registry != null) { final IExtension[] extensions = registry.getExtensionPoint(FILE_EXTENSIONS_POINT_ID).getExtensions(); for (IExtension extension : extensions) { final IConfigurationElement[] configElems = extension.getConfigurationElements(); for (IConfigurationElement elem : configElems) { try { List<String> fileExtensions = Splitter.on(',').trimResults().omitEmptyStrings() .splitToList(elem.getAttribute(ATT_FILE_EXTENSION)); String elementName = elem.getName(); if (ATT_TRANSPILABLE_FILE_EXTENSIONS.equals(elementName)) { transpilableFileExtensions.addAll(fileExtensions); } else if (ATT_TEST_FILE_EXTENSIONS.equals(elementName)) { testFileExtensions.addAll(fileExtensions); } else if (ATT_RUNNABLE_FILE_EXTENSIONS.equals(elementName)) { runnableFileExtensions.addAll(fileExtensions); } else if (ATT_TYPABLE_FILE_EXTENSIONS.equals(elementName)) { typableFileExtensions.addAll(fileExtensions); } else if (ATT_RAW_FILE_EXTENSIONS.equals(elementName)) { rawFileExtensions.addAll(fileExtensions); } else { LOGGER.error(new UnsupportedOperationException( "This file extension type " + elementName + " is not supported yet")); } } catch (Exception ex) { LOGGER.error("Error while reading extensions for extension point " + FILE_EXTENSIONS_POINT_ID, ex); } } } } }
Example #13
Source File: Repository.java From textuml with Eclipse Public License 1.0 | 5 votes |
private void initWeaver() { String weaverName = getProperties().getProperty(WEAVER); IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint(MDDCore.PLUGIN_ID, "modelWeaver"); IConfigurationElement[] elements = point.getConfigurationElements(); for (IConfigurationElement current : elements) if (weaverName.equals(current.getAttribute("name"))) { try { weaver = (IModelWeaver) current.createExecutableExtension("class"); } catch (CoreException e) { LogUtils.logError(MDDCore.PLUGIN_ID, "Could not instantiate weaver: " + weaverName, e); } return; } }
Example #14
Source File: CompilationDirector.java From textuml with Eclipse Public License 1.0 | 5 votes |
/** * Populates the language catalog from the extension registry. */ private void initLanguages() { IExtensionPoint point = RegistryFactory.getRegistry().getExtensionPoint(FrontEnd.PLUGIN_ID, "frontEndLanguage"); IConfigurationElement[] elements = point.getConfigurationElements(); languages = new HashMap<String, FrontEndLanguage>(); for (int i = 0; i < elements.length; i++) { FrontEndLanguage current = FrontEndLanguage.build(elements[i]); languages.put(current.fileExtension, current); } }
Example #15
Source File: ContentProviderRegistry.java From eclipsegraphviz with Eclipse Public License 1.0 | 5 votes |
private void build() { IExtensionRegistry registry = RegistryFactory.getRegistry(); new RegistryReader() { @Override protected String getNamespace() { return ContentSupport.PLUGIN_ID; } @Override protected boolean readElement(IConfigurationElement element) { addProvider(element); return true; } }.readRegistry(registry, CONTENT_PROVIDER_XP); }
Example #16
Source File: ReferenceDataImporterExtensionPoint.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
/** * loads all ExtensionPoints of type {@code ExtensionPointConstantsData.REFERENCE_DATA_IMPORTER} * and adds them to a list of available importers */ private static void initialize(){ try { importers = new HashMap<String, AbstractReferenceDataImporter>(); // load reference-data-extensionpoint IExtensionPoint refDataExtensionPoint = RegistryFactory.getRegistry().getExtensionPoint( ExtensionPointConstantsData.REFERENCE_DATA_IMPORTER); IConfigurationElement[] extensionPoints = refDataExtensionPoint.getConfigurationElements(); // add all found extensionPoints to the importer list for (IConfigurationElement ePoint : extensionPoints) { Object o = ePoint.createExecutableExtension(CLASS_PROPERTY); String refDataId = ePoint.getAttribute(ATTRIBUTE_REFDATA_ID); if (o instanceof AbstractReferenceDataImporter) { AbstractReferenceDataImporter importer = (AbstractReferenceDataImporter) o; importers.put(refDataId, importer); log.debug("Added ReferenceDataImporter for... " + refDataId); } } } catch (CoreException e) { log.error("Exception occured trying to load ReferenceDataImporter ExtensionPoints", e); } }
Example #17
Source File: AreaBasedPreferencePage.java From google-cloud-eclipse with Apache License 2.0 | 4 votes |
private static IExtensionRegistry getRegistry() { return RegistryFactory.getRegistry(); }
Example #18
Source File: Repository.java From textuml with Eclipse Public License 1.0 | 4 votes |
private void loadSystemPackages() { systemResources.clear(); IExtensionPoint xp = RegistryFactory.getRegistry().getExtensionPoint(MDDCore.PLUGIN_ID, "systemPackage"); IConfigurationElement[] configElems = xp.getConfigurationElements(); for (int i = 0; i < configElems.length; i++) { boolean autoLoad = !Boolean.FALSE.toString().equals(configElems[i].getAttribute("autoLoad")); if (!autoLoad) continue; String uriValue = configElems[i].getAttribute("uri"); URI uri = URI.createURI(uriValue); String requirements = configElems[i].getAttribute("requires"); if (requirements != null) { String[] propertyEntries = requirements.split(","); if (propertyEntries.length > 0) { boolean satisfied = true; for (String current : propertyEntries) { String[] components = StringUtils.split(current, '='); String propertyName = components[0]; String expectedValue = components.length > 1 ? components[1] : Boolean.TRUE.toString(); String actualValue = properties.getProperty(propertyName, System.getProperty(current)); if (!expectedValue.equals(actualValue)) { satisfied = false; break; } } if (!satisfied) { LogUtils.debug(MDDCore.PLUGIN_ID, () -> "System package skipped: " + uri); continue; } } } try { boolean lazyLoad = !Boolean.FALSE.toString().equals(configElems[i].getAttribute("lazyLoad")); Package systemPackage = getPackage(uri, lazyLoad); if (systemPackage != null) { addSystemPackage(systemPackage); LogUtils.debug(MDDCore.PLUGIN_ID, "Loading system package: " + uri); } else { LogUtils.logError(MDDCore.PLUGIN_ID, "System package not found: " + uri, null); } } catch (WrappedException e) { if (!(e instanceof Diagnostic)) throw e; LogUtils.logError(MDDCore.PLUGIN_ID, "Unexpected exception loading system package: " + uri, e); } } }