/*

 Copyright (c) 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

 Copyright (c) 2011, 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

 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

 Copyright (c) 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

 Copyright (c) 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
*/
(function(f,n){"function"===typeof define&&define.amd?define("orion/Deferred",n):"object"===typeof exports?module.exports=n():(f.orion=f.orion||{},f.orion.Deferred=n())})(this,function(){function f(){for(var m;m=b.shift();)m();d=!1}function n(m){b.push(m);d||(d=!0,e())}function p(d){return function(c){d(c)}}function l(){function d(){for(var h;h=k.shift();){var c=h.deferred,a="fulfilled"===g?"resolve":"reject";h=h[a];if("function"===typeof h)try{var b=h(q),m=b&&("object"===typeof b||"function"===typeof b)&&
b.then;if("function"===typeof m)if(b===c.promise)c.reject(new TypeError);else{var e=b.cancel;"function"===typeof e?c._parentCancel=e.bind(b):delete c._parentCancel;m.call(b,p(c.resolve),p(c.reject),p(c.progress))}else c.resolve(b)}catch(l){c.reject(l)}else c[a](q)}}function c(c){delete h._parentCancel;g="rejected";q=c;k.length&&n(d)}function b(a){function e(z){return function(c){(!g||"assumed"===g)&&z(c)}}delete h._parentCancel;try{var r=a&&("object"===typeof a||"function"===typeof a)&&a.then;if("function"===
typeof r)if(a===h)c(new TypeError);else{g="assumed";var p=a&&a.cancel;if("function"!==typeof p){var f=new l;a=f.promise;try{r(f.resolve,f.reject,f.progress)}catch(u){f.reject(u)}p=a.cancel;r=a.then}q=a;r.call(a,e(b),e(c));h._parentCancel=p.bind(a)}else g="fulfilled",q=a,k.length&&n(d)}catch(s){e(c)(s)}}function a(){var a=h._parentCancel;a?(delete h._parentCancel,a()):g||(a=Error("Cancel"),a.name="Cancel",c(a))}var q,g,k=[],h=this;this.resolve=function(a){g||b(a);return h};this.reject=function(a){g||
c(a);return h};this.progress=function(a){g||k.forEach(function(c){if(c.progress)try{c.progress(a)}catch(h){}});return h.promise};this.cancel=function(){h._parentCancel?setTimeout(a,0):a();return h};this.then=function(a,c,b){var e=new l;e._parentCancel=h.promise.cancel;k.push({resolve:a,reject:c,progress:b,deferred:e});("fulfilled"===g||"rejected"===g)&&n(d);return e.promise};this.promise={then:h.then,cancel:h.cancel}}var b=[],d=!1,e=function(){if("undefined"!==typeof process&&"function"===typeof process.nextTick){var b=
process.nextTick;return function(){b(f)}}if("function"===typeof MutationObserver){var c=document.createElement("div");(new MutationObserver(f)).observe(c,{attributes:!0});return function(){c.setAttribute("class","_tick")}}return function(){setTimeout(f,0)}}();l.all=function(b,c){function d(a,c){k||(g[a]=c,0===--e&&h.resolve(g))}function a(a,b){if(!k){if(c)try{d(a,c(b));return}catch(e){b=e}h.reject(b)}}var e=b.length,g=[],k=!1,h=new l;h.then(void 0,function(){k=!0;b.forEach(function(a){a.cancel&&a.cancel()})});
0===e?h.resolve(g):b.forEach(function(c,b){c.then(d.bind(void 0,b),a.bind(void 0,b))});return h.promise};l.when=function(b,c,d,a){var e;b&&"function"===typeof b.then||(e=new l,e.resolve(b),b=e.promise);return b.then(c,d,a)};return l});
define("orion/xhr",["orion/Deferred"],function(f){function n(f,l,b,d){var e="undefined"!==typeof b.response?b.response:b.responseText,m;try{m=b.status}catch(c){m=0}f={args:l,response:e,responseText:"string"===typeof e?e:null,status:m,url:f,xhr:b};"undefined"!==typeof d&&(f.error=d);return f}return function(p,l,b){b=b||{};var d=3<arguments.length&&arguments[3]?arguments[3]:new XMLHttpRequest,e=new f,m=b.headers||{},c=b.log||!1,t;"undefined"===typeof m["X-Requested-With"]&&(m["X-Requested-With"]="XMLHttpRequest");
if("undefined"!==typeof b.data&&("POST"===p||"PUT"===p))t=b.data;var a=!1,q=!1;e.promise.then(void 0,function(b){a=!0;!q&&(b instanceof Error&&"Cancel"===b.name)&&d.abort()});d.onabort=function(){q=!0;if(!a){var b=Error("Cancel");b.name="Cancel";e.reject(b)}};d.onload=function(){var a=n(l,b,d);200<=d.status&&400>d.status?e.resolve(a):(e.reject(a),c&&"undefined"!==typeof console&&console.log(Error(d.statusText)))};d.onerror=function(){var a=n(l,b,d);e.reject(a);c&&"undefined"!==typeof console&&console.log(Error(d.statusText))};
d.onprogress=function(a){a.xhr=d;e.progress(a)};try{d.open(p,l,!0);"string"===typeof b.responseType&&(d.responseType=b.responseType);if("number"===typeof b.timeout)if("number"===typeof d.timeout)d.timeout=b.timeout,d.addEventListener("timeout",function(a){e.reject(n(l,b,d,"Timeout exceeded"))});else{var g=setTimeout(function(){e.reject(n(l,b,d,"Timeout exceeded"))},b.timeout);e.promise.then(clearTimeout.bind(null,g),clearTimeout.bind(null,g))}Object.keys(m).forEach(function(a){d.setRequestHeader(a,
m[a])});d.send(t||null)}catch(k){e.reject(n(l,b,d,k))}return e.promise}});
(function(f,n){"function"===typeof define&&define.amd?define("orion/plugin",["orion/Deferred"],n):"object"===typeof exports?module.exports=n(require("orion/Deferred")):(f.orion=f.orion||{},f.orion.PluginProvider=n(f.orion.Deferred))})(this,function(f){function n(f,l){this.__objectId=f;this.__methods=l}return function(p){function l(a){k&&("undefined"===typeof ArrayBuffer&&(a=JSON.stringify(a)),k===self?k.postMessage(a):k.postMessage(a,"*"))}function b(){var a=[];Object.keys(u).forEach(function(b){var c=
u[b];a.push({serviceId:b,names:c.names,methods:c.methods,properties:c.properties})});return{headers:q||{},services:a}}function d(a,b){if(b&&b instanceof XMLHttpRequest){var c,d;try{c=b.status,d=b.statusText}catch(e){c=0,d=""}return{status:c||0,statusText:d}}return b}function e(a){var b=a?JSON.parse(JSON.stringify(a,d)):a;a instanceof Error&&(b.__isError=!0,b.message=b.message||a.message,b.name=b.name||a.name);return b}function m(a){if(!k)return(new f).reject(Error("plugin not connected"));a.id=String(h++);
var b=new f;v[a.id]=b;b.then(null,function(b){g&&(b instanceof Error&&"Cancel"===b.name)&&s({requestId:a.id,method:"cancel",params:b.message?[b.message]:[]})});var c=Object.prototype.toString;a.params.forEach(function(d,e){if("[object Object]"===c.call(d)&&!(d instanceof n)){var g,h;for(g in d)"[object Function]"===c.call(d[g])&&(h=h||[],h.push(g));if(h){var k=x++;w[k]=d;g=function(){delete w[k]};b.then(g,g);a.params[e]=new n(k,h)}}});s(a);return b.promise}function c(a,b){a||0===a?s({id:a,result:null,
error:b}):console.log(b)}function t(a,b,c,d){d.forEach(function(a,b){if(a&&"undefined"!==typeof a.__objectId){var c={};a.__methods.forEach(function(b){c[b]=function(){return m({objectId:a.__objectId,method:b,params:Array.prototype.slice.call(arguments)})}});d[b]=c}});var g=void 0===typeof a?null:{id:a,result:null,error:null};try{var h=c.apply(b,d);g&&(h&&"function"===typeof h.then?(r[a]=h,h.then(function(b){delete r[a];g.result=b;s(g)},function(b){r[a]&&(delete r[a],g.error=e(b),s(g))},function(){s({responseId:a,
method:"progress",params:Array.prototype.slice.call(arguments)})})):(g.result=h,s(g)))}catch(k){g&&(g.error=e(k),s(g))}}function a(a){if(!(a.source!==k&&"undefined"!==typeof window)){a="string"!==typeof a.data?a.data:JSON.parse(a.data);try{if(a.method){var b=a.method,d=a.params||[];if("serviceId"in a){var g=u[a.serviceId];g||c(a.id,"service not found");g=g.implementation;b in g?t(a.id,g,g[b],d):c(a.id,"method not found")}else if("objectId"in a){var e=w[a.objectId];e||c(a.id,"object not found");!b in
e?t(a.id,e,e[b],d):c(a.id,"method not found")}else if("requestId"in a){var h=r[a.requestId];h&&("cancel"===b&&h.cancel)&&h.cancel.apply(h,d)}else if("responseId"in a){var f=v[a.responseId];f&&("progress"===b&&f.progress)&&f.progress.apply(f,d)}else throw Error("Bad method: "+a.method);}else{var m=v[String(a.id)];delete v[String(a.id)];a.error?m.reject(a.error):m.resolve(a.result)}}catch(l){console.log("Plugin._messageHandler "+l)}}}var q=p,g=!1,k=null,h=0,x=0,y=0,r={},v={},w={},u={},s=l;this.updateHeaders=
function(a){if(g)throw Error("Cannot update headers. Plugin Provider is connected");q=a};this.registerServiceProvider=this.registerService=function(a,b,c){if(g)throw Error("Cannot register service. Plugin Provider is connected");"string"===typeof a?a=[a]:Array.isArray(a)||(a=[]);var d=null,e=[];for(d in b)"function"===typeof b[d]&&e.push(d);u[y++]={names:a,methods:e,implementation:b,properties:c||{},listeners:{}}};this.connect=function(c,d){if(!g){if("undefined"===typeof window)k=self;else if(window!==
window.parent)k=window.parent;else if(null!==window.opener)k=window.opener;else{d&&d("No valid plugin target");return}addEventListener("message",a,!1);var e={method:"plugin",params:[b()]};l(e);g=!0}c&&c()};this.disconnect=function(){g&&(removeEventListener("message",a),k=null,g=!1)}}});
define("orion/operation",["orion/xhr","orion/Deferred"],function(f,n){function p(b,d,e,m){f("GET",b,{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(c){c=c.response?JSON.parse(c.response):null;d.progress(c);!c.type||"loadstart"===c.type||"progress"===c.type?setTimeout(function(){p(b,d,e,m)},2E3):("error"===c.type||"abort"===c.type?d.reject(m?m(c):c.Result):d.resolve(e?e(c):c.Result.JsonData),c.Location||f("DELETE",b,{headers:{"Orion-Version":"1"},timeout:15E3}))},function(b){var e=b;if(void 0!==
b.responseText){e=b.responseText;try{e=JSON.parse(b.responseText)}catch(a){}}void 0!==e.Message?(e.HttpCode=void 0===e.HttpCode?b.status:e.HttpCode,e.Severity=void 0===e.Severity?"Error":e.Severity,d.reject(e)):d.reject({Severity:"Error",Message:e,HttpCode:b.status})})}function l(b,d){d.then(null,function(d){d instanceof Error&&"Cancel"===d.name&&f("PUT",b,{headers:{"Orion-Version":"1"},data:JSON.stringify({abort:!0}),timeout:15E3})})}return{handle:function(b,d,e){var f=new n;l(b,f);p(b,f,d,e);return f}}});
define("plugins/gitBlamePlugin",["require","orion/xhr","orion/plugin","orion/Deferred","orion/operation"],function(f,n,p,l,b){function d(a){var b,c=a.indexOf("/gitapi/commit/"),d;0===c&&(c=15,d=a.indexOf("/",c),b=a.substring(c,d),c=a.indexOf("/file"),d=a.indexOf("?",c),-1===d&&(d=a.length),a=a.substring(c,d));c=a.indexOf("/file");0<c&&(d=a.indexOf("?",c),-1===d&&(d=a.length),a=a.substring(c,d));var e=new l;t.getBlameInfo(a,b).then(function(a){var b=[];l.all(b,function(a){return{_error:a}}).then(function(){var c=
a.Children;c.sort(function(a,b){return a.Time<b.Time?1:a.Time>b.Time?-1:0});for(var d=0;d<c.length;d++)for(var g=0;g<c[d].Children.length;g++){var f=c[d].Children[g],k=c[d];f.AuthorName=k.AuthorName;f.AuthorEmail=k.AuthorEmail;f.CommitterName=k.CommitterName;f.CommitterEmail=k.CommitterEmail;f.Message=k.Message;f.AuthorImage=k.AuthorImage;f.Name=k.Name;f.Time=(new Date(k.Time)).toLocaleString();f.Shade=1/(c.length+1)*(c.length-d+1);f.CommitLink="{+OrionHome}/git/git-commit.html#"+k.CommitLocation+
"?page\x3d1\x26pageSize\x3d1";b.push(f)}e.resolve(b)})});return e}p=new p({name:"Git Blame Plugin",version:"1.0",description:"Git Blame Plugin"});var e=!0,m=document.createElement("a");m.href="../gitapi/blame/";var c=function(a){if(e)try{if(window.location.host===parent.location.host&&window.location.protocol===parent.location.protocol)return a.substring(parent.location.href.indexOf(parent.location.host)+parent.location.host.length);e=!1}catch(b){e=!1}return a}(m.href),t={getBlameInfo:function(a,
b){var d=this,e=new l;n("GET",f.toUrl(c)+(b?b:"HEAD")+a,{headers:{"Orion-Version":"1","Content-Type":"application/json; charset\x3dUTF-8"},timeout:15E3,handleAs:"json"}).then(function(a){d._getGitServiceResponse(e,a)},function(a){d._handleGitServiceResponseError(e,a)});return e},_getGitServiceResponse:function(a,c){var d=c.response?JSON.parse(c.response):null;if(c.xhr&&202===c.xhr.status){var e=b.handle(d.Location);e.then(a.resolve,function(b){b.failedOperation=d.Location;a.reject(b)},a.progress);
a.then(null,function(a){e.reject(a)})}else a.resolve(d)},_handleGitServiceResponseError:function(a,b){a.reject(b)}};p.registerService("orion.edit.blamer",{computeBlame:function(a,b){return d(b.metadata.Location)}},{name:"Git Blame",validationProperties:[{source:"Git",variableName:"Git"}]});p.connect()});
//@ sourceMappingURL=gitBlamePlugin.js.map