Skip to content

Commit

Permalink
[FIXED JENKINS-20164] Use dropdown for strategy instead of hetero-rad…
Browse files Browse the repository at this point in the history
…io, as it can conflicts with other plugins. Upgraded target Jenkins version as rendering an expanded help requires layoutUpdateCallback introduced in Jenkins 1.452.
  • Loading branch information
ikedam committed May 18, 2014
1 parent c7cf3bb commit 052a990
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.447</version>
<version>1.466</version>
</parent>

<artifactId>build-timeout</artifactId>
Expand Down
@@ -1,9 +1,8 @@
<?jelly escape-by-default='true'?>
<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">

<f:entry title="${%Time-out strategy}">
<f:hetero-radio field="strategy" descriptors="${descriptor.strategies}"/>
</f:entry>
<st:adjunct includes="hudson.plugins.build_timeout.nestedHelp"/>
<f:dropdownDescriptorSelector title="${%Time-out strategy}" field="strategy" descriptors="${descriptor.strategies}" />

<f:entry title="${%Time-out variable}" description="Set a build timeout environment variable">
<f:textbox field="timeoutEnvVar"/>
Expand Down
@@ -0,0 +1,65 @@
/*
* The MIT License
*
* Copyright (c) 2014 IKEDA Yasuyuki
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson.plugins.build_timeout;

import jenkins.model.Jenkins;

st = namespace("jelly:stapler");

def descriptor = Jenkins.instance.getDescriptorOrDie(BuildTimeoutWrapper.class);

def myselfName = descriptor.plugin.shortName;

// help file for strategy itself.
def strategyRawHelpFile = descriptor.getHelpFile("strategyRaw");

if (strategyRawHelpFile != null) {
div(
class: "build-timeout-nested-help",
helpURL: String.format("%s%s", rootURL, strategyRawHelpFile),
myselfName: myselfName,
) {
text("Loading...");
}
}

dl() {
descriptor.strategies.each() { d ->
def helpFile = d.getHelpFile();
dt(d.displayName);
if (helpFile != null) {
dd(
class: "build-timeout-nested-help",
helpURL: String.format("%s%s", rootURL, helpFile),
myselfName: myselfName,
) {
text("Loading...");
}
} else {
dd("No help available.");
}
}
}

@@ -0,0 +1,3 @@
<div>
Select one of following strategies:
</div>
@@ -0,0 +1,3 @@
<div>
以下の判定方法が利用可能です。
</div>
53 changes: 53 additions & 0 deletions src/main/resources/hudson/plugins/build_timeout/nestedHelp.js
@@ -0,0 +1,53 @@
/*
* The MIT License
*
* Copyright (c) 2014 IKEDA Yasuyuki
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
Behaviour.register({".build-timeout-nested-help": function(e) {
// ensure Behavior is applied only once.
$(e).removeClassName("build-timeout-nested-help");
new Ajax.Request(e.getAttribute("helpURL"), {
method : 'get',
onSuccess : function(x) {
e.innerHTML = x.responseText;
var myselfName = e.getAttribute("myselfName");
var pluginName = x.getResponseHeader("X-Plugin-Short-Name");
if (myselfName != pluginName) {
var from = x.getResponseHeader("X-Plugin-From");
if (from) {
e.innerHTML += "<div class='from-plugin'>"+from+"</div>";
}
}
layoutUpdateCallback.call();
},
onFailure : function(x) {
e.innerHTML = "<b>ERROR</b>: Failed to load help file: " + x.statusText;
}
});
}});

/**
* Allows run Behavior when help is loaded.
*/
layoutUpdateCallback.add(function() {
$$(".build-timeout-nested-help").each(function(e){Behaviour.applySubtree(e, true)});
});

0 comments on commit 052a990

Please sign in to comment.