Commit 2ca62f1f authored by Romain Courteaud's avatar Romain Courteaud

erp5_gadget_interface_validator: stop relying on appcache

Use the precache script to get the list of gadgets.
Ensure to also check the launcher gadget.

Report subgadget service error.
parent 5471b5bb
......@@ -257,8 +257,7 @@
// XXX Load in an iframe
return context.declareGadget('gadget_interface_loader.html', {
scope: gadget_to_check_url,
element: element,
sandbox: 'iframe'
element: element
});
})
.push(function (result) {
......@@ -356,118 +355,139 @@
return this.changeState(options);
})
.onStateChange(function () {
.onStateChange(function (modification_dict) {
var context = this,
required_interface_list = [],
gadget_method_list = [],
error_list = [];
return getOrDeclareGadget(context, context.state.gadget_to_check_url)
.push(function (gadget_to_check) {
// Get the list of interfaces/methods
return RSVP.all([
gadget_to_check.getGadgetToCheckInterfaceList(),
gadget_to_check.getGadgetToCheckMethodList('method')
]);
})
.push(function (result_list) {
required_interface_list = result_list[0];
gadget_method_list = result_list[1];
}, function (error) {
error_list.push({
details: "Error with gadget loading\n" + (error.message || '')
if (modification_dict.hasOwnProperty('gadget_to_check_url')) {
return getOrDeclareGadget(context, context.state.gadget_to_check_url)
/*
.push(undefined, function (error) {
console.warn('oups', error);
context.element.innerHTML = '';
return;
});
})
.push(function () {
// Get all methods definition for every interface
var promise_list = [],
i;
for (i = 0; i < required_interface_list.length; i += 1) {
promise_list.push(
getDefinedInterfaceMethodList(required_interface_list[i],
error_list)
);
}
return RSVP.all(promise_list);
})
.push(function (method_table) {
var interface_method_list = [],
i,
j,
promise_list = [];
for (i = 0; i < method_table.length; i += 1) {
for (j = 0; j < method_table[i].length; j += 1) {
// Check method declared twice
if (interface_method_list.indexOf(method_table[i][j].name) >= 0) {
*/
.push(function (gadget_to_check) {
// Get the list of interfaces/methods
return RSVP.all([
gadget_to_check.getGadgetToCheckInterfaceList(),
gadget_to_check.getGadgetToCheckMethodList('method')
]);
})
.push(function (result_list) {
required_interface_list = result_list[0];
gadget_method_list = result_list[1];
}, function (error) {
error_list.push({
details: "Error with gadget loading\n" + (error.message || '')
});
})
.push(function () {
// Get all methods definition for every interface
var promise_list = [],
i;
for (i = 0; i < required_interface_list.length; i += 1) {
promise_list.push(
getDefinedInterfaceMethodList(required_interface_list[i],
error_list)
);
}
return RSVP.all(promise_list);
})
.push(function (method_table) {
var interface_method_list = [],
i,
j,
promise_list = [];
for (i = 0; i < method_table.length; i += 1) {
for (j = 0; j < method_table[i].length; j += 1) {
// Check method declared twice
if (interface_method_list.indexOf(method_table[i][j].name) >=
0) {
error_list.push({
details: "Method documented in multiple interface\n" +
method_table[i][j].name
});
} else {
interface_method_list.push(method_table[i][j].name);
}
}
}
// Check unknown method declaration
for (i = 0; i < gadget_method_list.length; i += 1) {
if (interface_method_list.indexOf(
gadget_method_list[i]
) < 0) {
error_list.push({
details: "Method documented in multiple interface\n" +
method_table[i][j].name
details: "Method not documented in the interface\n" +
gadget_method_list[i]
});
} else {
interface_method_list.push(method_table[i][j].name);
}
}
}
// Check unknown method declaration
for (i = 0; i < gadget_method_list.length; i += 1) {
if (interface_method_list.indexOf(
gadget_method_list[i]
) < 0) {
error_list.push({
details: "Method not documented in the interface\n" +
gadget_method_list[i]
});
// Check that all interfaces are implemented
for (i = 0; i < required_interface_list.length; i += 1) {
promise_list.push(
verifyAllMethodDeclared(method_table[i], gadget_method_list,
error_list)
);
}
}
return RSVP.all(promise_list);
// Check that all interfaces are implemented
for (i = 0; i < required_interface_list.length; i += 1) {
promise_list.push(
verifyAllMethodDeclared(method_table[i], gadget_method_list,
error_list)
);
}
return RSVP.all(promise_list);
})
.push(function () {
// Display result
var i,
error_message = '',
summary_message;
if (error_list.length === 0) {
summary_message = 'Success';
} else {
summary_message = 'Failure';
}
for (i = 0; i < error_list.length; i += 1) {
error_message += (error_list[i].details + '\n\n');
}
if (context.state.summary) {
if (error_message !== '') {
console.warn(error_message, error_list);
})
.push(function () {
// Display result
var i,
error_message = '',
summary_message;
if (error_list.length === 0) {
summary_message = 'Success';
} else {
summary_message = 'Failure';
}
error_message = summary_message;
} else {
error_message = summary_message + '\n\n' + error_message;
}
context.element.firstElementChild.textContent = error_message;
})
.push(undefined, function (error) {
console.warn(error);
context.element.firstElementChild.textContent =
"Unexpected error";
});
for (i = 0; i < error_list.length; i += 1) {
error_message += (error_list[i].details + '\n\n');
}
if (context.state.summary) {
if (error_message !== '') {
console.warn(error_message, error_list);
}
error_message = summary_message;
} else {
error_message = summary_message + '\n\n' + error_message;
}
context.element.firstElementChild.textContent = error_message;
})
.push(undefined, function (error) {
console.warn(error);
context.element.firstElementChild.textContent =
"Unexpected error: " + error;
});
}
if (modification_dict.hasOwnProperty('error')) {
console.warn(context.state.error);
context.element.firstElementChild.textContent =
"Unexpected error: " + context.state.error;
}
})
.allowPublicAcquisition('reportServiceError', function (param_list) {
// Subgadget services failed.
// Report it as an error instead of crashing the page
return this.changeState({error: param_list[0]});
});
}(window, rJS, RSVP, DOMParser, jIO, console, document));
\ No newline at end of file
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
/*global rJS, window*/
(function (window, rJS) {
/*global rJS, window, document*/
(function (window, rJS, document) {
"use strict";
rJS(window)
.declareMethod("declareGadgetToCheck", function (url) {
return this.declareGadget(url, {
scope: 'gadget_to_check'
var div = document.createElement('div'),
gadget = this;
this.element.innerHTML = '';
this.element.appendChild(div);
return gadget.declareGadget(url, {
scope: 'gadget_to_check',
sandbox: 'iframe',
element: div
})
.push(function () {
// Do not return the loaded gadget.
......@@ -29,4 +35,4 @@
});
});
}(window, rJS));
\ No newline at end of file
}(window, rJS, document));
\ No newline at end of file
/*global window, rJS, RSVP, jIO, QueryFactory, SimpleQuery */
/*global window, rJS, RSVP, jIO, QueryFactory, SimpleQuery, URL */
/*jslint indent: 2, maxerr: 3, nomen: true */
(function (window, rJS, RSVP, jIO, QueryFactory, SimpleQuery) {
(function (window, rJS, RSVP, jIO, QueryFactory, SimpleQuery, URL) {
"use strict";
//////////////////////////////////////////////
......@@ -12,16 +12,25 @@
return (new RegExp(suffix + '$', 'i')).test(str);
}
function fetchAppcacheData(appcache_url) {
function fetchPrecacheData(precache_url) {
return new RSVP.Queue()
.push(function () {
return jIO.util.ajax({
url: appcache_url,
dataType: 'text'
url: precache_url,
dataType: 'json'
});
})
.push(function (evt) {
return evt.target.responseText.split('\n');
var key,
precache_dict = evt.target.response,
result_list = [],
precache_absolute_url = (new URL(precache_url, window.location)).href;
for (key in precache_dict) {
if (precache_dict.hasOwnProperty(key)) {
result_list.push((new URL(key, precache_absolute_url)).href);
}
}
return result_list;
});
}
......@@ -32,8 +41,8 @@
var gadget_list = [],
i;
for (i = 0; i < filename_list.length; i += 1) {
if (endsWith(filename_list[i], '.html') &&
(filename_list[i][0] !== '#')) {
if (endsWith(filename_list[i], '.html') ||
endsWith(filename_list[i], '/')) {
gadget_list.push(filename_list[i]);
}
}
......@@ -66,11 +75,11 @@
InterfaceValidatorStorage.prototype.buildQuery = function (options) {
// XXX HARDCODED
var query = QueryFactory.create(options.query || '');
if (!((query instanceof SimpleQuery) && (query.key === 'appcache_url'))) {
if (!((query instanceof SimpleQuery) && (query.key === 'precache_url'))) {
// Only accept simple query with an appcache_url
return [];
}
return fetchAppcacheData(query.value)
return fetchPrecacheData(query.value)
// return fetchAppcacheData('gadget_interface_validator_test.appcache')
.push(function (filename_list) {
return filterGadgetList(filename_list);
......@@ -123,4 +132,4 @@
return wrapJioCall(this, 'get', arguments);
});
}(window, rJS, RSVP, jIO, QueryFactory, SimpleQuery));
\ No newline at end of file
}(window, rJS, RSVP, jIO, QueryFactory, SimpleQuery, URL));
\ No newline at end of file
......@@ -93,7 +93,7 @@
"list_method": "portal_catalog",
"query": "urn:jio:allDocs",
"portal_type": [],
"search_column_list": [['appcache_url', 'Appcache']],
"search_column_list": [['precache_url', 'Precache']],
"sort_column_list": [],
"sort": [],
"title": "Gadgets",
......
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