Skip to content

Commit

Permalink
Defects in Stapler shouldn't cause Build Monitor to break.
Browse files Browse the repository at this point in the history
(Support for Jenkins 1.521-1.526 with jQuery plugin, closes #3)
  • Loading branch information
jan-molak committed Aug 13, 2013
1 parent a9951a9 commit f94cb1a
Showing 1 changed file with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:l="/lib/layout">

<l:layout norefresh="true">

Expand Down Expand Up @@ -47,29 +45,51 @@
</footer>
</div>

<script>
/*
* todo: (13.08.2013) Replace the below workaround with a custom Jelly tag (ExposeBindTag)
* extending either org.kohsuke.stapler.jelly.BindTag or AbstractStaplerTag,
* that would supersede currently defective BindTag implementation:
* - https://groups.google.com/forum/#!topic/jenkinsci-dev/S9bhX4ts0g4
* - https://issues.jenkins-ci.org/browse/JENKINS-18641
*
* Defect in BindTag manifests itself by causing a JavaScript error and preventing scripts after
* the &lt;st:bind&gt; invocation from executing, which results in an "empty Build Monitor".
* The issue occurs on Jenkins 1.521-1.526, only if the jQuery plugin is used.
*
* Motivation behind a custom Jelly tag:
* Original implementation of the BindTag doesn't provide an easy way of handling AJAX errors,
* which may happen if a network connection is lost or when Jenkins is restarted (which then makes
* Stapler's binding hash obsolete and Jenkins return 404 for any subsequent requests).
*
* Custom Jelly tag should generate a JSON object exposing the binding, leaving the implementation
* of the proxy to the Developer. It makes more sense for a developer to require a binding adapter
* implementation specific to their JavaScript framework of choice, rather than for Stapler to try
* to predict what JavaScript libraries will ever be used with it in the future...
*/
window.originalMakeStaplerProxy = window.makeStaplerProxy;
window.makeStaplerProxy = function(url, crumb, methods) {
return { url: url, crumb: crumb, methods: methods }
};
window.bindings={};
</script>
<st:bind var="window.bindings['buildMonitor']" value="${it}" />
<script>
window.makeStaplerProxy = window.originalMakeStaplerProxy;
delete window.originalMakeSteplerProxy;
</script>

<script src="${resourcesURL}/scripts/app.js"></script>
<script src="${resourcesURL}/scripts/services.js"></script>
<script src="${resourcesURL}/scripts/jenkins.js"></script>
<script src="${resourcesURL}/scripts/controllers.js"></script>
<script>
'use strict';

// self-executing function here ensures that I'm only overriding makeStaplerProxy within its scope
(function() {
// todo: replace with a custom Jelly tag extending org.kohsuke.stapler.jelly.BindTag,
// that would generate JSON describing the binding (such as below), to avoid having to use
// the current implementation of BindTag, which couples me tightly to either prototype or jQuery.
var makeStaplerProxy = function(url, crumb, methods) {
return { url: url, crumb: crumb, methods: methods }
},
bindings = { 'buildMonitor': <st:bind value="${it}"/> };
'use strict';

angular.module('buildMonitor').config(function(proxyProvider) {
proxyProvider.configureProxiesUsing(bindings);
proxyProvider.configureProxiesUsing(window.bindings);
});

angular.module('buildMonitor.services').value('buildMonitorName', '${it.displayName}');
})();
</script>
</l:main-panel>
</l:layout>
Expand Down

0 comments on commit f94cb1a

Please sign in to comment.