-
Notifications
You must be signed in to change notification settings - Fork 149
Parser now retrieves application metadata #388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ import * as messages from 'messages'; | |
import log from 'logger'; | ||
import { singleLineString } from 'utils'; | ||
|
||
const TARGET_APPLICATION_FIELDS = [ | ||
'id', 'minVersion', 'maxVersion', | ||
]; | ||
|
||
export default class InstallRdfParser { | ||
|
||
|
@@ -21,6 +24,7 @@ export default class InstallRdfParser { | |
type: this._getAddonType(), | ||
version: this._getVersion(), | ||
restartless: this._getIsBootstrapped(), | ||
application: this._getApplication(), | ||
}); | ||
} | ||
|
||
|
@@ -105,6 +109,40 @@ export default class InstallRdfParser { | |
this._getTopLevelNodeByTag('em:bootstrap')) === 'true'; | ||
} | ||
|
||
_getApplication() { | ||
var targetApplications = this._getTopLevelNodesByTag( | ||
'em:targetApplication'); | ||
var applications = []; | ||
|
||
for (let targetApplication of targetApplications) { | ||
let application = {}; | ||
let descriptionNodes = Array.prototype.slice.call( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anywhere you're doing this you can use |
||
targetApplication.childNodes) | ||
.filter((node) => node.nodeName === 'Description'); | ||
|
||
if (descriptionNodes.length !== 1) { | ||
throw new Error(singleLineString`<em:targetApplication> node should only | ||
have a single descendant <Description>`); | ||
} | ||
|
||
for (var i in descriptionNodes[0].childNodes) { | ||
let childNode = descriptionNodes[0].childNodes[i]; | ||
if (TARGET_APPLICATION_FIELDS.indexOf(childNode.localName) !== -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be able to use [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes |
||
application[childNode.localName] = this._getNodeValue(childNode); | ||
} | ||
} | ||
|
||
if (application.id && application.maxVersion && application.minVersion) { | ||
applications.push(application); | ||
} else { | ||
throw new Error(singleLineString`targetApplication must contain an id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be an error message pushed onto the collector? Also I think doing something a little more granular will help developers e.g. flag each field that's invalid separately so that it's clearer when just one thing is broken. |
||
minVersion and maxVersion fields to be valid.`); | ||
} | ||
} | ||
|
||
return applications; | ||
} | ||
|
||
_getGUID() { | ||
// Install.rdf only. | ||
var guid = this._getNodeValue(this._getTopLevelNodeByTag('em:id')); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move to
const
and add something to the name to reflect this is to do with RDF?