summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBogdan Gheorghe <gheorghe@ca.ibm.com>2014-08-07 12:29:46 -0400
committerBogdan Gheorghe <gheorghe@ca.ibn.com>2014-08-07 12:29:46 -0400
commitf48cc07040582479f50751325f4d2112c612b163 (patch)
tree2ef2f43b7d529bc823ba46df721c35d9cd7de3f1
parent7ebec2d8a5b93d2d9bd04ccefc82cc63da2cadbb (diff)
downloadorg.eclipse.orion.client-origin/silenio/gitFileClient.zip
org.eclipse.orion.client-origin/silenio/gitFileClient.tar.gz
org.eclipse.orion.client-origin/silenio/gitFileClient.tar.bz2
Add Git file serviceorigin/silenio/gitFileClient
Change-Id: Id40cb9c890c3ce2f135aa2ba8ecf589a5926855c
-rw-r--r--bundles/org.eclipse.orion.client.git/web/git/plugins/gitPlugin.js31
-rw-r--r--bundles/org.eclipse.orion.client.git/web/orion/git/GitFileImpl.js127
2 files changed, 156 insertions, 2 deletions
diff --git a/bundles/org.eclipse.orion.client.git/web/git/plugins/gitPlugin.js b/bundles/org.eclipse.orion.client.git/web/git/plugins/gitPlugin.js
index 0881400..6834cf5 100644
--- a/bundles/org.eclipse.orion.client.git/web/git/plugins/gitPlugin.js
+++ b/bundles/org.eclipse.orion.client.git/web/git/plugins/gitPlugin.js
@@ -11,8 +11,8 @@
/*eslint-env browser, amd*/
define(["orion/plugin", "orion/xhr", "orion/serviceregistry", "orion/git/gitClient", "orion/ssh/sshTools",
- "orion/i18nUtil", "orion/Deferred", "orion/git/util", "orion/URL-shim", "domReady!"],
-function(PluginProvider, xhr, mServiceregistry, mGitClient, mSshTools, i18nUtil, Deferred, mGitUtil) {
+ "orion/i18nUtil", "orion/Deferred", "orion/git/GitFileImpl", "orion/git/util", "orion/URL-shim", "domReady!"],
+function(PluginProvider, xhr, mServiceregistry, mGitClient, mSshTools, i18nUtil, Deferred, GitFileImpl, mGitUtil) {
var temp = document.createElement('a');
temp.href = "../mixloginstatic/LoginWindow.html";
var serviceRegistry = new mServiceregistry.ServiceRegistry();
@@ -237,6 +237,33 @@ function(PluginProvider, xhr, mServiceregistry, mGitClient, mSshTools, i18nUtil,
],
uriTemplate: "http://git.eclipse.org/c{+EclipseGitLocation}/commit/?id={+commitName}"
});
+
+ var tryParentRelative = true;
+ function makeParentRelative(location) {
+ if (tryParentRelative) {
+ try {
+ if (window.location.host === parent.location.host && window.location.protocol === parent.location.protocol) {
+ return location.substring(parent.location.href.indexOf(parent.location.host) + parent.location.host.length);
+ } else {
+ tryParentRelative = false;
+ }
+ } catch (e) {
+ tryParentRelative = false;
+ }
+ }
+ return location;
+ }
+
+ var url = new URL(window.location.href);
+ temp.href = "../../gitapi/";
+ var gitBase = makeParentRelative(temp.href);
+ var service = new GitFileImpl();
+
+ provider.registerService("orion.core.file", service, {
+ Name: 'Git File System',
+ top: gitBase,
+ pattern: gitBase
+ });
temp.href = "../../gitapi/diff/";
var base = temp.href;
diff --git a/bundles/org.eclipse.orion.client.git/web/orion/git/GitFileImpl.js b/bundles/org.eclipse.orion.client.git/web/orion/git/GitFileImpl.js
new file mode 100644
index 0000000..8582df8
--- /dev/null
+++ b/bundles/org.eclipse.orion.client.git/web/orion/git/GitFileImpl.js
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * @license
+ * Copyright (c) 2014 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*/
+/*global URL*/
+define(["orion/xhr","orion/encoding-shim", "orion/URL-shim"], function(xhr) {
+
+ function GitFileImpl() {
+ }
+
+ GitFileImpl.prototype = {
+ fetchChildren: function(location) {
+ var fetchLocation = location;
+ if (fetchLocation===this.fileBase) {
+ return this.loadWorkspace(fetchLocation).then(function(jsondata) {return jsondata.Children || [];});
+ }
+ //If fetch location does not have ?depth=, then we need to add the depth parameter. Otherwise server will not return any children
+ if (fetchLocation.indexOf("?depth=") === -1) { //$NON-NLS-0$
+ fetchLocation += "?depth=1"; //$NON-NLS-0$
+ }
+ // console.log("get children");
+ return xhr("GET", fetchLocation,{
+ headers: {
+ "Orion-Version": "1",
+ "Content-Type": "charset=UTF-8"
+ },
+ timeout: 15000
+ }).then(function(result) {
+ var jsonData = result.response ? JSON.parse(result.response) : {};
+ return jsonData.Children || [];
+ });
+ },
+ loadWorkspaces: function() {
+ return this.loadWorkspace(this._repoURL);
+ },
+ loadWorkspace: function(location) {
+ var _this = this;
+ var url = new URL(location);
+ return this.fetchChildren(location).then(function(children) {
+ var result = {
+ Attributes: {
+ Archive: false,
+ Hidden: false,
+ ReadOnly: true,
+ SymLink: false
+ },
+ Location: location,
+ Name: null,
+ Length: 0,
+ LocalTimeStamp: 0,
+ Directory: true,
+ ChildrenLocation: location,
+ Children: children
+ };
+ result.Parents = [];
+ result.Name = "GitRoot";
+ return result;
+ })
+ },
+ createProject: function(url, projectName, serverPath, create) {
+ throw "Not supported";
+ },
+ createFolder: function(parentLocation, folderName) {
+ throw "Not supported";
+ },
+ createFile: function(parentLocation, fileName) {
+ throw "Not supported";
+ },
+ deleteFile: function(location) {
+ throw "Not supported";
+ },
+ moveFile: function(sourceLocation, targetLocation, name) {
+ throw "Not supported";
+ },
+ copyFile: function(sourceLocation, targetLocation, name) {
+ throw "Not supported";
+ },
+ read: function(location, isMetadata) {
+ var url = new URL(location, window.location);
+ if (isMetadata) {
+ url.query.set("parts", "meta");
+ }
+ return xhr("GET", url.href, {
+ timeout: 15000,
+ headers: { "Orion-Version": "1" },
+ log: false
+ }).then(function(result) {
+ if (isMetadata) {
+ return result.response ? JSON.parse(result.response) : null;
+ } else {
+ return result.response;
+ }
+ });
+ },
+ write: function(location, contents, args) {
+ throw "Not supported";
+ },
+ remoteImport: function(targetLocation, options) {
+ throw "Not supported";
+ },
+ remoteExport: function(sourceLocation, options) {
+ throw "Not supported";
+ },
+ readBlob: function(location) {
+ return xhr("GET", location, {
+ responseType: "arraybuffer",
+ timeout: 15000
+ }).then(function(result) {
+ return result.response;
+ });
+ },
+ writeBlob: function(location, contents, args) {
+ throw "Not supported";
+ }
+ };
+ GitFileImpl.prototype.constructor = GitFileImpl;
+
+ return GitFileImpl;
+}); \ No newline at end of file