Skip to content

Commit

Permalink
Merge pull request #8 from mtooth/master
Browse files Browse the repository at this point in the history
JENKINS-26980 - Enable configuration of "Robot Results" column in the default job list view
  • Loading branch information
jussimalinen committed Feb 26, 2015
2 parents 4de7486 + 1f5c5e3 commit efd20e0
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 9 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.424</version><!-- which version of Hudson is this plugin built against? -->
<version>1.447</version><!-- which version of Hudson is this plugin built against? -->
</parent>

<artifactId>robot</artifactId>
Expand Down
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 efd20e0

Please sign in to comment.