类org.eclipse.core.runtime.RegistryFactory源码实例Demo

下面列出了怎么用org.eclipse.core.runtime.RegistryFactory的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: n4js   文件: TesterRegistry.java
/**
 * 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);
			}
		}
	}
}
 
源代码2 项目: n4js   文件: RunnerRegistry.java
/**
 * 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);
			}
		}
	}
}
 
源代码3 项目: google-cloud-eclipse   文件: BasePluginXmlTest.java
@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);
  }
}
 
源代码4 项目: dsl-devkit   文件: ExtensionRegistryMock.java
/**
 * 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);
    }
  }
}
 
源代码5 项目: dsl-devkit   文件: ExtensionRegistryMock.java
/**
 * 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);
  }
}
 
源代码6 项目: gwt-eclipse-plugin   文件: BundleUtilities.java
/**
 * 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;
}
 
源代码7 项目: textuml   文件: BasicResourceManager.java
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;
}
 
源代码8 项目: n4js   文件: FileExtensionsRegistry.java
/**
 * 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);
				}
			}
		}
	}
}
 
源代码9 项目: n4js   文件: JSONUiExtensionRegistry.java
/**
 * 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;
}
 
源代码10 项目: n4js   文件: SubGeneratorRegistry.java
/**
 * 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;
	}
}
 
源代码11 项目: n4js   文件: JSONExtensionRegistry.java
/**
 * 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;
}
 
源代码12 项目: google-cloud-eclipse   文件: UrlLinkTest.java
@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") + ").*");
}
 
源代码13 项目: textuml   文件: Repository.java
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;
        }
}
 
源代码14 项目: textuml   文件: CompilationDirector.java
/**
 * 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);
    }
}
 
源代码15 项目: eclipsegraphviz   文件: ContentProviderRegistry.java
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);
}
 
/**
 * 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);
	}
}
 
private static IExtensionRegistry getRegistry() {
  return RegistryFactory.getRegistry();
}
 
源代码18 项目: textuml   文件: Repository.java
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);
        }
    }
}
 
 类所在包
 类方法
 同包方法