Permalink
Browse files

move stuff into plugins (not working yet)

  • Loading branch information...
fjakobs committed Mar 2, 2012
1 parent 3982f3f commit 92b964b4b29656dd469fe11ca803e6b528636a8a
Showing with 2,033 additions and 35 deletions.
  1. +3 −1 .gitignore
  2. 0 {original → }/ChangeLog
  3. 0 {original → }/LICENSE
  4. 0 {original → }/README.md
  5. +18 −0 configs/default.js
  6. +1 −0 node_modules/architect
  7. 0 {original/server/cloud9 → node_modules/cloud9.core}/dav/permission.js
  8. 0 {original/server/cloud9 → node_modules/cloud9.core}/error.js
  9. +27 −0 node_modules/cloud9.core/ide-plugin.js
  10. 0 {original/server/cloud9 → node_modules/cloud9.core}/ide.js
  11. 0 {original/server/cloud9 → node_modules/cloud9.core}/index.js
  12. 0 {original/server/cloud9 → node_modules/cloud9.core}/middleware.js
  13. 0 {original/server/cloud9 → node_modules/cloud9.core}/netutil.js
  14. 0 {original/server/cloud9 → node_modules/cloud9.core}/optparse.js
  15. +20 −0 node_modules/cloud9.core/package.json
  16. 0 {original/server/cloud9 → node_modules/cloud9.core}/plugin.js
  17. 0 {original/server/cloud9 → node_modules/cloud9.core}/template.js
  18. 0 {original/server/cloud9 → node_modules/cloud9.core}/user.js
  19. 0 {original/server/cloud9 → node_modules/cloud9.core}/util.js
  20. 0 {original/server/cloud9 → node_modules/cloud9.core}/view/error.tmpl.html
  21. 0 {original/server/cloud9 → node_modules/cloud9.core}/view/ide.tmpl.html
  22. 0 {original/server/cloud9 → node_modules/cloud9.core}/workspace.js
  23. +0 −20 original/server/cloud9/test/v8bug.js
  24. +0 −5 original/server/cloud9/test/v8bugtest.js
  25. +10 −9 {original → }/package.json
  26. 0 {original/server/cloud9/ext → plugins}/auth/auth.js
  27. 0 {original/server/cloud9/ext → plugins}/blame/blame.js
  28. +55 −0 plugins/cloud9.connect/connect-plugin.js
  29. +21 −0 plugins/cloud9.connect/package.json
  30. +51 −0 plugins/cloud9.core/dav/permission.js
  31. +85 −0 plugins/cloud9.core/error.js
  32. +31 −0 plugins/cloud9.core/ide-plugin.js
  33. +361 −0 plugins/cloud9.core/ide.js
  34. +115 −0 plugins/cloud9.core/index.js
  35. +170 −0 plugins/cloud9.core/middleware.js
  36. +65 −0 plugins/cloud9.core/netutil.js
  37. +301 −0 plugins/cloud9.core/optparse.js
  38. +21 −0 plugins/cloud9.core/package.json
  39. +86 −0 plugins/cloud9.core/plugin.js
  40. +9 −0 plugins/cloud9.core/template.js
  41. +155 −0 plugins/cloud9.core/user.js
  42. +22 −0 plugins/cloud9.core/util.js
  43. +25 −0 plugins/cloud9.core/view/error.tmpl.html
  44. +227 −0 plugins/cloud9.core/view/ide.tmpl.html
  45. +96 −0 plugins/cloud9.core/workspace.js
  46. +30 −0 plugins/cloud9.log/log-service.js
  47. +13 −0 plugins/cloud9.log/package.json
  48. 0 {original/server/cloud9/ext → plugins}/git/git.js
  49. 0 {original/server/cloud9/ext → plugins}/gittools/gittools.js
  50. 0 {original/server/cloud9/ext → plugins}/hg/hg.js
  51. 0 {original/server/cloud9/ext → plugins}/run-node/chromedebugproxy.js
  52. 0 {original/server/cloud9/ext → plugins}/run-node/nodedebugproxy.js
  53. 0 {original/server/cloud9/ext → plugins}/run-node/run-node.js
  54. 0 {original/server/cloud9/ext → plugins}/run-python/run-python.js
  55. 0 {original/server/cloud9/ext → plugins}/settings/settings.js
  56. 0 {original/server/cloud9/ext → plugins}/shell/shell.js
  57. 0 {original/server/cloud9/ext → plugins}/state/state.js
  58. 0 {original/server/cloud9/ext → plugins}/watcher/watcher.js
  59. +15 −0 server.js
