Skip to content

Commit

Permalink
JENKINS-26980: Added general support for global plugin configuration …
Browse files Browse the repository at this point in the history
…and a checkbox to show/hide the 'Robot Results' column
  • Loading branch information
mtooth committed Feb 16, 2015
1 parent b162988 commit 1f5c5e3
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
35 changes: 35 additions & 0 deletions src/main/java/hudson/plugins/robot/RobotConfig.java
@@ -0,0 +1,35 @@
package hudson.plugins.robot;

import hudson.Extension;
import jenkins.model.GlobalConfiguration;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;

@Extension
public class RobotConfig extends GlobalConfiguration {

private boolean robotResultsColumnEnabled = true;

public RobotConfig() {
load();
}

@Override
public boolean configure(StaplerRequest req, JSONObject o) throws FormException {
// Get Robot Framework section
o = o.getJSONObject("robotFramework");

robotResultsColumnEnabled = o.getBoolean("robotResultsColumnEnabled");

save();
return super.configure(req, o);
}

public boolean isRobotResultsColumnEnabled() {
return robotResultsColumnEnabled;
}

public void setRobotResultsColumnEnabled(boolean robotResultsColumnEnabled) {
this.robotResultsColumnEnabled = robotResultsColumnEnabled;
}
}
24 changes: 19 additions & 5 deletions src/main/java/hudson/plugins/robot/view/RobotListViewColumn.java
Expand Up @@ -5,38 +5,41 @@
import hudson.model.Job;
import hudson.model.Run;
import hudson.plugins.robot.RobotBuildAction;
import hudson.plugins.robot.RobotConfig;
import hudson.plugins.robot.model.RobotResult;
import hudson.views.ListViewColumn;

import org.kohsuke.stapler.DataBoundConstructor;

import javax.inject.Inject;

public class RobotListViewColumn extends ListViewColumn {

@DataBoundConstructor
public RobotListViewColumn(){
}

@Override
public String getColumnCaption() {
return getDescriptor().getDisplayName();
}

public long getPass(Job job){
RobotResult lastRobotResult = getLastRobotResult(job);
if(lastRobotResult != null){
return lastRobotResult.getOverallPassed();
}
return 0;
}

public long getTotal(Job job){
RobotResult lastRobotResult = getLastRobotResult(job);
if(lastRobotResult != null){
return lastRobotResult.getOverallTotal();
}
return 0;
}

private RobotResult getLastRobotResult(Job job){
Run build = job.getLastCompletedBuild();
if(build != null) {
Expand All @@ -47,13 +50,24 @@ private RobotResult getLastRobotResult(Job job){
}
return null;
}


public boolean isRobotResultsColumnEnabled() {
return ((DescriptorImpl) this.getDescriptor()).isRobotResultsColumnEnabled();
}

@Extension
public static final class DescriptorImpl extends Descriptor<ListViewColumn>{

@Inject
private RobotConfig globalConfig;

@Override
public String getDisplayName() {
return "Robot pass/fail";
}

public boolean isRobotResultsColumnEnabled() {
return globalConfig.isRobotResultsColumnEnabled();
}
}
}
22 changes: 22 additions & 0 deletions src/main/resources/hudson/plugins/robot/RobotConfig/config.jelly
@@ -0,0 +1,22 @@
<!--
Copyright 2008-2014 Nokia Solutions and Networks Oy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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:section title="${%Robot Framework}" name="robotFramework">
<f:entry field="robotResultsColumnEnabled">
<f:checkbox name="robotResultsColumnEnabled"/>Display "Robot Results" column in the job list view
</f:entry>
</f:section>
</j:jelly>
Expand Up @@ -22,9 +22,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<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:if test="${it.isRobotResultsColumnEnabled()}">
<td style="white-space:nowrap;">
<j:if test="${it.getTotal(job) != 0}">
${it.getPass(job)} / ${it.getTotal(job)} passed <img src="${rootURL}/plugin/robot/robot.png" />
</j:if>
</td>
</j:if>
</j:jelly>
Expand Up @@ -22,7 +22,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler">
<th width="1" style="white-space:nowrap;">
Robot Results
</th>
<j:if test="${it.isRobotResultsColumnEnabled()}">
<th width="1" style="white-space:nowrap;">
Robot Results
</th>
</j:if>
</j:jelly>

0 comments on commit 1f5c5e3

Please sign in to comment.