Install preloaded plugins
Change-Id: Ib5695451a77cd047ee05b85da71d2ea895fb59d7
This commit is contained in:
@@ -37,9 +37,10 @@
|
|||||||
const jsPlugins =
|
const jsPlugins =
|
||||||
this._handleMigrations(plugins.js_resource_paths || [], htmlPlugins);
|
this._handleMigrations(plugins.js_resource_paths || [], htmlPlugins);
|
||||||
const defaultTheme = config.default_theme;
|
const defaultTheme = config.default_theme;
|
||||||
const pluginsPending =
|
const pluginsPending = []
|
||||||
[].concat(jsPlugins, htmlPlugins, defaultTheme || []).map(
|
.concat(jsPlugins, htmlPlugins, defaultTheme || [])
|
||||||
p => this._urlFor(p));
|
.filter(p => !Gerrit._isPluginPreloaded(p))
|
||||||
|
.map(p => this._urlFor(p));
|
||||||
Gerrit._setPluginsPending(pluginsPending);
|
Gerrit._setPluginsPending(pluginsPending);
|
||||||
if (defaultTheme) {
|
if (defaultTheme) {
|
||||||
// Make theme first to be first to load.
|
// Make theme first to be first to load.
|
||||||
|
@@ -187,5 +187,21 @@ limitations under the License.
|
|||||||
element.importHref.secondCall.args[2]();
|
element.importHref.secondCall.args[2]();
|
||||||
assert.equal(Gerrit._pluginInstallError.callCount, 2);
|
assert.equal(Gerrit._pluginInstallError.callCount, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('skips preloaded plugins', () => {
|
||||||
|
sandbox.stub(Gerrit, '_isPluginPreloaded')
|
||||||
|
.withArgs('plugins/foo/bar').returns(true)
|
||||||
|
.withArgs('plugins/42').returns(true);
|
||||||
|
sandbox.stub(Gerrit, '_setPluginsCount');
|
||||||
|
sandbox.stub(Gerrit, '_setPluginsPending');
|
||||||
|
element.config = {
|
||||||
|
plugin: {
|
||||||
|
html_resource_paths: ['plugins/foo/bar', 'plugins/baz'],
|
||||||
|
js_resource_paths: ['plugins/42'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
assert.isTrue(
|
||||||
|
Gerrit._setPluginsPending.calledWith([url + '/plugins/baz']));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@@ -412,6 +412,15 @@ limitations under the License.
|
|||||||
element.EventType.ADMIN_MENU_LINKS);
|
element.EventType.ADMIN_MENU_LINKS);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('preloaded plugins are installed', () => {
|
||||||
|
const installStub = sandbox.stub();
|
||||||
|
Gerrit._preloadedPlugins = {foo: installStub};
|
||||||
|
Gerrit._installPreloadedPlugins();
|
||||||
|
assert.isTrue(installStub.called);
|
||||||
|
const pluginApi = installStub.lastCall.args[0];
|
||||||
|
assert.strictEqual(pluginApi.getPluginName(), 'foo');
|
||||||
|
});
|
||||||
|
|
||||||
suite('test plugin with base url', () => {
|
suite('test plugin with base url', () => {
|
||||||
setup(() => {
|
setup(() => {
|
||||||
sandbox.stub(Gerrit.BaseUrlBehavior, 'getBaseUrl').returns('/r');
|
sandbox.stub(Gerrit.BaseUrlBehavior, 'getBaseUrl').returns('/r');
|
||||||
|
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
let _pluginsPendingCount = -1;
|
let _pluginsPendingCount = -1;
|
||||||
|
|
||||||
|
const PRELOADED_PROTOCOL = 'preloaded:';
|
||||||
|
|
||||||
const UNKNOWN_PLUGIN = 'unknown';
|
const UNKNOWN_PLUGIN = 'unknown';
|
||||||
|
|
||||||
const PANEL_ENDPOINTS_MAPPING = {
|
const PANEL_ENDPOINTS_MAPPING = {
|
||||||
@@ -101,6 +103,15 @@
|
|||||||
// http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html
|
// http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJSNI.html
|
||||||
window.$wnd = window;
|
window.$wnd = window;
|
||||||
|
|
||||||
|
function installPreloadedPlugins() {
|
||||||
|
if (!Gerrit._preloadedPlugins) { return; }
|
||||||
|
for (const name in Gerrit._preloadedPlugins) {
|
||||||
|
if (!Gerrit._preloadedPlugins.hasOwnProperty(name)) { continue; }
|
||||||
|
const callback = Gerrit._preloadedPlugins[name];
|
||||||
|
Gerrit.install(callback, API_VERSION, PRELOADED_PROTOCOL + name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function getPluginNameFromUrl(url) {
|
function getPluginNameFromUrl(url) {
|
||||||
if (!(url instanceof URL)) {
|
if (!(url instanceof URL)) {
|
||||||
try {
|
try {
|
||||||
@@ -110,6 +121,9 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (url.protocol === PRELOADED_PROTOCOL) {
|
||||||
|
return url.pathname;
|
||||||
|
}
|
||||||
const base = Gerrit.BaseUrlBehavior.getBaseUrl();
|
const base = Gerrit.BaseUrlBehavior.getBaseUrl();
|
||||||
const pathname = url.pathname.replace(base, '');
|
const pathname = url.pathname.replace(base, '');
|
||||||
// Site theme is server from predefined path.
|
// Site theme is server from predefined path.
|
||||||
@@ -432,6 +446,7 @@
|
|||||||
const app = document.querySelector('#app');
|
const app = document.querySelector('#app');
|
||||||
if (!app) {
|
if (!app) {
|
||||||
// No gr-app found (running tests)
|
// No gr-app found (running tests)
|
||||||
|
Gerrit._installPreloadedPlugins = installPreloadedPlugins;
|
||||||
Gerrit._resetPlugins = () => {
|
Gerrit._resetPlugins = () => {
|
||||||
_allPluginsPromise = null;
|
_allPluginsPromise = null;
|
||||||
_pluginsInstalled = [];
|
_pluginsInstalled = [];
|
||||||
@@ -622,5 +637,18 @@
|
|||||||
return `${pluginName}-screen-${screenName}`;
|
return `${pluginName}-screen-${screenName}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Gerrit._isPluginPreloaded = function(url) {
|
||||||
|
const name = getPluginNameFromUrl(url);
|
||||||
|
if (name && Gerrit._preloadedPlugins) {
|
||||||
|
return name in Gerrit._preloadedPlugins;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
window.Gerrit = Gerrit;
|
window.Gerrit = Gerrit;
|
||||||
|
|
||||||
|
// Preloaded plugins should be installed after Gerrit.install() is set,
|
||||||
|
// since plugin preloader substitutes Gerrit.install() temporarily.
|
||||||
|
installPreloadedPlugins();
|
||||||
})(window);
|
})(window);
|
||||||
|
Reference in New Issue
Block a user