/*******************************************************************************
 * @license
 * 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
 ******************************************************************************/

/*******************************************************************************
 * @license
 * 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
 *******************************************************************************/

/*******************************************************************************
 * @license
 * Copyright (c) 2011, 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
 *******************************************************************************/

/*******************************************************************************
 * @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
 ******************************************************************************/

/*

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