diff --git a/.gitignore b/.gitignore index 0b108e06..ac005ae1 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,7 @@ plugins/c9.fs/mock/ # ignore node_modules node_modules/* +plugins/c9.batch/analytics/node_modules/ # except git subtrees !node_modules/ace* !node_modules/architect* diff --git a/README.md b/README.md index 71a8e5d8..ae89a8aa 100644 --- a/README.md +++ b/README.md @@ -91,4 +91,4 @@ To protect the interests of the Cloud9 contributors and users we require contrib If you want to contribute to the Cloud9 SDK and/or open source plugins please go to the online form, fill it out and submit it. -Happy coding, Cloud9 +Happy coding, Cloud9 \ No newline at end of file diff --git a/bin/c9 b/bin/c9 index 32d1f9e5..9de38075 100755 --- a/bin/c9 +++ b/bin/c9 @@ -6,8 +6,6 @@ var architect = require("architect"); // Add ability to load AMD modules require("amd-loader"); -var verbose = process.argv.indexOf("--verbose") + 1 - || process.argv.indexOf("-v") + 1; architect.resolveConfig(require("../configs/cli.js")(), __dirname + "/../plugins", function (err, config) { diff --git a/configs/cli.js b/configs/cli.js index 9bfebe48..80a8d3f5 100644 --- a/configs/cli.js +++ b/configs/cli.js @@ -1,12 +1,14 @@ module.exports = function(options) { // workaround for api difference between node and c9 events modules -var EventEmitter = require("events").EventEmitter; -var emit_ = EventEmitter.prototype.emit -EventEmitter.prototype.emit = function() { - emit_.apply(this, arguments); - return true; -} +var EventEmitter = require("../plugins/c9.nodeapi/events").EventEmitter; +var Module = require("module"); +var _resolveFilename_orig = Module._resolveFilename +Module._resolveFilename = function(id, parent) { + if (id == "events" && parent && /c9.core[\\/]ext\.js/.test(parent.id)) + id = "../c9.nodeapi/events"; + return _resolveFilename_orig.call(Module, id, parent); +}; var PID = process.env.C9_PID || 526; var APIHOST = process.env.C9_APIHOST || "api.c9.io"; // "api.c9.io"; diff --git a/configs/client-default-local.js b/configs/client-default-local.js index 33361ca7..ff27686b 100644 --- a/configs/client-default-local.js +++ b/configs/client-default-local.js @@ -84,6 +84,9 @@ module.exports.makeLocal = function(config, options) { config[i].autoInit = false; } else if (config[i].packagePath == "plugins/c9.ide.tree/tree") { config[i].defaultExpanded = !config.hosted; + } else if (config[i].packagePath == "plugins/c9.ide.errorhandler/raygun_error_handler") { + // TODO fix cycle introduced by local/info and raygun_error_handler + config[i].packagePath = "plugins/c9.ide.errorhandler/simple_error_handler"; } } @@ -127,9 +130,13 @@ module.exports.makeLocal = function(config, options) { contents: options.project.contents, descr: options.project.descr } - }].filter(Boolean); + }, + c9Ws && "plugins/c9.ide.analytics/mock_analytics", + ].filter(Boolean); - var excludes = c9Ws ? {} : { + var excludes = c9Ws ? { + "plugins/c9.ide.analytics/analytics": true, + } : { "plugins/c9.ide.newresource/open": true, "plugins/c9.ide.info/info": true, // "plugins/c9.ide.login/login": true, diff --git a/configs/client-default.js b/configs/client-default.js index 19443ec5..746f4a6b 100644 --- a/configs/client-default.js +++ b/configs/client-default.js @@ -122,7 +122,8 @@ module.exports = function(options) { servers: options.vfsServers, updateServers: hosted, strictRegion: options.strictRegion - || options.mode === "beta" && "beta" + || options.mode === "beta" && "beta", + ignoreProtocolVersion: options.ignoreProtocolVersion, }, { packagePath: "plugins/c9.ide.auth/auth", @@ -381,7 +382,7 @@ module.exports = function(options) { "plugins/c9.ide.immediate/evaluator", "plugins/c9.ide.immediate/evaluators/browserjs", "plugins/c9.ide.immediate/evaluators/debugnode", - // "plugins/c9.ide.immediate/evaluators/bash", + "plugins/c9.ide.immediate/evaluators/bash", "plugins/c9.ide.run.debug/variables", "plugins/c9.ide.run.debug/watches", "plugins/c9.ide.run.debug/liveinspect", @@ -704,6 +705,22 @@ module.exports = function(options) { staticPrefix: staticPrefix + "/plugins/c9.ide.collab/notifications" }, + // Test + { + packagePath: "plugins/c9.ide.test/test" + }, + "plugins/c9.ide.test/testpanel", + "plugins/c9.ide.test/testrunner", + { + packagePath: "plugins/c9.ide.test/all", + staticPrefix: staticPrefix + "/plugins/c9.ide.test" + }, + "plugins/c9.ide.test/results", + "plugins/c9.ide.test/coverage", + "plugins/c9.ide.test/coverageview", + + "plugins/c9.ide.test.mocha/mocha", + // git integration "plugins/c9.ide.scm/scm", "plugins/c9.ide.scm/scmpanel", @@ -711,26 +728,9 @@ module.exports = function(options) { "plugins/c9.ide.scm/log", "plugins/c9.ide.scm/git", "plugins/c9.ide.scm/editor", + "plugins/c9.ide.scm/mergetool" ]; - if (!options.sdk) { - plugins.push( - // Test - "plugins/c9.ide.test/test", - "plugins/c9.ide.test/testpanel", - "plugins/c9.ide.test/testrunner", - { - packagePath: "plugins/c9.ide.test/all", - staticPrefix: staticPrefix + "/plugins/c9.ide.test" - }, - "plugins/c9.ide.test/results", - "plugins/c9.ide.test/coverage", - "plugins/c9.ide.test/coverageview", - - "plugins/c9.ide.test.mocha/mocha" - ); - } - if (packaging || !devel) { plugins.push({ diff --git a/configs/standalone.js b/configs/standalone.js index 01115eb1..1e83ff13 100644 --- a/configs/standalone.js +++ b/configs/standalone.js @@ -155,7 +155,9 @@ module.exports = function(config, optimist) { "c9.cli.bridge": true, "c9.nodeapi": true, "c9.ide.experiment": true, - "saucelabs.preview": true + "saucelabs.preview": true, + "salesforce.sync": true, + "salesforce.language": true } }, "./c9.preview/statics", @@ -184,6 +186,7 @@ module.exports = function(config, optimist) { "./c9.vfs.server/cache", "./c9.vfs.server/download", "./c9.vfs.server/filelist", + "./c9.vfs.server/fetchcache", "./c9.vfs.server/statics", "./c9.analytics/mock_analytics", "./c9.metrics/mock_metrics", diff --git a/local/index.html b/local/index.html index a5fd00b3..08375f35 100644 --- a/local/index.html +++ b/local/index.html @@ -271,7 +271,7 @@ function loadRequireJsConfig(cb) { var requirejs = window.requirejs; window.require = requirejs; - requirejs.setConfig = requirejs.config; + requirejs.setConfig = requirejs.setConfig || requirejs.config; requirejs.config = function(config) { config.baseUrl = requirejsBaseUrl + (config.baseUrl || ""); if (config.paths) { @@ -293,7 +293,7 @@ require.packaged = true; if (!packed || devel) { packageIsLoading = true; - loadScript("plugins/c9.vfs.standalone/www/require.js", function() { + loadScript("node_modules/architect-build/build_support/mini_require.js", function() { removeNwRequire(); startIde(); packageIsLoading = false; diff --git a/local/server.js b/local/server.js index 9598972f..206a0fe3 100644 --- a/local/server.js +++ b/local/server.js @@ -361,7 +361,7 @@ var server = { } } - if (p.staticPrefix && options.windowLocation && options.packed) { + if (p.staticPrefix && options.windowLocation && (options.packed || isRemote)) { p.staticPrefix = p.staticPrefix.replace(/^\/static/, options.windowLocation); } } @@ -392,6 +392,10 @@ var server = { plugins = require(configPath).makeLocal(config.plugins, settings); settings.url = config.url; } + plugins.forEach(function(p) { + if (p.staticPrefix) + p.staticPrefix = p.staticPrefix.replace(/^https?:\/\/.*?\/static/, "/static"); + }) updateFilePaths(plugins, function(){ cb(plugins, settings); }); @@ -415,7 +419,6 @@ var server = { openWindow : openWindow, parseArgs : parseArgs, getRecentWindows: getRecentWindows, - listC9Projects: listC9Projects, getRemoteWorkspaceConfig: getRemoteWorkspaceConfig }; @@ -1023,49 +1026,6 @@ function loadData(url, callback) { xhr.send(""); } -// TODO add proper api to c9 server -function listC9Projects(user, callback) { - if (!user) - return callback(null, []); - - var url = "https://c9.io/" + user.name; - loadData(url, function(err, result) { - if (err) return callback(err); - var ownProjects = []; - var sharedProjects = []; - try { - var pids = Object.create(null); - JSON.parse(result.match(/projects:\s*(.*),/)[1]).forEach(function(x) { - var userName = x.owner_username || user.name; - - var project = { - name: userName + "/" + x.name, - projectName: x.name, - pid: x.pid, - isRemote: true, - }; - - if (pids[project.pid]) - return; - - pids[project.pid] = project; - - if (userName == user.name) - ownProjects.push(project); - else - sharedProjects.push(project); - }); - } catch(e) { - console.error(e); - return callback(e); - } - callback(null, { - shared: sharedProjects, - own: ownProjects - }); - }); -} - function getRemoteWorkspaceConfig(projectName, callback) { var url = "https://ide.c9.io/" + projectName + "?config=1"; loadData(url, function(err, result, xhr) { diff --git a/node_modules/ace/lib/ace/lib/event.js b/node_modules/ace/lib/ace/lib/event.js index 459ce0f2..80a132c5 100644 --- a/node_modules/ace/lib/ace/lib/event.js +++ b/node_modules/ace/lib/ace/lib/event.js @@ -281,7 +281,9 @@ function normalizeCommandKeys(callback, e, keyCode) { keyCode = -1; } - if (hashId & 8 && (keyCode === 91 || keyCode === 92)) { + // keyCode of right command is 93 on mac and 92 on windows. + // keyCode of left command key is 91 + if (hashId & 8 && (keyCode >= 91 && keyCode <= 93)) { keyCode = -1; } diff --git a/node_modules/ace/lib/ace/line_widgets.js b/node_modules/ace/lib/ace/line_widgets.js index c8154a13..6eaffc88 100644 --- a/node_modules/ace/lib/ace/line_widgets.js +++ b/node_modules/ace/lib/ace/line_widgets.js @@ -294,6 +294,8 @@ function LineWidgets(session) { if (!w || !w.el) continue; if (w.session != this.session) continue; if (!w._inDocument) { + if (this.session.lineWidgets[w.row] != w) + continue; w._inDocument = true; renderer.container.appendChild(w.el); } diff --git a/node_modules/ace/lib/ace/scrollbar.js b/node_modules/ace/lib/ace/scrollbar.js index 466d1af1..465c6942 100644 --- a/node_modules/ace/lib/ace/scrollbar.js +++ b/node_modules/ace/lib/ace/scrollbar.js @@ -98,6 +98,7 @@ var VScrollBar = function(parent, renderer) { this.width = dom.scrollbarWidth(parent.ownerDocument); this.inner.style.width = this.element.style.width = (this.width || 15) + 5 + "px"; + this.$minWidth = 0; }; oop.inherits(VScrollBar, ScrollBar); @@ -124,7 +125,7 @@ oop.inherits(VScrollBar, ScrollBar); * @returns {Number} **/ this.getWidth = function() { - return this.isVisible ? this.width : 0; + return Math.max(this.isVisible ? this.width : 0, this.$minWidth || 0); }; /** diff --git a/node_modules/ace/lib/ace/selection.js b/node_modules/ace/lib/ace/selection.js index ed57682f..328df4b0 100644 --- a/node_modules/ace/lib/ace/selection.js +++ b/node_modules/ace/lib/ace/selection.js @@ -799,8 +799,10 @@ var Selection = function(session) { var docPos = this.session.screenToDocumentPosition(screenPos.row + rows, screenPos.column); if (rows !== 0 && chars === 0 && docPos.row === this.lead.row && docPos.column === this.lead.column) { - if (this.session.lineWidgets && this.session.lineWidgets[docPos.row]) - docPos.row++; + if (this.session.lineWidgets && this.session.lineWidgets[docPos.row]) { + if (docPos.row > 0 || rows > 0) + docPos.row++; + } } // move the cursor and update the desired column diff --git a/node_modules/architect-build/build_support/mini_require.js b/node_modules/architect-build/build_support/mini_require.js index 6e643a35..45407316 100644 --- a/node_modules/architect-build/build_support/mini_require.js +++ b/node_modules/architect-build/build_support/mini_require.js @@ -299,8 +299,17 @@ require.undef = function(module, recursive) { function undefAll(module, hash) { Object.keys(hash).forEach(function(key) { + var i = key.indexOf("!") + 1; if (key.lastIndexOf(module, 0) == 0) require.undef(key); + if (i) { + var plugin = key.slice(0, i - 1); + var resource = key.slice(i); + if (resource.lastIndexOf(module, 0) == 0 || plugin.lastIndexOf(module, 0) == 0) { + require.undef(key); + require.undef(resource); + } + } }); } diff --git a/node_modules/architect/architect.js b/node_modules/architect/architect.js index 9b2d602a..59d552b2 100644 --- a/node_modules/architect/architect.js +++ b/node_modules/architect/architect.js @@ -406,7 +406,9 @@ function checkCycles(config, lookup) { "\nMissing services:\n" + unresolvedList.join("\n") + "\n", unresolved, "\nResolved services:", Object.keys(resolved)); var err = new Error("Could not resolve dependencies\n" - + "Missing services: " + unresolvedList); + + (unresolvedList.length ? "Missing services: " + unresolvedList + : "Config contains cyclic dependencies" // TODO print cycles + )); err.unresolved = unresolvedList; throw err; } diff --git a/node_modules/c9/has-internal-domain.js b/node_modules/c9/has-internal-domain.js new file mode 100644 index 00000000..cf74b050 --- /dev/null +++ b/node_modules/c9/has-internal-domain.js @@ -0,0 +1,24 @@ +if (define === undefined) { + var define = function(fn) { + fn(require, exports, module); + }; +} + +define(function(require, exports, module) { + "use strict"; + + var _ = require("lodash"); + + var internalDomain = ['c9.io', 'cloud9beta.com']; + + function hasInternalDomain(email) { + if (!email) return false; + + var emailElements = email.split("@"); + var emailDomain = emailElements[emailElements.length - 1]; + + return _.contains(internalDomain, emailDomain); + } + + module.exports = hasInternalDomain; +}); \ No newline at end of file diff --git a/node_modules/c9/has-internal-domain_test.js b/node_modules/c9/has-internal-domain_test.js new file mode 100644 index 00000000..d045efee --- /dev/null +++ b/node_modules/c9/has-internal-domain_test.js @@ -0,0 +1,34 @@ +"use strict"; +"use mocha"; + +require("c9/inline-mocha")(module); +var assert = require("assert"); +var faker = require("faker"); +var hasInternalDomain= require("c9/has-internal-domain"); + +describe("has-internal-domain", function() { + + it("returns false when undefined email", function() { + var email; + + assert.equal(false, hasInternalDomain(email), "should return false when email undefined"); + }); + + it("returns true when email has c9.io domain", function() { + var email = "test@c9.io"; + + assert.equal(true, hasInternalDomain(email), "should return true when email has c9.io domain"); + }); + + it("returns true when has cloud9beta.com domain", function() { + var email = "test@cloud9beta.com"; + + assert.equal(true, hasInternalDomain(email), "should return true when email has cloud9beta.com domain"); + }); + + it("returns false when not internal email", function() { + var email = faker.internet.email(); + + assert.equal(false, hasInternalDomain(email), "should return false when email is not internal"); + }); +}); \ No newline at end of file diff --git a/node_modules/c9/json-with-re.js b/node_modules/c9/json-with-re.js new file mode 100644 index 00000000..e8f475db --- /dev/null +++ b/node_modules/c9/json-with-re.js @@ -0,0 +1,28 @@ +/** + * JSON (de-)serializer with support for encosing regular expressions + */ +"use strict"; + +exports.replacer = function(key, value) { + if (value instanceof RegExp) + return ("__REGEXP " + value.toString()); + else + return value; +}; + +exports.reviver = function(key, value) { + if ((value + "").indexOf("__REGEXP ") == 0) { + var m = value.match(/__REGEXP \/(.*)\/(.*)?/); + return new RegExp(m[1], m[2]); + } + else + return value; +}; + +exports.stringify = function(value, space) { + return JSON.stringify(value, exports.replacer, space); +}; + +exports.parse = function(rext) { + return JSON.parse(rext, exports.reviver); +}; \ No newline at end of file diff --git a/node_modules/c9/json-with-re_test.js b/node_modules/c9/json-with-re_test.js new file mode 100644 index 00000000..5ccb3ecb --- /dev/null +++ b/node_modules/c9/json-with-re_test.js @@ -0,0 +1,27 @@ +/*global describe it before after beforeEach afterEach define*/ +"use strict"; +"use server"; +"use mocha"; + +require("c9/inline-mocha")(module); + +var assert = require("assert-diff"); +var reJSON = require("./json-with-re"); + +describe(__filename, function(){ + it("should encode regular expressions", function() { + assert.deepEqual(reJSON.stringify({ foo: /foo/ }), '{"foo":"__REGEXP /foo/"}'); + assert.deepEqual(reJSON.stringify({ foo: /foo\//gi }), "{\"foo\":\"__REGEXP /foo\\\\//gi\"}"); + }); + it("should decode regular expressions", function() { + assert.deepEqual(reJSON.parse('{"foo":"__REGEXP /foo/"}'), { foo: /foo/ }); + assert.deepEqual(reJSON.parse("{\"foo\":\"__REGEXP /foo\\\\//gi\"}"), { foo: /foo\//gi }); + }); + it("should deal with null values", function() { + var o = { + foo: null, + bar: /dd/ + }; + assert.deepEqual(reJSON.parse(reJSON.stringify(o)), o); + }); +}); diff --git a/node_modules/c9/oberr.js b/node_modules/c9/oberr.js new file mode 100644 index 00000000..1a540724 --- /dev/null +++ b/node_modules/c9/oberr.js @@ -0,0 +1,15 @@ +define(function(require, exports, module) { + + /** + * Turns a JS Error into a proper object that can be stringified + * https://github.com/timjrobinson/oberr for more information + **/ + return function oberr(err) { + var ob = {}; + Object.getOwnPropertyNames(err).forEach(function(key) { + ob[key] = err[key]; + }); + return ob; + }; + +}); \ No newline at end of file diff --git a/node_modules/c9/object.js b/node_modules/c9/object.js new file mode 100644 index 00000000..875dc338 --- /dev/null +++ b/node_modules/c9/object.js @@ -0,0 +1,9 @@ +/* + * Swap keys and values of an object + */ +exports.invert = function(obj) { + return Object.keys(obj).reduce(function(res, key) { + res[obj[key]] = key; + return res; + }, {}); +}; \ No newline at end of file diff --git a/node_modules/c9/skip-analytics.js b/node_modules/c9/skip-analytics.js new file mode 100644 index 00000000..7362fd63 --- /dev/null +++ b/node_modules/c9/skip-analytics.js @@ -0,0 +1,20 @@ +if (define === undefined) { + var define = function(fn) { + fn(require, exports, module); + }; +} + +define(function(require, exports, module) { + "use strict"; + + var hasInternalDomain = require("c9/has-internal-domain"); + + function skipAnalytics(user) { + if (!user) return true; + if (user.id === -1) return true; + if (hasInternalDomain(user.email)) return true; + return false; + } + + module.exports = skipAnalytics; +}); \ No newline at end of file diff --git a/node_modules/c9/skip-analytics_test.js b/node_modules/c9/skip-analytics_test.js new file mode 100644 index 00000000..300251b0 --- /dev/null +++ b/node_modules/c9/skip-analytics_test.js @@ -0,0 +1,53 @@ +"use strict"; +"use mocha"; + +require("c9/inline-mocha")(module); +var assert = require("assert"); +var faker = require("faker"); +var skipAnalytics = require("c9/skip-analytics"); + +describe("skip-analytics", function() { + + it("returns true when user undefined", function() { + var user; + + assert.equal(true, skipAnalytics(user), "skipAnalytics should return true when user undefined"); + }); + + it("returns true when user id is -1", function() { + var user = { + id: -1 + }; + + assert.equal(true, skipAnalytics(user), "skipAnalytics should return true when user id is -1"); + }); + + it("returns false when user has no email", function() { + var user = { + id: faker.random.uuid() + }; + + assert.equal(false, skipAnalytics(user), "skipAnalytics should return false when user has no email"); + }); + + it("returns true when user has internal email", function() { + var user = { + id: faker.random.uuid(), + email: "test@c9.io" + }; + + assert.equal(true, skipAnalytics(user), "skipAnalytics should return true when user has internal email"); + + user.email = "test@cloud9beta.com"; + assert.equal(true, skipAnalytics(user), "skipAnalytics should return true when user has internal beta email"); + }); + + it("returns false when user is authorized and does not have intermal email", function() { + var user = { + id: faker.random.uuid(), + email: faker.internet.email() + }; + + assert.equal(false, skipAnalytics(user), "skipAnalytics should return false when user is authorized and does not have internal email"); + }); +}); \ No newline at end of file diff --git a/node_modules/c9/string.js b/node_modules/c9/string.js index 5e3714ce..2a28f65c 100644 --- a/node_modules/c9/string.js +++ b/node_modules/c9/string.js @@ -43,5 +43,14 @@ exports.repeat = function(str, times) { exports.count = function(str, substr){ return str.split(substr).length - 1; }; + +exports.endsWith = function(subjectString, searchString, position) { + if (typeof position !== 'number' || !isFinite(position) || Math.floor(position) !== position || position > subjectString.length) { + position = subjectString.length; + } + position -= searchString.length; + var lastIndex = subjectString.indexOf(searchString, position); + return lastIndex !== -1 && lastIndex === position; +}; }); \ No newline at end of file diff --git a/node_modules/c9/urls.js b/node_modules/c9/urls.js index a1b000af..0284030c 100644 --- a/node_modules/c9/urls.js +++ b/node_modules/c9/urls.js @@ -6,36 +6,71 @@ * @copyright 2015, Ajax.org B.V. */ -var plugin = module.exports = main; var assert = require("assert"); - -plugin.consumes = ["error.logger"]; -plugin.provides = ["urls"]; -var errorLogger = mockErrorLogger; +function getHost(req) { + var host = + req.headers && req.headers.host || + req.host || + req.url || + req; + + return host.replace(/^https?:\/\/([^/]*).*/, "$1"); +} -function main(options, imports, register) { - errorLogger = imports["error.logger"]; +function splitDomain(req, domains) { + var host = getHost(req); - register(null, { - urls: plugin - }); + var allDomains = domains.join("|"); + var domainRe = new RegExp("^(.*?)\\.?(" + allDomains.replace(".", "\\.") + ")(?::(\\d+))?$"); + + var m = host.match(domainRe); + if (m) { + return { + subDomains: m[1], + domainName: m[2], + port: m[3] || "" + }; + } else { + return { + subDomains: "", + domainName: host.split(":")[0], + port: host.split(":")[1] || "" + }; + } } /** * Get a desired base URL, given some context. * - * @param req The current request object or URL - * @param {String} [sourceUrlPattern] The source URL pattern, e.g. https://ide.$DOMAIN - * @param {String} targetBaseUrlPattern The target URL pattern, e.g. https://$DOMAIN + * Example for a request coming into the IDE service: + * + * ``` + * getBaseUrl(req, "https://ide.$DOMAIN", "https://preview.$DOMAIN"); + * ``` + * + * The above example will determine the domain name from the request, + * by stripping off the "https://ide." part. So, for a domain like + * "https://ide.c9.io" we'll get "c9.io". For a domain like + * "https://ide.dogfooding-lennartcl.c9.io" we'll get dogfooding-lennartcl.c9.io. + * If there is no match, a warning is shown. The target pattern + * is used to construct the resulting URL, e.g. https://preview.c9.io. + * + * @param req + * The current request object or URL + * @param {String} [sourceUrlPattern] + * The URL pattern of the current service, e.g. https://ide.$DOMAIN if + * we are getting an incoming request for the IDE service + * @param {String} targetBaseUrlPattern + * The URL pattern of the target service. E.g., if we want to + * construct the base URL of the API service, this might be https://api.$DOMAIN. */ -plugin.getBaseUrl = function(req, sourceBaseUrlPattern, targetBaseUrlPattern) { - var sourceHost = req.headers && req.headers.host - || req.host - || req.url && req.url.replace(/^https?:\/\/([^/]*).*/, "$1") - || req; +function getBaseUrl(req, sourceBaseUrlPattern, targetBaseUrlPattern) { + var sourceHost = getHost(req); + if (typeof sourceHost !== "string") throw new Error("Not a valid request object: " + req); + if (!sourceBaseUrlPattern) throw new Error("getBaseUrl() requires at least two arguments"); @@ -46,24 +81,29 @@ plugin.getBaseUrl = function(req, sourceBaseUrlPattern, targetBaseUrlPattern) { .replace("$DOMAIN", "([^/]+)"); var hostMatch = sourceHost.match(sourceHostMatcher); var targetHost; + if (hostMatch) { targetHost = hostMatch[1]; } else { - errorLogger.log(new Error("Could not construct URL: request host " - + sourceHost + " should match " + sourceBaseUrlPattern)); + console.error(new Error("Could not construct URL: request host " + sourceHost + " should match " + sourceBaseUrlPattern)); + targetHost = "c9.io"; } - - if (targetHost.match(/^(ide|vfs)./) && !targetBaseUrlPattern) - errorLogger.log(new Error("Warning: no targetBaseUrlPattern specified, will stay at " + targetHost), { sourceBaseUrlPattern: sourceBaseUrlPattern }); - if (targetHost.match(/^(ide|vfs)./)) - console.trace("Warning: possibly incorrect baseUrl constructed, with 'ide.' in the hostname: " + targetHost); + + if (/^(ide|vfs)./.test(targetHost) && !targetBaseUrlPattern) + console.error(new Error("Warning: no targetBaseUrlPattern specified, will stay at " + targetHost), { + sourceBaseUrlPattern: sourceBaseUrlPattern + }); + + if (/^(ide|vfs)./.test(targetHost)) + console.trace("Warning: possibly incorrect baseUrl constructed, with 'ide.' in the hostname: " + targetHost); + return replaceDomain(targetBaseUrlPattern || sourceBaseUrlPattern, targetHost) .replace(/\/$/, ""); -}; +} -plugin.replaceDomains = function(settings, domains) { +function replaceDomains(settings, domains) { domains = Array.isArray(domains) ? domains : domains.split(","); var primaryDomain = domains[0]; settings.domains = domains; @@ -85,14 +125,15 @@ plugin.replaceDomains = function(settings, domains) { }); } } -}; +} function replaceDomain(url, domain) { return url.replace("$DOMAIN", domain); } -function mockErrorLogger() {} -mockErrorLogger.log = function(err) { - console.error(err.stack); -}; -plugin.mockErrorLogger = mockErrorLogger; +module.exports = { + replaceDomains: replaceDomains, + getBaseUrl: getBaseUrl, + splitDomain: splitDomain, + getHost: getHost +}; \ No newline at end of file diff --git a/node_modules/c9/urls_test.js b/node_modules/c9/urls_test.js index 9e5bc0ec..18cd3fe6 100644 --- a/node_modules/c9/urls_test.js +++ b/node_modules/c9/urls_test.js @@ -9,7 +9,7 @@ if (typeof define === "undefined") { require("../../test/setup_paths"); } -var assert = require("assert"); +var assert = require("assert-diff"); var urls = require("./urls"); var url = require("url"); var sinon = require("sinon"); @@ -126,4 +126,28 @@ describe("urls", function() { var baseUrl = urls.getBaseUrl(input, "https://preview.$DOMAIN"); assert.equal(baseUrl, "https://preview.newclient-lennartcl.c9.io"); }); + + it("should split domains", function() { + var domains = ["c9.io", "c9users.io", "cs50.io"]; + assert.deepEqual(urls.splitDomain("fjakobs-ace.c9.io", domains), { + domainName: "c9.io", + subDomains: "fjakobs-ace", + port: "" + }); + assert.deepEqual(urls.splitDomain("preview.c9users.io", domains), { + domainName: "c9users.io", + subDomains: "preview", + port: "" + }); + assert.deepEqual(urls.splitDomain("fjakobs.ace.cs50.io", domains), { + domainName: "cs50.io", + subDomains: "fjakobs.ace", + port: "" + }); + assert.deepEqual(urls.splitDomain("fjakobs.ace.cs50.io:8081", domains), { + domainName: "cs50.io", + subDomains: "fjakobs.ace", + port: "8081" + }); + }); }); \ No newline at end of file diff --git a/node_modules/connect-architect/connect.redirect/redirect.js b/node_modules/connect-architect/connect.redirect/redirect.js index 010e98e8..43b634f6 100644 --- a/node_modules/connect-architect/connect.redirect/redirect.js +++ b/node_modules/connect-architect/connect.redirect/redirect.js @@ -1,11 +1,24 @@ "use strict"; +var url = require("url"); + module.exports = function(options, imports, register) { + var trustedDomainsRe = options.trustedDomainsRe || /.*/; + imports.connect.addResponseMethod("redirect", function(location) { this.writeHead(302, {Location: location}); this.end(""); }); + imports.connect.addResponseMethod("secureRedirect", function(location) { + var parsedLocation = url.parse(location); + + if (!trustedDomainsRe.test(parsedLocation.host)) + location = parsedLocation.path; + + this.writeHead(302, {Location: location}); + this.end(""); + }); imports.connect.addResponseMethod("returnTo", function(req, defaultReturn) { var url = defaultReturn || "/"; if (req.session && req.session.returnTo) { diff --git a/node_modules/vfs-local/localfs.js b/node_modules/vfs-local/localfs.js index 12fac9dd..f9376f77 100644 --- a/node_modules/vfs-local/localfs.js +++ b/node_modules/vfs-local/localfs.js @@ -1402,7 +1402,7 @@ module.exports = function setup(fsOptions) { tryConnect(); function tryConnect() { var called = false; - var socket = net.connect(port, process.env.OPENSHIFT_DIY_IP || "localhost", function() { + var socket = net.connect(port, "127.0.0.1", function() { if (called) return; called = true; diff --git a/package.json b/package.json index 8d641fbf..87d1324d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "c9", "description": "New Cloud9 Client", - "version": "3.0.2817", + "version": "3.1.190", "author": "Ajax.org B.V. ", "private": true, "main": "bin/c9", @@ -26,7 +26,7 @@ "mkdirp": "~0.3.5", "msgpack-js": "~0.1.1", "msgpack-js-browser": "~0.1.4", - "nak": "", + "nak": "git://github.com/cloud9ide/nak.git#719f2188ec1d8e4ce553286e80737d7e6434d777", "netutil": "~0.0.2", "optimist": "~0.6.0", "qs": "0.6.6", @@ -55,42 +55,42 @@ "c9" ], "c9plugins": { - "c9.ide.language": "#ff78609c3f", + "c9.ide.language": "#a6ffafabce", "c9.ide.language.css": "#a649f2a710", "c9.ide.language.generic": "#77d43cfaf0", "c9.ide.language.html": "#0f4078c187", "c9.ide.language.html.diff": "#24f3608d26", "c9.ide.language.javascript": "#2b77bdb96a", "c9.ide.language.javascript.immediate": "#0535804ada", - "c9.ide.language.javascript.eslint": "#df7e424b54", + "c9.ide.language.javascript.eslint": "#3ec4557969", "c9.ide.language.javascript.tern": "#ad1d9b1b3a", "c9.ide.language.javascript.infer": "#8478e3c702", - "c9.ide.language.jsonalyzer": "#83646961c7", - "c9.ide.collab": "#6066918891", - "c9.ide.local": "#a9703b630c", + "c9.ide.language.jsonalyzer": "#8401c240b3", + "c9.ide.collab": "#11bdc3aecf", + "c9.ide.local": "#a6e689e33b", "c9.ide.find": "#35379124ca", "c9.ide.find.infiles": "#c132ad243c", "c9.ide.find.replace": "#44772dd796", - "c9.ide.run.debug": "#e38e16e120", + "c9.ide.run.debug": "#3b76105b4e", "c9.automate": "#47e2c429c9", "c9.ide.ace.emmet": "#6dc4585e02", "c9.ide.ace.gotoline": "#a8ff07c8f4", - "c9.ide.ace.keymaps": "#bf6d36213f", - "c9.ide.ace.repl": "#7989bbd07f", + "c9.ide.ace.keymaps": "#2e3c6e3c8f", + "c9.ide.ace.repl": "#4b88a85b7b", "c9.ide.ace.split": "#0ae0151c78", "c9.ide.ace.statusbar": "#d95be89d53", "c9.ide.ace.stripws": "#cf0f42ac59", - "c9.ide.behaviors": "#e2c7f68242", + "c9.ide.behaviors": "#05e5681e2e", "c9.ide.closeconfirmation": "#cee4674141", - "c9.ide.configuration": "#382b61f4ab", + "c9.ide.configuration": "#a9066299a2", "c9.ide.dialog.wizard": "#7667ec79a8", "c9.ide.fontawesome": "#781602c5d8", - "c9.ide.format": "#b0bb91a623", + "c9.ide.format": "#5ec97fb083", "c9.ide.help.support": "#e95f98f87c", "c9.ide.imgeditor": "#66a9733dc1", - "c9.ide.immediate": "#18c23aa730", + "c9.ide.immediate": "#29fd6d3f51", "c9.ide.installer": "#0fde9f0067", - "c9.ide.mount": "#dccfb51a2b", + "c9.ide.mount": "#3e017a3324", "c9.ide.navigate": "#c191d9b92f", "c9.ide.newresource": "#981a408a7b", "c9.ide.openfiles": "#7fa4a97fed", @@ -102,14 +102,14 @@ "c9.ide.recentfiles": "#7c099abf40", "c9.ide.remote": "#301d2ab519", "c9.ide.processlist": "#2b12cd1bdd", - "c9.ide.run": "#ba97f384a6", + "c9.ide.run": "#f360984649", "c9.ide.run.build": "#0598fff697", "c9.ide.run.debug.xdebug": "#61dcbd0180", - "c9.ide.save": "#e00549cb0f", - "c9.ide.scm": "#38d2b48b31", + "c9.ide.save": "#4a4a60a004", + "c9.ide.scm": "#aabd0d181e", "c9.ide.terminal.monitor": "#b76f1c9f24", - "c9.ide.test": "#d312a01ac6", - "c9.ide.test.mocha": "#79ff886c04", + "c9.ide.test": "#26cd260224", + "c9.ide.test.mocha": "#f6cc482886", "c9.ide.theme.flat": "#2de8414db7", "c9.ide.threewaymerge": "#229382aa0b", "c9.ide.undo": "#b028bcb4d5", diff --git a/plugins/c9.cli.publish/publish.js b/plugins/c9.cli.publish/publish.js index 9d11b867..d3efede7 100644 --- a/plugins/c9.cli.publish/publish.js +++ b/plugins/c9.cli.publish/publish.js @@ -44,6 +44,7 @@ define(function(require, exports, module) { var force = false; var dryRun = false; var createTag = false; + var compress = false; // Set up basic auth for api if needed if (BASICAUTH) api.basicAuth = BASICAUTH; @@ -85,6 +86,11 @@ define(function(require, exports, module) { "alias": "t", "default": false, "boolean": true + }, + "compress" : { + "description": "Minify output with uglify.js", + "default": true, + "boolean": true } }, check: function(argv) { @@ -108,7 +114,7 @@ define(function(require, exports, module) { process.exit(1); } else if (!dryRun) { - console.log("Succesfully published version", data.version); + console.log("Successfully published version", data.version); process.exit(0); } }); @@ -125,9 +131,17 @@ define(function(require, exports, module) { "alias": "d", "default": false, "boolean": true + }, + "compress" : { + "description": "Minify output with uglify.js", + "default": false, + "boolean": true } }, exec: function(argv) { + compress = argv["compress"]; + verbose = argv["verbose"]; + force = argv["force"]; if (argv["devel"]) { var code = function(argument) { /* TODO explain */ @@ -159,13 +173,14 @@ define(function(require, exports, module) { } else { dryRun = true; - publish({local: true}, function(err){ + publish({local: true}, function(err, result){ if (err) { console.error(err); if (!verbose) console.error("\nTry running with --verbose flag for more information"); process.exit(1); } + console.log("Done!"); }); } } @@ -186,6 +201,7 @@ define(function(require, exports, module) { check: function(argv) {}, exec: function(argv) { verbose = argv["verbose"]; + compress = argv["compress"]; unpublish( function(err, data){ @@ -194,7 +210,7 @@ define(function(require, exports, module) { process.exit(1); } else { - console.log("Succesfully disabled package"); + console.log("Successfully disabled package"); process.exit(0); } }); @@ -234,6 +250,37 @@ define(function(require, exports, module) { return (verbose ? JSON.stringify(err, 4, " ") : (typeof err == "string" ? err : err.message)); } + function addMissingValues(json) { + json.permissions = json.permissions || "world"; + + return json; + } + + function validateConfig(json) { + var cwd = process.cwd(); + + // Basic Validation + if (json.private) + return new Error("ERROR: Private flag in package.json prevents from publishing"); + if (!json.name) + return new Error("ERROR: Missing name property in package.json"); + if (!json.name.match(/^[\w\._]+$/)) + return new Error("ERROR: Package name can only contain Alphanumeric characters, periods and underscores"); + if (basename(cwd) != json.name) { + console.warn("WARNING: The name property in package.json is not equal to the directory name, which is " + basename(cwd)); + if (!force) + return new Error("Use --force to ignore this warning."); + } + if (!json.repository) + return new Error("ERROR: Missing repository property in package.json"); + if (!json.repository.url) + return new Error("ERROR: Missing repository.url property in package.json"); + if (!json.categories || json.categories.length == 0) + return new Error("ERROR: At least one category is required in package.json"); + if (!json.permissions || !json.permissions.match(/org|world/)) + return new Error("ERROR: Permissions must be 'org' or 'world'"); + } + function publish(options, callback) { if (typeof options != "object") options = {version: options}; @@ -250,36 +297,29 @@ define(function(require, exports, module) { return callback(new Error("ERROR: Could not parse package.json: ", e.message)); } - // Basic Validation - if (json.private) - return callback(new Error("ERROR: Private flag in package.json prevents from publishing")); - if (!json.name) - return callback(new Error("ERROR: Missing name property in package.json")); - if (basename(cwd) != json.name) { - console.warn("WARNING: The name property in package.json is not equal to the directory name, which is " + basename(cwd)); - if (!force) - return callback(new Error("Use --force to ignore this warning.")); - } - if (!json.repository) - return callback(new Error("ERROR: Missing repository property in package.json")); - if (!json.repository.url) - return callback(new Error("ERROR: Missing repository.url property in package.json")); - if (!json.categories || json.categories.length == 0) - return callback(new Error("ERROR: At least one category is required in package.json")); + console.log("Permissions are: ", json.permissions); + console.log("Data is: ", data); + json = addMissingValues(json); + + console.log("Permissions are: ", json.permissions); + var validationError = validateConfig(json); + if (validationError) return callback(validationError); + + var description = json.description; + + if (description) + console.warn("WARNING: Description property in package.json will be ignored. README.md will be used."); // Validate README.md - if (!fs.existsSync(join(cwd, "README.md"))) { + if (fs.existsSync(join(cwd, "README.md"))) { + description = fs.readFileSync(join(cwd, "README.md"), "utf8") + .replace(/^\#.*\n*/, ""); + } else { console.warn("WARNING: README.md is missing."); if (!force) return callback(new Error("Use --force to ignore these warnings.")); } - if (json.description) - console.warn("WARNING: Description property in package.json will be ignored. README.md will be used."); - - var description = fs.readFileSync(join(cwd, "README.md"), "utf8") - .replace(/^\#.*\n*/, ""); - // Validate plugins var plugins = {}; @@ -572,7 +612,7 @@ define(function(require, exports, module) { enableBrowser: true, includeConfig: false, noArchitect: true, - compress: !dryRun, + compress: compress, obfuscate: true, oneLine: true, filter: [], @@ -683,7 +723,7 @@ define(function(require, exports, module) { description: description, owner_type: "user", // @TODO implement this when adding orgs owner_id: parseInt(user.id), - permissions: json.permissions || "world", + permissions: json.permissions, categories: json.categories, repository: json.repository, longname: json.longname, @@ -692,9 +732,10 @@ define(function(require, exports, module) { pricing: json.pricing || {} } }, function(err, pkg){ - if (err) + if (err) { return callback(new Error("ERROR: Failed to upload new package to API - " + stringifyError(err))); + } next(pkg); }); diff --git a/plugins/c9.cli.publish/publish_test.js b/plugins/c9.cli.publish/publish_test.js index 27574203..2eb96fff 100644 --- a/plugins/c9.cli.publish/publish_test.js +++ b/plugins/c9.cli.publish/publish_test.js @@ -2,8 +2,6 @@ "use strict"; "use server"; -"use blacklist"; - require("c9/inline-mocha")(module); if (typeof define === "undefined") { @@ -64,7 +62,7 @@ describe("cli.publish", function(){ "description": "", "star_count": 0, "star_total": 0, - + "installs": 0, "screenshots": [ // TODO Screenshots are broken @@ -95,6 +93,14 @@ describe("cli.publish", function(){ }); }); + it("should be fine if json.permissions is missing as it defaults to world", function(done){ + fs.writeFileSync(packagePath, packageJson.replace(/"permissions[\s\S]*?\],/, "")); + runCLI("publish", ["major"], function(err, stdout, stderr){ + assert(!err, err); + done(); + }); + }); + it("should warn if the package.json is missing", function(done){ fs.unlinkSync(packagePath); runCLI("publish", ["major"], function(err, stdout, stderr){ @@ -116,6 +122,13 @@ describe("cli.publish", function(){ done(); }); }); + it("should fail if the name in the package.json contains invalid characters", function(done){ + fs.writeFileSync(packagePath, packageJson.replace('c9.ide.example', 'c9-ide-example')); + runCLI("publish", ["major"], function(err, stdout, stderr){ + expect(stderr).to.match(/ERROR: Package name can only contain/); + done(); + }); + }); it("should fail if the name in the package.json is not equal to the directory", function(done){ fs.writeFileSync(packagePath, packageJson.replace('"name": "c9.ide.example"', '"name": "wrongname"')); runCLI("publish", ["major"], function(err, stdout, stderr){ @@ -137,6 +150,16 @@ describe("cli.publish", function(){ done(); }); }); + it("should fail if json.permissions is not org or world", function(done){ + var parsedJson = JSON.parse(packageJson); + parsedJson.permissions = "notvalid"; + fs.writeFileSync(packagePath, JSON.stringify(parsedJson)); + runCLI("publish", ["major"], function(err, stdout, stderr){ + console.log("stdout: ", stdout) + expect(stderr).to.match(/ERROR: Permissions must be/); + done(); + }); + }); it("should warn if a plugin is not listed in the package.json", function(done){ fs.writeFileSync(packagePath, packageJson.replace('"example": {}', '')); runCLI("publish", ["major"], function(err, stdout, stderr){ diff --git a/plugins/c9.core/ext.js b/plugins/c9.core/ext.js index f5b90e52..29369049 100644 --- a/plugins/c9.core/ext.js +++ b/plugins/c9.core/ext.js @@ -530,8 +530,8 @@ define(function(require, exports, module) { }); } - function cleanUp(keepElements) { - if (!keepElements) { + function cleanUp(what) { + if (!what || ~what.indexOf("elements")) { // Loop through elements elements.forEach(function(element) { element.destroy(true, true); @@ -542,33 +542,36 @@ define(function(require, exports, module) { } // Loop through events - events.forEach(function(eventRecord) { - var event = eventRegistry[eventRecord[0]]; - if (!event) return; // this happens with mock plugins during testing - var type = eventRecord[1]; - var id = eventRecord[2]; - var _events = event._events; - var eventList = _events && _events[type]; - if (typeof eventList == "function") { - if (eventList.listenerId == id) - event.off(type, eventList); - } else if (Array.isArray(eventList)) { - eventList.some(function(listener) { - if (listener.listenerId != id) return; - event.off(type, listener); - return true; - }); - } - }); - events = []; + if (!what || ~what.indexOf("events")) { + events.forEach(function(eventRecord) { + var event = eventRegistry[eventRecord[0]]; + if (!event) return; // this happens with mock plugins during testing + var type = eventRecord[1]; + var id = eventRecord[2]; + var _events = event._events; + var eventList = _events && _events[type]; + if (typeof eventList == "function") { + if (eventList.listenerId == id) + event.off(type, eventList); + } else if (Array.isArray(eventList)) { + eventList.some(function(listener) { + if (listener.listenerId != id) return; + event.off(type, listener); + return true; + }); + } + }); + events = []; + onNewEvents = {}; + } // Loop through other - other.forEach(function(o) { - o(); - }); - other = []; - - onNewEvents = {}; + if (!what || ~what.indexOf("other")) { + other.forEach(function(o) { + o(); + }); + other = []; + } } function setAPIKey(apikey){ diff --git a/plugins/c9.core/settings.js b/plugins/c9.core/settings.js index 27bee4f8..b9cb93d0 100644 --- a/plugins/c9.core/settings.js +++ b/plugins/c9.core/settings.js @@ -391,13 +391,14 @@ define(function(require, exports, module) { } if (hash[key] === value) return; - + + var oldValue = hash[key]; hash[key] = value; // Tell everyone this property changed - emit(parts.join("/"), value); + emit(parts.join("/"), value, oldValue); // Tell everyone it's parent changed - emit(query, value); + emit(query, value, oldValue); // Tell everyone the root type changed (user, project, state) scheduleAnnounce(parts[0], userData); @@ -422,7 +423,7 @@ define(function(require, exports, module) { function getJson(query) { var json = get(query, true); - if (query.indexOf("json()") == -1) + if (query.indexOf("@") == -1 && query.indexOf("json()") == -1) json = json["json()"]; if (typeof json === "object") @@ -433,6 +434,7 @@ define(function(require, exports, module) { return JSON.parse(json); } catch (e) {} } + // do not return null or undefined so that getJson(query).foo never throws return false; } diff --git a/plugins/c9.error/error_handler.js b/plugins/c9.error/error_handler.js index f2b8024a..29f4a9d4 100644 --- a/plugins/c9.error/error_handler.js +++ b/plugins/c9.error/error_handler.js @@ -115,11 +115,20 @@ function plugin(options, imports, register) { if (/json/.test(accept)) { var error = { code: statusCode, - message: err.message, hostname: options.hostname, scope: options.scope, - stack: stack, + stack: stack }; + + var allowedErrorKeys = [ + "message", "projectState", "premium", "retryIn", "progress", + "oldHost", "blocked" + ]; + + allowedErrorKeys.forEach(function(key) { + if (err.hasOwnProperty(key)) + error[key] = err[key]; + }); try { JSON.stringify(error); diff --git a/plugins/c9.error/error_handler_test.js b/plugins/c9.error/error_handler_test.js new file mode 100644 index 00000000..dea480db --- /dev/null +++ b/plugins/c9.error/error_handler_test.js @@ -0,0 +1,91 @@ +#!/usr/bin/env node +/*global describe it before after beforeEach afterEach */ +"use strict"; +"use server"; + +require("c9/inline-mocha")(module); +require("amd-loader"); + +var assert = require("assert-diff"); +var sinon = require("sinon"); +var error = require("http-error"); + +var errorHandlerPlugin = require("./error_handler"); + +describe(__filename, function(){ + this.timeout(2000); + + var errorHandler; + var imports; + var options = { + scope: "ide", + hostname: "fabian-dev" + }; + + beforeEach(function(done) { + imports = { + connect: { + useError: sinon.stub(), + useStart: sinon.stub() + }, + "connect.static": { + addStatics: sinon.stub() + } + }; + errorHandlerPlugin(options, imports, function(err, services) { + errorHandler = imports.connect.useError.lastCall.args[0]; + done(err); + }); + }); + + afterEach(function () { + }); + + it("should only pass white listed keys", function(done) { + var err = new error.PreconditionRequired("Resizing workspace; please retry later"); + err.projectState = 1; + err.premium = true; + err.retryIn = 2000; + err.progress = { + progress: 0, + nextProgress: 0 + }; + err.FOO = "not me"; + + var req = { + headers: { + accept: "application/json" + } + }; + + var res = { + json: function(err, body, code) { + assert(!body); + assert.equal(code, 428); + assert.deepEqual(err, { + error: { + code: 428, + hostname: "fabian-dev", + scope: "ide", + stack: undefined, + message: "Resizing workspace; please retry later", + projectState: 1, + premium: true, + retryIn: 2000, + progress: { + progress: 0, + nextProgress: 0 + } + } + }); + done(); + } + }; + + errorHandler(err, req, res, function() { + assert.fail(); + done(); + }); + }); + +}); \ No newline at end of file diff --git a/plugins/c9.error/logger.raygun.js b/plugins/c9.error/logger.raygun.js index 784832c8..c1997922 100644 --- a/plugins/c9.error/logger.raygun.js +++ b/plugins/c9.error/logger.raygun.js @@ -1,3 +1,8 @@ +/** + * This error handler is for server side error logging. + * + **/ + "use strict"; plugin.consumes = ["raygun"]; diff --git a/plugins/c9.error/raygun.connect.js b/plugins/c9.error/raygun.connect.js index ad0cbc64..c10315f2 100644 --- a/plugins/c9.error/raygun.connect.js +++ b/plugins/c9.error/raygun.connect.js @@ -4,7 +4,7 @@ var domain = require("domain"); var url = require("url"); var _ = require("lodash"); -plugin.consumes = ["raygun", "connect", "http", "connect.remote-address"]; +plugin.consumes = ["raygun", "connect", "http", "connect.remote-address", "metrics"]; plugin.provides = ["raygun.connect"]; module.exports = plugin; @@ -15,6 +15,7 @@ function plugin(options, imports, register) { var warningClient = raygun.warningClient; var connect = imports.connect; var server = imports.http.getServer(); + var metrics = imports.metrics; errorClient.user = warningClient.user = function(req) { return (req && req.user) ? req.user.name : ""; @@ -62,7 +63,6 @@ function plugin(options, imports, register) { var req = domain && domain.members[0]; if (req && req.url) sendRequestWarning(new Error("Request timed out: " + req.url), req); - }); function sendRequestError(err, req) { diff --git a/plugins/c9.fs/fs.cache.xml.js b/plugins/c9.fs/fs.cache.xml.js index 3aade7a0..dda745dd 100644 --- a/plugins/c9.fs/fs.cache.xml.js +++ b/plugins/c9.fs/fs.cache.xml.js @@ -292,29 +292,33 @@ define(function(require, exports, module) { // Validation var toNode = findNode(newPath); - if (parent) { // Dir is in cache - if (toNode) - deleteNode(toNode); + deleteNode(node, true); + if (toNode) + deleteNode(toNode, true); - createNode(newPath, null, node); // Move node - recurPathUpdate(node, oldPath, newPath); + createNode(newPath, null, node); // Move node + recurPathUpdate(node, oldPath, newPath); + + e.undo = function(){ + if (!parent) { + var tmpParent = node; + while (node.parent && tmpParent.parent.status == "pending") + tmpParent = tmpParent.parent; + if (tmpParent) + deleteNode(tmpParent, true); + } + deleteNode(node, true); + if (toNode) + createNode(newPath, null, toNode); - e.undo = function(){ - createNode(oldPath, null, node); - recurPathUpdate(node, newPath, oldPath); - - if (toNode) - createNode(newPath, null, toNode); - }; - e.confirm = function() { - if (node.status === "predicted") - node.status = "loaded"; - }; - node.status = "predicted"; - } - else { - removeSingleNode(e); - } + createNode(oldPath, null, node); + recurPathUpdate(node, newPath, oldPath); + }; + e.confirm = function() { + if (node.status === "predicted") + node.status = "loaded"; + }; + node.status = "predicted"; }, plugin); fs.on("afterRename", afterHandler, plugin); @@ -553,10 +557,6 @@ define(function(require, exports, module) { node.status = "loaded"; } - if (isFolder && !node.map) - node.map = {}; - else if (!isFolder && node.map) - delete node.map; if (stat.size != undefined) node.size = stat.size; if (stat.mtime != undefined) @@ -566,6 +566,11 @@ define(function(require, exports, module) { node.isFolder = isFolder; } + if (node.isFolder && !node.map) + node.map = {}; + else if (!node.isFolder && node.map) + delete node.map; + node.children = null; if (!updating) { diff --git a/plugins/c9.fs/fs.js b/plugins/c9.fs/fs.js index c71fc4b3..04e2d42d 100644 --- a/plugins/c9.fs/fs.js +++ b/plugins/c9.fs/fs.js @@ -347,7 +347,7 @@ define(function(require, exports, module) { * @param {String} path the path of the directory to get the listing from * @param {Function} callback called after the file listing is read * @param {Error} callback.err the error information returned by the operation - * @param {String[]} callback.files a list of strings containing the filenames of the files in the directory + * @param {Stat[]} callback.files a list of stat objects (See fs.stat) containing the file information of the files in the directory * @fires error */ readdir: api.readdir, diff --git a/plugins/c9.ide.ace/ace.js b/plugins/c9.ide.ace/ace.js index 5a1747ae..27275599 100644 --- a/plugins/c9.ide.ace/ace.js +++ b/plugins/c9.ide.ace/ace.js @@ -618,8 +618,8 @@ define(function(require, exports, module) { return isAvailable ? isAvailable(editor.ace) : true; }; - command.findEditor = function(editor) { - if (apf.activeElement && apf.activeElement.ace && apf.activeElement.ace.isFocused()) + command.findEditor = function(editor, e) { + if (e && apf.activeElement && apf.activeElement.ace && apf.activeElement.ace.isFocused()) return apf.activeElement.ace; return editor && editor.ace || editor; }; diff --git a/plugins/c9.ide.dialog.common/error.js b/plugins/c9.ide.dialog.common/error.js index 730e4c15..33e12738 100644 --- a/plugins/c9.ide.dialog.common/error.js +++ b/plugins/c9.ide.dialog.common/error.js @@ -1,7 +1,7 @@ define(function(require, exports, module) { "use strict"; - main.consumes = ["Plugin", "ui", "metrics"]; + main.consumes = ["Plugin", "ui", "metrics", "error_handler"]; main.provides = ["dialog.error"]; return main; @@ -9,6 +9,7 @@ define(function(require, exports, module) { var Plugin = imports.Plugin; var ui = imports.ui; var metrics = imports.metrics; + var errorHandler = imports.error_handler; /***** Initialization *****/ @@ -114,14 +115,17 @@ define(function(require, exports, module) { + (message.className ? message.className : ""); if (!message.noError) { - metrics.increment("dialog.error"); - if (!message) { console.trace(); return console.error("empty error message", message); } - console.error("Error dialog shown: ", getMessageString(message)); + metrics.increment("dialog.error"); + + errorHandler.log(new Error("Error dialog shown"), { + message: message, + messageString: getMessageString(message), + }); } hide(function() { diff --git a/plugins/c9.ide.dialog.file/file.css b/plugins/c9.ide.dialog.file/file.css index 20957fac..3e01b387 100644 --- a/plugins/c9.ide.dialog.file/file.css +++ b/plugins/c9.ide.dialog.file/file.css @@ -26,7 +26,6 @@ font-size: 8pt; overflow: hidden; position: relative; - height: 210px; border-radius:3px; } diff --git a/plugins/c9.ide.editors/document.js b/plugins/c9.ide.editors/document.js index 6c7174c5..e8b8f33d 100644 --- a/plugins/c9.ide.editors/document.js +++ b/plugins/c9.ide.editors/document.js @@ -55,6 +55,7 @@ define(function(require, module, exports) { function setBookmarkedValue(value, cleansed) { if (plugin.value == value) { + recentValue = value; undoManager.bookmark(); return; } diff --git a/plugins/c9.ide.editors/editors.js b/plugins/c9.ide.editors/editors.js index 4068104d..38c50e54 100644 --- a/plugins/c9.ide.editors/editors.js +++ b/plugins/c9.ide.editors/editors.js @@ -10,6 +10,9 @@ define(function(require, module, exports) { var Plugin = imports.Plugin; var menus = imports.menus; + var extname = require("path").extname; + var basename = require("path").basename; + /***** Initialization *****/ var plugin = new Plugin("Ajax.org", main.consumes); @@ -54,9 +57,20 @@ define(function(require, module, exports) { return editor; } + function editorSupportsFile(type, path) { + var extensions = findEditor(type).fileExtensions; + var ext = extname(path).substr(1).toLowerCase(); + var filename = basename(path).toLowerCase(); + return ~extensions.indexOf(path) + || ~extensions.indexOf(filename) + || ~extensions.indexOf(ext) ? true : false; + } + function findEditorByFilename(fn) { - var ext = fn.substr(fn.lastIndexOf(".") + 1).toLowerCase(); + var ext = extname(fn).substr(1).toLowerCase(); + var filename = basename(fn).toLowerCase(); var editor = fileExtensions[fn] && fileExtensions[fn][0] + || fileExtensions[filename] && fileExtensions[filename][0] || fileExtensions[ext] && fileExtensions[ext][0] || defaultEditor; @@ -169,6 +183,8 @@ define(function(require, module, exports) { }); plugin.on("unload", function(){ loaded = false; + defaultEditor = null; + group = null; }); /***** Register and define API *****/ @@ -245,6 +261,11 @@ define(function(require, module, exports) { */ findEditorByFilename: findEditorByFilename, + /** + * + */ + editorSupportsFile: editorSupportsFile, + /** * Create an editor instance based on it's type * @param {String} type The type of the editor to create diff --git a/plugins/c9.ide.editors/imgview.js b/plugins/c9.ide.editors/imgview.js index c3ffd614..c75f09ac 100644 --- a/plugins/c9.ide.editors/imgview.js +++ b/plugins/c9.ide.editors/imgview.js @@ -12,7 +12,7 @@ define(function(require, exports, module) { /***** Initialization *****/ - var extensions = ["gif", "ico", "svg"]; + var extensions = ["gif", "ico"]; function ImageEditor(){ var plugin = new Editor("Ajax.org", main.consumes, extensions); @@ -135,4 +135,4 @@ define(function(require, exports, module) { ImageEditor, extensions) }); } -}); +}); \ No newline at end of file diff --git a/plugins/c9.ide.editors/tab.js b/plugins/c9.ide.editors/tab.js index 1c197575..e841ebef 100644 --- a/plugins/c9.ide.editors/tab.js +++ b/plugins/c9.ide.editors/tab.js @@ -7,6 +7,7 @@ define(function(require, module, exports) { var Plugin = imports.Plugin; var Document = imports.Document; var ui = imports.ui; + var alert = imports["dialog.alert"].show; var stylesheet = ui.createStylesheet(); @@ -249,7 +250,7 @@ define(function(require, module, exports) { // var lastType = tab.editorType; amlPane.cloud9pane.createEditor(type, function(err, editor) { var info = {}; - if (editor.isValid(amlTab.document, info) === false) { + if (editor.isValid(amlTab.cloud9tab.document, info) === false) { alert( info.title || "Could not switch editor", info.head || "Could not switch editor because this document is invalid.", @@ -257,6 +258,8 @@ define(function(require, module, exports) { ); return; } + + var currentValue = plugin.document.value; editorType = type; amlTab.setAttribute("type", "editor::" + type); @@ -264,6 +267,11 @@ define(function(require, module, exports) { if (amlPane.getPage() == amlTab) { amlPane.activepage = -1; amlPane.set(amlTab); + + plugin.document.value = currentValue; + // TODO undo managers for different editors conflict + // however, resetting removes changed state + // plugin.document.undoManager.reset(); } callback(); diff --git a/plugins/c9.ide.editors/tabmanager.js b/plugins/c9.ide.editors/tabmanager.js index 2d76dbbf..21cad3e8 100644 --- a/plugins/c9.ide.editors/tabmanager.js +++ b/plugins/c9.ide.editors/tabmanager.js @@ -178,7 +178,7 @@ define(function(require, module, exports) { if (!editors.findEditor(e.value).fileExtensions.length) openEditor(e.value, true, function(){}); else if (focussedTab) - focussedTab.switchEditor(e.value, function(){}); + switchEditor(focussedTab, e.value, function(){}); }); editors.on("menuShow", function(e) { var group, editor = focussedTab && focussedTab.editor; @@ -186,13 +186,8 @@ define(function(require, module, exports) { group = node.group; var path = focussedTab && focussedTab.path || ""; - var ext = path.substr(path.lastIndexOf(".") + 1); - var type = node.value; - var extensions = editors.findEditor(type).fileExtensions; - var isAvailable = editors.defaultEditor == type - || extensions.indexOf(ext.toLowerCase()) > -1 - || !extensions.length; + var isAvailable = editors.editorSupportsFile(type, path); node.setAttribute("disabled", !isAvailable); }); @@ -1075,7 +1070,7 @@ define(function(require, module, exports) { options.document.title = basename(path); options.document.tooltip = path; } - if (typeof options.value == "string") + if (typeof options.value == "string" && !options.newOnError) options.document.value = options.value; // if (options.document.filter === undefined) // options.document.filter = true; @@ -1091,7 +1086,7 @@ define(function(require, module, exports) { var doc = options.document; var loadFromDisk = path && (!doc || doc.value === undefined) - && options.value === undefined + && (options.value === undefined || options.newOnError) // autoload to false prevents loading data, used by image editor && (!editor || editor.autoload !== false); @@ -1410,6 +1405,13 @@ define(function(require, module, exports) { return true; } + function switchEditor(tab, type, callback) { + tab.switchEditor(type, function(){ + emit("switchEditor", { tab: tab }); + callback.apply(this, arguments); + }); + } + /**** Support for state preservation ****/ function pauseTabResize(){ @@ -1961,6 +1963,11 @@ define(function(require, module, exports) { */ clone: clone, + /** + * + */ + switchEditor: switchEditor, + /** * @ignore */ diff --git a/plugins/c9.ide.editors/undomanager.js b/plugins/c9.ide.editors/undomanager.js index d3fabb20..a275e5a5 100644 --- a/plugins/c9.ide.editors/undomanager.js +++ b/plugins/c9.ide.editors/undomanager.js @@ -116,9 +116,11 @@ define(function(require, module, exports) { return { mark: mark, position: position, - stack: stack.map(function(item) { - return item.getState ? item.getState() : item; - }) + stack: stack + .filter(function(item){ return item; }) + .map(function(item) { + return item.getState ? item.getState() : item; + }) }; } diff --git a/plugins/c9.ide.errorhandler/raygun_error_handler.js b/plugins/c9.ide.errorhandler/raygun_error_handler.js index 10eae39d..6c20b7be 100644 --- a/plugins/c9.ide.errorhandler/raygun_error_handler.js +++ b/plugins/c9.ide.errorhandler/raygun_error_handler.js @@ -1,5 +1,7 @@ /** - * This error handler catches window.onerror and sends them to raygun.io + * This error handler is for client side error logging + * It also automatically catches window.onerror and sends them to raygun.io + * You can also import it and call .log to manually send an error * * @extends Plugin * @singleton diff --git a/plugins/c9.ide.help/help.xml b/plugins/c9.ide.help/help.xml index 81c21a71..f4cd6c88 100644 --- a/plugins/c9.ide.help/help.xml +++ b/plugins/c9.ide.help/help.xml @@ -21,9 +21,9 @@

