IGNITE-3319 Upgraded to latest jszip.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b2d7562c Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b2d7562c Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b2d7562c Branch: refs/heads/ignite-3262 Commit: b2d7562c30181aa2ec5f01dc82ebb50344556b77 Parents: 2579aba Author: Andrey Novikov <[email protected]> Authored: Tue Jun 28 16:14:00 2016 +0700 Committer: Andrey Novikov <[email protected]> Committed: Tue Jun 28 16:14:00 2016 +0700 ---------------------------------------------------------------------- modules/web-console/src/main/js/serve/agent.js | 89 +++++++++++---------- 1 file changed, 45 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/b2d7562c/modules/web-console/src/main/js/serve/agent.js ---------------------------------------------------------------------- diff --git a/modules/web-console/src/main/js/serve/agent.js b/modules/web-console/src/main/js/serve/agent.js index 77da925..a529e94 100644 --- a/modules/web-console/src/main/js/serve/agent.js +++ b/modules/web-console/src/main/js/serve/agent.js @@ -481,56 +481,57 @@ module.exports.factory = function(_, ws, fs, path, JSZip, socketio, settings, mo const jarFilter = (file) => path.extname(file) === '.jar'; - for (const archive of agentArchives) { - const filePath = path.join(settings.agent.dists, archive); - - const zip = new JSZip(fs.readFileSync(filePath)); - - const jarPath = _.find(_.keys(zip.files), jarFilter); - - const jar = new JSZip(zip.files[jarPath].asNodeBuffer()); - - const manifest = jar.files['META-INF/MANIFEST.MF'] - .asText() - .trim() - .split(/\s*\n+\s*/) - .map((line, r) => { - r = line.split(/\s*:\s*/); - - this[r[0]] = r[1]; - - return this; - }, {})[0]; + const agentsPromises = _.map(agentArchives, (fileName) => { + const filePath = path.join(settings.agent.dists, fileName); + + return JSZip.loadAsync(fs.readFileSync(filePath)) + .then((zip) => { + const jarPath = _.find(_.keys(zip.files), jarFilter); + + return JSZip.loadAsync(zip.files[jarPath].async('nodebuffer')) + .then((jar) => jar.files['META-INF/MANIFEST.MF'].async('string')) + .then((lines) => lines.trim() + .split(/\s*\n+\s*/) + .map((line, r) => { + r = line.split(/\s*:\s*/); + + this[r[0]] = r[1]; + + return this; + }, {})[0]) + .then((manifest) => { + const ver = manifest['Implementation-Version']; + const buildTime = manifest['Build-Time']; + + if (ver && buildTime) + return { fileName, filePath, ver, buildTime }; + }); + }); + }); - const ver = manifest['Implementation-Version']; + Promise.all(agentsPromises) + .then((agents) => { + this.supportedAgents = _.keyBy(_.remove(agents, null), 'ver'); - if (ver) { - this.supportedAgents[ver] = { - fileName: archive, - filePath, - buildTime: manifest['Build-Time'] - }; - } - } + const latest = _.head(Object.keys(this.supportedAgents).sort((a, b) => { + const aParts = a.split('.'); + const bParts = b.split('.'); - const latest = _.head(Object.keys(this.supportedAgents).sort((a, b) => { - const aParts = a.split('.'); - const bParts = b.split('.'); + for (let i = 0; i < aParts.length; ++i) { + if (bParts.length === i) + return 1; - for (let i = 0; i < aParts.length; ++i) { - if (bParts.length === i) - return 1; + if (aParts[i] === aParts[i]) + continue; - if (aParts[i] === aParts[i]) - continue; + return aParts[i] > bParts[i] ? 1 : -1; + } + })); - return aParts[i] > bParts[i] ? 1 : -1; - } - })); - - // Latest version of agent distribution. - if (latest) - this.supportedAgents.latest = this.supportedAgents[latest]; + // Latest version of agent distribution. + if (latest) + this.supportedAgents.latest = this.supportedAgents[latest]; + }); } attachLegacy(server) {
