Make findPlugins return plugin name

Required to let users enable them by hand.
This commit is contained in:
TheAssassin
2018-06-19 22:47:01 +02:00
parent 6c6b43a1ce
commit 2a769ac3d9
3 changed files with 21 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
// system includes
#include <set>
#include <map>
#include <string>
// library includes
@@ -66,6 +66,6 @@ namespace linuxdeploy {
/*
* Finds all linuxdeploy plugins in $PATH and the current executable's directory and returns IPlugin instances for them.
*/
std::vector<IPlugin*> findPlugins();
std::map<std::string, IPlugin*> findPlugins();
}
}

View File

@@ -36,8 +36,8 @@ namespace linuxdeploy {
return rv;
}
std::vector<IPlugin*> findPlugins() {
std::vector<IPlugin*> foundPlugins;
std::map<std::string, IPlugin*> findPlugins() {
std::map<std::string, IPlugin*> foundPlugins;
const auto PATH = getenv("PATH");
@@ -53,11 +53,13 @@ namespace linuxdeploy {
// file must be executable...
if (bf::status(*i).permissions() & (bf::owner_exe | bf::group_exe | bf::others_exe)) {
// ... and filename must match regular expression
if (boost::regex_match((*i).path().filename().string(), expr)) {
boost::cmatch res;
if (boost::regex_match((*i).path().filename().string().c_str(), res, expr)) {
try {
auto name = res[1].str();
auto* plugin = createPluginInstance(*i);
ldLog() << LD_DEBUG << "Found plugin:" << plugin->path() << std::endl;
foundPlugins.push_back(plugin);
ldLog() << LD_DEBUG << "Found plugin '" << LD_NO_SPACE << name << LD_NO_SPACE << "':" << plugin->path() << std::endl;
foundPlugins[name] = plugin;
} catch (const PluginError& e) {
ldLog() << LD_WARNING << "Could not load plugin" << (*i).path() << LD_NO_SPACE << ": " << e.what();
}

View File

@@ -1,5 +1,5 @@
#include <iostream>
#include <boost/filesystem.hpp>
#include <linuxdeploy/plugin/plugin.h>
namespace bf = boost::filesystem;
@@ -9,20 +9,24 @@ int main(const int argc, const char* const* const argv) {
if (argc > 1) {
for (int i = 1; i < argc; i++) {
const std::string path = argv[1];
const bf::path path = argv[1];
auto* plugin = linuxdeploy::plugin::createPluginInstance(path);
plugins.push_back(plugin);
plugins[path.filename().string()] = plugin;
}
}
for (const auto& plugin : plugins) {
std::cout << "Testing plugin: " << plugin->path().string() << std::endl;
std::vector<std::pair<std::string, linuxdeploy::plugin::IPlugin*>> pluginList;
for (const auto& plugin : plugins)
pluginList.push_back(plugin);
std::cout << "API level: " << plugin->apiLevel() << std::endl;
std::cout << "Plugin type: " << plugin->pluginType() << " (a.k.a. " << plugin->pluginTypeString() << ")"
for (const auto& plugin : pluginList) {
std::cout << "Testing plugin '" << plugin.first << "': " << plugin.second->path().string() << std::endl;
std::cout << "API level: " << plugin.second->apiLevel() << std::endl;
std::cout << "Plugin type: " << plugin.second->pluginType() << " (a.k.a. " << plugin.second->pluginTypeString() << ")"
<< std::endl;
if (plugin != plugins.back())
if (plugin != pluginList.back())
std::cout << std::endl;
}