Here are the examples of the java api org.pf4j.PluginWrapper taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
52 Examples
19
Source : Pf4jPluginManager.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
@Override
public PluginState startUpPlugin(String pluginId) {
PluginWrapper pluginWrapper = ofNullable(pluginManager.getPlugin(pluginId)).orElseThrow(() -> new ReportPortalException(ErrorType.UNABLE_INTERACT_WITH_INTEGRATION, "Plugin not found: " + pluginId));
return pluginManager.startPlugin(pluginWrapper.getPluginId());
}
19
Source : Pf4jPluginManager.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
private void deletePreviousPlugin(PluginWrapper previousPlugin) {
try {
Files.deleteIfExists(previousPlugin.getPluginPath());
} catch (IOException e) {
LOGGER.error("Unable to delete the old plugin file with id = '{}'", previousPlugin.getPluginId());
}
}
19
Source : Pf4jPluginManager.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
/**
* Validates plugin's extension clreplaced/clreplacedes and reloads the previous plugin if it is present and the validation failed
*
* @param newPluginId Id of the new plugin
* @param newPluginFileName New plugin file name
* @see PluginLoader#validatePluginExtensionClreplacedes(PluginWrapper))
*/
private void validateNewPluginExtensionClreplacedes(String newPluginId, String newPluginFileName) {
PluginWrapper newPlugin = getPluginById(newPluginId).orElseThrow(() -> new ReportPortalException(ErrorType.PLUGIN_UPLOAD_ERROR, Suppliers.formattedSupplier("Plugin with id = '{}' has not been found.", newPluginId).get()));
if (!pluginLoader.validatePluginExtensionClreplacedes(newPlugin)) {
pluginManager.unloadPlugin(newPluginId);
deleteTempPlugin(newPluginFileName);
throw new ReportPortalException(ErrorType.PLUGIN_UPLOAD_ERROR, Suppliers.formattedSupplier("New plugin with id = '{}' doesn't have mandatory extension clreplacedes.", newPluginId).get());
}
}
19
Source : Pf4jPluginManager.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
private void unloadPreviousPlugin(PluginWrapper pluginWrapper) {
destroyDependency(pluginWrapper.getPluginId());
if (!pluginManager.unloadPlugin(pluginWrapper.getPluginId())) {
throw new ReportPortalException(ErrorType.PLUGIN_REMOVE_ERROR, Suppliers.formattedSupplier("Failed to stop old plugin with id = '{}'", pluginWrapper.getPluginId()).get());
}
}
19
Source : CleanOutdatedPluginsJob.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
private boolean isPluginStillBeingUploaded(@NotNull PluginWrapper pluginWrapper) {
return pluginBox.isInUploadingState(pluginWrapper.getPluginPath().getFileName().toString());
}
19
Source : PluginLoaderImpl.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
@Override
public boolean validatePluginExtensionClreplacedes(PluginWrapper plugin) {
return plugin.getPluginManager().getExtensionClreplacedes(plugin.getPluginId()).stream().map(ExtensionPoint::findByExtension).anyMatch(Optional::isPresent);
}
19
Source : OPRSExternalPluginManager.java
with BSD 2-Clause "Simplified" License
from open-osrs
with BSD 2-Clause "Simplified" License
from open-osrs
public Set<String> getDependencies() {
Set<String> deps = new HashSet<>();
List<PluginWrapper> startedPlugins = getStartedPlugins();
for (PluginWrapper pluginWrapper : startedPlugins) {
for (PluginDependency pluginDependency : pluginWrapper.getDescriptor().getDependencies()) {
deps.add(pluginDependency.getPluginId());
}
}
return deps;
}
19
Source : OPRSExternalPluginManager.java
with BSD 2-Clause "Simplified" License
from open-osrs
with BSD 2-Clause "Simplified" License
from open-osrs
private Path stopPlugin(String pluginId) {
List<PluginWrapper> startedPlugins = List.copyOf(getStartedPlugins());
for (PluginWrapper pluginWrapper : startedPlugins) {
if (!pluginId.equals(pluginWrapper.getDescriptor().getPluginId())) {
continue;
}
List<Plugin> extensions = externalPluginManager.getExtensions(Plugin.clreplaced, pluginId);
for (net.runelite.client.plugins.Plugin plugin : runelitePluginManager.getPlugins()) {
if (!extensions.get(0).getClreplaced().getName().equals(plugin.getClreplaced().getName())) {
continue;
}
try {
SwingUtil.syncExec(() -> {
try {
runelitePluginManager.stopPlugin(plugin);
} catch (Exception e2) {
throw new RuntimeException(e2);
}
});
runelitePluginManager.remove(plugin);
pluginClreplacedLoaders.remove(plugin.getClreplaced().getClreplacedLoader());
eventBus.post(new OPRSPluginChanged(pluginId, plugin, false));
return pluginWrapper.getPluginPath();
} catch (Exception ex) {
log.warn("unable to stop plugin", ex);
return null;
}
}
}
return null;
}
19
Source : OPRSExternalPluginManager.java
with BSD 2-Clause "Simplified" License
from open-osrs
with BSD 2-Clause "Simplified" License
from open-osrs
public void loadPlugins() {
externalPluginManager.startPlugins();
List<PluginWrapper> startedPlugins = getStartedPlugins();
List<Plugin> scannedPlugins = new ArrayList<>();
for (PluginWrapper plugin : startedPlugins) {
checkDepsAndStart(startedPlugins, scannedPlugins, plugin);
}
scanAndInstantiate(scannedPlugins, false, false);
if (groups.getInstanceCount() > 1) {
for (String pluginId : getDisabledPluginIds()) {
groups.sendString("STOPEXTERNAL;" + pluginId);
}
} else {
for (String pluginId : getDisabledPluginIds()) {
externalPluginManager.enablePlugin(pluginId);
externalPluginManager.deletePlugin(pluginId);
}
}
}
19
Source : OPRSExternalPluginManager.java
with BSD 2-Clause "Simplified" License
from open-osrs
with BSD 2-Clause "Simplified" License
from open-osrs
public void receive(Message message) {
if (message.getObject() instanceof ConfigChanged) {
return;
}
String[] messageObject = ((String) message.getObject()).split(";");
if (messageObject.length < 2) {
return;
}
String command = messageObject[0];
String pluginId = messageObject[1];
switch(command) {
case "STARTEXTERNAL":
externalPluginManager.loadPlugins();
externalPluginManager.startPlugin(pluginId);
List<PluginWrapper> startedPlugins = List.copyOf(getStartedPlugins());
List<Plugin> scannedPlugins = new ArrayList<>();
for (PluginWrapper pluginWrapper : startedPlugins) {
if (!pluginId.equals(pluginWrapper.getDescriptor().getPluginId())) {
continue;
}
checkDepsAndStart(startedPlugins, scannedPlugins, pluginWrapper);
}
scanAndInstantiate(scannedPlugins, true, false);
break;
case "STOPEXTERNAL":
uninstall(pluginId, true);
externalPluginManager.unloadPlugin(pluginId);
groups.send(message.getSrc(), "STOPPEDEXTERNAL;" + pluginId);
break;
case "STOPPEDEXTERNAL":
groups.getMessageMap().get(pluginId).remove(message.getSrc());
if (groups.getMessageMap().get(pluginId).size() == 0) {
groups.getMessageMap().remove(pluginId);
externalPluginManager.deletePlugin(pluginId);
}
break;
}
}
19
Source : OPRSExternalPluginManager.java
with BSD 2-Clause "Simplified" License
from open-osrs
with BSD 2-Clause "Simplified" License
from open-osrs
private void checkDepsAndStart(List<PluginWrapper> startedPlugins, List<Plugin> scannedPlugins, PluginWrapper pluginWrapper) {
boolean depsLoaded = true;
for (PluginDependency dependency : pluginWrapper.getDescriptor().getDependencies()) {
if (startedPlugins.stream().noneMatch(pl -> pl.getPluginId().equals(dependency.getPluginId()))) {
depsLoaded = false;
}
}
if (!depsLoaded) {
// This should never happen but can crash the client
return;
}
scannedPlugins.addAll(loadPlugin(pluginWrapper.getPluginId()));
}
19
Source : OPRSExternalPluginManager.java
with BSD 2-Clause "Simplified" License
from open-osrs
with BSD 2-Clause "Simplified" License
from open-osrs
public Boolean reloadStart(String pluginId) {
externalPluginManager.loadPlugins();
externalPluginManager.startPlugin(pluginId);
List<PluginWrapper> startedPlugins = List.copyOf(getStartedPlugins());
List<PluginWrapper> disabledPlugins = List.copyOf(getDisabledPlugins());
List<PluginWrapper> combinedList = Stream.of(startedPlugins, disabledPlugins).flatMap(Collection::stream).collect(Collectors.toList());
List<Plugin> scannedPlugins = new ArrayList<>();
for (PluginWrapper pluginWrapper : combinedList) {
if (!pluginId.equals(pluginWrapper.getDescriptor().getPluginId())) {
continue;
}
checkDepsAndStart(combinedList, scannedPlugins, pluginWrapper);
}
scanAndInstantiate(scannedPlugins, true, false);
groups.broadcastSring("STARTEXTERNAL;" + pluginId);
return true;
}
19
Source : OPRSExternalPf4jPluginManager.java
with BSD 2-Clause "Simplified" License
from open-osrs
with BSD 2-Clause "Simplified" License
from open-osrs
@Override
public boolean deletePlugin(String pluginId) {
if (!plugins.containsKey(pluginId)) {
throw new IllegalArgumentException(String.format("Unknown pluginId %s", pluginId));
}
PluginWrapper pluginWrapper = getPlugin(pluginId);
// stop the plugin if it's started
PluginState pluginState = stopPlugin(pluginId);
if (PluginState.STARTED == pluginState) {
log.error("Failed to stop plugin '{}' on delete", pluginId);
return false;
}
// get an instance of plugin before the plugin is unloaded
// for reason see https://github.com/pf4j/pf4j/issues/309
org.pf4j.Plugin plugin = pluginWrapper.getPlugin();
if (!unloadPlugin(pluginId)) {
log.error("Failed to unload plugin '{}' on delete", pluginId);
return false;
}
// notify the plugin as it's deleted
plugin.delete();
Path pluginPath = pluginWrapper.getPluginPath();
return pluginRepository.deletePluginPath(pluginPath);
}
19
Source : OPRSExternalPf4jPluginManager.java
with BSD 2-Clause "Simplified" License
from open-osrs
with BSD 2-Clause "Simplified" License
from open-osrs
@Override
public boolean unloadPlugin(String pluginId) {
try {
PluginState pluginState = stopPlugin(pluginId);
if (PluginState.STARTED == pluginState) {
return false;
}
PluginWrapper pluginWrapper = getPlugin(pluginId);
// remove the plugin
plugins.remove(pluginId);
getResolvedPlugins().remove(pluginWrapper);
firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState));
// remove the clreplacedloader
Map<String, ClreplacedLoader> pluginClreplacedLoaders = getPluginClreplacedLoaders();
if (pluginClreplacedLoaders.containsKey(pluginId)) {
ClreplacedLoader clreplacedLoader = pluginClreplacedLoaders.remove(pluginId);
if (clreplacedLoader instanceof Closeable) {
try {
((Closeable) clreplacedLoader).close();
} catch (IOException e) {
throw new PluginRuntimeException(e, "Cannot close clreplacedloader");
}
}
}
return true;
} catch (IllegalArgumentException e) {
// ignore not found exceptions because this method is recursive
}
return false;
}
19
Source : SpringBootstrap.java
with Apache License 2.0
from hank-cp
with Apache License 2.0
from hank-cp
protected boolean importBeanFromDependentPlugin(AbstractApplicationContext applicationContext, Clreplaced<?> beanClreplaced) {
for (PluginDependency dependency : plugin.getWrapper().getDescriptor().getDependencies()) {
PluginWrapper dependentPlugin = plugin.getPluginManager().getPlugin(dependency.getPluginId());
if (dependentPlugin == null)
continue;
SpringBootPlugin sbPlugin = (SpringBootPlugin) dependentPlugin.getPlugin();
if (importBean(sbPlugin.getApplicationContext(), applicationContext, beanClreplaced))
return true;
}
return false;
}
19
Source : SpringBootstrap.java
with Apache License 2.0
from hank-cp
with Apache License 2.0
from hank-cp
protected boolean importBeanFromDependentPlugin(AbstractApplicationContext applicationContext, String beanName) {
for (PluginDependency dependency : plugin.getWrapper().getDescriptor().getDependencies()) {
PluginWrapper dependentPlugin = plugin.getPluginManager().getPlugin(dependency.getPluginId());
if (dependentPlugin == null)
continue;
SpringBootPlugin sbPlugin = (SpringBootPlugin) dependentPlugin.getPlugin();
if (importBean(sbPlugin.getApplicationContext(), applicationContext, beanName))
return true;
}
return false;
}
19
Source : MeshPluginManagerImpl.java
with Apache License 2.0
from gentics
with Apache License 2.0
from gentics
@Override
public Completable undeploy(String id) {
return Completable.fromRunnable(() -> {
resolvePlugins();
PluginWrapper wrapper = getPlugin(id);
if (wrapper == null) {
log.debug("Plugin with id {} could not be found", id);
return;
}
Plugin plugin = wrapper.getPlugin();
if (plugin instanceof MeshPlugin) {
try {
MeshPlugin meshPlugin = (MeshPlugin) plugin;
withTimeout(id, "shudown", pluginRegistry.deregister(meshPlugin).andThen(meshPlugin.shutdown()));
} catch (Throwable t) {
log.error("Error while calling shutdown of plugin. Trying to unload anyway.", t);
}
}
unloadPlugin(id);
});
}
19
Source : MeshPluginManagerImpl.java
with Apache License 2.0
from gentics
with Apache License 2.0
from gentics
@Override
public void unloadPlugins() {
for (PluginWrapper wrapper : getPlugins()) {
Plugin plugin = wrapper.getPlugin();
if (plugin instanceof MeshPlugin) {
MeshPlugin meshPlugin = (MeshPlugin) plugin;
try {
withTimeout(meshPlugin.id(), "shtdown", pluginRegistry.deregister((MeshPlugin) plugin).andThen(meshPlugin.shutdown()));
} catch (Exception e) {
log.error("Shutdown call of plugin {" + meshPlugin.id() + "} failed. Unloading anyway.", e);
}
}
undeploy(wrapper.getPluginId());
unloadPlugin(wrapper.getPluginId());
}
}
19
Source : PluginsViewController.java
with GNU General Public License v3.0
from EXXETA
with GNU General Public License v3.0
from EXXETA
private TableRow<PluginWrapper> getRowFactory(TableView<PluginWrapper> tv) {
TableRow<PluginWrapper> row = new TableRow<>();
row.setOnMouseClicked(event -> {
if (event.getClickCount() == 2 && (!row.isEmpty())) {
PluginWrapper rowData = row.gereplacedem();
ClipboardContent content = new ClipboardContent();
content.putString(rowData.getPluginId());
Clipboard.getSystemClipboard().setContent(content);
setStatusCopiedToClipboard(rowData.getPluginId());
}
});
return row;
}
18
Source : AopUtils.java
with Apache License 2.0
from starblues-zhuo
with Apache License 2.0
from starblues-zhuo
/**
* 解决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);
ClreplacedLoader pluginClreplacedLoader = pluginWrapper.getPluginClreplacedLoader();
for (ProxyWrapper proxyWrapper : PROXY_WRAPPERS) {
ProxyProcessorSupport proxyProcessorSupport = proxyWrapper.getProxyProcessorSupport();
ClreplacedLoader clreplacedLoader = getClreplacedLoader(proxyProcessorSupport);
proxyWrapper.setOriginalClreplacedLoader(clreplacedLoader);
proxyProcessorSupport.setProxyClreplacedLoader(pluginClreplacedLoader);
}
}
18
Source : PluginRegistryInfo.java
with Apache License 2.0
from starblues-zhuo
with Apache License 2.0
from starblues-zhuo
/**
* 注册的插件信息
*
* @author zhangzhuo
* @version 2.1.0
*/
public clreplaced PluginRegistryInfo {
/**
* 扩展存储项
*/
private Map<String, Object> extensionMap = new ConcurrentHashMap<>();
private PluginWrapper pluginWrapper;
private BasePlugin basePlugin;
/**
* 插件中的Clreplaced
*/
private List<Clreplaced<?>> clreplacedes = new ArrayList<>();
/**
* 插件中分类的Clreplaced
*/
private Map<String, List<Clreplaced<?>>> groupClreplacedes = new HashMap<>();
private Map<String, Object> processorInfo = new HashMap<>();
public PluginRegistryInfo(PluginWrapper pluginWrapper) {
this.pluginWrapper = pluginWrapper;
this.basePlugin = (BasePlugin) pluginWrapper.getPlugin();
}
public PluginWrapper getPluginWrapper() {
return pluginWrapper;
}
public BasePlugin getBasePlugin() {
return basePlugin;
}
/**
* 添加类到类集合容器
* @param aClreplaced 类
*/
public void addClreplacedes(Clreplaced<?> aClreplaced) {
if (aClreplaced != null) {
clreplacedes.add(aClreplaced);
}
}
/**
* 清除类集合容器
*/
public void cleanClreplacedes() {
clreplacedes.clear();
}
/**
* 得到类集合容器
* @return 类集合容器
*/
public List<Clreplaced<?>> getClreplacedes() {
List<Clreplaced<?>> result = new ArrayList<>();
result.addAll(clreplacedes);
return result;
}
/**
* 添加分组的类型
* @param key 分组key
* @param aClreplaced 类
*/
public void addGroupClreplacedes(String key, Clreplaced<?> aClreplaced) {
List<Clreplaced<?>> clreplacedes = groupClreplacedes.get(key);
if (clreplacedes == null) {
clreplacedes = new ArrayList<>();
groupClreplacedes.put(key, clreplacedes);
}
clreplacedes.add(aClreplaced);
}
/**
* 通过分组key得到分组中的类类型
* @param key 处理者key
* @return 类类型集合
*/
public List<Clreplaced<?>> getGroupClreplacedes(String key) {
List<Clreplaced<?>> clreplacedes = groupClreplacedes.get(key);
List<Clreplaced<?>> result = new ArrayList<>();
if (clreplacedes != null) {
result.addAll(clreplacedes);
}
return result;
}
/**
* 得到插件bean注册者信息
* @param key 扩展的key
* @param <T> 处理者类型
* @return 注册者信息
*/
public <T> T getProcessorInfo(String key) {
Object o = processorInfo.get(key);
if (o != null) {
return (T) o;
}
return null;
}
/**
* 添加插件bean注册者信息
* @param key 扩展的key
* @param value 扩展值
*/
public void addProcessorInfo(String key, Object value) {
processorInfo.put(key, value);
}
/**
* 添加扩展数据
* @param key 扩展的key
* @param value 扩展值
*/
public void addExtension(String key, Object value) {
extensionMap.put(key, value);
}
/**
* 获取扩展值
* @param key 扩展的key
* @param <T> 返回值泛型
* @return 扩展值
*/
public <T> T getExtension(String key) {
Object o = extensionMap.get(key);
if (o == null) {
return null;
} else {
return (T) o;
}
}
}
18
Source : Pf4jPluginManager.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
@Override
public boolean deletePlugin(PluginWrapper pluginWrapper) {
return integrationTypeRepository.findByName(pluginWrapper.getPluginId()).map(this::deletePlugin).orElseGet(() -> {
applicationEventPublisher.publishEvent(new PluginEvent(pluginWrapper.getPluginId(), UNLOAD_KEY));
deletePluginResources(Paths.get(resourcesDir, pluginWrapper.getPluginId()).toString());
destroyDependency(pluginWrapper.getPluginId());
return pluginManager.deletePlugin(pluginWrapper.getPluginId());
});
}
18
Source : OPRSExternalPf4jPluginManager.java
with BSD 2-Clause "Simplified" License
from open-osrs
with BSD 2-Clause "Simplified" License
from open-osrs
@Override
protected void resolvePlugins() {
// retrieves the plugins descriptors
List<org.pf4j.PluginDescriptor> descriptors = new ArrayList<>();
for (PluginWrapper plugin : plugins.values()) {
descriptors.add(plugin.getDescriptor());
}
// retrieves the plugins descriptors from the resolvedPlugins list. This allows to load plugins that have already loaded dependencies.
for (PluginWrapper plugin : resolvedPlugins) {
descriptors.add(plugin.getDescriptor());
}
DependencyResolver.Result result = dependencyResolver.resolve(descriptors);
if (result.hasCyclicDependency()) {
throw new DependencyResolver.CyclicDependencyException();
}
List<String> notFoundDependencies = result.getNotFoundDependencies();
if (!notFoundDependencies.isEmpty()) {
throw new DependencyResolver.DependenciesNotFoundException(notFoundDependencies);
}
List<DependencyResolver.WrongDependencyVersion> wrongVersionDependencies = result.getWrongVersionDependencies();
if (!wrongVersionDependencies.isEmpty()) {
throw new DependencyResolver.DependenciesWrongVersionException(wrongVersionDependencies);
}
List<String> sortedPlugins = result.getSortedPlugins();
// move plugins from "unresolved" to "resolved"
for (String pluginId : sortedPlugins) {
PluginWrapper pluginWrapper = plugins.get(pluginId);
// The plugin is already resolved. Don't put a copy in the resolvedPlugins.
if (resolvedPlugins.contains(pluginWrapper)) {
continue;
}
if (unresolvedPlugins.remove(pluginWrapper)) {
PluginState pluginState = pluginWrapper.getPluginState();
if (pluginState != PluginState.DISABLED) {
pluginWrapper.setPluginState(PluginState.RESOLVED);
}
resolvedPlugins.add(pluginWrapper);
firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState));
}
}
}
18
Source : OPRSExternalPf4jPluginManager.java
with BSD 2-Clause "Simplified" License
from open-osrs
with BSD 2-Clause "Simplified" License
from open-osrs
@Override
public PluginState stopPlugin(String pluginId) {
if (!plugins.containsKey(pluginId)) {
throw new IllegalArgumentException(String.format("Unknown pluginId %s", pluginId));
}
PluginWrapper pluginWrapper = getPlugin(pluginId);
org.pf4j.PluginDescriptor pluginDescriptor = pluginWrapper.getDescriptor();
PluginState pluginState = pluginWrapper.getPluginState();
if (PluginState.STOPPED == pluginState) {
log.debug("Already stopped plugin '{}'", getPluginLabel(pluginDescriptor));
return PluginState.STOPPED;
}
// test for disabled plugin
if (PluginState.DISABLED == pluginState) {
// do nothing
return pluginState;
}
pluginWrapper.getPlugin().stop();
pluginWrapper.setPluginState(PluginState.STOPPED);
startedPlugins.remove(pluginWrapper);
firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState));
return pluginWrapper.getPluginState();
}
18
Source : MeshPluginManagerImpl.java
with Apache License 2.0
from gentics
with Apache License 2.0
from gentics
@Override
public void startPlugins() {
for (PluginWrapper pluginWrapper : resolvedPlugins) {
PluginState pluginState = pluginWrapper.getPluginState();
if ((PluginState.DISABLED != pluginState) && (PluginState.STARTED != pluginState)) {
try {
log.info("Start plugin '{}'", getPluginLabel(pluginWrapper.getDescriptor()));
Plugin plugin = pluginWrapper.getPlugin();
plugin.start();
// Set state for PF4J
pluginWrapper.setPluginState(PluginState.STARTED);
if (plugin instanceof MeshPlugin) {
// Set status for Mesh
MeshPlugin meshPlugin = (MeshPlugin) plugin;
setStatus(meshPlugin.id(), PluginStatus.STARTED);
pluginRegistry.preRegister(meshPlugin);
}
startedPlugins.add(pluginWrapper);
firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState));
} catch (Throwable e) {
log.error("Error while starting plugins " + e.getMessage(), e);
}
}
}
}
18
Source : MeshPluginManagerImpl.java
with Apache License 2.0
from gentics
with Apache License 2.0
from gentics
private PluginWrapper loadPlugin(Clreplaced<?> clazz, String id) {
MeshPluginDescriptor pluginDescriptor = new MeshPluginDescriptorImpl(clazz, id);
log.debug("Found descriptor {}", pluginDescriptor);
String pluginClreplacedName = clazz.getName();
log.debug("Clreplaced '{}' for plugin", pluginClreplacedName);
PluginClreplacedLoader pluginClreplacedLoader = new PluginClreplacedLoader(this, pluginDescriptor, getClreplaced().getClreplacedLoader());
// create the plugin wrapper
log.debug("Creating wrapper for plugin '{}'", pluginClreplacedName);
PluginWrapper pluginWrapper = new PluginWrapper(this, pluginDescriptor, null, pluginClreplacedLoader);
pluginWrapper.setPluginFactory(getPluginFactory());
// test for disabled plugin
if (isPluginDisabled(pluginDescriptor.getPluginId())) {
log.info("Plugin '{}' is disabled", pluginClreplacedName);
pluginWrapper.setPluginState(PluginState.DISABLED);
}
// validate the plugin
if (!isPluginValid(pluginWrapper)) {
log.warn("Plugin '{}' is invalid and it will be disabled", pluginClreplacedName);
pluginWrapper.setPluginState(PluginState.DISABLED);
}
log.debug("Created wrapper '{}' for plugin '{}'", pluginWrapper, pluginClreplacedName);
// add plugin to the list with plugins
plugins.put(id, pluginWrapper);
getUnresolvedPlugins().add(pluginWrapper);
// add plugin clreplaced loader to the list with clreplaced loaders
getPluginClreplacedLoaders().put(id, pluginClreplacedLoader);
resolvePlugins();
return pluginWrapper;
}
18
Source : MeshPluginManagerImpl.java
with Apache License 2.0
from gentics
with Apache License 2.0
from gentics
@Override
public Single<String> deploy(Path path) {
Objects.requireNonNull(path, "The path must not be null");
log.debug("Deploying file {" + path + "}");
// 1. Initial checks
String name = path.getFileName().toString();
if (Files.notExists(path)) {
return rxError(BAD_REQUEST, "admin_plugin_error_plugin_deployment_failed", name);
}
// 2. Load plugin into p4fj
String id;
try {
id = loadPlugin(path);
} catch (PluginRuntimeException e) {
if (e.getMessage().startsWith("There is an already loaded plugin")) {
log.error("Plugin deployment of {" + name + "} failed.", e);
return rxError(BAD_REQUEST, "admin_plugin_error_plugin_with_id_already_deployed", name);
} else {
log.error("Plugin deployment of {" + name + "} failed.", e);
return rxError(INTERNAL_SERVER_ERROR, "admin_plugin_error_plugin_loading_failed", name);
}
} catch (Throwable e) {
log.error("Plugin deployment of {" + name + "} failed.", e);
return rxError(INTERNAL_SERVER_ERROR, "admin_plugin_error_plugin_loading_failed", name);
}
if (id == null) {
log.warn("The plugin was not registered after deployment. Maybe the initialisation failed. Going to unload the plugin.");
return rxError(INTERNAL_SERVER_ERROR, "admin_plugin_error_plugin_did_not_register", name);
}
setStatus(id, LOADED);
// 3. Invoke the validation of the plugin clreplaced
try {
PluginWrapper plugin = getPlugin(id);
if (plugin == null || plugin.getPlugin() == null) {
log.error("The plugin {" + path + "/" + id + "} could not be loaded.");
plugins.remove(id);
return rxError(INTERNAL_SERVER_ERROR, "admin_plugin_error_plugin_loading_failed", name);
}
validate(plugin.getPlugin());
setStatus(id, VALIDATED);
} catch (GenericRestException e) {
log.error("Post start validation of plugin {" + path + "/" + id + "} failed.", e);
removePlugin(id);
throw e;
} catch (Throwable e) {
log.error("Error while loading plugin clreplaced", e);
removePlugin(id);
return rxError(INTERNAL_SERVER_ERROR, "admin_plugin_error_plugin_loading_failed", name);
}
// 4. Start the plugin
try {
startPlugin(id);
setStatus(id, STARTED);
} catch (GenericRestException e) {
log.error("Starting of plugin {" + path + "/" + id + "} failed.", e);
rollback(id);
throw e;
} catch (Throwable e) {
log.error("Starting of plugin {" + path + "/" + id + "} failed.", e);
rollback(id);
return rxError(INTERNAL_SERVER_ERROR, "admin_plugin_error_plugin_starting_failed", name);
}
// 5. Pre-Register the plugin
try {
PluginWrapper wrapper = getPlugin(id);
Plugin plugin = wrapper.getPlugin();
if (plugin instanceof MeshPlugin) {
MeshPlugin meshPlugin = (MeshPlugin) plugin;
pluginRegistry.preRegister(meshPlugin);
}
} catch (Throwable e) {
log.error("Plugin registration failed with error", e);
rollback(id);
return rxError(INTERNAL_SERVER_ERROR, "admin_plugin_error_plugin_did_not_register");
}
return Single.just(id);
}
18
Source : MeshPluginManagerImpl.java
with Apache License 2.0
from gentics
with Apache License 2.0
from gentics
@Override
public Completable deploy(Clreplaced<?> clazz, String id) {
Objects.requireNonNull(id, "A plugin must have a unique id (e.g. hello-world)");
if (!isMeshPlugin(clazz)) {
return rxError(BAD_REQUEST, "admin_plugin_error_wrong_type").ignoreElement();
}
String name = clazz.getSimpleName();
return Completable.defer(() -> {
log.debug("Deploying plugin clreplaced {" + name + "}");
// 1. Load plugin
try {
PluginDescriptor desc = loadPlugin(clazz, id).getDescriptor();
if (!(desc instanceof MeshPluginDescriptor)) {
return rxError(INTERNAL_SERVER_ERROR, "plugin_desc_wrong").ignoreElement();
}
setStatus(id, LOADED);
} catch (Throwable e) {
log.error("Error while deploying plugin via clreplaced", e);
return Completable.error(new RuntimeException("Error while deploying plugin {" + clazz + "}", e));
}
// 2. Validate plugin
try {
PluginWrapper wrapper = getPlugin(id);
if (wrapper == null || wrapper.getPlugin() == null) {
log.error("The plugin {" + name + "/" + id + "} could not be loaded.");
removePlugin(id);
return rxError(INTERNAL_SERVER_ERROR, "admin_plugin_error_plugin_loading_failed", name).ignoreElement();
}
validate(wrapper.getPlugin());
setStatus(id, VALIDATED);
} catch (GenericRestException e) {
log.error("Post start validation of plugin {" + name + "/" + id + "} failed.", e);
removePlugin(id);
return Completable.error(e);
} catch (Throwable e) {
log.error("Error while loading plugin clreplaced", e);
removePlugin(id);
return rxError(INTERNAL_SERVER_ERROR, "admin_plugin_error_plugin_loading_failed", name).ignoreElement();
}
// 3. Start plugin
try {
startPlugin(id);
} catch (Throwable e) {
log.error("Error while starting plugin", e);
rollback(id);
return rxError(INTERNAL_SERVER_ERROR, "admin_plugin_error_plugin_starting_failed", name).ignoreElement();
}
// 4. Register plugin
try {
PluginWrapper wrapper = getPlugin(id);
Plugin plugin = wrapper.getPlugin();
if (plugin instanceof MeshPlugin) {
MeshPlugin meshPlugin = (MeshPlugin) plugin;
pluginRegistry.preRegister(meshPlugin);
}
} catch (Throwable e) {
log.error("Plugin registration failed with error", e);
try {
stopPlugin(id);
} catch (Exception e2) {
log.error("Error while stopping failed plugin. Directly unloading it.", e2);
}
rollback(id);
return rxError(INTERNAL_SERVER_ERROR, "admin_plugin_error_plugin_did_not_register").ignoreElement();
}
return Completable.complete();
});
}
18
Source : ArmoryObservabilityPluginTest.java
with Apache License 2.0
from armory-plugins
with Apache License 2.0
from armory-plugins
public clreplaced ArmoryObservabilityPluginTest {
@Mock
PluginWrapper pluginWrapper;
@Mock
BeanDefinitionRegistry registry;
ArmoryObservabilityPlugin sut;
@Before
public void before() {
initMocks(this);
sut = new ArmoryObservabilityPlugin(pluginWrapper);
}
@Test
public void test_that_registerBeanDefinitions_registers_some_beans() {
sut.registerBeanDefinitions(registry);
verify(registry, atLeast(1)).registerBeanDefinition(any(), any());
}
@Test(expected = PluginRuntimeException.clreplaced)
public void test_that_registerBeanDefinitions_throws_PRE_when_bean_registration_fails() {
doThrow(new BeanDefinitionStoreException("error")).when(registry).registerBeanDefinition(any(), any());
sut.registerBeanDefinitions(registry);
}
}
17
Source : ReportPortalExtensionFactoryTest.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
/**
* @author <a href="mailto:[email protected]">Ivan Budayeu</a>
*/
clreplaced ReportPortalExtensionFactoryTest {
private final String RESOURCES_DIR = "resources";
private final PluginManager pluginManager = mock(PluginManager.clreplaced);
private final PluginWrapper pluginWrapper = mock(PluginWrapper.clreplaced);
private final PluginDescriptor pluginDescriptor = mock(PluginDescriptor.clreplaced);
private final AbstractAutowireCapableBeanFactory beanFactory = mock(AbstractAutowireCapableBeanFactory.clreplaced);
private final ReportPortalExtensionFactory reportPortalExtensionFactory = new ReportPortalExtensionFactory(RESOURCES_DIR, pluginManager, beanFactory);
@Test
public void shouldReturnExistingBean() {
when(pluginWrapper.getPluginId()).thenReturn("testId");
when(pluginManager.whichPlugin(any())).thenReturn(pluginWrapper);
when(beanFactory.containsSingleton(pluginWrapper.getPluginId())).thenReturn(true);
when(beanFactory.getSingleton("testId")).thenReturn(new DummyPluginBean("testId"));
DummyPluginBean pluginBean = (DummyPluginBean) reportPortalExtensionFactory.create(DummyPluginBean.clreplaced);
replacedertEquals(pluginWrapper.getPluginId(), pluginBean.getId());
}
@Test
public void shouldCreateNewBean() {
when(pluginWrapper.getPluginId()).thenReturn("testId");
when(pluginDescriptor.getPluginId()).thenReturn("testId");
when(pluginWrapper.getDescriptor()).thenReturn(pluginDescriptor);
when(pluginManager.whichPlugin(any())).thenReturn(pluginWrapper);
when(beanFactory.containsSingleton(pluginWrapper.getPluginId())).thenReturn(false);
DummyPluginBean pluginBean = (DummyPluginBean) reportPortalExtensionFactory.create(DummyPluginBean.clreplaced);
replacedertEquals("resources/testId", String.valueOf(pluginBean.getInitParams().get(IntegrationTypeProperties.RESOURCES_DIRECTORY.getAttribute())));
verify(beanFactory, times(1)).autowireBean(pluginBean);
verify(beanFactory, times(1)).initializeBean(pluginBean, pluginWrapper.getDescriptor().getPluginId());
verify(beanFactory, times(1)).registerSingleton(pluginWrapper.getDescriptor().getPluginId(), pluginBean);
verify(beanFactory, times(1)).registerDisposableBean(pluginWrapper.getDescriptor().getPluginId(), (DisposableBean) pluginBean);
}
private static clreplaced DummyPluginBean implements DisposableBean {
private String id;
private Map<String, Object> initParams;
public DummyPluginBean(String id) {
this.id = id;
}
public DummyPluginBean(Map<String, Object> initParams) {
this.initParams = initParams;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Map<String, Object> getInitParams() {
return initParams;
}
public void setInitParams(Map<String, Object> initParams) {
this.initParams = initParams;
}
@Override
public void destroy() throws Exception {
}
}
}
17
Source : ReportPortalExtensionFactory.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
@Override
public Object create(Clreplaced<?> extensionClreplaced) {
PluginWrapper pluginWrapper = pluginManager.whichPlugin(extensionClreplaced);
if (beanFactory.containsSingleton(pluginWrapper.getPluginId())) {
return beanFactory.getSingleton(pluginWrapper.getPluginId());
} else {
return createExtension(extensionClreplaced, pluginWrapper);
}
}
17
Source : ReportPortalExtensionFactory.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
private Object createExtension(Clreplaced<?> extensionClreplaced, PluginWrapper pluginWrapper) {
Map<String, Object> initParams = getInitParams(pluginWrapper);
Object plugin = createPlugin(extensionClreplaced, initParams);
beanFactory.autowireBean(plugin);
beanFactory.initializeBean(plugin, pluginWrapper.getDescriptor().getPluginId());
beanFactory.registerSingleton(pluginWrapper.getDescriptor().getPluginId(), plugin);
if (DisposableBean.clreplaced.isreplacedignableFrom(extensionClreplaced)) {
beanFactory.registerDisposableBean(pluginWrapper.getDescriptor().getPluginId(), (DisposableBean) plugin);
}
return plugin;
}
17
Source : PluginConfigTest.java
with Apache License 2.0
from gentics
with Apache License 2.0
from gentics
private DummyPlugin mockPlugin() {
PluginWrapper wrapper = mock(PluginWrapper.clreplaced);
when(wrapper.getPluginId()).thenReturn("dummy");
MeshPluginDescriptorImpl descriptor = mock(MeshPluginDescriptorImpl.clreplaced);
when(descriptor.getName()).thenReturn("dummy");
PluginManifest manifest = new PluginManifest();
manifest.setName("dummy");
when(descriptor.toPluginManifest()).thenReturn(manifest);
when(wrapper.getDescriptor()).thenReturn(descriptor);
PluginEnvironment env = mock(PluginEnvironment.clreplaced);
when(env.options()).thenReturn(options);
DummyPlugin plugin = new DummyPlugin(wrapper, env);
return plugin;
}
17
Source : PluginHandler.java
with Apache License 2.0
from gentics
with Apache License 2.0
from gentics
/**
* Handle the plugin load request that returns information about the plugin with the provided id.
*
* @param ac
* @param id
*/
public void handleRead(InternalActionContext ac, String id) {
utils.syncTx(ac, tx -> {
if (!ac.getUser().isAdmin()) {
throw error(FORBIDDEN, "error_admin_permission_required");
}
PluginWrapper pluginWrapper = manager.getPlugin(id);
if (pluginWrapper == null) {
throw error(NOT_FOUND, "admin_plugin_error_plugin_not_found", id);
}
Plugin plugin = pluginWrapper.getPlugin();
if (plugin instanceof MeshPlugin) {
return manager.toResponse((MeshPlugin) plugin);
}
throw error(INTERNAL_SERVER_ERROR, "admin_plugin_error_wrong_type");
}, model -> ac.send(model, CREATED));
}
16
Source : PluginMybatisXmlProcessor.java
with Apache License 2.0
from starblues-zhuo
with Apache License 2.0
from starblues-zhuo
@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.getPluginClreplacedLoader());
}
16
Source : PluginLoaderServiceTest.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
/**
* @author <a href="mailto:[email protected]">Ivan Budayeu</a>
*/
clreplaced PluginLoaderServiceTest {
private IntegrationTypeRepository integrationTypeRepository = mock(IntegrationTypeRepository.clreplaced);
private Pf4jPluginBox pluginBox = mock(Pf4jPluginBox.clreplaced);
private PluginLoaderService pluginLoaderService = new PluginLoaderServiceImpl(integrationTypeRepository, pluginBox);
private PluginWrapper jiraPlugin = mock(PluginWrapper.clreplaced);
private PluginWrapper rallyPlugin = mock(PluginWrapper.clreplaced);
private PluginDescriptor jiraPluginDescriptor = mock(PluginDescriptor.clreplaced);
private PluginDescriptor rallyPluginDescriptor = mock(PluginDescriptor.clreplaced);
@Test
void getNotLoadedPluginsInfoTest() {
when(pluginBox.getPluginById("jira")).thenReturn(Optional.ofNullable(jiraPlugin));
when(pluginBox.getPluginById("rally")).thenReturn(Optional.ofNullable(rallyPlugin));
when(jiraPlugin.getDescriptor()).thenReturn(jiraPluginDescriptor);
when(jiraPluginDescriptor.getVersion()).thenReturn("v1");
when(rallyPlugin.getDescriptor()).thenReturn(rallyPluginDescriptor);
when(rallyPluginDescriptor.getVersion()).thenReturn("another version");
when(integrationTypeRepository.findAll()).thenReturn(getIntegrationTypes());
List<PluginInfo> notLoadedPluginsInfo = pluginLoaderService.getNotLoadedPluginsInfo();
replacedertions.replacedertFalse(notLoadedPluginsInfo.isEmpty());
replacedertions.replacedertEquals(1, notLoadedPluginsInfo.size());
replacedertions.replacedertEquals("rally", notLoadedPluginsInfo.get(0).getId());
}
@Test
void checkAndDeleteIntegrationTypeWhenPluginPositive() {
IntegrationType integrationType = new IntegrationType();
integrationType.setId(1L);
integrationType.setName("jira");
when(pluginBox.getPluginById(integrationType.getName())).thenReturn(Optional.ofNullable(jiraPlugin));
when(jiraPlugin.getPluginId()).thenReturn("jira");
when(jiraPlugin.getPluginPath()).thenReturn(Paths.get("plugins", "file.jar"));
when(pluginBox.unloadPlugin(integrationType)).thenReturn(true);
pluginLoaderService.checkAndDeleteIntegrationType(integrationType);
verify(integrationTypeRepository, times(1)).deleteById(integrationType.getId());
}
@Test
void checkAndDeleteIntegrationTypeWhenPluginNegative() {
IntegrationType integrationType = new IntegrationType();
integrationType.setId(1L);
integrationType.setName("jira");
when(pluginBox.getPluginById(integrationType.getName())).thenReturn(Optional.ofNullable(jiraPlugin));
when(jiraPlugin.getPluginId()).thenReturn("jira");
when(pluginBox.unloadPlugin(integrationType)).thenReturn(false);
pluginLoaderService.checkAndDeleteIntegrationType(integrationType);
verify(integrationTypeRepository, times(0)).deleteById(integrationType.getId());
}
@Test
void checkAndDeleteIntegrationTypeWhenNotPluginTest() {
IntegrationType integrationType = new IntegrationType();
integrationType.setId(1L);
integrationType.setName("EMAIL");
pluginLoaderService.checkAndDeleteIntegrationType(integrationType);
verify(integrationTypeRepository, times(0)).deleteById(integrationType.getId());
}
private List<IntegrationType> getIntegrationTypes() {
IntegrationType jira = new IntegrationType();
jira.setName("jira");
IntegrationTypeDetails jiraDetails = new IntegrationTypeDetails();
Map<String, Object> jiraParams = Maps.newHashMap();
jiraParams.put(IntegrationTypeProperties.FILE_ID.getAttribute(), "f1");
jiraParams.put(IntegrationTypeProperties.FILE_NAME.getAttribute(), "fname1");
jiraParams.put(IntegrationTypeProperties.VERSION.getAttribute(), "v1");
jiraParams.put(IntegrationTypeProperties.COMMANDS.getAttribute(), "");
jiraDetails.setDetails(jiraParams);
jira.setEnabled(true);
jira.setDetails(jiraDetails);
IntegrationType rally = new IntegrationType();
rally.setEnabled(true);
Map<String, Object> rallyParams = Maps.newHashMap();
rallyParams.put(IntegrationTypeProperties.FILE_ID.getAttribute(), "f2");
rallyParams.put(IntegrationTypeProperties.FILE_NAME.getAttribute(), "fname2");
rallyParams.put(IntegrationTypeProperties.VERSION.getAttribute(), "v2");
rallyParams.put(IntegrationTypeProperties.COMMANDS.getAttribute(), "");
IntegrationTypeDetails rallyDetails = new IntegrationTypeDetails();
rallyDetails.setDetails(rallyParams);
rally.setName("rally");
rally.setDetails(rallyDetails);
IntegrationType noDetails = new IntegrationType();
noDetails.setName("NO DETAILS");
IntegrationType emptyParams = new IntegrationType();
emptyParams.setName("EMPTY PARAMS");
emptyParams.setDetails(new IntegrationTypeDetails());
return Lists.newArrayList(jira, rally, noDetails, emptyParams);
}
}
16
Source : CleanOutdatedPluginsJobTest.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
/**
* @author <a href="mailto:[email protected]">Ivan Budayeu</a>
*/
clreplaced CleanOutdatedPluginsJobTest {
private static final String PLUGIN_TEMP_DIRECTORY = "/temp/";
private String pluginsRootPath = System.getProperty("java.io.tmpdir") + "/plugins";
private IntegrationTypeRepository integrationTypeRepository = mock(IntegrationTypeRepository.clreplaced);
private Pf4jPluginBox pluginBox = mock(Pf4jPluginBox.clreplaced);
private PluginLoaderService pluginLoaderService = mock(PluginLoaderService.clreplaced);
private PluginWrapper jiraPlugin = mock(PluginWrapper.clreplaced);
private IntegrationType jiraIntegrationType = mock(IntegrationType.clreplaced);
private PluginWrapper rallyPlugin = mock(PluginWrapper.clreplaced);
private IntegrationType rallyIntegrationType = mock(IntegrationType.clreplaced);
private CleanOutdatedPluginsJob cleanOutdatedPluginsJob = new CleanOutdatedPluginsJob(pluginsRootPath + PLUGIN_TEMP_DIRECTORY, integrationTypeRepository, pluginBox, pluginLoaderService);
@Test
void testExecutionWithoutPluginInCache() throws IOException {
File dir = new File(pluginsRootPath + PLUGIN_TEMP_DIRECTORY);
if (!dir.exists()) {
replacedertTrue(dir.mkdirs());
}
File file = new File(dir, "qwe.jar");
replacedertTrue(file.createNewFile());
when(pluginBox.isInUploadingState(any(String.clreplaced))).thenReturn(false);
cleanOutdatedPluginsJob.execute();
}
@Test
void testExecutionWithPluginInCache() throws IOException {
File dir = new File(pluginsRootPath + PLUGIN_TEMP_DIRECTORY);
if (!dir.exists()) {
replacedertTrue(dir.mkdirs());
}
File file = File.createTempFile("test", ".jar", dir);
file.deleteOnExit();
when(pluginBox.isInUploadingState(any(String.clreplaced))).thenReturn(true);
cleanOutdatedPluginsJob.execute();
}
@Test
void testBrokenIntegrationTypeRemoving() {
when(integrationTypeRepository.findAll()).thenReturn(getBrokenIntegrationType());
cleanOutdatedPluginsJob.execute();
verify(pluginLoaderService, times(2)).checkAndDeleteIntegrationType(any(IntegrationType.clreplaced));
}
@Test
void testTemporaryPluginRemoving() {
List<Plugin> plugins = getPlugins();
when(integrationTypeRepository.findAll()).thenReturn(Collections.emptyList());
when(pluginBox.getPlugins()).thenReturn(plugins);
when(pluginBox.getPluginById(plugins.get(0).getId())).thenReturn(ofNullable(jiraPlugin));
when(jiraPlugin.getPluginPath()).thenReturn(Paths.get(pluginsRootPath, "qwe.jar"));
when(pluginBox.isInUploadingState(jiraPlugin.getPluginPath().getFileName().toString())).thenReturn(false);
when(integrationTypeRepository.findByName(jiraPlugin.getPluginId())).thenReturn(Optional.of(jiraIntegrationType));
when(pluginBox.unloadPlugin(jiraIntegrationType)).thenReturn(true);
when(pluginBox.getPluginById(plugins.get(1).getId())).thenReturn(ofNullable(rallyPlugin));
when(rallyPlugin.getPluginPath()).thenReturn(Paths.get(pluginsRootPath, "qwe1.jar"));
when(pluginBox.isInUploadingState(rallyPlugin.getPluginPath().getFileName().toString())).thenReturn(false);
when(integrationTypeRepository.findByName(rallyPlugin.getPluginId())).thenReturn(Optional.of(rallyIntegrationType));
when(pluginBox.unloadPlugin(rallyIntegrationType)).thenReturn(false);
cleanOutdatedPluginsJob.execute();
}
private List<IntegrationType> getBrokenIntegrationType() {
IntegrationType jira = new IntegrationType();
jira.setName("jira");
jira.setDetails(new IntegrationTypeDetails());
IntegrationType rally = new IntegrationType();
rally.setName("rally");
return Lists.newArrayList(jira, rally);
}
private List<Plugin> getPlugins() {
return Lists.newArrayList(new Plugin("jira", ExtensionPoint.BTS), new Plugin("rally", ExtensionPoint.BTS));
}
}
16
Source : Pf4jPluginManager.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
/**
* Load and start up the previous plugin
*
* @param previousPlugin {@link PluginWrapper} with mandatory data for plugin loading: {@link PluginWrapper#getPluginPath()}
* @param newPluginDetails {@link IntegrationTypeDetails} of the plugin which uploading ended up with an error
* @return {@link PluginState}
*/
private PluginState loadPreviousPlugin(PluginWrapper previousPlugin, IntegrationTypeDetails newPluginDetails) {
if (previousPlugin.getPluginState() == PluginState.STARTED) {
return previousPlugin.getPluginState();
}
IntegrationTypeProperties.FILE_ID.getValue(newPluginDetails.getDetails()).map(String::valueOf).ifPresent(fileId -> {
try {
pluginLoader.deleteFromDataStore(fileId);
} catch (Exception e) {
LOGGER.error("Unable to delete new plugin file from the DataStore: '{}'", e.getMessage());
}
});
PluginState pluginState = ofNullable(pluginManager.getPlugin(previousPlugin.getPluginId())).map(loadedPlugin -> {
if (previousPlugin.getDescriptor().getVersion().equals(loadedPlugin.getDescriptor().getVersion())) {
return loadedPlugin.getPluginState();
} else {
pluginManager.deletePlugin(loadedPlugin.getPluginId());
deletePluginResources(String.valueOf(Paths.get(resourcesDir, loadedPlugin.getPluginId())));
return PluginState.DISABLED;
}
}).orElse(PluginState.DISABLED);
if (pluginState != PluginState.STARTED) {
try {
Path oldPluginPath = previousPlugin.getPluginPath();
PluginInfo oldPluginInfo = pluginLoader.extractPluginInfo(oldPluginPath);
String oldPluginFileName = generatePluginFileName(oldPluginInfo, oldPluginPath.toFile().getName());
try (InputStream fileStream = Files.newInputStream(oldPluginPath)) {
pluginLoader.saveToDataStore(oldPluginFileName, fileStream);
} catch (Exception e) {
throw new ReportPortalException(ErrorType.PLUGIN_UPLOAD_ERROR, Suppliers.formattedSupplier("Unable to upload old plugin file = '{}' to the data store", oldPluginFileName).get());
}
copyPluginResources(oldPluginPath, previousPlugin.getPluginId());
return startUpPlugin(ofNullable(pluginManager.loadPlugin(oldPluginPath)).orElseThrow(() -> new ReportPortalException(ErrorType.PLUGIN_UPLOAD_ERROR, Suppliers.formattedSupplier("Unable to reload previousPlugin with id = '{}': '{}'", previousPlugin.getPluginId()).get())));
} catch (PluginException e) {
throw new ReportPortalException(ErrorType.PLUGIN_UPLOAD_ERROR, Suppliers.formattedSupplier("Unable to reload previousPlugin with id = '{}': '{}'", previousPlugin.getPluginId(), e.getMessage()).get());
}
}
return PluginState.STARTED;
}
16
Source : SpringExtensionFactory.java
with Apache License 2.0
from hank-cp
with Apache License 2.0
from hank-cp
private GenericApplicationContext getApplicationContext(Clreplaced<?> extensionClreplaced) {
PluginWrapper pluginWrapper = pluginManager.whichPlugin(extensionClreplaced);
SpringBootPlugin plugin = (SpringBootPlugin) pluginWrapper.getPlugin();
return plugin.getApplicationContext();
}
16
Source : MeshPluginFactory.java
with Apache License 2.0
from gentics
with Apache License 2.0
from gentics
/**
* Creates a plugin instance. If an error occurs than that error is logged and the method returns null.
*
* @param pluginWrapper
* @return
*/
@Override
public Plugin create(final PluginWrapper pluginWrapper) {
String pluginClreplacedName = pluginWrapper.getDescriptor().getPluginClreplaced();
log.debug("Create instance for plugin '{}'", pluginClreplacedName);
Clreplaced<?> pluginClreplaced;
try {
pluginClreplaced = pluginWrapper.getPluginClreplacedLoader().loadClreplaced(pluginClreplacedName);
} catch (ClreplacedNotFoundException e) {
log.error(e.getMessage(), e);
return null;
}
// once we have the clreplaced, we can do some checks on it to ensure
// that it is a valid implementation of a plugin.
int modifiers = pluginClreplaced.getModifiers();
if (Modifier.isAbstract(modifiers) || Modifier.isInterface(modifiers) || (!MeshPlugin.clreplaced.isreplacedignableFrom(pluginClreplaced))) {
log.error("The plugin clreplaced '{}' is not a valid mesh plugin.", pluginClreplacedName);
return null;
}
// create the plugin instance
try {
Constructor<?> constructor = pluginClreplaced.getConstructor(new Clreplaced[] { PluginWrapper.clreplaced, PluginEnvironment.clreplaced });
return (Plugin) constructor.newInstance(pluginWrapper, pluginEnv);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return null;
}
16
Source : PermissionPluginFactory.java
with GNU General Public License v3.0
from EXXETA
with GNU General Public License v3.0
from EXXETA
@Override
public Plugin create(PluginWrapper pluginWrapper) {
Plugin plugin = super.create(pluginWrapper);
if (plugin instanceof PermissionPlugin) {
addPluginPermissions(pluginWrapper.getPluginId(), (PermissionPlugin) plugin);
}
return plugin;
}
15
Source : Pf4jPluginManagerTest.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
/**
* @author <a href="mailto:[email protected]">Ivan Budayeu</a>
*/
clreplaced Pf4jPluginManagerTest {
public static final String PLUGINS_PATH = "plugins";
public static final String RESOURCES_PATH = "resources";
public static final String PLUGINS_TEMP_PATH = "plugins/temp";
public static final String NEW_PLUGIN_FILE_NAME = "plugin.jar";
public static final String NEW_JIRA_PLUGIN_ID = "new_jira";
public static final String NEW_JIRA_PLUGIN_VERSION = "1.0";
private final PluginLoader pluginLoader = mock(PluginLoader.clreplaced);
private final IntegrationTypeRepository integrationTypeRepository = mock(IntegrationTypeRepository.clreplaced);
private final AutowireCapableBeanFactory beanFactory = mock(AutowireCapableBeanFactory.clreplaced);
private final PluginManager pluginManager = mock(PluginManager.clreplaced);
private final PluginWrapper previousPlugin = mock(PluginWrapper.clreplaced);
private final PluginWrapper newPlugin = mock(PluginWrapper.clreplaced);
private final ApplicationEventPublisher applicationEventPublisher = mock(ApplicationEventPublisher.clreplaced);
private final Pf4jPluginManager pluginBox = new Pf4jPluginManager(PLUGINS_PATH, PLUGINS_TEMP_PATH, RESOURCES_PATH, pluginLoader, integrationTypeRepository, pluginManager, beanFactory, applicationEventPublisher);
private final InputStream fileStream = mock(InputStream.clreplaced);
Pf4jPluginManagerTest() throws IOException {
}
@AfterEach
void cleanUp() throws IOException {
File directory = new File("plugins");
if (directory.exists()) {
FileUtils.deleteDirectory(directory);
}
}
@Test
void uploadPlugin() throws PluginException, IOException {
PluginInfo pluginInfo = getPluginInfo();
when(pluginLoader.extractPluginInfo(Paths.get(PLUGINS_TEMP_PATH, NEW_PLUGIN_FILE_NAME))).thenReturn(pluginInfo);
IntegrationType jiraIntegrationType = IntegrationTestUtil.getJiraIntegrationType();
IntegrationTypeDetails jiraDetails = jiraIntegrationType.getDetails();
when(pluginLoader.resolvePluginDetails(pluginInfo)).thenReturn(jiraDetails);
when(pluginManager.getPlugin("old_jira")).then((i) -> {
pluginInfo.setId(NEW_JIRA_PLUGIN_ID);
return null;
});
when(pluginManager.loadPlugin(Paths.get(PLUGINS_TEMP_PATH, NEW_PLUGIN_FILE_NAME))).thenReturn(NEW_JIRA_PLUGIN_ID);
when(pluginManager.getPlugin(NEW_JIRA_PLUGIN_ID)).thenReturn(newPlugin);
when(pluginManager.getPluginsRoot()).thenReturn(FileSystems.getDefault().getPath(PLUGINS_PATH));
when(pluginLoader.validatePluginExtensionClreplacedes(newPlugin)).thenReturn(true);
doNothing().when(pluginLoader).savePlugin(Paths.get(PLUGINS_PATH, NEW_PLUGIN_FILE_NAME), fileStream);
String pluginFileName = NEW_JIRA_PLUGIN_ID + "-" + NEW_JIRA_PLUGIN_VERSION + ".jar";
when(pluginLoader.saveToDataStore(pluginFileName, fileStream)).thenReturn(pluginFileName);
when(pluginManager.loadPlugin(Paths.get(PLUGINS_PATH, pluginFileName))).thenReturn(NEW_JIRA_PLUGIN_ID);
when(integrationTypeRepository.save(any(IntegrationType.clreplaced))).thenReturn(jiraIntegrationType);
Files.createFile(Paths.get(PLUGINS_TEMP_PATH, "plugin.jar"));
IntegrationType newIntegrationType = pluginBox.uploadPlugin(NEW_PLUGIN_FILE_NAME, fileStream);
replacedertEquals(1L, newIntegrationType.getId().longValue());
}
@Test
void uploadPluginWithExistingFile() throws PluginException, IOException {
File tempFile = File.createTempFile(NEW_PLUGIN_FILE_NAME, ".jar", new File(PLUGINS_TEMP_PATH));
tempFile.deleteOnExit();
PluginInfo pluginInfo = getPluginInfo();
when(pluginLoader.extractPluginInfo(Paths.get(PLUGINS_TEMP_PATH, tempFile.getName()))).thenReturn(pluginInfo);
IntegrationType jiraIntegrationType = IntegrationTestUtil.getJiraIntegrationType();
IntegrationTypeDetails jiraDetails = jiraIntegrationType.getDetails();
when(pluginLoader.resolvePluginDetails(pluginInfo)).thenReturn(jiraDetails);
when(pluginManager.getPlugin("old_jira")).then((i) -> {
pluginInfo.setId(NEW_JIRA_PLUGIN_ID);
return null;
});
when(pluginManager.loadPlugin(Paths.get(PLUGINS_TEMP_PATH, tempFile.getName()))).thenReturn(NEW_JIRA_PLUGIN_ID);
when(pluginManager.getPlugin(NEW_JIRA_PLUGIN_ID)).thenReturn(newPlugin);
when(pluginManager.getPluginsRoot()).thenReturn(FileSystems.getDefault().getPath(PLUGINS_PATH));
when(pluginLoader.validatePluginExtensionClreplacedes(newPlugin)).thenReturn(true);
String pluginFileName = NEW_JIRA_PLUGIN_ID + "-" + NEW_JIRA_PLUGIN_VERSION + ".jar";
when(pluginManager.loadPlugin(Paths.get(PLUGINS_PATH, pluginFileName))).thenReturn(NEW_JIRA_PLUGIN_ID);
when(integrationTypeRepository.save(any(IntegrationType.clreplaced))).thenReturn(jiraIntegrationType);
IntegrationType newIntegrationType = pluginBox.uploadPlugin(tempFile.getName(), fileStream);
replacedertEquals(1L, newIntegrationType.getId().longValue());
}
@Test
void uploadPluginWithLoadingError() throws PluginException {
PluginInfo pluginInfo = getPluginInfo();
when(pluginLoader.extractPluginInfo(Paths.get(PLUGINS_TEMP_PATH, NEW_PLUGIN_FILE_NAME))).thenReturn(pluginInfo);
IntegrationType jiraIntegrationType = IntegrationTestUtil.getJiraIntegrationType();
IntegrationTypeDetails jiraDetails = jiraIntegrationType.getDetails();
when(pluginLoader.resolvePluginDetails(pluginInfo)).thenReturn(jiraDetails);
when(pluginManager.getPlugin("old_jira")).then((i) -> {
pluginInfo.setId(NEW_JIRA_PLUGIN_ID);
return null;
});
when(previousPlugin.getPluginState()).thenReturn(PluginState.STARTED);
when(pluginManager.getPluginsRoot()).thenReturn(FileSystems.getDefault().getPath(PLUGINS_PATH));
when(pluginManager.loadPlugin(Paths.get(PLUGINS_TEMP_PATH, NEW_PLUGIN_FILE_NAME))).thenReturn(null);
final ReportPortalException exception = replacedertThrows(ReportPortalException.clreplaced, () -> pluginBox.uploadPlugin(NEW_PLUGIN_FILE_NAME, fileStream));
replacedertEquals("Error during plugin uploading: 'Failed to load new plugin from file = 'plugin.jar''", exception.getMessage());
}
@Test
void uploadPluginWithoutExtensionClreplacedes() throws PluginException {
PluginInfo pluginInfo = getPluginInfo();
when(pluginLoader.extractPluginInfo(Paths.get(PLUGINS_TEMP_PATH, NEW_PLUGIN_FILE_NAME))).thenReturn(pluginInfo);
IntegrationType jiraIntegrationType = IntegrationTestUtil.getJiraIntegrationType();
IntegrationTypeDetails jiraDetails = jiraIntegrationType.getDetails();
when(pluginLoader.resolvePluginDetails(pluginInfo)).thenReturn(jiraDetails);
when(pluginManager.getPlugin("old_jira")).then((i) -> {
pluginInfo.setId(NEW_JIRA_PLUGIN_ID);
return null;
});
when(pluginManager.loadPlugin(Paths.get(PLUGINS_TEMP_PATH, NEW_PLUGIN_FILE_NAME))).thenReturn(NEW_JIRA_PLUGIN_ID);
when(pluginManager.getPlugin(NEW_JIRA_PLUGIN_ID)).thenReturn(newPlugin);
when(pluginManager.getPluginsRoot()).thenReturn(FileSystems.getDefault().getPath(PLUGINS_PATH));
final ReportPortalException exception = replacedertThrows(ReportPortalException.clreplaced, () -> pluginBox.uploadPlugin(NEW_PLUGIN_FILE_NAME, fileStream));
replacedertEquals("Error during plugin uploading: 'New plugin with id = 'new_jira' doesn't have mandatory extension clreplacedes.'", exception.getMessage());
}
@Test
void uploadPluginWithPluginException() throws PluginException {
when(pluginLoader.extractPluginInfo(Paths.get(PLUGINS_TEMP_PATH, NEW_PLUGIN_FILE_NAME))).thenThrow(new PluginException("Manifest not found"));
final ReportPortalException exception = replacedertThrows(ReportPortalException.clreplaced, () -> pluginBox.uploadPlugin(NEW_PLUGIN_FILE_NAME, fileStream));
replacedertEquals("Error during plugin uploading: 'Manifest not found'", exception.getMessage());
}
@Test
void uploadPluginWithoutVersion() throws PluginException {
when(pluginLoader.extractPluginInfo(Paths.get(PLUGINS_TEMP_PATH, NEW_PLUGIN_FILE_NAME))).thenReturn(getPluginInfoWithoutVersion());
final ReportPortalException exception = replacedertThrows(ReportPortalException.clreplaced, () -> pluginBox.uploadPlugin(NEW_PLUGIN_FILE_NAME, fileStream));
replacedertEquals("Error during plugin uploading: 'Plugin version should be specified.'", exception.getMessage());
}
@Test
void getPlugins() {
when(pluginManager.getPlugins()).thenReturn(Lists.newArrayList(newPlugin));
when(newPlugin.getPluginId()).thenReturn(NEW_JIRA_PLUGIN_ID);
when(pluginManager.getExtensionClreplacedes(NEW_JIRA_PLUGIN_ID)).thenReturn(Lists.newArrayList(BtsExtension.clreplaced));
List<Plugin> plugins = pluginBox.getPlugins();
replacedertNotNull(plugins);
replacedertEquals(1L, plugins.size());
}
private PluginInfo getPluginInfo() {
return new PluginInfo("old_jira", NEW_JIRA_PLUGIN_VERSION);
}
private PluginInfo getPluginInfoWithoutVersion() {
return new PluginInfo("jira", null);
}
}
15
Source : LoadPluginsJobTest.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
/**
* @author <a href="mailto:[email protected]">Ivan Budayeu</a>
*/
clreplaced LoadPluginsJobTest {
private IntegrationTypeRepository integrationTypeRepository = mock(IntegrationTypeRepository.clreplaced);
private PluginLoaderService pluginLoaderService = mock(PluginLoaderService.clreplaced);
private String pluginsRootPath = "plugins";
private Pf4jPluginBox pluginBox = mock(Pf4jPluginBox.clreplaced);
private DataStore dataStore = mock(DataStore.clreplaced);
private PluginWrapper rallyPlugin = mock(PluginWrapper.clreplaced);
private IntegrationType rally = mock(IntegrationType.clreplaced);
private LoadPluginsJob loadPluginsJob = new LoadPluginsJob(pluginsRootPath, integrationTypeRepository, pluginLoaderService, pluginBox, dataStore);
@AfterAll
public static void clearPluginDirectory() throws IOException {
FileUtils.deleteDirectory(new File(System.getProperty("user.dir") + "/plugins"));
}
@Test
void loadDisabledPluginTest() throws IOException {
List<IntegrationType> integrationTypes = getIntegrationTypes();
when(integrationTypeRepository.findAll()).thenReturn(integrationTypes);
List<PluginInfo> pluginInfos = getPluginInfos();
File tempFile = File.createTempFile("file", ".jar");
tempFile.deleteOnExit();
when(dataStore.load(any(String.clreplaced))).thenReturn(new FileInputStream(tempFile));
when(pluginBox.loadPlugin(any(String.clreplaced), any(IntegrationTypeDetails.clreplaced))).thenReturn(true);
when(pluginLoaderService.getNotLoadedPluginsInfo()).thenReturn(pluginInfos);
when(pluginBox.getPluginById(any(String.clreplaced))).thenReturn(java.util.Optional.ofNullable(rallyPlugin));
when(rallyPlugin.getPluginId()).thenReturn("rally");
when(integrationTypeRepository.findByName(any(String.clreplaced))).thenReturn(java.util.Optional.ofNullable(rally));
when(pluginBox.unloadPlugin(rally)).thenReturn(true);
loadPluginsJob.execute();
}
private List<IntegrationType> getIntegrationTypes() {
IntegrationType jira = new IntegrationType();
jira.setName("jira");
IntegrationType rally = new IntegrationType();
rally.setName("rally");
return Lists.newArrayList(jira, rally);
}
private List<PluginInfo> getPluginInfos() {
return Lists.newArrayList(new PluginInfo("jira", "v1.0", "file Id", "jira file", true), new PluginInfo("rally", "v2.0", "file Id", "rally file", false));
}
}
15
Source : UpdatePluginHandlerTest.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
/**
* @author <a href="mailto:[email protected]">Ivan Budayeu</a>
*/
clreplaced UpdatePluginHandlerTest {
private static final String FILE_NAME = "file-name";
private final Pf4jPluginBox pluginBox = mock(Pf4jPluginBox.clreplaced);
private final IntegrationTypeRepository integrationTypeRepository = mock(IntegrationTypeRepository.clreplaced);
private final DataStore dataStore = mock(DataStore.clreplaced);
private PluginWrapper pluginWrapper = mock(PluginWrapper.clreplaced);
private final UpdatePluginHandler updatePluginHandler = new UpdatePluginHandlerImpl(pluginBox, integrationTypeRepository);
@AfterAll
static void clearPluginDirectory() throws IOException {
FileUtils.deleteDirectory(new File(System.getProperty("user.dir") + "/plugins"));
}
@Test
void shouldNotUpdatePluginIntegrationWhenNotExistsById() {
UpdatePluginStateRQ updatePluginStateRQ = new UpdatePluginStateRQ();
updatePluginStateRQ.setEnabled(true);
when(integrationTypeRepository.findById(1L)).thenReturn(Optional.empty());
final ReportPortalException exception = replacedertThrows(ReportPortalException.clreplaced, () -> updatePluginHandler.updatePluginState(1L, updatePluginStateRQ));
replacedertEquals(Suppliers.formattedSupplier("Impossible interact with integration. Integration type with id - '{}' not found.", 1L).get(), exception.getMessage());
}
@Test
void shouldUpdateNotPluginIntegrationWhenExists() {
UpdatePluginStateRQ updatePluginStateRQ = new UpdatePluginStateRQ();
updatePluginStateRQ.setEnabled(true);
IntegrationType emailIntegrationType = IntegrationTestUtil.getEmailIntegrationType();
when(integrationTypeRepository.findById(1L)).thenReturn(Optional.of(emailIntegrationType));
OperationCompletionRS operationCompletionRS = updatePluginHandler.updatePluginState(1L, updatePluginStateRQ);
replacedertions.replacedertEquals(Suppliers.formattedSupplier("Enabled state of the plugin with id = '{}' has been switched to - '{}'", emailIntegrationType.getName(), updatePluginStateRQ.getEnabled()).get(), operationCompletionRS.getResultMessage());
}
@Test
void shouldUnloadPluginWhenDisabledAndIsPresent() {
UpdatePluginStateRQ updatePluginStateRQ = new UpdatePluginStateRQ();
updatePluginStateRQ.setEnabled(false);
IntegrationType jiraIntegrationType = IntegrationTestUtil.getJiraIntegrationType();
when(integrationTypeRepository.findById(1L)).thenReturn(Optional.of(jiraIntegrationType));
when(pluginBox.getPluginById(jiraIntegrationType.getName())).thenReturn(Optional.ofNullable(pluginWrapper));
when(pluginWrapper.getPluginId()).thenReturn(jiraIntegrationType.getName());
when(pluginBox.unloadPlugin(jiraIntegrationType)).thenReturn(true);
OperationCompletionRS operationCompletionRS = updatePluginHandler.updatePluginState(1L, updatePluginStateRQ);
replacedertions.replacedertEquals(Suppliers.formattedSupplier("Enabled state of the plugin with id = '{}' has been switched to - '{}'", jiraIntegrationType.getName(), updatePluginStateRQ.getEnabled()).get(), operationCompletionRS.getResultMessage());
}
@Test
void shouldThrowWhenNotUnloaded() {
UpdatePluginStateRQ updatePluginStateRQ = new UpdatePluginStateRQ();
updatePluginStateRQ.setEnabled(false);
IntegrationType jiraIntegrationType = IntegrationTestUtil.getJiraIntegrationType();
when(integrationTypeRepository.findById(1L)).thenReturn(Optional.of(jiraIntegrationType));
when(pluginBox.getPluginById(jiraIntegrationType.getName())).thenReturn(Optional.ofNullable(pluginWrapper));
when(pluginWrapper.getPluginId()).thenReturn(jiraIntegrationType.getName());
when(pluginBox.unloadPlugin(jiraIntegrationType)).thenReturn(false);
final ReportPortalException exception = replacedertThrows(ReportPortalException.clreplaced, () -> updatePluginHandler.updatePluginState(1L, updatePluginStateRQ));
replacedertEquals(Suppliers.formattedSupplier("Impossible interact with integration. Error during unloading the plugin with id = '{}'", jiraIntegrationType.getName()).get(), exception.getMessage());
}
@Test
void shouldNotUpdatePluginIntegrationWhenReportPortalIntegrationNotExists() {
UpdatePluginStateRQ updatePluginStateRQ = new UpdatePluginStateRQ();
updatePluginStateRQ.setEnabled(true);
IntegrationType emailIntegrationType = IntegrationTestUtil.getEmailIntegrationType();
final String wrongIntegrationTypeName = "QWEQWE";
emailIntegrationType.setName(wrongIntegrationTypeName);
when(integrationTypeRepository.findById(1L)).thenReturn(Optional.of(emailIntegrationType));
final ReportPortalException exception = replacedertThrows(ReportPortalException.clreplaced, () -> updatePluginHandler.updatePluginState(1L, updatePluginStateRQ));
replacedertEquals(Suppliers.formattedSupplier("Impossible interact with integration. Error during loading the plugin with id = 'QWEQWE'", wrongIntegrationTypeName).get(), exception.getMessage());
}
@Test
void shouldLoadPluginWhenEnabledAndIsNotPresent() throws IOException {
UpdatePluginStateRQ updatePluginStateRQ = new UpdatePluginStateRQ();
updatePluginStateRQ.setEnabled(true);
IntegrationType jiraIntegrationType = IntegrationTestUtil.getJiraIntegrationType();
jiraIntegrationType.getDetails().setDetails(getCorrectJiraIntegrationDetailsParams());
when(integrationTypeRepository.findById(1L)).thenReturn(ofNullable(jiraIntegrationType));
when(pluginBox.getPluginById(jiraIntegrationType.getName())).thenReturn(Optional.empty());
File tempFile = File.createTempFile("qwe", "txt");
tempFile.deleteOnExit();
when(dataStore.load(any(String.clreplaced))).thenReturn(new FileInputStream(tempFile));
when(pluginBox.loadPlugin(jiraIntegrationType.getName(), jiraIntegrationType.getDetails())).thenReturn(true);
OperationCompletionRS operationCompletionRS = updatePluginHandler.updatePluginState(1L, updatePluginStateRQ);
replacedertions.replacedertEquals(Suppliers.formattedSupplier("Enabled state of the plugin with id = '{}' has been switched to - '{}'", jiraIntegrationType.getName(), updatePluginStateRQ.getEnabled()).get(), operationCompletionRS.getResultMessage());
}
private Map<String, Object> getCorrectJiraIntegrationDetailsParams() {
Map<String, Object> params = new HashMap<>();
params.put(IntegrationTypeProperties.FILE_ID.getAttribute(), "file-id");
params.put(IntegrationTypeProperties.FILE_NAME.getAttribute(), FILE_NAME);
params.put(IntegrationTypeProperties.VERSION.getAttribute(), "1.0.0");
return params;
}
}
15
Source : ReportPortalExtensionFactory.java
with Apache License 2.0
from reportportal
with Apache License 2.0
from reportportal
private Map<String, Object> getInitParams(PluginWrapper pluginWrapper) {
Map<String, Object> initParams = new HashMap<>();
initParams.put(IntegrationTypeProperties.RESOURCES_DIRECTORY.getAttribute(), Paths.get(resourcesDir, pluginWrapper.getPluginId()));
return initParams;
}
15
Source : AuthcPluginTest.java
with Apache License 2.0
from hiwepy
with Apache License 2.0
from hiwepy
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.clreplaced);
for (AuthcExtensionPoint point : extensions) {
ExtensionMapping m = point.getClreplaced().getAnnotation(ExtensionMapping.clreplaced);
System.out.println(m.replacedle());
}
/**
* 调用Plugin实现类的stop()方法
*/
pluginManager.stopPlugins();
System.out.println("=============");
}
15
Source : PluginTypeProvider.java
with Apache License 2.0
from gentics
with Apache License 2.0
from gentics
public GraphQLFieldDefinition createPluginField() {
return newFieldDefinition().name("plugin").description("Load plugin by id").argument(createIdArg("Id of the plugin.")).type(new GraphQLTypeReference(PLUGIN_TYPE_NAME)).dataFetcher(env -> {
GraphQLContext gc = env.getContext();
if (!gc.getUser().isAdmin()) {
return new PermissionException("plugins", "Missing admin permission");
}
String id = env.getArgument("id");
if (id == null) {
return null;
}
PluginWrapper pluginWrapper = manager.getPlugin(id);
if (pluginWrapper == null) {
return null;
}
Plugin p = pluginWrapper.getPlugin();
if (p instanceof MeshPlugin) {
return p;
} else {
log.warn("The found plugin is not a Gentics Mesh Plugin");
}
return null;
}).build();
}
14
Source : PluginResourceResolver.java
with Apache License 2.0
from hank-cp
with Apache License 2.0
from hank-cp
@Override
protected Resource getResource(String resourcePath, Resource location) throws IOException {
if (!(location instanceof ClreplacedPathResource))
return null;
ClreplacedPathResource clreplacedPathLocation = (ClreplacedPathResource) location;
// pluginManager might not be autowired correctly because resolve bean
// is instantiated before PluginManager.
if (pluginManager == null) {
pluginManager = ApplicationContextProvider.getBean(PluginManager.clreplaced);
}
for (PluginWrapper plugin : pluginManager.getPlugins(PluginState.STARTED)) {
Resource pluginLocation = new ClreplacedPathResource(clreplacedPathLocation.getPath(), plugin.getPluginClreplacedLoader());
Resource resource = pluginLocation.createRelative(resourcePath);
if (resource.isReadable()) {
if (checkResource(resource, pluginLocation)) {
return resource;
} else if (logger.isWarnEnabled()) {
Resource[] allowedLocations = getAllowedLocations();
logger.warn("Resource path \"" + resourcePath + "\" was successfully resolved " + "but resource \"" + resource.getURL() + "\" is neither under the " + "current location \"" + location.getURL() + "\" nor under any of the " + "allowed locations " + (allowedLocations != null ? Arrays.asList(allowedLocations) : "[]"));
}
}
}
return super.getResource(resourcePath, location);
}
14
Source : PluginHandler.java
with Apache License 2.0
from gentics
with Apache License 2.0
from gentics
/**
* Handle a plugin deployment request.
*
* @param ac
*/
public void handleDeploy(InternalActionContext ac) {
utils.syncTx(ac, tx -> {
if (!ac.getUser().isAdmin()) {
throw error(FORBIDDEN, "error_admin_permission_required");
}
PluginDeploymentRequest requestModel = JsonUtil.readValue(ac.getBodyreplacedtring(), PluginDeploymentRequest.clreplaced);
String path = requestModel.getPath();
return manager.deploy(path).map(pluginId -> {
log.debug("Deployed plugin with deployment name {" + path + "} - Id {" + pluginId + "}");
PluginWrapper pluginWrapper = manager.getPlugin(pluginId);
if (pluginWrapper == null) {
log.error("The plugin was deployed but it could not be found by the manager. It seems that the plugin registration failed.");
throw error(NOT_FOUND, "admin_plugin_error_plugin_not_found", pluginId);
}
Plugin plugin = pluginWrapper.getPlugin();
if (plugin instanceof MeshPlugin) {
MeshPlugin meshPlugin = (MeshPlugin) plugin;
return manager.toResponse(meshPlugin);
}
throw error(INTERNAL_SERVER_ERROR, "admin_plugin_error_wrong_type");
}).blockingGet();
}, model -> ac.send(model, CREATED));
}
13
Source : DefaultPluginFactory.java
with Apache License 2.0
from starblues-zhuo
with Apache License 2.0
from starblues-zhuo
@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();
}
}
See More Examples