Commit 6556859d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

when plugin crash on upload it's removed from the system properly

parent b9e9d3c9
Pipeline #12731 passed with stage
in 12 minutes and 14 seconds
...@@ -8,6 +8,8 @@ minerva (14.0.0~alpha.1) unstable; urgency=low ...@@ -8,6 +8,8 @@ minerva (14.0.0~alpha.1) unstable; urgency=low
* Bug fix: some project couldn't be accessed due to problem with migration of * Bug fix: some project couldn't be accessed due to problem with migration of
reaction with unknown boolean operator (#880) reaction with unknown boolean operator (#880)
* Bug fix: problem with unloading plugin is properly handled (#884) * Bug fix: problem with unloading plugin is properly handled (#884)
* Bug fix: upload of invalid plugin doesn't add it to plugin tab and list of
loaded plugins (#885)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 12 Aug 2019 10:00:00 +0200 -- Piotr Gawron <piotr.gawron@uni.lu> Mon, 12 Aug 2019 10:00:00 +0200
......
...@@ -107,6 +107,10 @@ Plugin.prototype.getMinervaPluginProxy = function () { ...@@ -107,6 +107,10 @@ Plugin.prototype.getMinervaPluginProxy = function () {
* @returns {string} * @returns {string}
*/ */
Plugin.prototype.getPluginId = function () { Plugin.prototype.getPluginId = function () {
if (this.getMinervaPluginProxy() === undefined) {
logger.warn("Plugin is not loaded properly");
return undefined;
}
return this.getMinervaPluginProxy().pluginId; return this.getMinervaPluginProxy().pluginId;
}; };
......
...@@ -94,6 +94,7 @@ PluginManager.prototype.addPlugin = function (options) { ...@@ -94,6 +94,7 @@ PluginManager.prototype.addPlugin = function (options) {
map: self.getMap(), map: self.getMap(),
serverConnector: self.getServerConnector() serverConnector: self.getServerConnector()
}); });
self._plugins.push(plugin);
} else { } else {
plugin = new Plugin({ plugin = new Plugin({
url: options.url, url: options.url,
...@@ -105,11 +106,11 @@ PluginManager.prototype.addPlugin = function (options) { ...@@ -105,11 +106,11 @@ PluginManager.prototype.addPlugin = function (options) {
plugin.addListener("onUnload", function () { plugin.addListener("onUnload", function () {
self.getGuiUtils().removeTab(self, element); self.getGuiUtils().removeTab(self, element);
}); });
self._plugins.push(plugin);
if (!self.isValidUrl(options.url)) { if (!self.isValidUrl(options.url)) {
return Promise.reject(new InvalidArgumentError("url: '" + options.url + "' is invalid")); return Promise.reject(new InvalidArgumentError("url: '" + options.url + "' is invalid"));
} }
} }
self._plugins.push(plugin);
return plugin.load(); return plugin.load();
}).then(function () { }).then(function () {
$("a[href='#" + element.parentNode.id + "']", $(self.getElement()))[0].innerHTML = plugin.getName(); $("a[href='#" + element.parentNode.id + "']", $(self.getElement()))[0].innerHTML = plugin.getName();
...@@ -140,7 +141,7 @@ PluginManager.prototype.addPlugin = function (options) { ...@@ -140,7 +141,7 @@ PluginManager.prototype.addPlugin = function (options) {
GuiConnector.setUrlParam("plugins", self._getLoadedPluginsAsHashList()); GuiConnector.setUrlParam("plugins", self._getLoadedPluginsAsHashList());
return plugin; return plugin;
}).catch(function (e) { }).catch(function (e) {
return plugin.unload().then(function () { return self.removePlugin(plugin).then(function () {
GuiConnector.alert("Problem with loading plugin:<br/>" + e.message); GuiConnector.alert("Problem with loading plugin:<br/>" + e.message);
}); });
}); });
......
...@@ -88,10 +88,11 @@ describe('PluginManager', function () { ...@@ -88,10 +88,11 @@ describe('PluginManager', function () {
it('with error', function () { it('with error', function () {
var manager = createPluginManager(); var manager = createPluginManager();
return manager.addPlugin({url: "./invalid.js"}).then(function (plugin) { return manager.addPlugin({url: "./invalid.js"}).then(function () {
assert.notOk("Expected error"); assert.notOk("Expected error");
}).catch(function (e) { }).catch(function (e) {
assert.ok(e.message.indexOf("Problem with loading plugin") >= 0) assert.ok(e.message.indexOf("Problem with loading plugin") >= 0);
assert.equal(0, manager.getPlugins().length);
}); });
}); });
it('with invalid url', function () { it('with invalid url', function () {
...@@ -99,7 +100,7 @@ describe('PluginManager', function () { ...@@ -99,7 +100,7 @@ describe('PluginManager', function () {
manager.isValidUrl = function () { manager.isValidUrl = function () {
return false; return false;
}; };
return manager.addPlugin({url: "xx"}).then(function (plugin) { return manager.addPlugin({url: "xx"}).then(function () {
assert.notOk("Expected error"); assert.notOk("Expected error");
}).catch(function (e) { }).catch(function (e) {
assert.ok(e.message.indexOf("Problem with loading plugin") >= 0) assert.ok(e.message.indexOf("Problem with loading plugin") >= 0)
...@@ -146,7 +147,14 @@ describe('PluginManager', function () { ...@@ -146,7 +147,14 @@ describe('PluginManager', function () {
it('removing non existing plugin', function () { it('removing non existing plugin', function () {
var manager = createPluginManager(); var manager = createPluginManager();
var plugin = new Plugin({url: "testFiles/plugin/empty.js"}); var plugin = new Plugin({
url: "testFiles/plugin/empty.js",
map: manager.getMap(),
configuration: manager.getConfiguration(),
serverConnector: manager.getServerConnector(),
element: testDiv
});
return manager.removePlugin(plugin).then(function () { return manager.removePlugin(plugin).then(function () {
assert.notOk("Error expected"); assert.notOk("Error expected");
}, function (error) { }, function (error) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment