org.pf4j.PluginWrapper Java Examples
The following examples show how to use
org.pf4j.PluginWrapper.
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: PluginManagerImpl.java From webanno with Apache License 2.0 | 6 votes |
@Override public void afterPropertiesSet() throws Exception { loadPlugins(); startPlugins(); AbstractAutowireCapableBeanFactory beanFactory = (AbstractAutowireCapableBeanFactory) applicationContext.getAutowireCapableBeanFactory(); ExtensionsInjector extensionsInjector = new ExtensionsInjector(this, beanFactory); extensionsInjector.injectExtensions(); // Add child application contexts for every plugin for (PluginWrapper plugin : getStartedPlugins()) { Class pluginClass = plugin.getPlugin().getClass(); LOG.info("Found plugin: {}", plugin.getDescriptor().getPluginId()); // Attach the plugin application context to the main application context such that it // can access its beans for auto-wiring GenericApplicationContext pluginContext = (GenericApplicationContext) ((Plugin) plugin.getPlugin()).getApplicationContext(); pluginContext.setParent(applicationContext); } }
Example #2
Source File: PluginManagerController.java From sbp with Apache License 2.0 | 6 votes |
@PostMapping(value = "${spring.sbp.controller.base-path:/sbp}/restart-all") public int restartAll() { List<String> startedPluginIds = new ArrayList<>(); List<PluginWrapper> loadedPlugins = pluginManager.getPlugins(); loadedPlugins.forEach(plugin -> { if (plugin.getPluginState() == PluginState.STARTED) { startedPluginIds.add(plugin.getPluginId()); } pluginManager.unloadPlugin(plugin.getPluginId()); }); pluginManager.loadPlugins(); startedPluginIds.forEach(pluginId -> { // restart started plugin if (pluginManager.getPlugin(pluginId) != null) { pluginManager.startPlugin(pluginId); } }); return 0; }
Example #3
Source File: AopUtils.java From springboot-plugin-framework-parent with Apache License 2.0 | 6 votes |
/** * 解决AOP无法代理到插件类的问题 * @param pluginWrapper 插件包装类 */ public static synchronized void resolveAop(PluginWrapper pluginWrapper){ if(PROXY_WRAPPERS.isEmpty()){ LOG.warn("ProxyProcessorSupports is empty, And Plugin AOP can't used"); return; } if(!isRecover.get()){ throw new RuntimeException("Not invoking resolveAop(). And can not AopUtils.resolveAop"); } isRecover.set(false); ClassLoader pluginClassLoader = pluginWrapper.getPluginClassLoader(); for (ProxyWrapper proxyWrapper : PROXY_WRAPPERS) { ProxyProcessorSupport proxyProcessorSupport = proxyWrapper.getProxyProcessorSupport(); ClassLoader classLoader = getClassLoader(proxyProcessorSupport); proxyWrapper.setOriginalClassLoader(classLoader); proxyProcessorSupport.setProxyClassLoader(pluginClassLoader); } }
Example #4
Source File: PluginMybatisXmlProcessor.java From springboot-plugin-framework-parent with Apache License 2.0 | 6 votes |
@Override public void registry(PluginRegistryInfo pluginRegistryInfo) throws Exception { if(mybatisXmlProcess == null){ return; } BasePlugin basePlugin = pluginRegistryInfo.getBasePlugin(); PluginWrapper pluginWrapper = pluginRegistryInfo.getPluginWrapper(); ResourceWrapper resourceWrapper = basePlugin.getPluginResourceLoadFactory().getPluginResources(PluginMybatisXmlLoader.KEY); if(resourceWrapper == null){ return; } List<Resource> pluginResources = resourceWrapper.getResources(); if(pluginResources == null || pluginResources.isEmpty()){ return; } mybatisXmlProcess.loadXmlResource(pluginResources, pluginWrapper.getPluginClassLoader()); }
Example #5
Source File: PluginManagerController.java From sbp with Apache License 2.0 | 5 votes |
@PostMapping(value = "${spring.sbp.controller.base-path:/sbp}/restart/{pluginId}") public int restart(@PathVariable String pluginId) { PluginWrapper plugin = pluginManager.getPlugin(pluginId); if (plugin == null) return -1; pluginManager.unloadPlugin(pluginId); String newPluginId = pluginManager.loadPlugin(plugin.getPluginPath()); pluginManager.startPlugin(newPluginId); return 0; }
Example #6
Source File: UpdateManager.java From pf4j-update with Apache License 2.0 | 5 votes |
/** * Return a list of plugins that are newer versions of already installed plugins. * * @return list of plugins that have updates */ public List<PluginInfo> getUpdates() { List<PluginInfo> updates = new ArrayList<>(); for (PluginWrapper installed : pluginManager.getPlugins()) { String pluginId = installed.getPluginId(); if (hasPluginUpdate(pluginId)) { updates.add(getPluginsMap().get(pluginId)); } } return updates; }
Example #7
Source File: DefaultPluginFactory.java From springboot-plugin-framework-parent with Apache License 2.0 | 5 votes |
@Override public synchronized PluginFactory registry(PluginWrapper pluginWrapper) throws Exception { if(pluginWrapper == null){ throw new IllegalArgumentException("Parameter:pluginWrapper cannot be null"); } if(registerPluginInfoMap.containsKey(pluginWrapper.getPluginId())){ throw new IllegalAccessException("The plugin " + pluginWrapper.getPluginId() +"already exists, Can't register"); } if(!buildContainer.isEmpty() && buildType == 2){ throw new IllegalAccessException("Unable to Registry operate. Because there's no build"); } PluginRegistryInfo registerPluginInfo = new PluginRegistryInfo(pluginWrapper); AopUtils.resolveAop(pluginWrapper); try { pluginProcessor.registry(registerPluginInfo); registerPluginInfoMap.put(pluginWrapper.getPluginId(), registerPluginInfo); buildContainer.add(registerPluginInfo); return this; } catch (Exception e) { pluginListenerFactory.failure(pluginWrapper.getPluginId(), e); throw e; } finally { buildType = 1; AopUtils.recoverAop(); } }
Example #8
Source File: ModuleClassTest.java From buck with Apache License 2.0 | 5 votes |
private static PluginWrapper getPluginWrapperForClass(PluginManager pluginManager, Class<?> cls) throws Exception { Field pluginDescriptorField = PluginClassLoader.class.getDeclaredField("pluginDescriptor"); pluginDescriptorField.setAccessible(true); PluginDescriptor pluginDescriptor = (PluginDescriptor) pluginDescriptorField.get(cls.getClassLoader()); return pluginManager.getPlugin(pluginDescriptor.getPluginId()); }
Example #9
Source File: BuckExtensionFinder.java From buck with Apache License 2.0 | 5 votes |
@Override public <T> List<ExtensionWrapper<T>> find(Class<T> type) { Map<Class<?>, ExtensionWrapper<T>> extensions = new HashMap<>(); ServiceLoader<T> serviceLoader = ServiceLoader.load(type); serviceLoader.forEach(extension -> addExtension(extensions, extension)); for (PluginWrapper pluginWrapper : pluginManager.getPlugins()) { ServiceLoader<T> pluginServiceLoader = ServiceLoader.load(type, pluginWrapper.getPluginClassLoader()); pluginServiceLoader.forEach(extension -> addExtension(extensions, extension)); } return new ArrayList<>(extensions.values()); }
Example #10
Source File: BuckModuleJarHashProvider.java From buck with Apache License 2.0 | 5 votes |
/** @return the hash of a jar that contains a Buck module. */ public String getModuleHash(PluginWrapper modulePluginWrapper) { URL binaryHashLocation = modulePluginWrapper.getPluginClassLoader().getResource(MODULE_BINARY_HASH_LOCATION); if (binaryHashLocation == null) { throw new IllegalStateException(createFailureMessage(modulePluginWrapper)); } try { return Resources.toString(binaryHashLocation, Charset.defaultCharset()); } catch (IOException e) { throw new RuntimeException(createFailureMessage(modulePluginWrapper), e); } }
Example #11
Source File: DefaultBuckModuleManager.java From buck with Apache License 2.0 | 5 votes |
@Override public ImmutableSortedSet<String> getModuleIds() { ImmutableSortedSet.Builder<String> moduleIds = ImmutableSortedSet.naturalOrder(); for (PluginWrapper pluginWrapper : pluginManager.getPlugins()) { moduleIds.add(pluginWrapper.getPluginId()); } return moduleIds.build(); }
Example #12
Source File: DefaultBuckModuleManager.java From buck with Apache License 2.0 | 5 votes |
@Override public String load(String pluginId) { Hasher hasher = Hashing.murmur3_128().newHasher(); PluginWrapper pluginWrapper = pluginManager.getPlugin(pluginId); pluginWrapper .getDescriptor() .getDependencies() .forEach( pluginDependency -> hasher.putUnencodedChars( moduleHashCache.getUnchecked(pluginDependency.getPluginId()))); hasher.putUnencodedChars(getBuckModuleJarHash(pluginId)); return hasher.hash().toString(); }
Example #13
Source File: FetcherChromeActivator.java From sparkler with Apache License 2.0 | 4 votes |
public FetcherChromeActivator(PluginWrapper wrapper) { super(wrapper); }
Example #14
Source File: HelloPlugin.java From pf4j-spring with Apache License 2.0 | 4 votes |
public HelloPlugin(PluginWrapper wrapper) { super(wrapper); }
Example #15
Source File: FetcherJBrowserActivator.java From sparkler with Apache License 2.0 | 4 votes |
public FetcherJBrowserActivator(PluginWrapper wrapper) { super(wrapper); }
Example #16
Source File: HtmlUnitFetcherActivator.java From sparkler with Apache License 2.0 | 4 votes |
public HtmlUnitFetcherActivator(PluginWrapper wrapper) { super(wrapper); }
Example #17
Source File: NopPlugin.java From pf4j-update with Apache License 2.0 | 4 votes |
public NopPlugin(PluginWrapper wrapper) { super(wrapper); }
Example #18
Source File: UnsafeTestPlugin.java From kork with Apache License 2.0 | 4 votes |
public UnsafeTestPlugin(PluginWrapper wrapper) { super(wrapper); }
Example #19
Source File: BuckModuleJarHashProvider.java From buck with Apache License 2.0 | 4 votes |
private String createFailureMessage(PluginWrapper modulePluginWrapper) { return String.format( "Could not load module binary hash for module loaded in plugin %s", modulePluginWrapper); }
Example #20
Source File: Plugin.java From webanno with Apache License 2.0 | 4 votes |
public Plugin(PluginWrapper wrapper) { super(wrapper); }
Example #21
Source File: WelcomePlugin.java From pf4j-spring with Apache License 2.0 | 4 votes |
public WelcomePlugin(PluginWrapper wrapper) { super(wrapper); }
Example #22
Source File: HivePf4jPlugin.java From dremio-oss with Apache License 2.0 | 4 votes |
public HivePf4jPlugin(PluginWrapper wrapper) { super(wrapper); }
Example #23
Source File: EvilPluginFailingToStart.java From exonum-java-binding with Apache License 2.0 | 4 votes |
public EvilPluginFailingToStart(PluginWrapper wrapper) { super(wrapper); }
Example #24
Source File: ServiceArtifactBuilderSmokeIntegrationTest.java From exonum-java-binding with Apache License 2.0 | 4 votes |
@Test @DisplayName("Created plugin must be successfully loaded and unloaded by the PluginManager. " + "If this test does not work, subsequent use of ServiceArtifactBuilder in other ITs makes " + "no sense.") void createdArtifactCanBeLoaded(@TempDir Path tmp) throws IOException { Path pluginPath = tmp.resolve("test-plugin.jar"); String pluginId = "test-plugin"; String version = "1.0.1"; Class<?> pluginClass = TestPlugin.class; new ServiceArtifactBuilder() .setPluginId(pluginId) .setPluginVersion(version) .setManifestEntry("Plugin-Class", pluginClass.getName()) .addClass(pluginClass) .addExtensionClass(TestServiceExtensionImpl.class) .writeTo(pluginPath); PluginManager pluginManager = new DefaultPluginManager(); // Try to load the plugin String loadedPluginId = pluginManager.loadPlugin(pluginPath); assertThat(loadedPluginId).isEqualTo(pluginId); // Check it has correct version PluginWrapper plugin = pluginManager.getPlugin(pluginId); assertThat(plugin.getDescriptor().getVersion()).isEqualTo(version); assertNamesEqual(plugin.getPlugin().getClass(), pluginClass); // Try to start PluginState pluginState = pluginManager.startPlugin(pluginId); assertThat(pluginState).isEqualTo(PluginState.STARTED); // Check the extensions List<Class<? extends TestServiceExtension>> extensionClasses = pluginManager .getExtensionClasses(TestServiceExtension.class, pluginId); assertThat(extensionClasses).hasSize(1); Class<?> extensionType = extensionClasses.get(0); assertNamesEqual(extensionType, TestServiceExtensionImpl.class); // Try to stop and unload pluginState = pluginManager.stopPlugin(pluginId); assertThat(pluginState).isEqualTo(PluginState.STOPPED); boolean unloadResult = pluginManager.unloadPlugin(pluginId); assertTrue(unloadResult); }
Example #25
Source File: TestPlugin.java From exonum-java-binding with Apache License 2.0 | 4 votes |
public TestPlugin(PluginWrapper wrapper) { super(wrapper); }
Example #26
Source File: Pf4jApplication.java From spring-boot-starter-samples with Apache License 2.0 | 4 votes |
@Override public void run(ApplicationArguments args) throws Exception { List<PluginWrapper> list = pluginManager.getPlugins(); for (PluginWrapper pluginWrapper : list) { System.out.println(pluginWrapper.getPluginId()); List<?> extensions = pluginManager.getExtensions(pluginWrapper.getPluginId()); for (Object extension : extensions) { System.out.println(extension); } } pluginManager.stopPlugins(); System.out.println("============="); }
Example #27
Source File: AuthcPluginImpl1.java From spring-boot-starter-samples with Apache License 2.0 | 4 votes |
public AuthcPluginImpl1(PluginWrapper wrapper) { super(wrapper); }
Example #28
Source File: AuthcPluginImpl2.java From spring-boot-starter-samples with Apache License 2.0 | 4 votes |
public AuthcPluginImpl2(PluginWrapper wrapper) { super(wrapper); }
Example #29
Source File: SpringPlugin.java From pf4j-spring with Apache License 2.0 | 4 votes |
public SpringPlugin(PluginWrapper wrapper) { super(wrapper); }
Example #30
Source File: AuthcPluginTest.java From spring-boot-starter-samples with Apache License 2.0 | 4 votes |
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("============="); }