Cleaning out bundle activation and requires
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 9d31d9d..f165f5d 100644
--- a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Bundle.js
+++ b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Bundle.js
@@ -5,15 +5,12 @@
this._version = null;
this._singleton = false;
this._imports = [];
- this._requires = [];
this._exports = [];
this._resources = {};
this._globals = [];
- this._markedStarted = false;
this._state = orion.Bundle.INSTALLED;
this._scope = {};
this._bundleContext = null;
- this._activator = null;
this._script = null;
var headers = bundleData.getHeaders();
@@ -22,7 +19,6 @@
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);
@@ -31,9 +27,6 @@
orion.Bundle.UNINSTALLED = 1;
orion.Bundle.INSTALLED = 2;
orion.Bundle.RESOLVED = 4;
-orion.Bundle.STARTING = 8;
-orion.Bundle.STOPPING = 16;
-orion.Bundle.ACTIVE = 32;
orion.Bundle.prototype = {
getName : function() {
@@ -79,28 +72,7 @@
if (resource)
return resource;
}
- }
-
- // process requires
- for (i = 0; i < this._requires.length; i++) {
- var jsRequire = this._requires[i];
- var wiredBundle = jsRequire.getWiredBundle();
- if (!wiredBundle) {
- continue; //optional
- }
- var wiredBundleExports = wiredBundle._getExports();
- for (var j=0; j < wiredBundleExports.length; j++) {
- jsExport = wiredBundleExports[j];
- var name = jsExport.getName();
- if (name.charAt(0) != "/")
- continue; // not a resource
- if (path.indexOf(name)==0) {
- resource = jsExport.getExportingBundle().getEntry(path);
- if (resource)
- return resource;
- }
- }
- }
+ }
return this.getEntry(path);
},
equals : function(other) {
@@ -122,30 +94,6 @@
uninstall : function() {
this._state = orion.Bundle.UNINSTALLED;
},
- start : function() {
- this._markedStarted = true;
- if (this._state !== orion.Bundle.RESOLVED)
- return;
-
- this._state = orion.Bundle.STARTING;
- this._bundleContext = this._framework._getBundleContext(this);
- this._activator = this._createActivatorInstance();
- if (this._activator) {
- this._activator.start(this._bundleContext);
- }
- this._state = orion.Bundle.ACTIVE;
- },
- stop : function() {
- markedStarted = false;
- if (this._state !== orion.Bundle.ACTIVE)
- return;
-
- this._state = orion.Bundle.STOPPING;
- if (this._activator) {
- this._activator.stop(this._bundleContext);
- }
- this._state = orion.Bundle.RESOLVED;
- },
load : function(name) {
var value = this._scope;
if (value === null || value === undefined) {
@@ -163,28 +111,12 @@
_isSingleton : function() {
return this._singleton;
},
- _isMarkedStarted : function() {
- return this._markedStarted;
- },
_getImports : function() {
return this._imports;
},
_getExports : function() {
return this._exports;
},
- _getRequires : function() {
- return this._requires;
- },
- _createActivatorInstance : function() {
- var activatorName = this.getHeaders().activator;
- if (activatorName === null || activatorName === undefined)
- return null;
-
- var activatorFunction = this.load(activatorName);
- if (typeof activatorFunction !== "function")
- throw "" + activatorName + " is not a function.";
- return new activatorFunction();
- },
_resolve : function() {
if (this._state != orion.Bundle.INSTALLED)
return;
@@ -205,24 +137,6 @@
namedExports[name] = jsImport.getWiredExport();
}
- // process requires
- for (i = 0; i < this._requires.length; i++) {
- var jsRequire = this._requires[i];
- var wiredBundle = jsRequire.getWiredBundle();
- if (!wiredBundle) {
- continue; //optional
- }
- var wiredBundleExports = wiredBundle._getExports();
- for (var j=0; j < wiredBundleExports.length; j++) {
- jsExport = wiredBundleExports[j];
- var name = jsExport.getName();
- if (name.charAt(0) == "/")
- continue; // resource
- if (!namedExports.hasOwnProperty(name))
- namedExports[name] = jsImport.getWiredExport();
- }
- }
-
var names = [];
var exportName = null;
for (exportName in namedExports) {
@@ -245,12 +159,8 @@
this._state = orion.Bundle.RESOLVED;
},
_evalScript : function(importScope) {
- var parameterNames = ["getResource"];
- var that = this;
- var boundGetResource = function(path) {
- return that.getResource(path);
- };
- var parameterValues = [boundGetResource];
+ var parameterNames = ["bundleContext"];
+ var parameterValues = [this._framework._getBundleContext(this)];
var parameterName = null;
for (parameterName in importScope) {
if (importScope.hasOwnProperty(parameterName)) {
@@ -283,12 +193,7 @@
this._scope = load.apply(null, parameterValues);
},
_unresolve : function() {
- if (this._state == orion.Bundle.ACTIVE) {
- this.stop();
- markedStarted = true;
- }
this._scope = null;
-
if (this._state == orion.Bundle.RESOLVED)
this._state = orion.Bundle.INSTALLED;
},
@@ -322,16 +227,6 @@
}
}
},
- _parseRequires : function(header) {
- if (!header)
- return;
-
- for ( var i = 0; i < header.length; i++) {
- var jsRequire = new orion.Require(header[i]);
- if (jsRequire !== null)
- this._requires.push(jsRequire);
- }
- },
_parseExports : function(header) {
if (!header)
return;
diff --git a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Framework.js b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Framework.js
index d6ca0fc..da56a86 100644
--- a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Framework.js
+++ b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Framework.js
@@ -92,17 +92,11 @@
else
break;
}
- for (i = 0; i < resolvedBundles; i++) {
- resolvedBundle = resolvedBundles[i];
- if (resolvedBundle.isMarkedStarted())
- resolvedBundle.start();
- }
},
shutdown : function() {
var reversed = this._installOrderBundles.slice().reverse();
for ( var i = 0; i < reversed.length; i++) {
var bundle = reversed[i];
- bundle.stop();
bundle.uninstall();
}
this.refresh();
@@ -135,29 +129,6 @@
return false;
},
_wire : function(bundle) {
- return this._wireRequires(bundle) && this._wireImports(bundle);
- },
- _wireRequires : function(bundle) {
- var requires = bundle._getRequires();
- for (var i = 0; i < requires.length; i++) {
- var jsRequire = requires[i];
- var name = jsRequire.getName();
- var candidates = this._requiredBundles[name];
- var satisfied = false;
- if (candidates) {
- for (var j = 0; j < candidates.length; j++) {
- var candidate = candidates[j];
- satisfied = jsRequire.wire(candidate);
- if (satisfied)
- break;
- }
- }
- if (!satisfied && !jsRequire.isOptional())
- return false;
- }
- return true;
- },
- _wireImports : function(bundle) {
var imports = bundle._getImports();
for (var i = 0; i < imports.length; i++) {
var jsImport = imports[i];
@@ -242,22 +213,11 @@
delete this._requiredBundles[name];
},
_unwire : function(bundle) {
- this._unwireImports(bundle);
- this._unwireRequires(bundle);
- },
- _unwireImports : function(bundle) {
var imports = bundle._getImports();
for ( var i = 0; i < imports.length; i++) {
var jsImport = imports[i];
jsImport.unwire();
}
- },
- _unwireRequires : function(bundle) {
- var requires = bundle._getRequires();
- for ( var i = 0; i < requires.length; i++) {
- var jsRequires = requires[i];
- jsRequires.unwire();
- }
}
};
diff --git a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Require.js b/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Require.js
deleted file mode 100644
index 6778003..0000000
--- a/bundles/org.eclipse.e4.languages.javascript.framework/scripts/Require.js
+++ /dev/null
@@ -1,71 +0,0 @@
-orion.Require = function(header) {
- if (header === null)
- throw "header cannot be null";
-
- this._name = null;
- this._attributes = {};
- this._optional = false;
- this._bundleVersionRange = orion.VersionRange.emptyRange;
- this._wiredBundle = null;
-
- this._parseRequire(header);
-};
-
-orion.Require.prototype = {
- _parseRequire : function(header) {
- if (typeof header == "string") {
- this._name = header;
- return;
- }
-
- 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;
- },
- getBundleVersionRange : function() {
- return this._bundleVersionRange;
- },
- isOptional : function() {
- return this._optional;
- },
- getAttributes : function() {
- this._attributes;
- },
- wire : function(candidate) {
- if (this._name !== candidate.getName())
- return false;
-
- if (!this._checkAttributes(candidate))
- return false;
-
- this._wiredBundle = candidate;
- return true;
- },
- _checkAttributes : function(candidate) {
- for ( var key in this._attributes) {
- if (key === "bundleVersion") {
- if (!this._bundleVersionRange.isIncluded(candidate.getVersion()))
- return false;
- }
- }
- return true;
- },
- getWiredBundle : function() {
- return this._wiredBundle;
- },
- unwire : function() {
- this._wiredBundle = null;
- }
-};
diff --git a/tests/org.eclipse.e4.languages.javascript.framework.test/scripts/BundleTest.js b/tests/org.eclipse.e4.languages.javascript.framework.test/scripts/BundleTest.js
index 2fde78b..78f5a1e 100644
--- a/tests/org.eclipse.e4.languages.javascript.framework.test/scripts/BundleTest.js
+++ b/tests/org.eclipse.e4.languages.javascript.framework.test/scripts/BundleTest.js
@@ -53,10 +53,6 @@
assertEquals(orion.Bundle.INSTALLED, b.getState());
framework.resolve();
assertEquals(orion.Bundle.RESOLVED, b.getState());
- b.start();
- assertEquals(orion.Bundle.ACTIVE, b.getState());
- b.stop();
- assertEquals(orion.Bundle.RESOLVED, b.getState());
b.uninstall();
assertEquals(orion.Bundle.UNINSTALLED, b.getState());
};
@@ -81,35 +77,6 @@
assertNotNull(b2.getResource("/abc/def.jpg"));
};
-BundleTest.prototype.testStartStop = function() {
- var framework = new orion.Framework();
- var b = framework.installBundle("xyz", {
- name:"xyz",
- version:"1.2.3.test",
- exports: ["abc"],
- script: "var abc = {};\n" +
- "abc.A = function() {};\n" +
- "abc.A.prototype.start = function() { abc.test = 'start'};\n" +
- "abc.A.prototype.stop = function() { abc.test = 'stop'};\n",
- activator: "abc.A"
- });
- assertEquals(orion.Bundle.INSTALLED, b.getState());
- framework.resolve();
- assertEquals(orion.Bundle.RESOLVED, b.getState());
- b.start();
- assertEquals(orion.Bundle.ACTIVE, b.getState());
- assertEquals("start", b.load("abc.test"));
-
- b.stop();
- assertEquals(orion.Bundle.RESOLVED, b.getState());
- assertEquals("stop", b.load("abc.test"));
-
- b.uninstall();
- assertEquals(orion.Bundle.UNINSTALLED, b.getState());
-
-
-
-};
diff --git a/tests/org.eclipse.e4.languages.javascript.framework.test/scripts/FrameworkTest.js b/tests/org.eclipse.e4.languages.javascript.framework.test/scripts/FrameworkTest.js
index ac57acf..fd98793 100644
--- a/tests/org.eclipse.e4.languages.javascript.framework.test/scripts/FrameworkTest.js
+++ b/tests/org.eclipse.e4.languages.javascript.framework.test/scripts/FrameworkTest.js
@@ -236,74 +236,6 @@
assertEquals(9, b.load("ghi").bye);
};
-FrameworkTest.prototype.testResolveRequiresFail = function() {
- var framework = new orion.Framework();
- var b = framework.installBundle("xyz", {name:"xyz", requires:["abc"]});
- assertEquals(1, framework.getBundles().length);
- assertEquals(orion.Bundle.INSTALLED, b.getState());
- framework.resolve();
- assertFalse(orion.Bundle.RESOLVED == b.getState());
-};
-
-FrameworkTest.prototype.testResolveOptionalRequires = function() {
- var framework = new orion.Framework();
- var b = framework.installBundle("xyz", {name:"xyz", requires:[{name:"abc",resolution:"optional"}]});
- assertEquals(1, framework.getBundles().length);
- assertEquals(orion.Bundle.INSTALLED, b.getState());
- framework.resolve();
- assertTrue(orion.Bundle.RESOLVED == b.getState());
-};
-
-
-FrameworkTest.prototype.testResolveRequiresFailAfterUninstall = function() {
- var framework = new orion.Framework();
- var a = framework.installBundle("abc", {name:"abc"});
- var b = framework.installBundle("xyz", {name:"xyz", requires:["abc"]});
- framework.resolve();
- assertTrue(orion.Bundle.RESOLVED == a.getState());
- assertTrue(orion.Bundle.RESOLVED == b.getState());
- a.uninstall();
- framework.refresh();
- assertFalse(orion.Bundle.RESOLVED == b.getState());
-};
-
-FrameworkTest.prototype.testResolveRequiresSuccess = function() {
- var framework = new orion.Framework();
- var a = framework.installBundle("abc", {name:"abc"});
- var b = framework.installBundle("xyz", {name:"xyz", requires:["abc"]});
- assertEquals(2, framework.getBundles().length);
- assertEquals(orion.Bundle.INSTALLED, a.getState());
- assertEquals(orion.Bundle.INSTALLED, b.getState());
- framework.resolve();
- assertTrue(orion.Bundle.RESOLVED == a.getState());
- assertTrue(orion.Bundle.RESOLVED == b.getState());
-};
-
-FrameworkTest.prototype.testResolveVersionedRequiresSuccess = function() {
- var framework = new orion.Framework();
- var a = framework.installBundle("abc", {name:"abc", version:"1.2"});
- var b = framework.installBundle("xyz", {name:"xyz", requires:[{name:"abc",bundleVersion:"1.2"}]});
- assertEquals(2, framework.getBundles().length);
- assertEquals(orion.Bundle.INSTALLED, a.getState());
- assertEquals(orion.Bundle.INSTALLED, b.getState());
- framework.resolve();
- assertTrue(orion.Bundle.RESOLVED == a.getState());
- assertTrue(orion.Bundle.RESOLVED == b.getState());
-};
-
-FrameworkTest.prototype.testResolveVersionedRequiresFail = function() {
- var framework = new orion.Framework();
- var a = framework.installBundle("abc", {name:"abc", version:"1.1"});
- var b = framework.installBundle("xyz", {name:"xyz", requires:[{name:"abc",bundleVersion:"1.2"}]});
- assertEquals(2, framework.getBundles().length);
- assertEquals(orion.Bundle.INSTALLED, a.getState());
- assertEquals(orion.Bundle.INSTALLED, b.getState());
- framework.resolve();
- assertTrue(orion.Bundle.RESOLVED == a.getState());
- assertFalse(orion.Bundle.RESOLVED == b.getState());
-};
-
-
FrameworkTest.prototype.testEmptyShutdown = function() {
var framework = new orion.Framework();
framework.shutdown();