Java Code Examples for org.eclipse.core.runtime.RegistryFactory#getRegistry()

The following examples show how to use org.eclipse.core.runtime.RegistryFactory#getRegistry() . 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: TesterRegistry.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 2
Source File: RunnerRegistry.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 3
Source File: BasePluginXmlTest.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: ExtensionRegistryMock.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 5
Source File: BundleUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 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 6
Source File: FileExtensionsRegistry.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 7
Source File: JSONUiExtensionRegistry.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 8
Source File: SubGeneratorRegistry.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 9
Source File: JSONExtensionRegistry.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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 10
Source File: UrlLinkTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: ContentProviderRegistry.java    From eclipsegraphviz with Eclipse Public License 1.0 5 votes vote down vote up
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 12
Source File: AreaBasedPreferencePage.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
private static IExtensionRegistry getRegistry() {
  return RegistryFactory.getRegistry();
}