Java Code Examples for org.pf4j.PluginManager#getExtensions()

The following examples show how to use org.pf4j.PluginManager#getExtensions() . 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: KnownBuildRuleDescriptionsFactory.java    From buck with Apache License 2.0 6 votes vote down vote up
static ImmutableList<Description<?>> createBuildDescriptions(
    BuckConfig config,
    ProcessExecutor processExecutor,
    ToolchainProvider toolchainProvider,
    PluginManager pluginManager,
    SandboxExecutionStrategyFactory sandboxExecutionStrategyFactory) {

  ImmutableList.Builder<Description<?>> builder = ImmutableList.builder();

  SandboxExecutionStrategy sandboxExecutionStrategy =
      sandboxExecutionStrategyFactory.create(processExecutor, config);

  DescriptionCreationContext descriptionCreationContext =
      DescriptionCreationContext.of(
          config, toolchainProvider, sandboxExecutionStrategy, pluginManager);
  List<DescriptionProvider> descriptionProviders =
      pluginManager.getExtensions(DescriptionProvider.class);
  for (DescriptionProvider provider : descriptionProviders) {
    builder.addAll(provider.getDescriptions(descriptionCreationContext));
  }

  return builder.build();
}
 
Example 2
Source File: ModuleClassTest.java    From buck with Apache License 2.0 6 votes vote down vote up
private static void testBuckModuleHashProvider() throws Exception {
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();

  List<TestExtension> extensions = pluginManager.getExtensions(TestExtension.class);

  assertEquals(1, extensions.size());

  TestExtension testExtension = extensions.get(0);

  BuckModuleJarHashProvider hashProvider = new BuckModuleJarHashProvider();
  BuckModuleManager moduleManager = new DefaultBuckModuleManager(pluginManager, hashProvider);

  try {
    moduleManager.getModuleHash(testExtension.getClass());
  } catch (UncheckedExecutionException e) {
    assertEquals(
        "Could not load module binary hash for "
            + "module loaded in plugin "
            + getPluginWrapperForClass(pluginManager, testExtension.getClass()),
        e.getCause().getMessage());
  }
}
 
Example 3
Source File: XCodeDescriptionsFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
public static XCodeDescriptions create(PluginManager pluginManager) {
  List<XCodeDescriptionClassSupplier> xcodeDescriptionClassSuppliers =
      pluginManager.getExtensions(XCodeDescriptionClassSupplier.class);

  return new XCodeDescriptions(
      xcodeDescriptionClassSuppliers.stream()
          .flatMap(supplier -> supplier.getXCodeDescriptions().stream())
          .collect(ImmutableSet.toImmutableSet()));
}
 
Example 4
Source File: KnownBuildRuleDescriptionsFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
static ImmutableList<BuiltInProvider<?>> createBuiltInProviders(PluginManager pluginManager) {
  ImmutableList.Builder<BuiltInProvider<?>> builder = ImmutableList.builder();
  List<BuiltInProviderProvider> providerProviders =
      pluginManager.getExtensions(BuiltInProviderProvider.class);
  for (BuiltInProviderProvider provider : providerProviders) {
    builder.addAll(provider.getBuiltInProviders());
  }
  return builder.build();
}
 
Example 5
Source File: PluginBasedKnownConfigurationDescriptionsFactory.java    From buck with Apache License 2.0 5 votes vote down vote up
/** Create rule descriptors using provided plugin manager */
public static ImmutableList<ConfigurationRuleDescription<?, ?>> createFromPlugins(
    PluginManager pluginManager) {

  List<ConfigurationRuleDescriptionProvider> descriptionProviders =
      pluginManager.getExtensions(ConfigurationRuleDescriptionProvider.class);

  return descriptionProviders.stream()
      .map(ConfigurationRuleDescriptionProvider::getDescriptions)
      .flatMap(Collection::stream)
      .collect(ImmutableList.toImmutableList());
}
 
Example 6
Source File: Container.java    From pf4j-spring-tutorial with MIT License 4 votes vote down vote up
public static void main(String[] args){
    final PluginManager pm = new DefaultPluginManager();

    pm.loadPlugins();

    pm.startPlugins();

    final List<PluginInterface> plugins = pm.getExtensions(PluginInterface.class);

    log.info(MessageFormat.format(" {0} Plugin(s) found ", String.valueOf(plugins.size())));

    plugins.forEach(g ->
            log.info(MessageFormat.format(" {0}: {1}",
                    g.getClass().getCanonicalName(),
                    g.identify())));

    pm.stopPlugins();

}
 
Example 7
Source File: AuthcPluginTest.java    From spring-boot-starter-samples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
	
	System.setProperty("pf4j.mode", RuntimeMode.DEPLOYMENT.toString());
	System.setProperty("pf4j.pluginsDir", "plugins");
	
	if(RuntimeMode.DEPLOYMENT.compareTo(RuntimeMode.DEPLOYMENT) == 0) {
		//System.setProperty("pf4j.pluginsDir", System.getProperty("app.home","e:/root") + "/plugins");
	}
	
	/**
	 * 创建PluginManager对象,此处根据生产环境选择合适的实现,或者自定义实现
	 */
	PluginManager pluginManager = new DefaultPluginManager();
	// PluginManager pluginManager = new Pf4jPluginManager();
	// PluginManager pluginManager = new SpringPluginManager();
	// PluginManager pluginManager = new Pf4jJarPluginManager();
	// PluginManager pluginManager = new Pf4jJarPluginWhitSpringManager();

	/**
	 * 加载插件到JVM
	 */
    pluginManager.loadPlugins();

    /**
     * 调用Plugin实现类的start()方法: 
     */
    pluginManager.startPlugins();
    
    List<PluginWrapper> list = pluginManager.getPlugins();
    for (PluginWrapper pluginWrapper : list) {
		System.out.println(pluginWrapper.getPluginId());
	}
    
    
    List<AuthcExtensionPoint> extensions = pluginManager.getExtensions(AuthcExtensionPoint.class);
    
    for (AuthcExtensionPoint point : extensions) {
    	
    	ExtensionMapping m = point.getClass().getAnnotation(ExtensionMapping.class);
    	System.out.println(m.title());
    	
	}
    
    /**
     * 调用Plugin实现类的stop()方法
     */
    pluginManager.stopPlugins();
    
    System.out.println("=============");
	
}
 
Example 8
Source File: ModuleWithExternalDependenciesTest.java    From buck with Apache License 2.0 4 votes vote down vote up
private static List<TestExtension> loadTestExtensionsFromPlugin() {
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();
  return pluginManager.getExtensions(TestExtension.class);
}
 
Example 9
Source File: ModuleWithDependenciesTest.java    From buck with Apache License 2.0 4 votes vote down vote up
private static List<TestExtension> loadTestExtensionsFromPlugin() {
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();
  return pluginManager.getExtensions(TestExtension.class);
}
 
Example 10
Source File: ModuleClassTest.java    From buck with Apache License 2.0 4 votes vote down vote up
private static TestExtension loadTestExtensionFromPlugin() {
  PluginManager pluginManager = BuckPluginManagerFactory.createPluginManager();
  List<TestExtension> extensions = pluginManager.getExtensions(TestExtension.class);
  assertEquals(1, extensions.size());
  return extensions.get(0);
}