use of org.pf4j.PluginManager in project spring-boot-starter-samples by vindell.
the class AuthcPluginTest method main.
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("=============");
}
use of org.pf4j.PluginManager in project pf4j-update by pf4j.
the class UpdateTest method update.
private static void update() throws Exception {
// start the web server that serves the repository's artifacts
try {
new WebServer().start();
} catch (Exception e) {
e.printStackTrace();
return;
}
// create plugin manager
PluginManager pluginManager = new DefaultPluginManager();
VersionManager versionManager = pluginManager.getVersionManager();
String systemVersion = pluginManager.getSystemVersion();
pluginManager.loadPlugins();
// create update manager
UpdateManager updateManager = new UpdateManager(pluginManager);
// >> keep system up-to-date <<
boolean systemUpToDate = true;
// check for updates
if (updateManager.hasUpdates()) {
List<PluginInfo> updates = updateManager.getUpdates();
log.debug("Found {} updates", updates.size());
for (PluginInfo plugin : updates) {
log.debug("Found update for plugin '{}'", plugin.id);
PluginInfo.PluginRelease lastRelease = plugin.getLastRelease(systemVersion, versionManager);
String lastVersion = lastRelease.version;
String installedVersion = pluginManager.getPlugin(plugin.id).getDescriptor().getVersion();
log.debug("Update plugin '{}' from version {} to version {}", plugin.id, installedVersion, lastVersion);
boolean updated = updateManager.updatePlugin(plugin.id, lastVersion);
if (updated) {
log.debug("Updated plugin '{}'", plugin.id);
} else {
log.error("Cannot update plugin '{}'", plugin.id);
systemUpToDate = false;
}
}
} else {
log.debug("No updates found");
}
// check for available (new) plugins
if (updateManager.hasAvailablePlugins()) {
List<PluginInfo> availablePlugins = updateManager.getAvailablePlugins();
log.debug("Found {} available plugins", availablePlugins.size());
for (PluginInfo plugin : availablePlugins) {
log.debug("Found available plugin '{}'", plugin.id);
PluginInfo.PluginRelease lastRelease = plugin.getLastRelease(systemVersion, versionManager);
String lastVersion = lastRelease.version;
log.debug("Install plugin '{}' with version {}", plugin.id, lastVersion);
boolean installed = updateManager.installPlugin(plugin.id, lastVersion);
if (installed) {
log.debug("Installed plugin '{}'", plugin.id);
} else {
log.error("Cannot install plugin '{}'", plugin.id);
systemUpToDate = false;
}
}
} else {
log.debug("No available plugins found");
}
if (systemUpToDate) {
log.debug("System up-to-date");
}
}
use of org.pf4j.PluginManager in project pf4j-wicket by pf4j.
the class PluginManagerInitializer method createPluginManager.
private PluginManager createPluginManager(Application application) {
File pluginsDir = getPluginsDir(application);
log.debug("Plugins directory is {} ", pluginsDir);
// TODO check more locations for PluginManagerFactory similar with getPluginsDir();
// now I checked only Application if it implements PluginManagerFactory ?!
PluginManager pluginManager;
if (application instanceof PluginManagerFactory) {
log.debug("Create custom plugin manager");
pluginManager = ((PluginManagerFactory) application).createPluginManager(pluginsDir.toPath());
} else {
log.debug("Create default plugin manager");
pluginManager = pluginsDir != null ? new DefaultPluginManager(pluginsDir.toPath()) : new DefaultPluginManager();
}
return pluginManager;
}
use of org.pf4j.PluginManager in project pf4j-spring by pf4j.
the class Boot method main.
public static void main(String[] args) {
// print logo
printLogo();
// retrieves the spring application context
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfiguration.class);
// retrieves automatically the extensions for the Greeting.class extension point
Greetings greetings = applicationContext.getBean(Greetings.class);
greetings.printGreetings();
// stop plugins
PluginManager pluginManager = applicationContext.getBean(PluginManager.class);
/*
// retrieves manually the extensions for the Greeting.class extension point
List<Greeting> greetings = pluginManager.getExtensions(Greeting.class);
System.out.println("greetings.size() = " + greetings.size());
*/
pluginManager.stopPlugins();
}
Aggregations