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