From ff1f41ee0144f0000a3c9e337d89de267e026da0 Mon Sep 17 00:00:00 2001 From: Kingsley Hendrickse Date: Tue, 17 Apr 2012 14:41:51 +0100 Subject: [PATCH] Fixed config values not being retained and added path to specify plugin url --- cucumber-reports.iml | 12 ++++- pom.xml | 2 +- .../jenkins/CucumberReportPublisher.java | 8 ++-- .../jenkins/SingleResultParser.java | 44 +++++++++++-------- .../CucumberReportPublisher/config.jelly | 3 ++ .../resources/templates/featureOverview.vm | 22 +++++----- src/main/resources/templates/featureReport.vm | 14 +++--- 7 files changed, 63 insertions(+), 42 deletions(-) diff --git a/cucumber-reports.iml b/cucumber-reports.iml index 80214fc..439a0c8 100644 --- a/cucumber-reports.iml +++ b/cucumber-reports.iml @@ -1,5 +1,10 @@ + + + + + @@ -10,8 +15,11 @@ + + + + - @@ -78,6 +86,7 @@ + @@ -92,7 +101,6 @@ - diff --git a/pom.xml b/pom.xml index e436629..cbf3e5d 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ net.masterthought.jenkins cucumber-reports - 1.0-SNAPSHOT + 0.0.1 hpi diff --git a/src/main/java/net/masterthought/jenkins/CucumberReportPublisher.java b/src/main/java/net/masterthought/jenkins/CucumberReportPublisher.java index 8371ee6..0d5cbb4 100644 --- a/src/main/java/net/masterthought/jenkins/CucumberReportPublisher.java +++ b/src/main/java/net/masterthought/jenkins/CucumberReportPublisher.java @@ -23,11 +23,13 @@ import java.io.IOException; public class CucumberReportPublisher extends Recorder { - private final String jsonReportDirectory; + public final String jsonReportDirectory; + public final String pluginUrlPath; @DataBoundConstructor - public CucumberReportPublisher(String jsonReportDirectory) { + public CucumberReportPublisher(String jsonReportDirectory, String pluginUrlPath) { this.jsonReportDirectory = jsonReportDirectory; + this.pluginUrlPath = pluginUrlPath; } private String[] findJsonFiles(File targetDirectory) { @@ -65,7 +67,7 @@ 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, buildNumber, buildProject); + SingleResultParser singleResultParser = new SingleResultParser(new File(targetBuildDirectory, file).getAbsolutePath(), targetBuildDirectory, pluginUrlPath, buildNumber, buildProject); try { singleResultParser.generateReports(); } catch (Exception e) { diff --git a/src/main/java/net/masterthought/jenkins/SingleResultParser.java b/src/main/java/net/masterthought/jenkins/SingleResultParser.java index f0cafd4..5a97ccb 100644 --- a/src/main/java/net/masterthought/jenkins/SingleResultParser.java +++ b/src/main/java/net/masterthought/jenkins/SingleResultParser.java @@ -20,13 +20,15 @@ public class SingleResultParser { private String buildNumber; private String buildProject; private List totalSteps; + private String pluginUrlPath; - public SingleResultParser(String jsonResultFile, File reportDirectory, String buildNumber, String buildProject) throws IOException { + public SingleResultParser(String jsonResultFile, File reportDirectory, String pluginUrlPath, String buildNumber, String buildProject) throws IOException { this.featureList = parseJson(jsonResultFile); this.totalSteps = getAllStepStatuses(); this.reportDirectory = reportDirectory; this.buildNumber = buildNumber; this.buildProject = buildProject; + this.pluginUrlPath = getPluginUrlPath(pluginUrlPath); } public void generateReports() throws Exception { @@ -50,10 +52,32 @@ public class SingleResultParser { context.put("total_skipped", getTotalSkipped()); context.put("chart_data", XmlChartBuilder.donutChart(getTotalPasses(), getTotalFails(), getTotalSkipped())); context.put("time_stamp", timeStamp()); + context.put("jenkins_base", pluginUrlPath); generateReport("feature-overview.html", featureOverview, context); } - + public void generateFeatureReports() throws Exception { + for (Feature feature : featureList) { + VelocityEngine ve = new VelocityEngine(); + ve.init(getProperties()); + Template featureResult = ve.getTemplate("templates/featureReport.vm"); + VelocityContext context = new VelocityContext(); + context.put("feature", feature); + context.put("report_status_colour", getReportStatusColour(feature)); + context.put("build_project", buildProject); + context.put("build_number", buildNumber); + context.put("scenarios", feature.getElements()); + context.put("time_stamp", timeStamp()); + context.put("jenkins_base", pluginUrlPath); + generateReport(feature.getFileName(), featureResult, context); + } + } + + + private String getPluginUrlPath(String path){ + return path.isEmpty() ? "/" : path; + } + private int getTotalSteps() { return totalSteps.size(); } @@ -94,22 +118,6 @@ public class SingleResultParser { return scenarios; } - public void generateFeatureReports() throws Exception { - for (Feature feature : featureList) { - VelocityEngine ve = new VelocityEngine(); - ve.init(getProperties()); - Template featureResult = ve.getTemplate("templates/featureReport.vm"); - VelocityContext context = new VelocityContext(); - context.put("feature", feature); - context.put("report_status_colour", getReportStatusColour(feature)); - context.put("build_project", buildProject); - context.put("build_number", buildNumber); - context.put("scenarios", feature.getElements()); - context.put("time_stamp", timeStamp()); - generateReport(feature.getFileName(), featureResult, context); - } - } - private void generateReport(String fileName, Template featureResult, VelocityContext context) throws Exception { Writer writer = new FileWriter(new File(reportDirectory, fileName)); featureResult.merge(context, writer); diff --git a/src/main/resources/net/masterthought/jenkins/CucumberReportPublisher/config.jelly b/src/main/resources/net/masterthought/jenkins/CucumberReportPublisher/config.jelly index 41ffbc5..a581f06 100644 --- a/src/main/resources/net/masterthought/jenkins/CucumberReportPublisher/config.jelly +++ b/src/main/resources/net/masterthought/jenkins/CucumberReportPublisher/config.jelly @@ -11,6 +11,9 @@ --> + + + diff --git a/src/main/resources/templates/featureOverview.vm b/src/main/resources/templates/featureOverview.vm index 41467ec..16bfcbb 100644 --- a/src/main/resources/templates/featureOverview.vm +++ b/src/main/resources/templates/featureOverview.vm @@ -3,7 +3,7 @@ - + Cucumber-JVM Html Reports - Feature Overview - - - - - - + + + + + +