Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 267009 Details for
Bug 511326
Provide getProject support in the file client
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fix including the server changes
org.eclipse.orion.client.getproject3.patch (text/plain), 12.25 KB, created by
Michael Rennie
on 2017-02-27 11:24:32 EST
(
hide
)
Description:
Fix including the server changes
Filename:
MIME Type:
Creator:
Michael Rennie
Created:
2017-02-27 11:24:32 EST
Size:
12.25 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js b/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js >index 13f4879..a756c1c 100644 >--- a/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js >+++ b/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js >@@ -142,6 +142,12 @@ > }, 100); > return d; > }, >+ /** >+ * @description Computes the project context from the given location >+ * @param {String} context The resource context to find the project for >+ * @since 14.0 >+ */ >+ getProject: _noMatch, > search: _noMatch, > createProject: _noMatch, > createFolder: _noMatch, >@@ -361,7 +367,14 @@ > changeWorkspace: function(workspaceLocation) { > return _doServiceCall(this._getService(), "changeWorkspace", arguments); //$NON-NLS-1$ > }, >- >+ /** >+ * @description Computes the project context from the given location >+ * @param {String} context The resource context to find the project for >+ * @since 14.0 >+ */ >+ getProject: function getProject(resource) { >+ return _doServiceCall(this._getService(resource), "getProject", arguments); >+ }, > _createArtifact: function(parentLocation, funcName, eventData, funcArgs) { > return _doServiceCall(this._getService(parentLocation), funcName, funcArgs).then(function(result){ > if(this.isEventFrozen()) { >diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/javascriptProject.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/javascriptProject.js >index 5dc369a..05e1de3 100644 >--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/javascriptProject.js >+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/javascriptProject.js >@@ -692,26 +692,30 @@ > deferred.resolve({Location: "/file/"}); > } else { > if(Util.isElectron) { >- //TODO call out the server for #getProject >- var promises = [], >- prnt = parents[parents.length-1]; >- this.projectFiles.forEach(function(_f) { >- promises.push(this.getFile(_f, prnt.Location)); >- promises.push(this.getFile(_f, "/file/")); >- }.bind(this)); >- promises.reduce(function(prev, item, index, array) { >- return prev.then(function(_file) { >- if(_file && _file.contents) { >- deferred.resolve({Location: _file.project}); >- return item.reject("done"); >- } >- if(index === array.length-1) { >- //nothing was found, assume /file/ >- deferred.resolve({Location: "/file/"}); >- } >- return item; >- }); >- }, new Deferred().resolve()); >+ this.getFileClient().getProject(floc, {names: [this.PACKAGE_JSON, this.TERN_PROJECT]}).then(function(projectPath) { >+ if(projectPath) { >+ return deferred.resolve({Location: projectPath.Location}); >+ } >+ var promises = [], >+ prnt = parents[parents.length-1]; >+ this.projectFiles.forEach(function(_f) { >+ promises.push(this.getFile(_f, prnt.Location)); >+ promises.push(this.getFile(_f, "/file/")); >+ }.bind(this)); >+ promises.reduce(function(prev, item, index, array) { >+ return prev.then(function(_file) { >+ if(_file && _file.contents) { >+ deferred.resolve({Location: _file.project}); >+ return item.reject("done"); >+ } >+ if(index === array.length-1) { >+ //nothing was found, assume /file/ >+ deferred.resolve({Location: "/file/"}); >+ } >+ return item; >+ }); >+ }, new Deferred().resolve()); >+ }); > } else { > deferred.resolve(parents[parents.length-1]); > } >diff --git a/bundles/org.eclipse.orion.client.ui/web/plugins/filePlugin/fileImpl.js b/bundles/org.eclipse.orion.client.ui/web/plugins/filePlugin/fileImpl.js >index aeecd4d..f79f79f 100644 >--- a/bundles/org.eclipse.orion.client.ui/web/plugins/filePlugin/fileImpl.js >+++ b/bundles/org.eclipse.orion.client.ui/web/plugins/filePlugin/fileImpl.js >@@ -1,6 +1,6 @@ > /******************************************************************************* > * @license >- * Copyright (c) 2010, 2016 IBM Corporation and others. >+ * Copyright (c) 2010, 2017 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials are made > * available under the terms of the Eclipse Public License v1.0 > * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution >@@ -360,7 +360,37 @@ > return result; > }.bind(this)); > }, >- >+ /** >+ * @description Computes the project context from the given location >+ * @param {String} resourceLocation The resource context to find the project for >+ * @param {?} options The options map >+ * @since 14.0 >+ */ >+ getProject: function getProject(resourceLocation, options) { >+ var url = new URL(resourceLocation, self.location); >+ url.query.set("project", "true"); >+ if(options && Array.isArray(options.names)) { >+ var names = ''; >+ options.names.forEach(function(item, index) { >+ names += encodeURIComponent(item); >+ if (index < options.names.length - 1) { >+ names += ","; >+ } >+ }); >+ url.query.set("names", names); >+ } >+ return _xhr("GET", url.href, { >+ headers: { >+ "Orion-Version": "1" >+ }, >+ timeout: 15000, >+ log: false >+ }).then(function(result) { >+ return result.response ? JSON.parse(result.response) : null; >+ },/* @callback */ function reject(err) { >+ return null; >+ }); >+ }, > /** > * Creates a folder. > * @param {String} parentLocation The location of the parent folder >diff --git a/modules/orionode/.vscode/launch.json b/modules/orionode/.vscode/launch.json >new file mode 100644 >index 0000000..5fb2adf >--- /dev/null >+++ b/modules/orionode/.vscode/launch.json >@@ -0,0 +1,43 @@ >+{ >+ "version": "0.2.0", >+ "configurations": [ >+ { >+ "name": "Launch", >+ "type": "node", >+ "request": "launch", >+ "program": "${workspaceRoot}/server.js", >+ "stopOnEntry": false, >+ "args": [], >+ "cwd": "${workspaceRoot}", >+ "preLaunchTask": null, >+ "runtimeExecutable": null, >+ "runtimeArgs": [ >+ "--nolazy" >+ ], >+ "env": { >+ "NODE_ENV": "development" >+ }, >+ "sourceMaps": false, >+ "outFiles": [] >+ }, >+ { >+ "name": "DebugInElectron", >+ "type": "node", >+ "request": "launch", >+ "program": "${workspaceRoot}/server.js", >+ "stopOnEntry": false, >+ "args": [], >+ "cwd": "${workspaceRoot}", >+ "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron", >+ "runtimeArgs": [ >+ ".", >+ "--enable-logging" >+ ], >+ "env": { >+ "NODE_ENV": "development" >+ }, >+ "sourceMaps": false, >+ "outFiles": [] >+ } >+ ] >+} >diff --git a/modules/orionode/lib/file.js b/modules/orionode/lib/file.js >index 9d2bb1d..a3cc657 100755 >--- a/modules/orionode/lib/file.js >+++ b/modules/orionode/lib/file.js >@@ -159,7 +159,25 @@ > var rest = req.params["0"].substring(1), > readIfExists = req.headers ? Boolean(req.headers['read-if-exists']).valueOf() : false, > filepath = getSafeFilePath(req, rest); >- fileUtil.withStatsAndETag(filepath, function(error, stats, etag) { >+ if(filepath && req.query && req.query.project === "true") { >+ //TODO add support for caller to pass in names or regex to determine project context >+ var n = req.query.names.split(','), >+ names = {}; >+ n.forEach(function(item) { >+ names[decodeURIComponent(item)] = Object.create(null); >+ }); >+ return fileUtil.getProject(req.user.workspaceDir, fileRoot, filepath, names).then(function(project) { >+ if(!project) { >+ res.sendStatus(204); >+ } else { >+ api.write(null, res, null, project); >+ } >+ }, function reject(err) { >+ //don't send back 404, this API asks a question, it does not ask to actually get a resource >+ res.sendStatus(204); >+ }); >+ } >+ return fileUtil.withStatsAndETag(filepath, function(error, stats, etag) { > if (error && error.code === 'ENOENT') { > if(typeof readIfExists === 'boolean' && readIfExists) { > res.sendStatus(204); >diff --git a/modules/orionode/lib/fileUtil.js b/modules/orionode/lib/fileUtil.js >index bf19063..23ba53f 100644 >--- a/modules/orionode/lib/fileUtil.js >+++ b/modules/orionode/lib/fileUtil.js >@@ -47,9 +47,13 @@ > return null; // suppress rejection > }); > }); >+ }, function reject(err) { >+ return []; > }) > .then(function(results) { > return results.filter(function(r) { return r; }); >+ }, function reject(err) { >+ return []; > }); > }; > >@@ -77,12 +81,14 @@ > return safePath(workspaceDir, path.join(workspaceDir, filepath)); > }; > >-var getParents = exports.getParents = function(fileRoot, relativePath) { >+var getParents = exports.getParents = function(fileRoot, relativePath, includeFolder) { > var segs = relativePath.split('/'); > if(segs && segs.length > 0 && segs[segs.length-1] === ""){// pop the last segment if it is empty. In this case wwwpath ends with "/". > segs.pop(); > } >- segs.pop();//The last segment now is the directory itself. We do not need it in the parents array. >+ if(!includeFolder) { >+ segs.pop();//The last segment now is the directory itself. We do not need it in the parents array. >+ } > var loc = fileRoot; > var parents = []; > for (var i=0; i < segs.length; i++) { >@@ -99,6 +105,64 @@ > }; > > /** >+ * @description Tries to compute the project path for the given file path >+ * @param {string} workspaceDir The root workspace directory >+ * @param {string} fileRoot The root file path of the server >+ * @param {string} relativePath The path we want the project for >+ * @param {?} options The optional map of options to use while looking for a project >+ * @returns {Promise} A promise to resolve the project >+ * @since 14.0 >+ */ >+var getProject = exports.getProject = function getProject(workspaceDir, fileRoot, relativePath, options) { >+ var parents = getParents(fileRoot, relativePath, true), >+ names = options && typeof options.names === "object" ? options.names : {}; >+ names['.git'] = {isDirectory: true}; >+ names['project.json'] = Object.create(null); >+ if(Array.isArray(parents) && parents.length > 0) { >+ var promises = []; >+ for(var i = 0, len = parents.length; i < len; i++) { >+ var parentFile = parents[i], >+ filepath = parentFile.Location.slice(fileRoot.length); >+ if(filepath.indexOf(workspaceDir) !== 0) { >+ break; >+ } >+ promises.push(findProject(fileRoot, workspaceDir, filepath, names)); >+ } >+ return Promise.any(promises); >+ } >+}; >+/** >+ * @description Finds the project from the given file context >+ * @param {string} fileRoot The root file context >+ * @param {string} workspaceDir The root workspace location >+ * @param {string} filepath The absolute path to the file context we are starting from >+ * @param {?} names The map of names to check against to determine project-ness >+ * @since 14.0 >+ * @returns {Promise} Returns a promise to try and resolve the project from the context >+ */ >+function findProject(fileRoot, workspaceDir, filepath, names) { >+ return new Promise(function(resolve, reject) { >+ getChildren(fileRoot, workspaceDir, filepath, 1).then(function(children) { >+ if(Array.isArray(children) && children.length > 0) { >+ for(var i = 0, len = children.length; i < len; i++) { >+ var c = children[i], >+ n = names[c.Name]; >+ if(n && (c.Directory && n.isDirectory)) { >+ var wwwpath = api.toURLPath(filepath.substring(workspaceDir.length + 1)); >+ return resolve({ >+ Name: path.basename(filepath), >+ Location: getFileLocation(fileRoot, wwwpath, true), >+ Directory: true, >+ Parents: getParents(fileRoot, wwwpath) >+ }); >+ } >+ } >+ } >+ return reject(new Error('not a project')); >+ }); >+ }); >+} >+/** > * Performs the equivalent of rm -rf on a directory. > * @param {Function} callback Invoked as callback(error) > */
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 511326
:
267005
|
267007
| 267009 |
267035