Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 511326 | Differences between
and this patch

Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js (-1 / +14 lines)
Lines 142-147 Link Here
142
				}, 100);
142
				}, 100);
143
				return d;
143
				return d;
144
			},
144
			},
145
			/**
146
			 * @description Computes the project context from the given location
147
			 * @param {String} context The resource context to find the project for
148
			 * @since 14.0
149
			 */
150
			getProject: _noMatch,
145
			search: _noMatch,
151
			search: _noMatch,
146
			createProject: _noMatch,
152
			createProject: _noMatch,
147
			createFolder: _noMatch,
153
			createFolder: _noMatch,
Lines 361-367 Link Here
361
		changeWorkspace: function(workspaceLocation) {
367
		changeWorkspace: function(workspaceLocation) {
362
			return _doServiceCall(this._getService(), "changeWorkspace", arguments); //$NON-NLS-1$
368
			return _doServiceCall(this._getService(), "changeWorkspace", arguments); //$NON-NLS-1$
363
		},
369
		},
364
370
		/**
371
		 * @description Computes the project context from the given location
372
		 * @param {String} context The resource context to find the project for
373
		 * @since 14.0
374
		 */
375
		getProject: function getProject(resource) {
376
			return _doServiceCall(this._getService(resource), "getProject", arguments);	
377
		},