- Arron Bailiss, Bas de Wachter, Fabian Jakobs, Harutyun Amirjanyan, + Arron Bailiss, Bas de Wachter, Dana Ivan, Fabian Jakobs, Harutyun Amirjanyan, Ivar Pruijn, Justin Dray, Lennart Kats, Luca Cipriani, - Mostafa Eweda, Matthijs van Henten, Nikolai Onken, Tim Robinson, Ruben Daniels + Mostafa Eweda, Matthijs van Henten, Nikolai Onken, Suraj Biyani, Tim Robinson, Ruben Daniels

diff --git a/plugins/c9.ide.keys/commands.js b/plugins/c9.ide.keys/commands.js index 90f73771..b95d6d6c 100644 --- a/plugins/c9.ide.keys/commands.js +++ b/plugins/c9.ide.keys/commands.js @@ -127,10 +127,10 @@ define(function(require, exports, module) { } if (command.isAvailable && !command.isAvailable(editor, args, e)) - return; //Disable commands for other contexts + return; // Disable commands for other contexts if (command.findEditor) - editor = command.findEditor(editor); + editor = command.findEditor(editor, e); if (editor && editor.$readOnly && !command.readOnly) return false; diff --git a/plugins/c9.ide.layout.classic/themes/default-flat-light.less b/plugins/c9.ide.layout.classic/themes/default-flat-light.less index 18b8e002..cba9923c 100644 --- a/plugins/c9.ide.layout.classic/themes/default-flat-light.less +++ b/plugins/c9.ide.layout.classic/themes/default-flat-light.less @@ -1226,7 +1226,7 @@ @dropdown-black-image-height: 5px; @dropdown-black-background-position: 50% 50%; @dropdown-black-height: 28px; -@dropdown-black-padding: 8px 0 5px 9px; +@dropdown-black-padding: 7px 8px 5px 9px; @dropdown-black-font-family: @general-font-family; @dropdown-black-font-size: 13px; @dropdown-black-button-width: 24px; diff --git a/plugins/c9.ide.layout.classic/themes/flat-light.less b/plugins/c9.ide.layout.classic/themes/flat-light.less index e5308d0f..f0377679 100644 --- a/plugins/c9.ide.layout.classic/themes/flat-light.less +++ b/plugins/c9.ide.layout.classic/themes/flat-light.less @@ -305,6 +305,9 @@ .filetree .tree-row > span.caption { margin-left: 4px; } +.filetree .tree-row.heading > span.caption { + margin-left: 0; +} .toolbar-top.basic .c9-menu-btnDown.scripts{ border: 0; @@ -417,6 +420,8 @@ .has_apf .toolbar-top .sbtb_middle{ height: auto; padding: 4px 25px 3px 5px; + border: 0; + margin-right: 1px; } .top-test-panel{ @@ -424,8 +429,26 @@ box-shadow: none; } -.runner-form-header{ - border-bottom: 1px solid @border-highlight-dark; +body .runner-form-header{ + background: whitesmoke; +} + +.runtestbtn .icon{ + background-position: 1px 2px; + height: 22px; +} + +.coverage-toolbar{ + background-color:#f7f7f7; + border-bottom: 1px solid #ECECEC; + box-sizing: border-box; +} +.coverage-toolbar .label{ + padding:7px; +} +.coverage-toolbar .black_dropdown{ + margin: 0 !important; + min-height: 28px !important; } @media print, (-o-min-device-pixel-ratio: 5/4), (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 1.25dppx) { @@ -483,4 +506,7 @@ .c9-toolbarbutton-glossy .c9-icon { height: 19px; } + .runtestbtn .icon{ + height: 21px; + } } \ No newline at end of file diff --git a/plugins/c9.ide.preferences/general.js b/plugins/c9.ide.preferences/general.js index 1c656659..18114a70 100644 --- a/plugins/c9.ide.preferences/general.js +++ b/plugins/c9.ide.preferences/general.js @@ -16,7 +16,7 @@ define(function(require, exports, module) { /***** Initialization *****/ var plugin = new PreferencePanel("Ajax.org", main.consumes, { - caption: "Settings", + caption: "User Settings", form: true, index: 100 }); diff --git a/plugins/c9.ide.terminal/terminal.js b/plugins/c9.ide.terminal/terminal.js index d13279e9..29cbc884 100644 --- a/plugins/c9.ide.terminal/terminal.js +++ b/plugins/c9.ide.terminal/terminal.js @@ -258,10 +258,10 @@ define(function(require, exports, module) { ["foregroundColor", colors[1]], ["selectionColor", colors[2]], ["antialiasedfonts", colors[3]], - ["fontfamily", "Ubuntu Mono, Menlo, Consolas, monospace"], //Monaco, + ["fontfamily", "Ubuntu Mono, Menlo, Consolas, monospace"], // Monaco, ["fontsize", "12"], ["blinking", "false"], - ["scrollback", "1000"] + ["scrollback", 10000] ]); setSettings(); @@ -356,6 +356,13 @@ define(function(require, exports, module) { } }); }); + handle.on("unload", function(){ + mnuTerminal = null; + lastEditor = null; + lastTerminal = null; + shownDotsHelp = null; + installPrompted = null; + }); handle.draw = function(){ ui.insertMarkup(null, markupMenu, handle); diff --git a/plugins/c9.ide.tree/tree.js b/plugins/c9.ide.tree/tree.js index 54b8e134..788068a8 100644 --- a/plugins/c9.ide.tree/tree.js +++ b/plugins/c9.ide.tree/tree.js @@ -278,9 +278,9 @@ define(function(require, exports, module) { tree.renderer.on("scrollbarVisibilityChanged", updateScrollBarSize); tree.renderer.on("resize", updateScrollBarSize); function updateScrollBarSize() { - var w = tree.renderer.scrollBarV.getWidth(); + var scrollBarV = tree.renderer.scrollBarV; + var w = scrollBarV.isVisible ? scrollBarV.getWidth() : 0; btnTreeSettings.$ext.style.marginRight = Math.max(w - 2, 0) + "px"; - tree.renderer.scroller.style.right = Math.max(w, 10) + "px"; } tree.on("drop", function(e) { diff --git a/plugins/c9.ide.ui/forms.js b/plugins/c9.ide.ui/forms.js index ba36edb7..0ab3e6f8 100644 --- a/plugins/c9.ide.ui/forms.js +++ b/plugins/c9.ide.ui/forms.js @@ -240,9 +240,13 @@ define(function(require, exports, module) { value: options.path ? createBind(options.path) : (options.defaultValue || ""), - min: options.min, - max: options.max, - realtime: typeof options.realtime !== "undefined" ? options.realtime : 1 + min: options.min || 0, + max: options.max || 10, + realtime: typeof options.realtime !== "undefined" ? options.realtime : 1, + onafterchange: function(e) { + if (options.onchange) + options.onchange({ value: e.value }); + }, }) ]; break; @@ -254,16 +258,24 @@ define(function(require, exports, module) { : (options.defaultCheckboxValue || ""), width: width, maxwidth: maxwidth, label: name + ":", - skin: "checkbox_black" + skin: "checkbox_black", + onafterchange: function(e) { + if (options.onchange) + options.onchange({ value: e.value, type: "checkbox" }); + }, }), new ui.spinner({ width: options.width || widths["checked-spinner"], value: options.path ? createBind(options.path) : (options.defaultValue || ""), - min: options.min, - max: options.max, - realtime: typeof options.realtime !== "undefined" ? options.realtime : 1 + min: options.min || 0, + max: options.max || 10, + realtime: typeof options.realtime !== "undefined" ? options.realtime : 1, + onafterchange: function(e) { + if (options.onchange) + options.onchange({ value: e.value, type: "spinner" }); + }, }) ]; break; @@ -275,7 +287,11 @@ define(function(require, exports, module) { : (options.defaultValue || ""), width: options.width || widths["checked-single"], label: name, - skin: "checkbox_black" + skin: "checkbox_black", + onafterchange: function(e){ + if (options.onchange) + options.onchange({ value: e.value }); + } }) ]; break; @@ -421,8 +437,8 @@ define(function(require, exports, module) { }); } - if (options.name) { - node.setAttribute("id", options.name); + if (options.id || options.name) { + node.setAttribute("id", options.id || options.name); elements[node.name] = node; } @@ -440,20 +456,25 @@ define(function(require, exports, module) { case "dropdown": var dropdown = el.lastChild; - var data = item.items.map(function(item) { - return ""; - }).join(""); - if (data) { - setTimeout(function(){ - dropdown.$model.load("" + data + ""); - + if (item.items) { + var data = item.items.map(function(item) { + return ""; + }).join(""); + if (data) { setTimeout(function(){ - var value = item.value || dropdown.value; - dropdown.value = -999; - dropdown.setAttribute("value", value); + dropdown.$model.load("" + data + ""); + + setTimeout(function(){ + var value = item.value || dropdown.value; + dropdown.value = -999; + dropdown.setAttribute("value", value); + }); }); - }); + } + } + else if (item.value) { + dropdown.setAttribute("value", item.value); } break; default: diff --git a/plugins/c9.ide.ui/lib/menu/menu.js b/plugins/c9.ide.ui/lib/menu/menu.js index 8c786579..711e7ac9 100644 --- a/plugins/c9.ide.ui/lib/menu/menu.js +++ b/plugins/c9.ide.ui/lib/menu/menu.js @@ -738,6 +738,8 @@ apf.menu = function(struct, tagName){ * @param {String} value The value of the item to select. */ this.select = function(group, value){ + this.selectedValue = value; + var nodes = this.childNodes; var i, l = nodes.length; for (i = 0; i < l; i++) { @@ -1530,8 +1532,8 @@ apf.item = function(struct, tagName){ //@todo Anim effect here? this.dispatchEvent("click", { - xmlContext : this.parentNode.xmlReference, - opener : this.parentNode.opener + xmlContext : (this.parentNode || 0).xmlReference, + opener : (this.parentNode || 0).opener }); diff --git a/plugins/c9.ide.ui/lib/splitbox.js b/plugins/c9.ide.ui/lib/splitbox.js index febfabb3..830137ec 100644 --- a/plugins/c9.ide.ui/lib/splitbox.js +++ b/plugins/c9.ide.ui/lib/splitbox.js @@ -577,6 +577,7 @@ apf.vsplitbox = function(struct, tagName) { if (isPercentage) { fNode.$ext.style.height = ""; fNode.$ext.style.bottom = (100 - parseFloat(fNode.height)) + "%"; + lNode.$ext.style.height = ""; } if (this.$handle) { diff --git a/plugins/c9.ide.ui/lib_apf.js b/plugins/c9.ide.ui/lib_apf.js index c6715caf..25988dc1 100644 --- a/plugins/c9.ide.ui/lib_apf.js +++ b/plugins/c9.ide.ui/lib_apf.js @@ -33555,7 +33555,9 @@ apf.splitbutton = function(struct, tagName) { var diff = apf.getAbsolutePosition(split.$button2.$ext)[0] - apf.getAbsolutePosition(split.$button1.$ext)[0]; - this.$ext.style.marginLeft = "-" + diff + "px"; + this.$ext.style.marginLeft = ~this.$ext.className.indexOf("moveleft") + ? 0 + : "-" + diff + "px"; }); menu.$splitInited = true; } @@ -33568,6 +33570,8 @@ apf.splitbutton = function(struct, tagName) { var _self = this; this.$ext = this.$pHtmlNode.appendChild(document.createElement("div")); this.$ext.className = "splitbutton"; + if (this.getAttribute("style")) + this.$ext.setAttribute("style", this.getAttribute("style")); var skin = this["button-skin"] || this.getAttribute("skin") || this.localName; diff --git a/plugins/c9.ide.ui/menus.js b/plugins/c9.ide.ui/menus.js index 57206a7b..359af59f 100644 --- a/plugins/c9.ide.ui/menus.js +++ b/plugins/c9.ide.ui/menus.js @@ -942,6 +942,10 @@ define(function(require, exports, module) { return item; } + function remove(item){ + aml.removeChild(item.aml); + } + function show(x, y) { lastCoords = { x : x, y : y }; aml.display(x, y); @@ -951,6 +955,11 @@ define(function(require, exports, module) { aml = new ui.menu({ id: options.id, zindex: options.zindex, + visible: options.visible, + width: options.width, + height: options.height, + minWidth: options.minWidth, + minHeight: options.minHeight, "onprop.visible" : function(e) { emit(e.value ? "show" : "hide", lastCoords); checkItems.call(this, e); @@ -1057,6 +1066,30 @@ define(function(require, exports, module) { */ get zindex(){ return aml && ui.getStyle(aml.$ext, "z-index"); }, set zindex(value) { aml && aml.setAttribute("zindex", value); }, + /** + * Specifies the width of the menu + * @property {Number} width + */ + get width(){ return aml && aml.getWidth(); }, + set width(value) { aml && aml.setAttribute("width", value); }, + /** + * Specifies the height of the menu + * @property {Number} height + */ + get height(){ return aml && aml.getHeight(); }, + set height(value) { aml && aml.setAttribute("height", value); }, + /** + * Specifies the minimal width of the menu + * @property {Number} width + */ + get minWidth(){ return aml && aml.getAttribute("minwidth"); }, + set minWidth(value) { aml && aml.setAttribute("minwidth", value); }, + /** + * Specifies the minimal height of the menu + * @property {Number} height + */ + get minHeight(){ return aml && aml.getAttribute("minheight"); }, + set minHeight(value) { aml && aml.setAttribute("minheight", value); }, /** * The menu items appended to this menu * @property {MenuItem[]} items @@ -1089,6 +1122,12 @@ define(function(require, exports, module) { */ append: append, + /** + * Remove a menu item from this menu + * @param {MenuItem} item The item to remove from this menu. + */ + remove: remove, + /** * Show the menu at the specified position * @param {Number} x The x coordinate specified in pixels from the left of the browser window. diff --git a/plugins/c9.ide.ui/widgets.tree.js b/plugins/c9.ide.ui/widgets.tree.js index 9781c2b1..3970bfbb 100644 --- a/plugins/c9.ide.ui/widgets.tree.js +++ b/plugins/c9.ide.ui/widgets.tree.js @@ -16,8 +16,9 @@ define(function(require, exports, module) { if (!options.baseName) options.baseName = "tree"; - if (!options.model) { - var model = new TreeModel(); + var model = options.model; + if (!model) { + model = new TreeModel(); options.model = model; } diff --git a/plugins/c9.metrics/mock_metrics.js b/plugins/c9.metrics/mock_metrics.js index 56a13241..7eb884f4 100644 --- a/plugins/c9.metrics/mock_metrics.js +++ b/plugins/c9.metrics/mock_metrics.js @@ -13,7 +13,8 @@ function plugin(options, imports, register) { register(null, { "metrics": { log: function() {}, - increment: function() {} + increment: function() {}, + timing: function() {} } }); } \ No newline at end of file diff --git a/plugins/c9.nodeapi/events.js b/plugins/c9.nodeapi/events.js index 027cace5..ccfe19c9 100644 --- a/plugins/c9.nodeapi/events.js +++ b/plugins/c9.nodeapi/events.js @@ -60,9 +60,6 @@ EventEmitter.prototype.emit = function(type) { if (!this._events) return; - if (arguments[2] === true) - throw new Error("Please use emit.sticky() instead of passing sticky=true for event: " + type); - var handler = this._events[type]; if (!handler) return; @@ -190,7 +187,7 @@ EventEmitter.prototype.on = EventEmitter.prototype.addListener; * ``` */ -EventEmitter.prototype.once = function(type, listener) { +EventEmitter.prototype.once = function(type, listener, plugin) { var self = this; var wrapped = function() { @@ -199,7 +196,7 @@ EventEmitter.prototype.once = function(type, listener) { } wrapped.listener = listener; - self.on(type, wrapped); + self.on(type, wrapped, plugin); return this; }; diff --git a/plugins/c9.preview/preview.handler.js b/plugins/c9.preview/preview.handler.js index d59b24bd..3bf1f351 100644 --- a/plugins/c9.preview/preview.handler.js +++ b/plugins/c9.preview/preview.handler.js @@ -39,7 +39,13 @@ define(function(require, exports, module) { session.ws = {}; req.projectSession = session.ws[ws]; - if (!req.projectSession || !req.projectSession.expires || req.projectSession.expires <= Date.now()) { + + if ( + !req.projectSession || + !req.projectSession.expires || + req.projectSession.expires <= Date.now() || + req.projectSession.uid != req.user.id + ) { req.projectSession = session.ws[ws] = { expires: Date.now() + 10000 }; @@ -77,6 +83,7 @@ define(function(require, exports, module) { } req.projectSession.role = role; req.projectSession.pid = project.id; + req.projectSession.uid = req.user.id; var type = project.scm; req.projectSession.type = type; @@ -137,8 +144,8 @@ define(function(require, exports, module) { var path = req.params.path; var url = req.proxyUrl + path; - if (req.session.token) - url += "?access_token=" + encodeURIComponent(req.session.token.id || req.session.token); + if (req.user.code) + url += "?access_token=" + encodeURIComponent(req.user.code); var parsedUrl = parseUrl(url); var httpModule = parsedUrl.protocol == "https:" ? https : http; diff --git a/plugins/c9.preview/preview.js b/plugins/c9.preview/preview.js index 33aa8b31..95f6e72c 100644 --- a/plugins/c9.preview/preview.js +++ b/plugins/c9.preview/preview.js @@ -5,7 +5,9 @@ define(function(require, exports, module) { "session", "db", "c9.login", - "preview.handler" + "preview.handler", + "user-content.redirect", + "connect.remote-address" ]; main.provides = []; return main; @@ -18,6 +20,7 @@ define(function(require, exports, module) { var db = imports.db; var ensureLoggedIn = imports["c9.login"].ensureLoggedIn(); var handler = imports["preview.handler"]; + var userContent = imports["user-content.redirect"]; var frontdoor = require("frontdoor"); var error = require("http-error"); @@ -34,6 +37,8 @@ define(function(require, exports, module) { next(); }); + api.use(userContent.redirectPreview()); + session.use(api); api.get("/:username/:projectname/:path*", { diff --git a/plugins/c9.vfs.client/endpoint.js b/plugins/c9.vfs.client/endpoint.js index b2c4524f..f3484697 100644 --- a/plugins/c9.vfs.client/endpoint.js +++ b/plugins/c9.vfs.client/endpoint.js @@ -44,6 +44,7 @@ define(function(require, exports, module) { options.updateServers = false; var strictRegion = query.region || options.strictRegion; + var ignoreProtocolVersion = options.ignoreProtocolVersion; var region = strictRegion || options.region; var servers; @@ -319,7 +320,7 @@ define(function(require, exports, module) { return isBetaServer === isBetaClient; }); servers = servers.filter(function(s) { - return s.version == undefined || s.version == version; + return ignoreProtocolVersion || s.version == undefined || s.version == version; }); return servers.sort(function(a, b) { if (a.region == b.region) { diff --git a/plugins/c9.vfs.client/vfs_client.js b/plugins/c9.vfs.client/vfs_client.js index fbeb8195..f03bb749 100644 --- a/plugins/c9.vfs.client/vfs_client.js +++ b/plugins/c9.vfs.client/vfs_client.js @@ -246,6 +246,8 @@ define(function(require, exports, module) { function showVfsError(err) { switch (err.action) { case "dashboard": + if (/Permission denied \(public key/.test(err.message)) + err.message = "SSH permission denied. Please review your workspace configuration."; return showAlert("Workspace Error", "Unable to access your workspace", err.message, function() { window.location = dashboardUrl; }); diff --git a/plugins/c9.vfs.server/cache.js b/plugins/c9.vfs.server/cache.js index bc174ae4..69d21f9c 100644 --- a/plugins/c9.vfs.server/cache.js +++ b/plugins/c9.vfs.server/cache.js @@ -1,14 +1,18 @@ define(function(require, exports, module) { "use strict"; - main.consumes = ["Plugin", "vfs.connect"]; + main.consumes = [ + "Plugin", + "vfs.connect", + "metrics" + ]; main.provides = ["vfs.cache"]; return main; - function main(options, imports, register) { var Plugin = imports.Plugin; var connectVfs = imports["vfs.connect"].connect; + var metrics = imports.metrics; var async = require("async"); var uid = require("c9/uid"); @@ -54,10 +58,12 @@ define(function(require, exports, module) { if (err) return done(err); entry.connectTime = Date.now() - entry.startTime; + metrics.timing("vfs.connect.time", entry.connectTime); entry.emit("loaded"); cache[vfsid] = entry; + entry.keepalive(); vfs.on("destroy", function() { remove(vfsid); @@ -126,7 +132,6 @@ define(function(require, exports, module) { }; entry.keepalive = function() { - clearTimeout(timer); startTimer(); }; @@ -139,7 +144,6 @@ define(function(require, exports, module) { }, maxAge); } - startTimer(); return entry; } diff --git a/plugins/c9.vfs.server/fetchcache.js b/plugins/c9.vfs.server/fetchcache.js new file mode 100644 index 00000000..7e6b4392 --- /dev/null +++ b/plugins/c9.vfs.server/fetchcache.js @@ -0,0 +1,106 @@ +define(function(require, exports, module) { + "use strict"; + + main.consumes = ["Plugin", "vfs.cache", "connect"]; + main.provides = ["vfs.fetchcache"]; + return main; + + function main(options, imports, register) { + var Plugin = imports.Plugin; + var cache = imports["vfs.cache"]; + + var error = require("http-error"); + var Path = require("path"); + var async = require("async"); + + /***** Initialization *****/ + + var plugin = new Plugin("Ajax.org", main.consumes); + + var compress = imports.connect.getModule().compress(); + + cache.registerExtension(function(vfs, callback) { + var restful = vfs.restful.home; + + vfs.restful.home = function(req, res, next) { + var path = unescape(req.uri.pathname); + + if (req.method == "GET" && path.indexOf("/.c9/cache") === 0) { + compress(req, res, function(err) { + if (err) return next(err); + + fetchcache(vfs.vfs, vfs.vfs.env.HOME, vfs.vfsOptions, req, res, next); + }); + } + else + restful(req, res, next); + }; + + callback(); + }); + + function readFile(vfs, path, callback) { + vfs.readfile(path, { encoding: "utf8" }, function(err, meta) { + if (err) + return callback(err); + + var data = ""; + meta.stream.on("data", function(d) { + data += d; + }) + + var done; + meta.stream.on("error", function(e) { + if (done) return; + done = true; + callback(e); + }); + + meta.stream.on("end", function() { + if (done) return; + done = true; + callback(null, data); + }); + }); + } + + function fetchcache(vfs, root, vfsOptions, req, res, next) { + var path = unescape(req.uri.pathname); + + // sandbox path to workspaceDir + path = Path.join(root, path); + // if (path.indexOf(root) !== 0) + // return next(new error.Forbidden("Can't list files outside of the workspace")); + + // Fetch index + readFile(vfs, Path.join(path, "index"), function(err, list){ + if (err) { + var httpErr = new error.NotFound(err.message); + return next(httpErr); + } + + // Fetch each file in the index + async.mapLimit(list.split("\n"), 50, function(p, callback){ + readFile(vfs, Path.join(path, p.replace(/\//g, "\\")), function(ignore, data){ + var json; + try { json = JSON.parse(data); } + catch(e) { json = { type: "file", path: p } } + + callback(null, json); + }); + }, function(ignore, results){ + res.writeHead(200, { "Content-Type": "text/json" }); + res.write(JSON.stringify(results)); + res.end(); + }); + }); + } + + plugin.freezePublicAPI({ + // for testing only + fetchcache: fetchcache + }); + + register(null, { "vfs.fetchcache" : plugin }); + } +}); \ No newline at end of file diff --git a/plugins/c9.vfs.server/vfs.server.js b/plugins/c9.vfs.server/vfs.server.js index 37fbc2c4..5a117cf3 100644 --- a/plugins/c9.vfs.server/vfs.server.js +++ b/plugins/c9.vfs.server/vfs.server.js @@ -36,7 +36,6 @@ function plugin(options, imports, register) { var connect = imports.connect; var render = imports["connect.render"]; var analytics = imports["analytics"]; - var async = require("async"); var Types = require("frontdoor").Types; var error = require("http-error"); @@ -327,15 +326,6 @@ function plugin(options, imports, register) { if (new Date(user.lastVfsAccess).getDate() != new Date().getDate() || Date.now() > user.lastVfsAccess + VFS_ACTIVITY_WINDOW) { - // Keeping this temporarily to be replaced by API request only - async.series([ - analytics.aliasClean.bind(analytics, req.cookies.mixpanelAnonymousId, user.id), - analytics.identifyClean.bind(analytics, user, {}), - analytics.trackClean.bind(analytics, user, "VFS is active", { uid: user.id }), - ], function(err) { - if (err) return console.log("Error logging activity", err.stack || err); - }); - analytics.superagent && analytics.superagent .post(options.apiBaseUrl + "/metric/usage/" + req.params.pid + "?access_token=" + req.query.access_token) .end(function() {}); diff --git a/server.js b/server.js index 2711230c..a67c528b 100755 --- a/server.js +++ b/server.js @@ -23,14 +23,13 @@ var DEFAULT_CONFIG = "s"; var DEFAULT_SETTINGS = getDefaultSettings(); var shortcuts = { - "dev" : ["ide", "preview", "vfs", "api", "sapi", "proxy", "redis", "profile", "oldclient", "homepage", "apps-proxy", "-s", "devel"], - "odev" : ["ide", "preview", "vfs", "api", "proxy", "oldclient", "homepage", "apps-proxy", "profile", "worker", "-s", "onlinedev"], - "bill" : ["ide", "preview", "vfs", "api", "proxy", "oldclient", "homepage", "apps-proxy", "profile", "-s", "billing"], - "beta" : ["ide", "preview", "vfs", "proxy", "-s", "beta"], - "ci" : ["ide", "preview", "vfs", "proxy", "-s", "ci"], - "s" : ["standalone", "-s", "standalone"] + "dev": ["ide", "preview", "user-content", "vfs", "api", "sapi", "proxy", "redis", "profile", "oldclient", "homepage", "apps-proxy", "-s", "devel"], + "onlinedev": ["ide", "preview", "user-content", "vfs", "api", "proxy", "oldclient", "homepage", "apps-proxy", "profile", "worker", "-s", "onlinedev"], + "beta": ["ide", "preview", "user-content", "vfs", "proxy", "-s", "beta"], + "s": ["standalone", "-s", "standalone"] }; -var delayLoadConfigs = ["preview", "api", "oldclient", "apps-proxy", "worker"]; +shortcuts.odev = shortcuts.onlinedev; // For backwards compatibility, if you see this in 2016 remove this line +var delayLoadConfigs = ["preview", "user-content", "api", "oldclient", "apps-proxy", "worker"]; module.exports = main; @@ -42,6 +41,7 @@ function getDefaultSettings() { var suffix = hostname.trim().split("-").pop() || ""; var modes = { + "workflowstaging": "workflow-staging", "prod": "deploy", "beta": "beta", "dev": "devel", diff --git a/settings/local.js b/settings/local.js index a04636db..c0244bf7 100644 --- a/settings/local.js +++ b/settings/local.js @@ -47,9 +47,9 @@ module.exports = function(manifest, installPath, settingDir) { // config.update.port = "8888" // config.update.host = "http" - config.nodeBin = [process.platform == "win32" - ? path.join(process.execPath, "..\\node.exe") - : path.join(installPath, "node/bin/node")]; + // config.nodeBin = [process.platform == "win32" + // ? path.join(process.execPath, "..\\node.exe") + // : path.join(installPath, "node/bin/node")]; config.bashBin = process.platform == "win32" ? process.env.C9_BASH_BIN || "C:\\cygwin\\bin\\bash.exe" : "/bin/bash";