Search in sources :

Example 1 with PluginWrapper

use of org.pf4j.PluginWrapper in project pf4j-spring by pf4j.

the class SpringExtensionFactory method create.

@Override
public Object create(Class<?> extensionClass) {
    Object extension = createWithoutSpring(extensionClass);
    if (autowire && extension != null) {
        // test for SpringBean
        PluginWrapper pluginWrapper = pluginManager.whichPlugin(extensionClass);
        if (pluginWrapper != null) {
            Plugin plugin = pluginWrapper.getPlugin();
            if (plugin instanceof SpringPlugin) {
                // autowire
                ApplicationContext pluginContext = ((SpringPlugin) plugin).getApplicationContext();
                pluginContext.getAutowireCapableBeanFactory().autowireBean(extension);
            }
        }
    }
    return extension;
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) PluginWrapper(org.pf4j.PluginWrapper) Plugin(org.pf4j.Plugin)

Example 2 with PluginWrapper

use of org.pf4j.PluginWrapper in project pf4j-update by pf4j.

the class UpdateManager method getUpdates.

/**
 * 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<>();
    Map<String, PluginInfo> pluginMap = getPluginsMap();
    for (PluginWrapper installed : pluginManager.getPlugins()) {
        PluginInfo pluginFromRepo = pluginMap.get(installed.getPluginId());
        if (pluginFromRepo != null) {
            String installedVersion = installed.getDescriptor().getVersion();
            if (pluginFromRepo.hasUpdate(systemVersion, installedVersion, versionManager)) {
                updates.add(pluginFromRepo);
            }
        }
    }
    return updates;
}
Also used : PluginWrapper(org.pf4j.PluginWrapper)

Example 3 with PluginWrapper

use of org.pf4j.PluginWrapper in project pf4j-wicket by pf4j.

the class PluginManagerInitializer method init.

@Override
public void init(Application application) {
    pluginManager = createPluginManager(application);
    if (pluginManager == null) {
        throw new WicketRuntimeException("Plugin manager cannot be null");
    }
    log.debug("Created plugin manager {}", pluginManager);
    // load plugins
    pluginManager.loadPlugins();
    // init plugins
    List<PluginWrapper> resolvedPlugins = pluginManager.getResolvedPlugins();
    for (PluginWrapper plugin : resolvedPlugins) {
        if (plugin.getPlugin() instanceof WicketPlugin) {
            ((WicketPlugin) plugin.getPlugin()).init(application);
        }
    }
    // start plugins
    pluginManager.startPlugins();
    // set class resolver
    CompoundClassResolver classResolver = new CompoundClassResolver();
    classResolver.add(new DefaultClassResolver());
    List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins();
    for (PluginWrapper plugin : startedPlugins) {
        classResolver.add(new PluginClassResolver(plugin));
    }
    application.getApplicationSettings().setClassResolver(classResolver);
    // store plugin manager in application
    application.setMetaData(PLUGIN_MANAGER_KEY, pluginManager);
    // add PluginComponentInjector
    application.getComponentInstantiationListeners().add(new PluginComponentInjector(application));
}
Also used : DefaultClassResolver(org.apache.wicket.application.DefaultClassResolver) CompoundClassResolver(org.apache.wicket.application.CompoundClassResolver) WicketRuntimeException(org.apache.wicket.WicketRuntimeException) PluginWrapper(org.pf4j.PluginWrapper)

Example 4 with PluginWrapper

use of org.pf4j.PluginWrapper in project pf4j-wicket by pf4j.

the class PluginManagerInitializer method destroy.

@Override
public void destroy(Application application) {
    List<PluginWrapper> startedPlugins = pluginManager.getStartedPlugins();
    Collections.reverse(startedPlugins);
    // stop plugins
    pluginManager.stopPlugins();
    // destroy started plugins in reverse order
    for (PluginWrapper plugin : startedPlugins) {
        if (plugin.getPlugin() instanceof WicketPlugin) {
            ((WicketPlugin) plugin.getPlugin()).destroy(application);
        }
    }
}
Also used : PluginWrapper(org.pf4j.PluginWrapper)

Example 5 with PluginWrapper

use of org.pf4j.PluginWrapper in project legendarybot by greatman.

the class ReloadPluginsCommand method execute.

@Override
public void execute(MessageReceivedEvent event, String[] args) {
    if (args.length == 1) {
        bot.getPluginManager().unloadPlugin(args[0]);
    } else {
        for (PluginWrapper wrapper : bot.getPluginManager().getPlugins()) {
            bot.getPluginManager().unloadPlugin(wrapper.getPluginId());
        }
    }
    bot.getPluginManager().loadPlugins();
    bot.getPluginManager().startPlugins();
    event.getChannel().sendMessage("Plugins reloaded!").queue();
}
Also used : PluginWrapper(org.pf4j.PluginWrapper)

Aggregations

PluginWrapper (org.pf4j.PluginWrapper)8 WicketRuntimeException (org.apache.wicket.WicketRuntimeException)1 CompoundClassResolver (org.apache.wicket.application.CompoundClassResolver)1 DefaultClassResolver (org.apache.wicket.application.DefaultClassResolver)1 DefaultPluginManager (org.pf4j.DefaultPluginManager)1 Plugin (org.pf4j.Plugin)1 PluginManager (org.pf4j.PluginManager)1 Pf4jJarPluginManager (org.pf4j.spring.boot.ext.Pf4jJarPluginManager)1 ApplicationContext (org.springframework.context.ApplicationContext)1 AuthcExtensionPoint (pf4j2.plugin.api.AuthcExtensionPoint)1 ExtensionMapping (pf4j2.plugin.api.annotation.ExtensionMapping)1