365
		_createArtifact: function(parentLocation, funcName, eventData, funcArgs) {
378
		_createArtifact: function(parentLocation, funcName, eventData, funcArgs) {
366
			return _doServiceCall(this._getService(parentLocation), funcName, funcArgs).then(function(result){
379
			return _doServiceCall(this._getService(parentLocation), funcName, funcArgs).then(function(result){
367
				if(this.isEventFrozen()) {
380
				if(this.isEventFrozen()) {
(-)a/bundles/org.eclipse.orion.client.javascript/web/javascript/javascriptProject.js (-20 / +24 lines)
Lines 692-717 Link Here
692
				deferred.resolve({Location: "/file/"});
692
				deferred.resolve({Location: "/file/"});
693
			} else {
693
			} else {
694
				if(Util.isElectron) {
694
				if(Util.isElectron) {
695
					//TODO call out the server for #getProject
695
					this.getFileClient().getProject(floc, {names: [this.PACKAGE_JSON, this.TERN_PROJECT]}).then(function(projectPath) {
696
					var promises = [],
696
						if(projectPath) {
697
						prnt = parents[parents.length-1];
697
							return deferred.resolve({Location: projectPath.Location});
698
					this.projectFiles.forEach(function(_f) {
698
						}
699
						promises.push(this.getFile(_f, prnt.Location));
699
						var promises = [],
700
						promises.push(this.getFile(_f, "/file/"));
700
							prnt = parents[parents.length-1];
701
					}.bind(this));
701
						this.projectFiles.forEach(function(_f) {
702
					promises.reduce(function(prev, item, index, array) {
702
							promises.push(this.getFile(_f, prnt.Location));
703
                        return prev.then(function(_file) {
703
							promises.push(this.getFile(_f, "/file/"));
704
                            if(_file && _file.contents) {
704
						}.bind(this));
705
                                deferred.resolve({Location: _file.project});
705
						promises.reduce(function(prev, item, index, array) {
706
                                return item.reject("done");
706
	                        return prev.then(function(_file) {
707
                            }
707
	                            if(_file && _file.contents) {
708
                            if(index === array.length-1) {
708
	                                deferred.resolve({Location: _file.project});
709
                                //nothing was found, assume /file/
709
	                                return item.reject("done");
710
                                deferred.resolve({Location: "/file/"});
710
	                            }
711
                            }
711
	                            if(index === array.length-1) {
712
                            return item;
712
	                                //nothing was found, assume /file/
713
                        });
713
	                                deferred.resolve({Location: "/file/"});
714
					}, new Deferred().resolve());
714
	                            }
715
	                            return item;
716
	                        });
717
						}, new Deferred().resolve());
718
					});
715
				} else {
719
				} else {
716
					deferred.resolve(parents[parents.length-1]);
720
					deferred.resolve(parents[parents.length-1]);
717
				}
721
				}
(-)a/bundles/org.eclipse.orion.client.ui/web/plugins/filePlugin/fileImpl.js (-2 / +32 lines)
Lines 1-6 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * @license
2
 * @license
3
 * Copyright (c) 2010, 2016 IBM Corporation and others.
3
 * Copyright (c) 2010, 2017 IBM Corporation and others.
4
 * All rights reserved. This program and the accompanying materials are made
4
 * All rights reserved. This program and the accompanying materials are made
5
 * available under the terms of the Eclipse Public License v1.0
5
 * available under the terms of the Eclipse Public License v1.0
6
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
6
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
Lines 360-366 Link Here
360
				return result;
360
				return result;
361
			}.bind(this));
361
			}.bind(this));
362
		},
362
		},
363
363
		/**
364
		 * @description Computes the project context from the given location
365
		 * @param {String} resourceLocation The resource context to find the project for
366
		 * @param {?} options The options map
367
		 * @since 14.0
368
		 */
369
		getProject: function getProject(resourceLocation, options) {
370
			var url = new URL(resourceLocation, self.location);
371
			url.query.set("project", "true");
372
			if(options && Array.isArray(options.names)) {
373
				var names = '';
374
				options.names.forEach(function(item, index) {
375
					names += encodeURIComponent(item);
376
					if (index < options.names.length - 1) {
377
						names += ",";
378
					}
379
				});
380
				url.query.set("names", names);
381
			}
382
			return _xhr("GET", url.href, {
383
				headers: {
384
					"Orion-Version": "1"
385
				},
386
				timeout: 15000,
387
				log: false
388
			}).then(function(result) {
389
				return result.response ? JSON.parse(result.response) : null;
390
			},/* @callback */ function reject(err) {
391
				return null;
392
			});
393
		},
364
		/**
394
		/**
365
		 * Creates a folder.
395
		 * Creates a folder.
366
		 * @param {String} parentLocation The location of the parent folder
396
		 * @param {String} parentLocation The location of the parent folder
(-)a/modules/orionode/.vscode/launch.json (+43 lines)
Added Link Here
1
{
2
   "version": "0.2.0",
3
   "configurations": [
4
       {
5
           "name": "Launch",
6
           "type": "node",
7
           "request": "launch",
8
           "program": "${workspaceRoot}/server.js",
9
           "stopOnEntry": false,
10
           "args": [],
11
           "cwd": "${workspaceRoot}",
12
           "preLaunchTask": null,
13
           "runtimeExecutable": null,
14
           "runtimeArgs": [
15
               "--nolazy"
16
           ],
17
           "env": {
18
               "NODE_ENV": "development"
19
           },
20
           "sourceMaps": false,
21
           "outFiles": []
22
       },
23
       {
24
           "name": "DebugInElectron",
25
           "type": "node",
26
           "request": "launch",
27
           "program": "${workspaceRoot}/server.js",
28
           "stopOnEntry": false,
29
           "args": [],
30
           "cwd": "${workspaceRoot}",
31
           "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
32
           "runtimeArgs": [
33
               ".",
34
               "--enable-logging"
35
           ],
36
           "env": {
37
               "NODE_ENV": "development"
38
           },
39
           "sourceMaps": false,
40
           "outFiles": []
41
       }
42
   ]
43
}
(-)a/modules/orionode/lib/file.js (-1 / +19 lines)
Lines 159-165 Link Here
159
		var rest = req.params["0"].substring(1),
159
		var rest = req.params["0"].substring(1),
160
			readIfExists = req.headers ? Boolean(req.headers['read-if-exists']).valueOf() : false,
160
			readIfExists = req.headers ? Boolean(req.headers['read-if-exists']).valueOf() : false,
161
			filepath = getSafeFilePath(req, rest);
161
			filepath = getSafeFilePath(req, rest);
162
		fileUtil.withStatsAndETag(filepath, function(error, stats, etag) {
162
		if(filepath && req.query && req.query.project === "true") {
163
			//TODO add support for caller to pass in names or regex to determine project context
164
			var n = req.query.names.split(','),
165
				names = {};
166
			n.forEach(function(item) {
167
				names[decodeURIComponent(item)] = Object.create(null);
168
			});
169
			return fileUtil.getProject(req.user.workspaceDir, fileRoot, filepath, names).then(function(project) {
170
				if(!project) {
171
					res.sendStatus(204);
172
				} else {
173
					api.write(null, res, null, project);
174
				}
175
			}, function reject(err) {
176
				//don't send back 404, this API asks a question, it does not ask to actually get a resource
177
				res.sendStatus(204);
178
			});
179
		}
180
		return fileUtil.withStatsAndETag(filepath, function(error, stats, etag) {
163
			if (error && error.code === 'ENOENT') {
181
			if (error && error.code === 'ENOENT') {
164
				if(typeof readIfExists === 'boolean' && readIfExists) {
182
				if(typeof readIfExists === 'boolean' && readIfExists) {
165
					res.sendStatus(204);
183
					res.sendStatus(204);
(-)a/modules/orionode/lib/fileUtil.js (-2 / +66 lines)
Lines 47-55 Link Here
47
				return null; // suppress rejection
47
				return null; // suppress rejection
48
			});
48
			});
49
		});
49
		});
50
	}, function reject(err) {
51
		return [];
50
	})
52
	})
51
	.then(function(results) {
53
	.then(function(results) {
52
		return results.filter(function(r) { return r; });
54
		return results.filter(function(r) { return r; });
55
	}, function reject(err) {
56
		return [];
53
	});
57
	});
54
};
58
};
55
59
Lines 77-88 Link Here
77
	return safePath(workspaceDir, path.join(workspaceDir, filepath));
81
	return safePath(workspaceDir, path.join(workspaceDir, filepath));
78
};
82
};
79
83
80
var getParents = exports.getParents = function(fileRoot, relativePath) {
84
var getParents = exports.getParents = function(fileRoot, relativePath, includeFolder) {
81
	var segs = relativePath.split('/');
85
	var segs = relativePath.split('/');
82
	if(segs && segs.length > 0 && segs[segs.length-1] === ""){// pop the last segment if it is empty. In this case wwwpath ends with "/".
86
	if(segs && segs.length > 0 && segs[segs.length-1] === ""){// pop the last segment if it is empty. In this case wwwpath ends with "/".
83
		segs.pop();
87
		segs.pop();
84
	}
88
	}
85
	segs.pop();//The last segment now is the directory itself. We do not need it in the parents array.
89
	if(!includeFolder) {
90
		segs.pop();//The last segment now is the directory itself. We do not need it in the parents array.
91
	}
86
	var loc = fileRoot;
92
	var loc = fileRoot;
87
	var parents = [];
93
	var parents = [];
88
	for (var i=0; i < segs.length; i++) {
94
	for (var i=0; i < segs.length; i++) {
Lines 99-104 Link Here
99
};
105
};
100
106
101
/**
107
/**
108
 * @description Tries to compute the project path for the given file path
109
 * @param {string} workspaceDir The root workspace directory
110
 * @param {string} fileRoot The root file path of the server
111
 * @param {string} relativePath The path we want the project for
112
 * @param {?} options The optional map of options to use while looking for a project
113
 * @returns {Promise} A promise to resolve the project
114
 * @since 14.0
115
 */
116
var getProject = exports.getProject = function getProject(workspaceDir, fileRoot, relativePath, options) {
117
	var parents = getParents(fileRoot, relativePath, true),
118
		names = options && typeof options.names === "object" ? options.names : {};
119
	names['.git'] = {isDirectory: true};
120
	names['project.json'] = Object.create(null);
121
	if(Array.isArray(parents) && parents.length > 0) {
122
		var promises = [];
123
		for(var i = 0, len = parents.length; i < len; i++) {
124
			var parentFile = parents[i],
125
				filepath = parentFile.Location.slice(fileRoot.length);
126
			if(filepath.indexOf(workspaceDir) !== 0) {
127
				break;
128
			}
129
			promises.push(findProject(fileRoot, workspaceDir, filepath, names));
130
		}
131
		return Promise.any(promises);
132
	}
133
};
134
/**
135
 * @description Finds the project from the given file context
136
 * @param {string} fileRoot The root file context
137
 * @param {string} workspaceDir The root workspace location
138
 * @param {string} filepath The absolute path to the file context we are starting from
139
 * @param {?} names The map of names to check against to determine project-ness
140
 * @since 14.0
141
 * @returns {Promise} Returns a promise to try and resolve the project from the context
142
 */
143
function findProject(fileRoot, workspaceDir, filepath, names) {
144
	return new Promise(function(resolve, reject) {
145
		getChildren(fileRoot, workspaceDir, filepath, 1).then(function(children) {
146
			if(Array.isArray(children) && children.length > 0) {
147
				for(var i = 0, len = children.length; i < len; i++) {
148
					var c = children[i],
149
						n = names[c.Name];
150
					if(n && (c.Directory && n.isDirectory)) {
151
						var wwwpath = api.toURLPath(filepath.substring(workspaceDir.length + 1));
152
						return resolve({
153
							Name: path.basename(filepath),
154
							Location: getFileLocation(fileRoot, wwwpath, true),
155
							Directory: true,
156
							Parents: getParents(fileRoot, wwwpath)
157
						});
158
					}
159
				}
160
			}
161
			return reject(new Error('not a project'));
162
		});
163
	});
164
}
165
/**
102
 * Performs the equivalent of rm -rf on a directory.
166
 * Performs the equivalent of rm -rf on a directory.
103
 * @param {Function} callback Invoked as callback(error)
167
 * @param {Function} callback Invoked as callback(error)
104
 */
168
 */

Return to bug 511326