converting to JSON and adding a few more tests
diff --git a/bundles/org.eclipse.e4.languages.javascript.framework/.externalToolBuilders/Javascript Concat.launch b/bundles/org.eclipse.e4.languages.javascript.framework/.externalToolBuilders/JavaScript Concat.launch
similarity index 100%
rename from bundles/org.eclipse.e4.languages.javascript.framework/.externalToolBuilders/Javascript Concat.launch
rename to bundles/org.eclipse.e4.languages.javascript.framework/.externalToolBuilders/JavaScript Concat.launch
diff --git a/bundles/org.eclipse.e4.languages.javascript.framework/.project b/bundles/org.eclipse.e4.languages.javascript.framework/.project
index 6ca93b6..6102309 100644
--- a/bundles/org.eclipse.e4.languages.javascript.framework/.project
+++ b/bundles/org.eclipse.e4.languages.javascript.framework/.project
@@ -31,7 +31,7 @@
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
- <value><project>/.externalToolBuilders/Javascript Concat.launch</value>
+ <value><project>/.externalToolBuilders/JavaScript Concat.launch</value>
</dictionary>
</arguments>
</buildCommand>
diff --git a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Bundle.js b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Bundle.js
index ee35784..9d31d9d 100644
--- a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Bundle.js
+++ b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Bundle.js
@@ -3,11 +3,12 @@
this._bundleData = bundleData;
this._name = null;
this._version = null;
+ this._singleton = false;
this._imports = [];
this._requires = [];
this._exports = [];
this._resources = {};
- this._singleton = false;
+ this._globals = [];
this._markedStarted = false;
this._state = orion.Bundle.INSTALLED;
this._scope = {};
@@ -16,13 +17,15 @@
this._script = null;
var headers = bundleData.getHeaders();
- this._parseName(headers[orion.Constants.BUNDLE_NAME]);
- this._parseVersion(headers[orion.Constants.BUNDLE_VERSION]);
- this._parseImports(headers[orion.Constants.BUNDLE_IMPORTS]);
- this._parseExports(headers[orion.Constants.BUNDLE_EXPORTS]);
- this._parseRequires(headers[orion.Constants.BUNDLE_REQUIRES]);
- this._parseResources(headers[orion.Constants.BUNDLE_RESOURCES]);
- this._parsePath(headers[orion.Constants.BUNDLE_PATH]);
+ this._parseName(headers.name);
+ this._parseVersion(headers.version);
+ this._parseSingleton(headers.singleton);
+ this._parseImports(headers.imports);
+ this._parseExports(headers.exports);
+ this._parseRequires(headers.requires);
+ this._parseResources(headers.resources);
+ this._parsePath(headers.path);
+ this._parseGlobals(headers.globals);
};
orion.Bundle.UNINSTALLED = 1;
@@ -173,7 +176,7 @@
return this._requires;
},
_createActivatorInstance : function() {
- var activatorName = this.getHeaders()[orion.Constants.BUNDLE_ACTIVATOR];
+ var activatorName = this.getHeaders().activator;
if (activatorName === null || activatorName === undefined)
return null;
@@ -242,19 +245,22 @@
this._state = orion.Bundle.RESOLVED;
},
_evalScript : function(importScope) {
- var parameterNames = [];
- var parameterValues = [];
+ var parameterNames = ["getResource"];
+ var that = this;
+ var boundGetResource = function(path) {
+ return that.getResource(path);
+ };
+ var parameterValues = [boundGetResource];
var parameterName = null;
for (parameterName in importScope) {
if (importScope.hasOwnProperty(parameterName)) {
parameterNames.push(parameterName);
parameterValues.push(importScope[parameterName]);
}
-
}
var exportNames = [];
- for (i = 0; i < this._exports.length; i++) {
+ for (var i = 0; i < this._exports.length; i++) {
var exportName = this._exports[i].getName();
if (exportName.charAt(0) == "/")
continue; // resource
@@ -270,20 +276,11 @@
var parameterStatement = parameterNames.join(",");
var returnStatement = "\n\nreturn {" + exportNames.join(",") + "};";
-
- var that = this;
- var _ResourceWrapper = function() {
- this.getResources = function(path) {
- return that.getResources(path);
- };
- };
- _ResourceWrapper.prototype = orion.global;
- var context = new _ResourceWrapper();
+
var finalScript = this._script + returnStatement;
- var load = new Function(parameterStatement, finalScript);
- // or alternately
- // var load = eval("(function("+parameterStatement+") {\n" + finalScript + "\n})");
- this._scope = load.apply(context, parameterValues);
+ // var load = new Function(parameterStatement, finalScript);
+ var load = orion.Framework._eval("(function("+parameterStatement+") {\n" + finalScript + "\n})//@ sourceURL=" + this.getLocation());
+ this._scope = load.apply(null, parameterValues);
},
_unresolve : function() {
if (this._state == orion.Bundle.ACTIVE) {
@@ -296,48 +293,41 @@
this._state = orion.Bundle.INSTALLED;
},
_parseName : function(header) {
- var tokens = header.split(orion.Constants.PARAMETER_DELIMITER);
- this._name = tokens[0].replace(/^\s+|\s+$/g, '');
- for ( var i = 1; i < tokens.length; i++) {
- var token = tokens[i];
- if (token.indexOf(orion.Constants.DIRECTIVE_EQUALS) != -1) {
- var index = token.indexOf(orion.Constants.DIRECTIVE_EQUALS);
- var directiveName = token.substring(0, index).replace(/^\s+|\s+$/g, '');
- if (directiveName.length === 0)
- throw "bad syntax: " + token + " in " + header;
-
- if (directiveName !== orion.Constants.SINGLETON_DIRECTIVE)
- continue;
- var value = token.substring(index + orion.Constants.DIRECTIVE_EQUALS.length).replace(/^\s+|\s+$/g, '');
- if (value.toLowerCase() === "true")
- this._singleton = true;
- } else
- throw "bad syntax: " + token + " in " + header;
- }
+ this._name = header;
+ },
+ _parseSingleton : function(header) {
+ if (typeof header == "boolean")
+ this._singleton = header;
},
_parseVersion : function(header) {
this._version = orion.Version.parseVersion(header);
},
+ _parseGlobals : function(header) {
+ if (!header)
+ return;
+
+ for ( var i = 0; i < header.length; i++) {
+ if (header[i]) {
+ this._globals.push(header[i]);
+ }
+ }
+ },
_parseResources : function(header) {
if (!header)
return;
- var tokens = header.split(orion.Constants.CLAUSE_DELIMITER);
- for ( var i = 0; i < tokens.length; i++) {
- if (tokens[i]) {
- var path = tokens[i].replace(/^\s+|\s+$/g, '');
- this._resources[path] = true;
+ for ( var i = 0; i < header.length; i++) {
+ if (header[i]) {
+ this._resources[header[i]] = true;
}
}
},
_parseRequires : function(header) {
- if (!header)
+ if (!header)
return;
- var tokens = header.split(orion.Constants.CLAUSE_DELIMITER);
- for ( var i = 0; i < tokens.length; i++) {
- var token = tokens[i];
- var jsRequire = new orion.Require(token);
+ for ( var i = 0; i < header.length; i++) {
+ var jsRequire = new orion.Require(header[i]);
if (jsRequire !== null)
this._requires.push(jsRequire);
}
@@ -345,10 +335,9 @@
_parseExports : function(header) {
if (!header)
return;
- var tokens = header.split(orion.Constants.CLAUSE_DELIMITER);
- for ( var i = 0; i < tokens.length; i++) {
- var token = tokens[i];
- var jsExport = new orion.Export(token, this);
+
+ for ( var i = 0; i < header.length; i++) {
+ var jsExport = new orion.Export(header[i], this);
if (jsExport !== null)
this._exports.push(jsExport);
}
@@ -357,26 +346,22 @@
if (!header)
return;
- var tokens = header.split(orion.Constants.CLAUSE_DELIMITER);
- for ( var i = 0; i < tokens.length; i++) {
- var token = tokens[i];
- var jsImport = new orion.Import(token);
+ for ( var i = 0; i < header.length; i++) {
+ var jsImport = new orion.Import(header[i]);
if (jsImport !== null)
this._imports.push(jsImport);
}
},
_parsePath : function(header) {
if (!header) {
- this._script = this._bundleData.getHeaders()[orion.Constants.BUNDLE_SCRIPT] || "";
+ this._script = this._bundleData.getHeaders().script || "";
return;
}
- var tokens = header.split(orion.Constants.CLAUSE_DELIMITER);
var scripts = [];
- for ( var i = 0; i < tokens.length; i++) {
- var token = tokens[i];
- var path = token.replace(/^\s+|\s+$/g, '');
+ for ( var i = 0; i < header.length; i++) {
+ var path = header[i];
if (path === ".") {
- scripts[i] = this._bundleData.getHeaders()[orion.Constants.BUNDLE_SCRIPT];
+ scripts[i] = this._bundleData.getHeaders().script || "";
} else {
var scriptURL = this.getResource(path);
scripts[i] = orion.Framework._fetch(scriptURL);
diff --git a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Constants.js b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Constants.js
deleted file mode 100644
index 1f2d726..0000000
--- a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Constants.js
+++ /dev/null
@@ -1,27 +0,0 @@
-orion.Constants = {
- ATTRIBUTE_EQUALS : "=",
- DIRECTIVE_EQUALS : ":=",
- PARAMETER_DELIMITER : ";",
- MANDATORY_DELIMITER : ",",
- SCRIPT_PATH_DELIMITER : ",",
- CLAUSE_DELIMITER : ",",
- BUNDLE_NAME : "name",
- BUNDLE_VERSION : "version",
- BUNDLE_IMPORTS : "imports",
- BUNDLE_EXPORTS : "exports",
- BUNDLE_REQUIRES : "requires",
- BUNDLE_SCRIPT : "script",
- BUNDLE_PATH : "path",
- BUNDLE_ACTIVATOR : "activator",
- BUNDLE_RESOURCES : "resources",
- BUNDLE_GLOBALS : "globals",
- SCRIPT_PATH_DOT : ".",
- BUNDLE_NAME_ATTRIBUTE : "bundle-name",
- BUNDLE_VERSION_ATTRIBUTE : "bundle-version",
- VERSION_ATTRIBUTE : "version",
- RESOLUTION_DIRECTIVE : "resolution",
- RESOLUTION_OPTIONAL : "optional",
- RESOLUTION_MANDATORY : "mandatory",
- MANDATORY_DIRECTIVE : "mandatory",
- SINGLETON_DIRECTIVE : "singleton"
-};
\ No newline at end of file
diff --git a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Export.js b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Export.js
index d4e577a..71e3df3 100644
--- a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Export.js
+++ b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Export.js
@@ -8,7 +8,6 @@
this._name = null;
this._version = orion.Version.EMPTY_VERSION;
this._attributes = {};
- this._directives = {};
this._mandatory = [];
this._exportingBundle = exportingBundle;
@@ -17,49 +16,27 @@
orion.Export.prototype = {
_parseExport : function(header) {
- var tokens = header.split(orion.Constants.PARAMETER_DELIMITER);
- this._name = tokens[0].replace(/^\s+|\s+$/g, '');
- for ( var i = 1; i < tokens.length; i++) {
- var token = tokens[i];
- if (token.indexOf(orion.Constants.DIRECTIVE_EQUALS) !== -1)
- this._parseDirective(token);
- else if (token.indexOf(orion.Constants.ATTRIBUTE_EQUALS) !== -1)
- this._parseAttribute(token);
- else
- throw "bad export syntax: " + token + " in " + header;
+ if (typeof header == "string") {
+ this._name = header;
+ return;
+ }
+
+ this._name = header.name;
+ if (header.version)
+ this._version = orion.Version.parseVersion(header.version);
+
+ if (header.mandatory)
+ this._parseMandatory(header.mandatory);
+
+ var attributeName;
+ for (attributeName in header) {
+ if (header.hasOwnProperty(attributeName))
+ this._attributes[attributeName] = header[attributeName];
}
},
- _parseAttribute : function(token) {
- var index = token.indexOf(orion.Constants.ATTRIBUTE_EQUALS);
- var attributeName = token.substring(0, index).replace(/^\s+|\s+$/g, '');
- if (attributeName.length === 0)
- return;
-
- var value = token.substring(index + orion.Constants.ATTRIBUTE_EQUALS.length).replace(/^\s+|\s+$/g, '');
-
- if (attributeName === orion.Constants.VERSION_ATTRIBUTE)
- this._version = orion.Version.parseVersion(value);
-
- this._attributes[attributeName] = value;
- },
- _parseDirective : function(token) {
- var index = token.indexOf(orion.Constants.DIRECTIVE_EQUALS);
- var directiveName = token.substring(0, index).replace(/^\s+|\s+$/g, '');
- if (directiveName.length === 0)
- return;
-
- var value = token.substring(index + orion.Constants.DIRECTIVE_EQUALS.length).replace(/^\s+|\s+$/g, '');
- if (directiveName === orion.Constants.MANDATORY_DIRECTIVE)
- this._parseMandatory(value);
-
- this._directives[directiveName] = value;
- },
- _parseMandatory : function(value) {
- var tokens = value.split(orion.Constants.MANDATORY_DELIMITER);
- for ( var i = 0; i < tokens.length; i++) {
- var token = tokens[i].replace(/^\s+|\s+$/g, '');
- if (token.length > 0)
- this._mandatory.push(token);
+ _parseMandatory : function(mandatory) {
+ for ( var i = 0; i < mandatory.length; i++) {
+ this._mandatory.push(mandatory[i]);
}
},
getName : function() {
@@ -71,17 +48,14 @@
getBundleId : function() {
return this._exportingBundle.getBundleId();
},
- getBundleSymbolicName : function() {
- return this._exportingBundle.getSymbolicName();
+ getBundleName : function() {
+ return this._exportingBundle.getName();
},
getBundleVersion : function() {
return this._exportingBundle.getVersion();
},
getAttributes : function() {
- this._attributes;
- },
- getDirectives : function() {
- return this._directives;
+ return this._attributes;
},
getExportingBundle : function() {
return this._exportingBundle;
diff --git a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Import.js b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Import.js
index d8f87a2..4814945 100644
--- a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Import.js
+++ b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Import.js
@@ -4,11 +4,10 @@
this._name = null;
this._versionRange = orion.VersionRange.EMPTY_RANGE;
- this._bundleSymbolicName = null;
+ this._bundleName = null;
this._bundleVersionRange = orion.VersionRange.EMPTY_RANGE;
this._optional = false;
this._attributes = {};
- this._directives = {};
this._wiredExport = null;
this._parseImport(header);
@@ -16,44 +15,29 @@
orion.Import.prototype = {
_parseImport : function(header) {
- var tokens = header.split(orion.Constants.PARAMETER_DELIMITER);
- this._name = tokens[0].replace(/^\s+|\s+$/g, '');
- for ( var i = 1; i < tokens.length; i++) {
- var token = tokens[i];
- if (token.indexOf(orion.Constants.DIRECTIVE_EQUALS) !== -1)
- this._parseDirective(token);
- else if (token.indexOf(orion.Constants.ATTRIBUTE_EQUALS) !== -1)
- this._parseAttribute(token);
- else
- throw "bad import syntax: " + token + " in " + header;
+ if (typeof header == "string") {
+ this._name = header;
+ return;
}
- },
- _parseAttribute : function(token) {
- var index = token.indexOf(orion.Constants.ATTRIBUTE_EQUALS);
- var attributeName = token.substring(0, index).replace(/^\s+|\s+$/g, '');
- if (attributeName.length === 0)
- return;
-
- var value = token.substring(index + orion.Constants.ATTRIBUTE_EQUALS.length).replace(/^\s+|\s+$/g, '');
-
- if (attributeName === orion.Constants.VERSION_ATTRIBUTE)
- this._versionRange = orion.VersionRange.parseVersionRange(value);
- else if (attributeName === orion.Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE)
- this._bundleSymbolicName = value;
- else if (attributeName === orion.Constants.BUNDLE_VERSION_ATTRIBUTE)
- this._bundleVersionRange = orion.VersionRange.parseVersionRange(value);
- this._attributes[attributeName] = value;
- },
- _parseDirective : function(token) {
- var index = token.indexOf(orion.Constants.DIRECTIVE_EQUALS);
- var directiveName = token.substring(0, index).replace(/^\s+|\s+$/g, '');
- if (directiveName.length === 0)
- return;
-
- var value = token.substring(index + orion.Constants.DIRECTIVE_EQUALS.length).replace(/^\s+|\s+$/g, '');
- if (directiveName === orion.Constants.RESOLUTION_DIRECTIVE && value === orion.Constants.RESOLUTION_OPTIONAL)
- this._optional = true;
- this._directives[directiveName] = value;
+
+ this._name = header.name;
+ if (header.version)
+ this._versionRange = orion.VersionRange.parseVersionRange(header.version);
+
+ if (header.bundleName)
+ this._bundleName = orion.VersionRange.parseVersionRange(header.bundleName);
+
+ if (header.bundleVersion)
+ this._bundleVersionRange = orion.VersionRange.parseVersionRange(header.bundleVersion);
+
+ if (header.resolution)
+ this._optional = (header.resolution === "optional");
+
+ var attributeName;
+ for (attributeName in header) {
+ if (header.hasOwnProperty(attributeName))
+ this._attributes[attributeName] = header[attributeName];
+ }
},
getName : function() {
return this._name;
@@ -61,8 +45,8 @@
getVersionRange : function() {
return this._versionRange;
},
- getBundleSymbolicName : function() {
- return this._bundleSymbolicName;
+ getBundleName : function() {
+ return this._bundleName;
},
getBundleVersionRange : function() {
return this._bundleVersionRange;
@@ -73,9 +57,6 @@
getAttributes : function() {
this._attributes;
},
- getDirectives : function() {
- return this._directives;
- },
wire : function(candidate) {
if (this._name !== candidate.getName())
return false;
@@ -91,13 +72,13 @@
},
_checkAttributes : function(candidate) {
for ( var key in this._attributes) {
- if (key === orion.Constants.VERSION_ATTRIBUTE) {
+ if (key === "version") {
if (!this._versionRange.isIncluded(candidate.getVersion()))
return false;
- } else if (key === orion.Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE) {
- if (!this._bundleSymbolicName === candidate.getBundleSymbolicName())
+ } else if (key === "bundleName") {
+ if (this._bundleName !== candidate.getBundleName())
return false;
- } else if (key === orion.Constants.BUNDLE_VERSION_ATTRIBUTE) {
+ } else if (key === "bundleVersion") {
if (!this._bundleVersionRange.isIncluded(candidate.getBundleVersion()))
return false;
} else {
diff --git a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Require.js b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Require.js
index 6ede964..6778003 100644
--- a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Require.js
+++ b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Require.js
@@ -4,7 +4,6 @@
this._name = null;
this._attributes = {};
- this._directives = {};
this._optional = false;
this._bundleVersionRange = orion.VersionRange.emptyRange;
this._wiredBundle = null;
@@ -13,42 +12,24 @@
};
orion.Require.prototype = {
- _parseRequire : function(header) {
- var tokens = header.split(orion.Constants.PARAMETER_DELIMITER);
- this._name = tokens[0].replace(/^\s+|\s+$/g, '');
- for ( var i = 1; i < tokens.length; i++) {
- var token = tokens[i];
- if (token.indexOf(orion.Constants.DIRECTIVE_EQUALS) !== -1)
- this._parseDirective(token);
- else if (token.indexOf(orion.Constants.ATTRIBUTE_EQUALS) !== -1)
- this._parseAttribute(token);
- else
- throw "bad import syntax: " + token + " in " + header;
+ _parseRequire : function(header) {
+ if (typeof header == "string") {
+ this._name = header;
+ return;
}
- },
- _parseAttribute : function(token) {
- var index = token.indexOf(orion.Constants.ATTRIBUTE_EQUALS);
- var attributeName = token.substring(0, index).replace(/^\s+|\s+$/g, '');
- if (attributeName.length === 0)
- return;
-
- var value = token.substring(index + orion.Constants.ATTRIBUTE_EQUALS.length).replace(/^\s+|\s+$/g, '');
-
- if (attributeName === orion.Constants.BUNDLE_VERSION_ATTRIBUTE)
- this._bundleVersionRange = orion.VersionRange.parseVersionRange(value);
-
- this._attributes[attributeName] = value;
- },
- _parseDirective : function(token) {
- var index = token.indexOf(orion.Constants.DIRECTIVE_EQUALS);
- var directiveName = token.substring(0, index).replace(/^\s+|\s+$/g, '');
- if (directiveName.length === 0)
- return;
-
- var value = token.substring(index + orion.Constants.DIRECTIVE_EQUALS.length).replace(/^\s+|\s+$/g, '');
- if (directiveName === orion.Constants.RESOLUTION_DIRECTIVE && value === orion.Constants.RESOLUTION_OPTIONAL)
- this._optional = true;
- this._directives[directiveName] = value;
+
+ this._name = header.name;
+ if (header.bundleVersion)
+ this._bundleVersionRange = orion.VersionRange.parseVersionRange(header.bundleVersion);
+
+ if (header.resolution)
+ this._optional = (header.resolution === "optional");
+
+ var attributeName;
+ for (attributeName in header) {
+ if (header.hasOwnProperty(attributeName))
+ this._attributes[attributeName] = header[attributeName];
+ }
},
getName : function() {
return this._name;
@@ -62,9 +43,6 @@
getAttributes : function() {
this._attributes;
},
- getDirectives : function() {
- return this._directives;
- },
wire : function(candidate) {
if (this._name !== candidate.getName())
return false;
@@ -77,7 +55,7 @@
},
_checkAttributes : function(candidate) {
for ( var key in this._attributes) {
- if (key === orion.Constants.BUNDLE_VERSION_ATTRIBUTE) {
+ if (key === "bundleVersion") {
if (!this._bundleVersionRange.isIncluded(candidate.getVersion()))
return false;
}