use of ro.fortsoft.pf4j.PluginWrapper in project gitblit by gitblit.
the class PluginManager method removePlugin.
protected boolean removePlugin(String pluginId, boolean isUninstall) {
PluginWrapper pluginWrapper = getPlugin(pluginId);
final String name = pluginWrapper.getPluginPath().substring(1);
if (isUninstall) {
// allow the plugin to prepare for uninstallation
if (pluginWrapper.getPlugin() instanceof GitblitPlugin) {
((GitblitPlugin) pluginWrapper.getPlugin()).onUninstall();
}
}
if (pf4j.deletePlugin(pluginId)) {
// delete the checksums
File pFolder = runtimeManager.getFileOrFolder(Keys.plugins.folder, "${baseFolder}/plugins");
File[] checksums = pFolder.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
if (!file.isFile()) {
return false;
}
return file.getName().startsWith(name) && (file.getName().toLowerCase().endsWith(".sha1") || file.getName().toLowerCase().endsWith(".md5"));
}
});
if (checksums != null) {
for (File checksum : checksums) {
checksum.delete();
}
}
return true;
}
return false;
}
use of ro.fortsoft.pf4j.PluginWrapper in project gitblit by gitblit.
the class PluginManager method installPlugin.
/**
* Installs the plugin from the url.
*
* @param url
* @param verifyChecksum
* @return true if successful
*/
@Override
public synchronized boolean installPlugin(String url, boolean verifyChecksum) throws IOException {
File file = download(url, verifyChecksum);
if (file == null || !file.exists()) {
logger.error("Failed to download plugin {}", url);
return false;
}
String pluginId = pf4j.loadPlugin(file);
if (StringUtils.isEmpty(pluginId)) {
logger.error("Failed to load plugin {}", file);
return false;
}
// allow the plugin to prepare for operation after installation
PluginWrapper pluginWrapper = pf4j.getPlugin(pluginId);
if (pluginWrapper.getPlugin() instanceof GitblitPlugin) {
((GitblitPlugin) pluginWrapper.getPlugin()).onInstall();
}
PluginState state = pf4j.startPlugin(pluginId);
return PluginState.STARTED.equals(state);
}
use of ro.fortsoft.pf4j.PluginWrapper in project gitblit by gitblit.
the class PluginClassResolver method getResources.
@Override
public Iterator<URL> getResources(final String name) {
Set<URL> urls = new TreeSet<URL>(new UrlExternalFormComparator());
for (PluginWrapper plugin : pluginManager.getPlugins()) {
if (PluginState.STARTED != plugin.getPluginState()) {
// ignore this plugin
continue;
}
Iterator<URL> it = getResources(name, plugin);
while (it.hasNext()) {
URL url = it.next();
urls.add(url);
}
}
Iterator<URL> it = coreResolver.getResources(name);
while (it.hasNext()) {
URL url = it.next();
urls.add(url);
}
return urls.iterator();
}
use of ro.fortsoft.pf4j.PluginWrapper in project spring-boot-starter-samples by vindell.
the class Pf4jApplication method run.
@Override
public void run(ApplicationArguments args) throws Exception {
System.setProperty("pf4j.mode", RuntimeMode.DEPLOYMENT.toString());
// if(RuntimeMode.DEPLOYMENT.compareTo(RuntimeMode.DEPLOYMENT) == 0) {
// System.setProperty("pf4j.pluginsDir", System.getProperty("app.home","e:/root") + "/plugins");
// } else {
// System.setProperty("pf4j.pluginsDir", "plugins");
// }
// PluginManager pluginManager = new DefaultPluginManager(new File("E:/root/").toPath());
PluginManager pluginManager = new JarPluginManager();
// PluginManager pluginManager = new Pf4jJarPluginManager();
// PluginManager pluginManager = new Pf4jJarPluginWhitSpringManager();
// PluginManager pluginManager = new Pf4jPluginManager();
pluginManager.loadPlugins();
pluginManager.startPlugins();
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("=============");
}
Aggregations