summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSilenio Quarti <Silenio_Quarti@ca.ibm.com>2015-12-10 16:59:15 -0500
committerSilenio Quarti <Silenio_Quarti@ca.ibm.com>2015-12-10 16:59:15 -0500
commit941718bd0943ebb90e62cd49045add914de9217c (patch)
treefef899707bc2de36cce28d0855d6eb44dc19288c
parent35de8d0a5e1b1b9d6af8a8f2cb51b53b0e52cecf (diff)
downloadorg.eclipse.orion.client-origin/silenio/fileClientService.zip
org.eclipse.orion.client-origin/silenio/fileClientService.tar.gz
org.eclipse.orion.client-origin/silenio/fileClientService.tar.bz2
Bug 393711 - Provide support for trusted pluginsorigin/silenio/fileClientService
Make file client and search client a service
-rw-r--r--bundles/org.eclipse.orion.client.core/web/orion/fileClient.js1
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/commands/refsCommand.js6
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js17
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/scriptResolver.js16
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/javascript/ternProjectManager.js18
-rw-r--r--bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/scriptResolverTests.js7
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/compare-tree/compare-tree.js2
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/edit/setup.js1
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/orion/compare/compareTreeExplorer.js4
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/orion/gSearchClient.js166
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/orion/inlineSearchResultExplorer.js19
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/orion/search/InlineSearchPane.js7
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/orion/searchClient.js156
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/orion/sidebar.js2
-rw-r--r--bundles/org.eclipse.orion.client.ui/web/orion/webui/dialogs/OpenResourceDialog.js10
-rw-r--r--bundles/org.eclipse.orion.client.webtools/web/webtools/plugins/webToolsPlugin.js9
16 files changed, 195 insertions, 246 deletions
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 8a89e37..6017297 100644
--- a/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js
+++ b/bundles/org.eclipse.orion.client.core/web/orion/fileClient.js
@@ -217,6 +217,7 @@ define(['i18n!orion/navigate/nls/messages', "orion/Deferred", "orion/i18nUtil"],
var i = this._getServiceIndex(location);
return i === -1 ? _allFileSystemsService.Location : _fileSystemsRoots[i].Location;
};
+ serviceRegistry.registerService("orion.core.file.client", this); //$NON-NLS-1$
}
FileClient.prototype = /**@lends orion.fileClient.FileClient.prototype */ {
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/refsCommand.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/refsCommand.js
index a987436..fbd2bca 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/refsCommand.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/commands/refsCommand.js
@@ -26,12 +26,12 @@ define([
* @returns {javascript.commands.RenameCommand} A new command
* @since 10.0
*/
- function RefsCommand(ternWorker, astManager, scriptResolver, cuProvider, searchClient) {
+ function RefsCommand(ternWorker, astManager, scriptResolver, cuProvider, serviceRegistry) {
this.ternworker = ternWorker;
this.scriptresolver = scriptResolver;
this.astmanager = astManager;
this.cuprovider = cuProvider;
- this.searchclient = searchClient;
+ this.serviceRegistry = serviceRegistry;
}
/**
@@ -183,7 +183,7 @@ define([
expected.params = searchParams;
expected.deferred = deferred;
var srcCache = {};
- that.searchclient.search(searchParams, true, true).then(function(searchResult) {
+ that.serviceRegistry.getService("orion.core.search.client").search(searchParams, true, true).then(function(searchResult) { //$NON-NLS-1$
expected.result = searchResult;
for (var h = 0, l1 = searchResult.length; h < l1; h++) {
var file = searchResult[h];
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js
index 657e561..b5c99bd 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js
@@ -18,7 +18,6 @@ define([
'orion/plugin',
'orion/serviceregistry',
'orion/Deferred',
-'orion/fileClient',
'orion/metrics',
'esprima/esprima',
'estraverse/estraverse',
@@ -40,7 +39,6 @@ define([
'javascript/commands/openImplementation',
'javascript/commands/renameCommand',
'javascript/commands/refsCommand',
-'orion/gSearchClient',
'orion/editor/stylers/application_javascript/syntax',
'orion/editor/stylers/application_json/syntax',
'orion/editor/stylers/application_schema_json/syntax',
@@ -48,9 +46,9 @@ define([
'i18n!javascript/nls/messages',
'orion/i18nUtil',
'orion/URL-shim'
-], function(PluginProvider, mServiceRegistry, Deferred, FileClient, Metrics, Esprima, Estraverse, ScriptResolver, ASTManager, QuickFixes, TernAssist,
+], function(PluginProvider, mServiceRegistry, Deferred, Metrics, Esprima, Estraverse, ScriptResolver, ASTManager, QuickFixes, TernAssist,
EslintValidator, Occurrences, Hover, Outliner, CUProvider, TernProjectManager, Util, Logger, AddToTernCommand, GenerateDocCommand, OpenDeclCommand, OpenImplCommand,
- RenameCommand, RefsCommand, mGSearchClient, mJS, mJSON, mJSONSchema, mEJS, javascriptMessages, i18nUtil) {
+ RenameCommand, RefsCommand, mJS, mJSON, mJSONSchema, mEJS, javascriptMessages, i18nUtil) {
var serviceRegistry = new mServiceRegistry.ServiceRegistry();
var provider = new PluginProvider({
@@ -88,16 +86,12 @@ define([
* @since 9.0
*/
Estraverse.VisitorKeys.RecoveredNode = []; //do not visit
- /**
- * Create the file client early
- */
- var fileClient = new FileClient.FileClient(serviceRegistry);
/**
* Create the script resolver
* @since 8.0
*/
- var scriptresolver = new ScriptResolver.ScriptResolver(fileClient);
+ var scriptresolver = new ScriptResolver.ScriptResolver(serviceRegistry);
/**
* Create the AST manager
*/
@@ -209,6 +203,7 @@ define([
*/
function doRead(request) {
var response = {request: 'read', ternID: request.ternID, args: {}}; //$NON-NLS-1$
+ var fileClient = serviceRegistry.getService("orion.core.file.client"); //$NON-NLS-1$
if(typeof(request.args.file) === 'object') {
var _l = request.args.file.logical;
response.args.logical = _l;
@@ -388,7 +383,7 @@ define([
types: ["ModelChanging", 'onInputChanged'] //$NON-NLS-1$ //$NON-NLS-2$
});
- var ternProjectManager = new TernProjectManager.TernProjectManager(ternWorker, scriptresolver, fileClient);
+ var ternProjectManager = new TernProjectManager.TernProjectManager(ternWorker, scriptresolver);
/**
* Register Tern project manager as input changed listener
*/
@@ -455,7 +450,7 @@ define([
astManager,
scriptresolver,
CUProvider,
- new mGSearchClient.GSearchClient({serviceRegistry: serviceRegistry, fileClient: fileClient}));
+ serviceRegistry);
provider.registerServiceProvider("orion.edit.command", //$NON-NLS-1$
{
execute: function(editorContext, options) {
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/scriptResolver.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/scriptResolver.js
index 295a954..70b8ae1 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/scriptResolver.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/scriptResolver.js
@@ -23,12 +23,12 @@ define([
* @name ScriptResolver
* @description Creates a new script resolver for finding workspace file based
* on a given logical path and search options
- * @param {orion.FileClient} fileclient The bootstrap object
+ * @param {orion.ServiceRegistry} serviceRegistry The service registry object
* @constructor
* @since 8.0
*/
- function ScriptResolver(fileclient) {
- this.fileclient = fileclient;
+ function ScriptResolver(serviceRegistry) {
+ this.serviceRegistry = serviceRegistry;
this.cache = new LRU(10);
}
@@ -56,7 +56,7 @@ define([
this.searchLocation = searchLocation;
},
getSearchLocation: function() {
- return this.searchLocation || this.fileclient.fileServiceRootURL();
+ return this.searchLocation || "";
},
_getFile : function _getFile(name, options) {
var files = this.cache.get(name);
@@ -75,9 +75,9 @@ define([
var searchname = filename.slice(idx+1);
// Search for it
- return this.fileclient.search(
+ return this.serviceRegistry.getService("orion.core.file.client").search( //$NON-NLS-1$
{
- 'resource': that.searchLocation || this.fileclient.fileServiceRootURL(),
+ 'resource': that.searchLocation || "",
'keyword': searchname,
'sort': 'Name asc', //$NON-NLS-1$
'nameSearch': true,
@@ -263,10 +263,10 @@ define([
return name.replace(/^(?:org\.eclipse\.orion\.client)?(?:\/)?bundles\//, '');
},
- _newFileObj: function _newFileObj(name, location, path, icon, type, fileClient) {
+ _newFileObj: function _newFileObj(name, location, path, icon, type) {
var meta = Object.create(null);
meta.name = name;
- meta.location = location ? location : fileClient.getServiceRootURL() + '/' + path;
+ meta.location = location;
meta.path = path;
meta.contentType = Object.create(null);
if(icon) {
diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/ternProjectManager.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/ternProjectManager.js
index 6320b5c..47bdb13 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/javascript/ternProjectManager.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/ternProjectManager.js
@@ -25,15 +25,23 @@ define([
* @returns {javascript.commands.OpenDeclarationCommand} A new command
* @since 8.0
*/
- function TernProjectManager(ternWorker, scriptResolver, fileClient) {
+ function TernProjectManager(ternWorker, scriptResolver) {
this.ternWorker = ternWorker;
this.scriptResolver = scriptResolver;
- this.fileClient = fileClient;
this.currentProjectLocation = null;
this.timeout = null;
}
Objects.mixin(TernProjectManager.prototype, {
+ /**
+ * @name getFileClient
+ * @description Get the file client;
+ * @function
+ * @returns {orion.FileClient} returns a file client
+ */
+ getFileClient: function() {
+ return this.scriptResolver.getFileClient();
+ },
/**
* Returns the top level file folder representing the project that contains the given file.
@@ -65,7 +73,7 @@ define([
if(projectFile.Children){
deferred = new Deferred().resolve(projectFile.Children);
} else if(projectFile.ChildrenLocation) {
- deferred = this.fileClient.fetchChildren(projectFile.ChildrenLocation);
+ deferred = this.getFileClient().fetchChildren(projectFile.ChildrenLocation);
}
return deferred.then(function(children){
for(var i=0; i<children.length; i++){
@@ -87,7 +95,7 @@ define([
enureTernProjectFileLocation: function(projectFile){
return this.getTernProjectFileLocation(projectFile).then(function(ternFileLocation){
if (!ternFileLocation){
- return this.fileClient.createFile(projectFile.Location, '.tern-project').then(function(){ //$NON-NLS-1$
+ return this.getFileClient().createFile(projectFile.Location, '.tern-project').then(function(){ //$NON-NLS-1$
return ternFileLocation;
});
} else {
@@ -102,7 +110,7 @@ define([
* @returns {Deferred} Deferred to get a parsed JSON object or an empty object if there is an error
*/
parseTernJSON: function(fileLocation){
- return this.fileClient.read(fileLocation).then(function(content) {
+ return this.getFileClient().read(fileLocation).then(function(content) {
try {
return content ? JSON.parse(content) : {};
} catch(e) {
diff --git a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/scriptResolverTests.js b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/scriptResolverTests.js
index 7bbb74b..a0aa9b8 100644
--- a/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/scriptResolverTests.js
+++ b/bundles/org.eclipse.orion.client.javascript/web/js-tests/javascript/scriptResolverTests.js
@@ -15,8 +15,9 @@ define([
'chai/chai',
'javascript/scriptResolver',
'orion/Deferred',
+ 'orion/serviceregistry',
'mocha/mocha', //must stay at the end, not a module
-], function(chai, Resolver, Deferred) {
+], function(chai, Resolver, Deferred, mServiceRegistry) {
var assert = chai.assert;
@@ -57,7 +58,9 @@ define([
}
};
- var resolver = new Resolver.ScriptResolver(testFileClient);
+ var serviceRegistry = new mServiceRegistry.ServiceRegistry();
+ serviceRegistry.registerService("orion.core.file.client", testFileClient);
+ var resolver = new Resolver.ScriptResolver(serviceRegistry);
describe('Script resolver tests', function() {
it('Test getWorkspaceFile 1', function() {
diff --git a/bundles/org.eclipse.orion.client.ui/web/compare-tree/compare-tree.js b/bundles/org.eclipse.orion.client.ui/web/compare-tree/compare-tree.js
index d16fb33..0c1d831 100644
--- a/bundles/org.eclipse.orion.client.ui/web/compare-tree/compare-tree.js
+++ b/bundles/org.eclipse.orion.client.ui/web/compare-tree/compare-tree.js
@@ -31,7 +31,7 @@ define(['i18n!orion/compare/nls/messages', 'orion/bootstrap', 'orion/status', 'o
var startWidget = function(){
var compareParams = PageUtil.matchResourceParameters();
- var compareTreeExplorer = new mCompareTreeExplorer.CompareTreeExplorer(serviceRegistry, "compare-tree-results", commandRegistry); //$NON-NLS-0$
+ var compareTreeExplorer = new mCompareTreeExplorer.CompareTreeExplorer(serviceRegistry, "compare-tree-results", commandRegistry, fileClient); //$NON-NLS-0$
compareTreeExplorer.startup(compareParams);
mGlobalCommands.setPageTarget({
task: messages.compareTreeTitle
diff --git a/bundles/org.eclipse.orion.client.ui/web/edit/setup.js b/bundles/org.eclipse.orion.client.ui/web/edit/setup.js
index b2094bb..61b751b 100644
--- a/bundles/org.eclipse.orion.client.ui/web/edit/setup.js
+++ b/bundles/org.eclipse.orion.client.ui/web/edit/setup.js
@@ -664,6 +664,7 @@ objects.mixin(EditorSetup.prototype, {
outlineService: this.outlineService,
parent: this.sidebarDomNode,
progressService: this.progressService,
+ searcher: this.searcher,
selection: this.selection,
serviceRegistry: this.serviceRegistry,
sidebarNavInputManager: this.sidebarNavInputManager,
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/compare/compareTreeExplorer.js b/bundles/org.eclipse.orion.client.ui/web/orion/compare/compareTreeExplorer.js
index 2ef2eaf..7829487 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/compare/compareTreeExplorer.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/compare/compareTreeExplorer.js
@@ -186,11 +186,11 @@ define(['i18n!orion/compare/nls/messages', 'require', 'orion/webui/littlelib', '
CompareTreeExplorerRenderer.prototype.constructor = CompareTreeExplorerRenderer;
- function CompareTreeExplorer(registry, parentId, commandService){
+ function CompareTreeExplorer(registry, parentId, commandService, fileClient){
this.selection = new mSelection.Selection(registry, "orion.compare.selection"); //$NON-NLS-0$
this.registry = registry;
this._commandService = commandService;
- this._fileClient = new mFileClient.FileClient(this.registry);
+ this._fileClient = fileClient;
this._progress = registry.getService("orion.page.progress"); //$NON-NLS-0$
this.parentId = parentId;
this.renderer = new CompareTreeExplorerRenderer({checkbox: false}, this);
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/gSearchClient.js b/bundles/org.eclipse.orion.client.ui/web/orion/gSearchClient.js
deleted file mode 100644
index 6ee11e2..0000000
--- a/bundles/org.eclipse.orion.client.ui/web/orion/gSearchClient.js
+++ /dev/null
@@ -1,166 +0,0 @@
-/*******************************************************************************
- * @license
- * Copyright (c) 2010, 2012 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
- * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html).
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-
-/*eslint-env browser, amd*/
-define("orion/gSearchClient", [ //$NON-NLS-0$
- 'orion/fileClient', //$NON-NLS-0$
- 'orion/Deferred', //$NON-NLS-0$
- 'orion/crawler/searchCrawler', //$NON-NLS-0$
- 'orion/searchUtils' //$NON-NLS-0$
-], function(mFileClient, Deferred, mSearchCrawler, mSearchUtils) {
- /**
- * Creates a new global search client.
- * @param {Object} options The options object
- * @param {orion.serviceregistry.ServiceRegistry} options.serviceRegistry The service registry
- * @param {orion.fileClient.FileClient} options.fileClient The file client that provide search API
- * @name orion.search.GSearchClient
- * @class Provides API for searching the workspace or under a certain folder.
- */
- function GSearchClient(options) {
- this._registry = options.serviceRegistry;
- this._fileClient = options.fileClient;
- if(!this._fileClient) {
- this._fileClient = new mFileClient.FileClient(this._registry);
- }
- }
- GSearchClient.prototype = /**@lends orion.search.GSearchClient.prototype*/ {
- /**
- * Runs a search and displays the results under the given DOM node.
- * @public
- * @param {Object} searchParams The search parameters.
- * @param {Function(JSONObject)} Callback function that receives the results of the query.
- */
- search: function(searchParams, generateMatches, generateMeta) {
- var result = new Deferred();
- try {
- this._searchDeferred = this._fileClient.search(searchParams);
- this._searchDeferred.then(function(jsonData) { //$NON-NLS-1$ //$NON-NLS-0$
- this._searchDeferred = null;
- var searchResult = this.convert(jsonData, searchParams);
- this._generateMatches(searchParams, searchResult, generateMatches).then(function() {
- this._generateMeta(searchResult, generateMeta).then(function() {
- result.resolve(searchResult);
- });
- }.bind(this));
- }.bind(this), function(error) {
- this._searchDeferred = null;
- result.reject(error);
- }.bind(this));
- }
- catch(err){
- var error = err.message || err;
- if(typeof(error) === "string" && error.toLowerCase().indexOf("search") > -1){ //$NON-NLS-1$ //$NON-NLS-0$
- if(!this._crawler) {
- this._crawler = this._createCrawler(searchParams);
- }
- if(searchParams.nameSearch) {
- this._crawler.searchName(searchParams).then(function(jsonData) { //$NON-NLS-1$ //$NON-NLS-0$
- this._searchDeferred = null;
- result.resolve(this.convert(jsonData, searchParams));
- }.bind(this));
- } else {
- this._crawler.search(function() {
- result.progress(arguments[0], arguments[1]);
- }).then(function(jsonData) { //$NON-NLS-1$ //$NON-NLS-0$
- this._searchDeferred = null;
- result.resolve(this.convert(jsonData, searchParams));
- }.bind(this));
- }
- } else {
- throw error;
- }
- }
- return result;
- },
- _generateSingle: function(sResult, searchHelper) {
- return this._fileClient.read(sResult.location).then(function(jsonData) {
- mSearchUtils.searchWithinFile(searchHelper.inFileQuery, sResult, jsonData, false, searchHelper.params.caseSensitive, true);
- return sResult;
- }.bind(this),
- function(error) {
- var statusService = this._registry.getService("orion.page.message"); //$NON-NLS-1$
- if (statusService) {
- statusService.setProgressResult({Message: error.message, Severity: "Error"}); //$NON-NLS-1$
- }
- }.bind(this));
-
- },
- _generateMatches: function(searchParams, searchResult, generateMatches) {
- if(!generateMatches || searchResult.length === 0) {
- return new Deferred().resolve(searchResult);
- }
- var searchHelper = mSearchUtils.generateSearchHelper(searchParams);
-
- var promises = [];
- searchResult.forEach(function(sResult) {
- promises.push(this._generateSingle(sResult, searchHelper));
- }.bind(this));
- return Deferred.all(promises, function(error) { return {_error: error}; });
- },
- _generateSingleMeta: function(sResult) {
- return this._fileClient.read(sResult.location, true).then(function(jsonData) {
- sResult.metadata = jsonData;
- return sResult;
- }.bind(this),
- function(error) {
- var statusService = this._registry.getService("orion.page.message"); //$NON-NLS-1$
- if (statusService) {
- statusService.setProgressResult({Message: error.message, Severity: "Error"}); //$NON-NLS-1$
- }
- }.bind(this));
-
- },
- _generateMeta: function(searchResult, generateMeta) {
- if(!generateMeta || searchResult.length === 0) {
- return new Deferred().resolve(searchResult);
- }
- var promises = [];
- searchResult.forEach(function(sResult) {
- promises.push(this._generateSingleMeta(sResult));
- }.bind(this));
- return Deferred.all(promises, function(error) { return {_error: error}; });
- },
- convert: function(jsonData, searchParams) {
- var converted = [];
- var rootURL = this._fileClient.fileServiceRootURL(searchParams.resource);
- if (jsonData.response.numFound > 0) {
- for (var i=0; i < jsonData.response.docs.length; i++) {
- var hit = jsonData.response.docs[i];
- if (!hit.Directory) {
- var loc = hit.Location;
- var path = hit.Path;
- if (!path) {
- path = loc.substring(rootURL ? rootURL.length : 0); //remove file service root from path
- }
- converted.push({location: loc, path: path, name: hit.Name});
- }
- }
- }
- return converted;
- },
- cancel: function() {
- if(this._searchDeferred) {
- return this._searchDeferred.cancel();
- }
- return new Deferred().resolve();
- },
- _createCrawler: function(searchParams, options) {
- this._crawler = new mSearchCrawler.SearchCrawler(this._registry, this._fileClient, searchParams, options);
- return this._crawler;
- }
- };
-
- GSearchClient.prototype.constructor = GSearchClient;
- return {
- GSearchClient:GSearchClient
- };
-}); \ No newline at end of file
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/inlineSearchResultExplorer.js b/bundles/org.eclipse.orion.client.ui/web/orion/inlineSearchResultExplorer.js
index 8f5f104..16fccc1 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/inlineSearchResultExplorer.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/inlineSearchResultExplorer.js
@@ -14,13 +14,13 @@
/*eslint-env browser */
define(['i18n!orion/search/nls/messages', 'orion/Deferred', 'orion/webui/littlelib', 'orion/contentTypes', 'orion/i18nUtil', 'orion/explorers/explorer',
- 'orion/fileClient', 'orion/commands', 'orion/searchUtils', 'orion/compare/compareView',
+ 'orion/commands', 'orion/searchUtils', 'orion/compare/compareView',
'orion/highlight', 'orion/webui/tooltip', 'orion/explorers/navigatorRenderer', 'orion/extensionCommands',
- 'orion/searchModel', 'orion/gSearchClient', 'orion/explorers/fileDetailRenderer'
+ 'orion/searchModel', 'orion/explorers/fileDetailRenderer'
],
-function(messages, Deferred, lib, mContentTypes, i18nUtil, mExplorer, mFileClient, mCommands,
+function(messages, Deferred, lib, mContentTypes, i18nUtil, mExplorer, mCommands,
mSearchUtils, mCompareView, mHighlight, mTooltip,
- navigatorRenderer, extensionCommands, mSearchModel, mGSearchClient, mFileDetailRenderer
+ navigatorRenderer, extensionCommands, mSearchModel, mFileDetailRenderer
) {
/* Internal wrapper functions*/
function _empty(nodeToEmpty) {
@@ -384,14 +384,15 @@ function(messages, Deferred, lib, mContentTypes, i18nUtil, mExplorer, mFileClien
* Creates a new search result explorer.
* @name orion.InlineSearchResultExplorer
*/
- function InlineSearchResultExplorer(registry, commandService, inlineSearchPane, preferences) {
+ function InlineSearchResultExplorer(registry, commandService, inlineSearchPane, preferences, fileClient, searcher) {
this.registry = registry;
this._commandService = commandService;
- this.fileClient = new mFileClient.FileClient(this.registry);
+ this.fileClient = fileClient;
this.defaulRows = 40;
this._contentTypeService = new mContentTypes.ContentTypeRegistry(this.registry);
this._inlineSearchPane = inlineSearchPane;
this._preferences = preferences;
+ this._searcher = searcher;
this._replaceRenderer = new SearchResultRenderer({
checkbox: true,
highlightSelection: false,
@@ -1243,8 +1244,8 @@ function(messages, Deferred, lib, mContentTypes, i18nUtil, mExplorer, mFileClien
return;
}
this.registry.getService("orion.page.message").setProgressMessage(messages["Searching..."]); //$NON-NLS-0$
- var gSearchClient = new mGSearchClient.GSearchClient({serviceRegistry: this.registry, fileClient: this.fileClient});
- gSearchClient.search(searchParams).then(function(searchResult) {
+ var searchClient = this._searcher;
+ searchClient.search(searchParams).then(function(searchResult) {
this.registry.getService("orion.page.message").setProgressMessage(""); //$NON-NLS-0$
if(searchResult) {
this._renderSearchResult(resultsNode, searchParams, searchResult);
@@ -1253,7 +1254,7 @@ function(messages, Deferred, lib, mContentTypes, i18nUtil, mExplorer, mFileClien
var message = i18nUtil.formatMessage(messages["${0}. Try your search again."], error && error.error ? error.error : "Error"); //$NON-NLS-0$
this.registry.getService("orion.page.message").setProgressResult({Message: message, Severity: "Error"}); //$NON-NLS-1$ //$NON-NLS-2$
}.bind(this), function(jsonData, incremental) {
- this._renderSearchResult(resultsNode, searchParams, gSearchClient.convert(jsonData, searchParams), incremental);
+ this._renderSearchResult(resultsNode, searchParams, searchClient.convert(jsonData, searchParams), incremental);
}.bind(this));
};
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/search/InlineSearchPane.js b/bundles/org.eclipse.orion.client.ui/web/orion/search/InlineSearchPane.js
index 8143e41..5783069 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/search/InlineSearchPane.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/search/InlineSearchPane.js
@@ -13,7 +13,6 @@ define([
'orion/objects',
'orion/webui/littlelib',
'text!orion/search/InlineSearchPane.html',
- 'orion/searchClient',
'orion/inlineSearchResultExplorer',
'orion/searchUtils',
'orion/Deferred',
@@ -22,7 +21,7 @@ define([
'i18n!orion/search/nls/messages',
'orion/webui/Slideout'
], function(
- objects, lib, InlineSearchPaneTemplate, mSearchClient, InlineSearchResultExplorer,
+ objects, lib, InlineSearchPaneTemplate, InlineSearchResultExplorer,
mSearchUtils, Deferred, DirectoryPrompterDialog, ComboTextInput, messages, mSlideout
) {
var SlideoutViewMode = mSlideout.SlideoutViewMode;
@@ -35,6 +34,7 @@ define([
this._serviceRegistry = options.serviceRegistry;
this._commandRegistry = options.commandRegistry;
this._fileClient = options.fileClient;
+ this._searcher = options.searcher;
this._preferences = options.preferences;
this._initialize();
}
@@ -68,8 +68,7 @@ define([
this._replaceCompareTitleDiv = lib.node("replaceCompareTitleDiv"); //$NON-NLS-0$
this._replaceCompareDiv = lib.node("replaceCompareDiv"); //$NON-NLS-0$
- this._searcher = new mSearchClient.Searcher({serviceRegistry: this._serviceRegistry, commandService: this._commandRegistry, fileService: this._fileClient});
- this._searchResultExplorer = new InlineSearchResultExplorer(this._serviceRegistry, this._commandRegistry, this, this._preferences);
+ this._searchResultExplorer = new InlineSearchResultExplorer(this._serviceRegistry, this._commandRegistry, this, this._preferences, this._fileClient, this._searcher);
this._initControls();
this._initHTMLLabels();
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/searchClient.js b/bundles/org.eclipse.orion.client.ui/web/orion/searchClient.js
index 8cbc122..7737582 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/searchClient.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/searchClient.js
@@ -20,27 +20,6 @@ define([
'orion/Deferred'
], function(messages, lib, i18nUtil, mSearchUtils, mSearchCrawler, Deferred){
- function _convert(jsonData, rootURL, folderKeyword) {
- var converted = [];
- if (jsonData.response.numFound > 0) {
- for (var i=0; i < jsonData.response.docs.length; i++) {
- var hit = jsonData.response.docs[i];
- if (!hit.Directory) {
- var loc = hit.Location;
- var path = hit.Path;
- if (!path) {
- path = loc.substring(rootURL ? rootURL.length : 0); //remove file service root from path
- }
- //If folderKeyword is defined then we filter on the keyword on path
- var folderCheck = folderKeyword ? (path.indexOf(folderKeyword) >= 0) : true;
- if(folderCheck) {
- converted.push({location: loc, path: path, name: hit.Name});
- }
- }
- }
- }
- return converted;
- }
/**
* Creates a new search client.
* @param {Object} options The options object
@@ -52,10 +31,12 @@ define([
this._registry= options.serviceRegistry;
this._commandService = options.commandService;
this._fileClient = options.fileService;
+ //TODO clean up the search client API. Make any helper private
+ this._registry.registerService("orion.core.search.client", this); //$NON-NLS-1$
}
Searcher.prototype = /**@lends orion.searchClient.Searcher.prototype*/ {
getFileService: function(){
- return this._fileClient;
+ return this.getFileClient();
},
setLocationByMetaData: function(meta, useParentLocation){
var locationName = "";
@@ -131,6 +112,137 @@ define([
return this._fileClient.fileServiceRootURL();
}
},
+
+ /**
+ * @name getFileClient
+ * @description Get the file client;
+ * @function
+ * @returns {orion.FileClient} returns a file client
+ */
+ getFileClient: function() {
+ return this._fileClient ? this._fileClient : this._registry.getService("orion.core.file.client"); //$NON-NLS-1$
+ },
+ /**
+ * Runs a search and displays the results under the given DOM node.
+ * @public
+ * @param {Object} searchParams The search parameters.
+ * @param {Function(JSONObject)} Callback function that receives the results of the query.
+ */
+ search: function(searchParams, generateMatches, generateMeta) {
+ var result = new Deferred();
+ try {
+ this._searchDeferred = this.getFileClient().search(searchParams);
+ this._searchDeferred.then(function(jsonData) { //$NON-NLS-1$ //$NON-NLS-0$
+ this._searchDeferred = null;
+ var searchResult = this.convert(jsonData, searchParams);
+ this._generateMatches(searchParams, searchResult, generateMatches).then(function() {
+ this._generateMeta(searchResult, generateMeta).then(function() {
+ result.resolve(searchResult);
+ });
+ }.bind(this));
+ }.bind(this), function(error) {
+ this._searchDeferred = null;
+ result.reject(error);
+ }.bind(this));
+ }
+ catch(err){
+ var error = err.message || err;
+ if(typeof(error) === "string" && error.toLowerCase().indexOf("search") > -1){ //$NON-NLS-1$ //$NON-NLS-0$
+ if(!this._crawler) {
+ this._crawler = this._createCrawler(searchParams);
+ }
+ if(searchParams.nameSearch) {
+ this._crawler.searchName(searchParams).then(function(jsonData) { //$NON-NLS-1$ //$NON-NLS-0$
+ this._searchDeferred = null;
+ result.resolve(this.convert(jsonData, searchParams));
+ }.bind(this));
+ } else {
+ this._crawler.search(function() {
+ result.progress(arguments[0], arguments[1]);
+ }).then(function(jsonData) { //$NON-NLS-1$ //$NON-NLS-0$
+ this._searchDeferred = null;
+ result.resolve(this.convert(jsonData, searchParams));
+ }.bind(this));
+ }
+ } else {
+ throw error;
+ }
+ }
+ return result;
+ },
+ _generateSingle: function(sResult, searchHelper) {
+ return this.getFileClient().read(sResult.location).then(function(jsonData) {
+ mSearchUtils.searchWithinFile(searchHelper.inFileQuery, sResult, jsonData, false, searchHelper.params.caseSensitive, true);
+ return sResult;
+ }.bind(this),
+ function(error) {
+ var statusService = this._registry.getService("orion.page.message"); //$NON-NLS-1$
+ if (statusService) {
+ statusService.setProgressResult({Message: error.message, Severity: "Error"}); //$NON-NLS-1$
+ }
+ }.bind(this));
+ },
+ _generateMatches: function(searchParams, searchResult, generateMatches) {
+ if(!generateMatches || searchResult.length === 0) {
+ return new Deferred().resolve(searchResult);
+ }
+ var searchHelper = mSearchUtils.generateSearchHelper(searchParams);
+ var promises = [];
+ searchResult.forEach(function(sResult) {
+ promises.push(this._generateSingle(sResult, searchHelper));
+ }.bind(this));
+ return Deferred.all(promises, function(error) { return {_error: error}; });
+ },
+ _generateSingleMeta: function(sResult) {
+ return this.getFileClient().read(sResult.location, true).then(function(jsonData) {
+ sResult.metadata = jsonData;
+ return sResult;
+ }.bind(this), function(error) {
+ var statusService = this._registry.getService("orion.page.message"); //$NON-NLS-1$
+ if (statusService) {
+ statusService.setProgressResult({Message: error.message, Severity: "Error"}); //$NON-NLS-1$
+ }
+ }.bind(this));
+ },
+ _generateMeta: function(searchResult, generateMeta) {
+ if(!generateMeta || searchResult.length === 0) {
+ return new Deferred().resolve(searchResult);
+ }
+ var promises = [];
+ searchResult.forEach(function(sResult) {
+ promises.push(this._generateSingleMeta(sResult));
+ }.bind(this));
+ return Deferred.all(promises, function(error) { return {_error: error}; });
+ },
+ convert: function(jsonData, searchParams) {
+ var converted = [];
+ var rootURL = this._fileClient.fileServiceRootURL(searchParams.resource);
+ if (jsonData.response.numFound > 0) {
+ for (var i=0; i < jsonData.response.docs.length; i++) {
+ var hit = jsonData.response.docs[i];
+ if (!hit.Directory) {
+ var loc = hit.Location;
+ var path = hit.Path;
+ if (!path) {
+ path = loc.substring(rootURL ? rootURL.length : 0); //remove file service root from path
+ }
+ converted.push({location: loc, path: path, name: hit.Name});
+ }
+ }
+ }
+ return converted;
+ },
+ cancel: function() {
+ if(this._searchDeferred) {
+ return this._searchDeferred.cancel();
+ }
+ return new Deferred().resolve();
+ },
+ _createCrawler: function(searchParams, options) {
+ this._crawler = new mSearchCrawler.SearchCrawler(this._registry, this.getFileClient(), searchParams, options);
+ return this._crawler;
+ },
+
/**
* Returns a query object for search. The return value has the propertyies of resource and parameters.
* @param {String} keyword The text to search for, or null when searching purely on file name
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/sidebar.js b/bundles/org.eclipse.orion.client.ui/web/orion/sidebar.js
index c537b62..4bb736d 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/sidebar.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/sidebar.js
@@ -45,6 +45,7 @@ define(['orion/objects', 'orion/commands', 'orion/outliner', 'orion/webui/little
this.commandRegistry = params.commandRegistry;
this.contentTypeRegistry = params.contentTypeRegistry;
this.fileClient = params.fileClient;
+ this.searcher = params.searcher;
this.editorInputManager = params.editorInputManager;
this.outlineService = params.outlineService;
this.parentNode = lib.node(params.parent);
@@ -318,6 +319,7 @@ define(['orion/objects', 'orion/commands', 'orion/outliner', 'orion/webui/little
serviceRegistry: this.serviceRegistry,
commandRegistry: this.commandRegistry,
fileClient: this.fileClient,
+ searcher: this.searcher,
preferences: this.preferences
});
diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialogs/OpenResourceDialog.js b/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialogs/OpenResourceDialog.js
index fab2f54..9c893ae 100644
--- a/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialogs/OpenResourceDialog.js
+++ b/bundles/org.eclipse.orion.client.ui/web/orion/webui/dialogs/OpenResourceDialog.js
@@ -16,7 +16,6 @@ define([
'i18n!orion/widgets/nls/messages',
'i18n!orion/search/nls/messages',
'orion/extensionCommands',
- 'orion/gSearchClient',
'orion/i18nUtil',
'orion/searchUtils',
'orion/explorers/navigatorRenderer',
@@ -27,7 +26,7 @@ define([
'orion/webui/dialog',
'orion/metrics',
'orion/Deferred'
-], function(messages, searchMSG, extensionCommands, mGSearchClient, i18nUtil, mSearchUtils, navigatorRenderer, mContentTypes, require, lib, util, dialog, mMetrics, Deferred) {
+], function(messages, searchMSG, extensionCommands, i18nUtil, mSearchUtils, navigatorRenderer, mContentTypes, require, lib, util, dialog, mMetrics, Deferred) {
//default search renderer until we factor this out completely
function DefaultSearchRenderer(serviceRegistry, commandRegistry) {
this.serviceRegistry = serviceRegistry;
@@ -234,7 +233,6 @@ define([
if (!this._fileClient) {
throw new Error(messages['Missing required argument: fileService']);
}
- this._gSearchClient = new mGSearchClient.GSearchClient({serviceRegistry: this.serviceRegistry, fileClient: this._fileClient});
this._searchRenderer = new DefaultSearchRenderer(this.serviceRegistry, this.commandRegistry);
this._initialize();
};
@@ -339,7 +337,7 @@ define([
setTimeout(function() {
if(self._forceUseCrawler || !self._fileClient.getService(self._searcher.getSearchLocation())["search"]){//$NON-NLS-0$
var searchLoc = self._searchOnRoot ? self._searcher.getSearchRootLocation() : self._searcher.getChildrenLocation();
- self._crawler = self._gSearchClient._createCrawler({resource: searchLoc}, {searchOnName: true});
+ self._crawler = self._searcher._createCrawler({resource: searchLoc}, {searchOnName: true});
self._crawler.buildSkeleton(function() {
self.$crawlingProgress.style.display = "inline"; //$NON-NLS-0$
self.$progress.appendChild(document.createTextNode(messages['Building file skeleton...']));
@@ -450,14 +448,14 @@ define([
this.$results.appendChild(div);
var deferredSearch;
if(this._searchPending) {
- deferredSearch = this._gSearchClient.cancel();
+ deferredSearch = this._searcher.cancel();
this.cancelled = true;
} else {
deferredSearch = new Deferred().resolve();
}
deferredSearch.then(function(/*result*/) {
this._searchPending = true;
- this._gSearchClient.search(searchParams).then(function(searchResult) {
+ this._searcher.search(searchParams).then(function(searchResult) {
this._searchPending = false;
if (renderFunction === this.currentSearch || this.cancelled) {
this.cancelled = false;
diff --git a/bundles/org.eclipse.orion.client.webtools/web/webtools/plugins/webToolsPlugin.js b/bundles/org.eclipse.orion.client.webtools/web/webtools/plugins/webToolsPlugin.js
index d66f6a4..369e6e9 100644
--- a/bundles/org.eclipse.orion.client.webtools/web/webtools/plugins/webToolsPlugin.js
+++ b/bundles/org.eclipse.orion.client.webtools/web/webtools/plugins/webToolsPlugin.js
@@ -12,7 +12,6 @@
/*eslint-env browser, amd*/
define(['orion/plugin',
'orion/serviceregistry',
-'orion/fileClient',
'orion/metrics',
'javascript/scriptResolver',
'webtools/htmlAstManager',
@@ -28,7 +27,7 @@ define(['orion/plugin',
'webtools/cssResultManager',
'orion/editor/stylers/text_css/syntax',
'i18n!webtools/nls/messages'
-], function(PluginProvider, mServiceRegistry, FileClient, Metrics, ScriptResolver, HtmlAstManager, htmlHover, htmlContentAssist, htmlOutliner,
+], function(PluginProvider, mServiceRegistry, Metrics, ScriptResolver, HtmlAstManager, htmlHover, htmlContentAssist, htmlOutliner,
mHTML, cssContentAssist, mCssValidator, mCssOutliner, cssHover, cssQuickFixes, cssResultManager, mCSS, messages) {
/**
@@ -61,10 +60,6 @@ define(['orion/plugin',
}
]
});
- /**
- * load file client early
- */
- var fileClient = new FileClient.FileClient(serviceRegistry);
var cssResultMgr = new cssResultManager();
/**
@@ -152,7 +147,7 @@ define(['orion/plugin',
}
}
- var resolver = new ScriptResolver.ScriptResolver(fileClient);
+ var resolver = new ScriptResolver.ScriptResolver(serviceRegistry);
/**
* Register the hover support