Fixed bug with featureOverview only showing last feature set and added data table support
This commit is contained in:
parent
ff1f41ee01
commit
5aaeb8b44e
2
pom.xml
2
pom.xml
|
@ -10,7 +10,7 @@
|
|||
|
||||
<groupId>net.masterthought.jenkins</groupId>
|
||||
<artifactId>cucumber-reports</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
<packaging>hpi</packaging>
|
||||
|
||||
<!-- get every artifact through repo.jenkins-ci.org, which proxies all the artifacts that we need -->
|
||||
|
|
|
@ -20,6 +20,8 @@ import org.kohsuke.stapler.QueryParameter;
|
|||
import javax.servlet.ServletException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CucumberReportPublisher extends Recorder {
|
||||
|
||||
|
@ -65,15 +67,13 @@ public class CucumberReportPublisher extends Recorder {
|
|||
}
|
||||
|
||||
String[] jsonReportFiles = findJsonFiles(targetBuildDirectory);
|
||||
for (String file : jsonReportFiles) {
|
||||
listener.getLogger().println("[CucumberReportPublisher] Generating HTML reports based on: " + file);
|
||||
SingleResultParser singleResultParser = new SingleResultParser(new File(targetBuildDirectory, file).getAbsolutePath(), targetBuildDirectory, pluginUrlPath, buildNumber, buildProject);
|
||||
listener.getLogger().println("[CucumberReportPublisher] Generating HTML reports");
|
||||
FeatureReportGenerator featureReportGenerator = new FeatureReportGenerator(fullPathToJsonFiles(jsonReportFiles, targetBuildDirectory), targetBuildDirectory, pluginUrlPath, buildNumber, buildProject);
|
||||
try {
|
||||
singleResultParser.generateReports();
|
||||
featureReportGenerator.generateReports();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
listener.getLogger().println("[CucumberReportPublisher] here were no json results found in: " + workspaceJsonReportDirectory);
|
||||
|
@ -83,6 +83,14 @@ public class CucumberReportPublisher extends Recorder {
|
|||
return true;
|
||||
}
|
||||
|
||||
private List<String> fullPathToJsonFiles(String[] jsonFiles, File targetBuildDirectory){
|
||||
List<String> fullPathList = new ArrayList<String>();
|
||||
for(String file : jsonFiles){
|
||||
fullPathList.add(new File(targetBuildDirectory, file).getAbsolutePath());
|
||||
}
|
||||
return fullPathList;
|
||||
}
|
||||
|
||||
@Extension
|
||||
public static class DescriptorImpl extends BuildStepDescriptor<Publisher> {
|
||||
@Override
|
||||
|
|
|
@ -13,17 +13,19 @@ import java.io.*;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class SingleResultParser {
|
||||
public class FeatureReportGenerator {
|
||||
|
||||
private List<Feature> featureList;
|
||||
private Map<String, List<Feature>> jsonResultFiles;
|
||||
private File reportDirectory;
|
||||
private String buildNumber;
|
||||
private String buildProject;
|
||||
private List<Util.Status> totalSteps;
|
||||
private String pluginUrlPath;
|
||||
private List<Feature> allFeatures;
|
||||
|
||||
public SingleResultParser(String jsonResultFile, File reportDirectory, String pluginUrlPath, String buildNumber, String buildProject) throws IOException {
|
||||
this.featureList = parseJson(jsonResultFile);
|
||||
public FeatureReportGenerator(List<String> jsonResultFiles, File reportDirectory, String pluginUrlPath, String buildNumber, String buildProject) throws IOException {
|
||||
this.jsonResultFiles = parseJsonResults(jsonResultFiles);
|
||||
this.allFeatures = listAllFeatures();
|
||||
this.totalSteps = getAllStepStatuses();
|
||||
this.reportDirectory = reportDirectory;
|
||||
this.buildNumber = buildNumber;
|
||||
|
@ -31,6 +33,15 @@ public class SingleResultParser {
|
|||
this.pluginUrlPath = getPluginUrlPath(pluginUrlPath);
|
||||
}
|
||||
|
||||
private Map<String, List<Feature>> parseJsonResults(List<String> jsonResultFiles) throws FileNotFoundException {
|
||||
Map<String, List<Feature>> featureResults = new HashMap<String, List<Feature>>();
|
||||
for (String jsonFile : jsonResultFiles) {
|
||||
FileReader reader = new FileReader(jsonFile);
|
||||
featureResults.put(jsonFile, Arrays.asList(new Gson().fromJson(reader, Feature[].class)));
|
||||
}
|
||||
return featureResults;
|
||||
}
|
||||
|
||||
public void generateReports() throws Exception {
|
||||
generateFeatureReports();
|
||||
generateFeatureOverview();
|
||||
|
@ -43,7 +54,7 @@ public class SingleResultParser {
|
|||
VelocityContext context = new VelocityContext();
|
||||
context.put("build_project", buildProject);
|
||||
context.put("build_number", buildNumber);
|
||||
context.put("features", featureList);
|
||||
context.put("features", allFeatures);
|
||||
context.put("total_features", getTotalFeatures());
|
||||
context.put("total_scenarios", getTotalScenarios());
|
||||
context.put("total_steps", getTotalSteps());
|
||||
|
@ -56,7 +67,24 @@ public class SingleResultParser {
|
|||
generateReport("feature-overview.html", featureOverview, context);
|
||||
}
|
||||
|
||||
private List<Feature> listAllFeatures(){
|
||||
List<Feature> allFeatures = new ArrayList<Feature>();
|
||||
Iterator it = jsonResultFiles.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pairs = (Map.Entry) it.next();
|
||||
List<Feature> featureList = (List<Feature>) pairs.getValue();
|
||||
allFeatures.addAll(featureList);
|
||||
}
|
||||
return allFeatures;
|
||||
}
|
||||
|
||||
public void generateFeatureReports() throws Exception {
|
||||
|
||||
Iterator it = jsonResultFiles.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry pairs = (Map.Entry) it.next();
|
||||
List<Feature> featureList = (List<Feature>) pairs.getValue();
|
||||
|
||||
for (Feature feature : featureList) {
|
||||
VelocityEngine ve = new VelocityEngine();
|
||||
ve.init(getProperties());
|
||||
|
@ -74,6 +102,9 @@ public class SingleResultParser {
|
|||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String getPluginUrlPath(String path) {
|
||||
return path.isEmpty() ? "/" : path;
|
||||
}
|
||||
|
@ -96,7 +127,7 @@ public class SingleResultParser {
|
|||
|
||||
private List<Util.Status> getAllStepStatuses() {
|
||||
List<Util.Status> steps = new ArrayList<Util.Status>();
|
||||
for (Feature feature : featureList) {
|
||||
for (Feature feature : allFeatures) {
|
||||
for (Element scenario : feature.getElements()) {
|
||||
for (Step step : scenario.getSteps()) {
|
||||
steps.add(step.getStatus());
|
||||
|
@ -107,12 +138,12 @@ public class SingleResultParser {
|
|||
}
|
||||
|
||||
private int getTotalFeatures() {
|
||||
return featureList.size();
|
||||
return allFeatures.size();
|
||||
}
|
||||
|
||||
private int getTotalScenarios() {
|
||||
int scenarios = 0;
|
||||
for (Feature feature : featureList) {
|
||||
for (Feature feature : allFeatures) {
|
||||
scenarios = scenarios + feature.getNumberOfScenarios();
|
||||
}
|
||||
return scenarios;
|
||||
|
@ -136,10 +167,10 @@ public class SingleResultParser {
|
|||
return feature.getStatus() == Util.Status.PASSED ? "#C5D88A" : "#D88A8A";
|
||||
}
|
||||
|
||||
private List<Feature> parseJson(String jsonResultFile) throws FileNotFoundException {
|
||||
FileReader reader = new FileReader(jsonResultFile);
|
||||
return Arrays.asList(new Gson().fromJson(reader, Feature[].class));
|
||||
}
|
||||
// private List<Feature> parseJson(String jsonResultFile) throws FileNotFoundException {
|
||||
// FileReader reader = new FileReader(jsonResultFile);
|
||||
// return Arrays.asList(new Gson().fromJson(reader, Feature[].class));
|
||||
// }
|
||||
|
||||
private String timeStamp() {
|
||||
return new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date());
|
|
@ -1,15 +1,20 @@
|
|||
package net.masterthought.jenkins;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Runner {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
File rd = new File("/Users/kings/visa/jenkins-plugin-development/jenkins-java-plugin/cucumber-reports/work/jobs/ssss/builds/10/cucumber-html-reports");
|
||||
SingleResultParser singleResultParser = new SingleResultParser("/Users/kings/visa/jenkins-plugin-development/jenkins-java-plugin/cucumber-reports/work/jobs/ssss/builds/10/cucumber-html-reports/cucumber.json",rd,"10","ssss");
|
||||
singleResultParser.generateReports();
|
||||
|
||||
}
|
||||
}
|
||||
//package net.masterthought.jenkins;
|
||||
//
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//public class Runner {
|
||||
//
|
||||
// public static void main(String[] args) throws Exception {
|
||||
// File rd = new File("/Users/kings/.jenkins/jobs/aaaaa/builds/3/cucumber-html-reports");
|
||||
// List<String> list = new ArrayList<String>();
|
||||
// list.add("/Users/kings/.jenkins/jobs/aaaaa/builds/3/cucumber-html-reports/ss_cucumber.json");
|
||||
// list.add("/Users/kings/.jenkins/jobs/aaaaa/builds/3/cucumber-html-reports/co_cucumber.json");
|
||||
//
|
||||
// FeatureReportGenerator featureReportGenerator = new FeatureReportGenerator(list,rd,"","3","aaaa");
|
||||
// featureReportGenerator.generateReports();
|
||||
//
|
||||
// }
|
||||
//}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package net.masterthought.jenkins.json;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Step {
|
||||
|
||||
private String name;
|
||||
private String keyword;
|
||||
private Result result;
|
||||
private Row[] rows;
|
||||
|
||||
public Step(String name, String keyword) {
|
||||
this.name = name;
|
||||
|
@ -12,10 +16,47 @@ public class Step {
|
|||
|
||||
}
|
||||
|
||||
// public Row getTitleRow(){
|
||||
// return rows[0];
|
||||
// }
|
||||
|
||||
// public List getRows(){
|
||||
// return Arrays.asList(rows).subList(1, -1);
|
||||
// }
|
||||
|
||||
public Row[] getRows(){
|
||||
return rows;
|
||||
}
|
||||
|
||||
public boolean hasRows(){
|
||||
boolean result = false;
|
||||
if(rows != null){
|
||||
if(rows.length > 0){
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Util.Status getStatus() {
|
||||
return Util.resultMap.get(result.getStatus());
|
||||
}
|
||||
|
||||
public String getDataTableClass(){
|
||||
String content = "";
|
||||
Util.Status status = getStatus();
|
||||
if(status == Util.Status.FAILED){
|
||||
content = "failed";
|
||||
} else if(status == Util.Status.PASSED){
|
||||
content = "passed";
|
||||
} else if(status == Util.Status.SKIPPED){
|
||||
content = "skipped";
|
||||
} else {
|
||||
content = "";
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
String content = "";
|
||||
if(getStatus() == Util.Status.FAILED){
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
This view is used to render the installed plugins page.
|
||||
-->
|
||||
<div>
|
||||
This plugin is a sample to explain how to write a Jenkins plugin.
|
||||
This plugin creates pretty cucumber-jvm html reports on jenkins
|
||||
</div>
|
||||
|
|
|
@ -52,6 +52,39 @@ border-color: gray;
|
|||
background-color: white;
|
||||
-moz-border-radius: ;
|
||||
}
|
||||
|
||||
table.data-table {
|
||||
color: black;
|
||||
border-width: 1px;
|
||||
border-spacing: 2px;
|
||||
border-style: outset;
|
||||
border-color: #d6d6d6;
|
||||
border-collapse: collapse;
|
||||
background-color: beige;
|
||||
}
|
||||
table.data-table th {
|
||||
color:black;
|
||||
border-width: 1px;
|
||||
padding: 5px;
|
||||
border-style: inset;
|
||||
border-color: #d6d6d6;
|
||||
background-color: #66CCEE;
|
||||
}
|
||||
table.data-table td {
|
||||
color:black;
|
||||
text-align: center;
|
||||
border-width: 1px;
|
||||
padding: 5px;
|
||||
border-style: inset;
|
||||
border-color: #d6d6d6;
|
||||
background-color: beige;
|
||||
}
|
||||
|
||||
.data {
|
||||
padding-left:50px;
|
||||
padding-bottom: 10px;
|
||||
padding-top: 10px;
|
||||
}
|
||||
</style>
|
||||
|
||||
</head>
|
||||
|
@ -88,6 +121,19 @@ background-color: white;
|
|||
$scenario.getName()
|
||||
#foreach($step in $scenario.getSteps())
|
||||
$step.getName()
|
||||
#if($step.hasRows())
|
||||
<div class="data $step.getDataTableClass()">
|
||||
<table class="data-table">
|
||||
#foreach($row in $step.getRows())
|
||||
<tr>
|
||||
#foreach($cell in $row.getCells())
|
||||
<td>$cell</td>
|
||||
#end
|
||||
</tr>
|
||||
#end
|
||||
</table>
|
||||
</div>
|
||||
#end
|
||||
#end
|
||||
#end
|
||||
|
||||
|
|
Loading…
Reference in New Issue