View
@@ -17,4 +17,6 @@ client/build
aut.js
helloworld.js
.*.gz
-.c9revisions
+.c9revisions
+plugins/cloud9.core/node_modules/
+plugins/cloud9.connect/node_modules/
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,18 @@
+module.exports = {
+ name: "Cloud9",
+ tmpdir: __dirname + "/../.architect",
+ containers: {
+ master: {
+ title: "Cloud9",
+ plugins: [{
+ packagePath: __dirname + "/../plugins/cloud9.connect",
+ port: process.env.PORT || 3131,
+ host: "localhost"
+ }, {
+ packagePath: __dirname + "/../plugins/cloud9.log"
+ }, {
+ packagePath: __dirname + "/../plugins/cloud9.core"
+ }]
+ }
+ }
+};
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
File renamed without changes.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
File renamed without changes.
File renamed without changes.
@@ -1,20 +0,0 @@
-require("../../../support/paths");
-
-var NodeSocket = require("v8debug/NodeSocket");
-var StandaloneV8DebuggerService = require("v8debug/StandaloneV8DebuggerService");
-var V8Debugger = require("v8debug/V8Debugger");
-
-var socket = new NodeSocket("127.0.0.1", parseInt(process.argv[2]));
-var service = new StandaloneV8DebuggerService(socket);
-console.log("here")
-service.attach(0, function() {
- console.log("attached");
-
- var dbg = new V8Debugger(0, service);
- dbg.version(function(version) {
- console.log(version);
- service.detach(0, function() {
- console.log("done");
- });
- });
-});
@@ -1,5 +0,0 @@
-var i = 0
-console.log("HIII");
-setInterval(function() {
- console.log(i++);
-}, 1000)
@@ -1,20 +1,21 @@
{
"name": "cloud9",
"description": "Cloud9 IDE",
- "version": "0.6",
+ "version": "0.7",
"homepage" : "http://github.com/ajaxorg/cloud9",
- "engines": {"node": ">= 0.4.0"},
+ "engines": {"node": ">= 0.6.0"},
"author": "Ajax.org B.V. <info@ajax.org>",
- "main": "bin/cloud9",
+
+ "dependencies": {
+ "architect": "0.0.x"
+ },
+
"repository" : {
"type" : "git",
"url" : "git://github.com/ajaxorg/cloud9.git"
},
- "bin" : {
- "cloud9" : "./bin/cloud9-npm.js"
- },
"licenses": [{
"type": "GPLv3",
- "url": "http://www.gnu.org/licenses/gpl-3.0.txt"}
- ]
-}
+ "url": "http://www.gnu.org/licenses/gpl-3.0.txt"
+ }]
+}
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,55 @@
+var connect = require("connect");
+
+/**
+ * In this example all interactions with the plugin system are encaplsulated in
+ * the startup() function. This makes it easy to test and develop
+ * the main functionality (createServer) independently.
+ */
+
+var exports = module.exports = function startup(options, imports, register) {
+ imports.log.info("connect plugin start");
+ var server = exports.createServer();
+
+ server.listen(options.port, options.host, function(err) {
+ if (err)
+ return register(err);
+
+ imports.log.info("Connect server listening at http://" + options.host + ":" + options.port);
+
+ register(null, {
+ "onDestruct": function(callback) {
+ server.close();
+ server.on("close", callback);
+ },
+ "connect.route": {
+ addRoute: server.addRoute
+ },
+ "http": {
+ getServer: function() {
+ return server;
+ }
+ }
+ });
+ });
+};
+
+/**
+ * The main funcitonality.
+ *
+ * It is good practice to make this also usable without the plugin system. In
+ * bigger plugins this should be extgracted in a separate module
+ */
+exports.createServer = function(routes) {
+ var app;
+
+ var server = connect()
+ .use(connect.router(function(app_) {
+ app = app_;
+ }));
+
+ server.addRoute = function(method, route, handler) {
+ method = method.toLowerCase() || "get";
+ app[method](route, handler);
+ };
+ return server;
+};
@@ -0,0 +1,21 @@
+{
+ "name": "architect-demo.connect",
+ "version": "0.0.1",
+
+ "main": "./connect-plugin",
+
+ "dependencies": {
+ "connect": "1.8.x"
+ },
+
+ "plugin": {
+ "provides": [
+ "connect.route",
+ "http"
+ ],
+
+ "consumes": [
+ "log"
+ ]
+ }
+}
@@ -0,0 +1,51 @@
+var jsDAV_ServerPlugin = require("jsdav/lib/DAV/plugin").jsDAV_ServerPlugin;
+var util = require("util");
+
+var Permission = module.exports = function(handler) {
+ jsDAV_ServerPlugin.call(this, handler);
+
+ this.handler = handler;
+ handler.addEventListener("beforeMethod", this.checkPermission.bind(this));
+};
+
+util.inherits(Permission, jsDAV_ServerPlugin);
+
+(function() {
+
+ this.READ_METHODS = {
+ "OPTIONS":1,
+ "GET":1,
+ "HEAD":1,
+ "PROPFIND":1,
+ "REPORT":1
+ };
+
+ this.WRITE_METHODS = {
+ "DELETE":1,
+ "MKCOL":1,
+ "PUT":1,
+ "PROPPATCH":1,
+ "COPY":1,
+ "MOVE":1,
+ "LOCK":1,
+ "UNLOCK":1
+ };
+
+ this.checkPermission = function(e, method) {
+ var permissions = this.handler.server.permissions;
+
+ if (!permissions)
+ return e.next();
+
+ if (this.READ_METHODS[method] && permissions.dav.indexOf("r") > -1)
+ return e.next();
+
+ if (this.WRITE_METHODS[method] && permissions.dav.indexOf("w") > -1)
+ return e.next();
+
+ this.handler.httpResponse.writeHead(403);
+ this.handler.httpResponse.end("operation not permitted!");
+ e.stop();
+ };
+
+}).call(Permission.prototype);
@@ -0,0 +1,85 @@
+var util = require("util");
+
+exports.HttpError = function(message, code) {
+ Error.call(this, message);
+ //Error.captureStackTrace(this, arguments.callee);
+ this.message = message;
+ this.code = code;
+};
+util.inherits(exports.HttpError, Error);
+
+(function() {
+
+ this.toString = function() {
+ return this.message;
+ };
+
+}).call(exports.HttpError.prototype);
+
+
+var statusCodes = {
+ 400: "Bad Request",
+ 401: "Unauthorized",
+ 402: "Payment Required",
+ 403: "Forbidden",
+ 404: "Not Found",
+ 405: "Method Not Allowed",
+ 406: "Not Acceptable",
+ 407: "Proxy Authentication Required",
+ 408: "Request Timeout",
+ 409: "Conflict",
+ 410: "Gone",
+ 411: "Length Required",
+ 412: "Precondition Failed",
+ 413: "Request Entity Too Large",
+ 414: "Request-URI Too Long",
+ 415: "Unsupported Media Type",
+ 416: "Requested Range Not Satisfiable",
+ 417: "Expectation Failed",
+ 418: "Im a Teapot", // (RFC 2324) http://tools.ietf.org/html/rfc2324
+ 420: "Enhance Your Calm", // Returned by the Twitter Search and Trends API when the client is being rate limited
+ 422: "Unprocessable Entity", // (WebDAV) (RFC 4918)
+ 423: "Locked", // (WebDAV) (RFC 4918)
+ 424: "Failed Dependency", // (WebDAV) (RFC 4918)
+ 425: "Unordered Collection", // (RFC 3648)
+ 426: "Upgrade Required", // (RFC 2817)
+ 428: "Precondition Required",
+ 429: "Too Many Requests", // Used for rate limiting
+ 431: "Request Header Fields Too Large",
+ 444: "No Response", // An nginx HTTP server extension. The server returns no information to the client and closes the connection (useful as a deterrent for malware).
+ 449: "Retry With", // A Microsoft extension. The request should be retried after performing the appropriate action.
+ 450: "Blocked By Windows Parental Controls",
+ 499: "Client Closed Request",
+ 500: "Internal Server Error",
+ 501: "Not Implemented",
+ 502: "Bad Gateway",
+ 503: "Service Unavailable",
+ 504: "Gateway Timeout",
+ 505: "HTTP Version Not Supported"
+};
+
+for (var status in statusCodes) {
+ var defaultMsg = statusCodes[status];
+
+ var error = (function(defaultMsg, status) {
+ return function(msg) {
+ this.defaultMessage = defaultMsg;
+ exports.HttpError.call(this, msg || status + ": " + defaultMsg, status);
+
+ if (status >= 500)
+ Error.captureStackTrace(this, arguments.callee);
+ };
+ })(defaultMsg, status);
+
+ util.inherits(error, exports.HttpError);
+
+ var className = toCamelCase(defaultMsg);
+ exports[className] = error;
+ exports[status] = error;
+}
+
+function toCamelCase(str) {
+ return str.toLowerCase().replace(/(?:(^.)|(\s+.))/g, function(match) {
+ return match.charAt(match.length-1).toUpperCase();
+ });
+}
@@ -0,0 +1,31 @@
+var IdeServer = require("./ide");
+
+module.exports = function setup(options, imports, register) {
+
+ var log = imports.log;
+ var hub = imports.hub;
+
+ var plugins = {};
+
+ register(null, {
+ ide: {
+ register: function(name, plugin, callback) {
+ plugins[name] = plugin;
+ callback();
+ }
+ }
+ });
+
+ hub.on("containersDone", function() {
+
+ var server = imports.http.getServer();
+
+ var ideOptions = {
+ workspaceDir: options.workspaceDir || __dirname + "/../../"
+ };
+
+ var ide = new IdeServer(ideOptions, server, plugins);
+
+ log.info("IDE server initialized");
+ });
+};
Oops, something went wrong.

0 comments on commit 92b964b

Please sign in to comment.