diff --git a/.gitignore b/.gitignore index 264d709..de5d7fa 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ target .DS_Store .log .idea +velocity.log diff --git a/src/main/java/net/masterthought/jenkins/FeatureReportGenerator.java b/src/main/java/net/masterthought/jenkins/FeatureReportGenerator.java index cda497b..d6a9fd1 100644 --- a/src/main/java/net/masterthought/jenkins/FeatureReportGenerator.java +++ b/src/main/java/net/masterthought/jenkins/FeatureReportGenerator.java @@ -159,11 +159,14 @@ public class FeatureReportGenerator { tagMap = createOrAppendToTagMap(tagMap, feature.getTagList(), scenarioList); } } - for (Element scenario : feature.getElements()) { - if (scenario.hasTags()) { - scenarioList = addScenarioUnlessExists(scenarioList, new ScenarioTag(scenario, feature.getFileName())); + + if (Util.hasScenarios(feature)) { + for (Element scenario : feature.getElements()) { + if (scenario.hasTags()) { + scenarioList = addScenarioUnlessExists(scenarioList, new ScenarioTag(scenario, feature.getFileName())); + } + tagMap = createOrAppendToTagMap(tagMap, scenario.getTagList(), scenarioList); } - tagMap = createOrAppendToTagMap(tagMap, scenario.getTagList(), scenarioList); } } return tagMap; @@ -247,7 +250,10 @@ public class FeatureReportGenerator { int steps = 0; for (TagObject tag : allTags) { for (ScenarioTag scenarioTag : tag.getScenarios()) { - steps += scenarioTag.getScenario().getSteps().length; + Step[] stepList = scenarioTag.getScenario().getSteps(); + if (stepList != null && stepList.length != 0) { + steps += stepList.length; + } } } return steps; @@ -256,9 +262,13 @@ public class FeatureReportGenerator { private String getTotalDuration() { Long duration = 0L; for (Feature feature : allFeatures) { - for (Element scenario : feature.getElements()) { - for (Step step : scenario.getSteps()) { - duration = duration + step.getDuration(); + if (Util.hasScenarios(feature)) { + for (Element scenario : feature.getElements()) { + if (Util.hasSteps(scenario)) { + for (Step step : scenario.getSteps()) { + duration = duration + step.getDuration(); + } + } } } } @@ -269,8 +279,10 @@ public class FeatureReportGenerator { Long duration = 0L; for (TagObject tagObject : allTags) { for (ScenarioTag scenario : tagObject.getScenarios()) { - for (Step step : scenario.getScenario().getSteps()) { - duration = duration + step.getDuration(); + if (Util.hasSteps(scenario)) { + for (Step step : scenario.getScenario().getSteps()) { + duration = duration + step.getDuration(); + } } } } @@ -289,7 +301,7 @@ public class FeatureReportGenerator { return Util.findStatusCount(totalSteps, Util.Status.SKIPPED); } - private int getTotalPending(){ + private int getTotalPending() { return Util.findStatusCount(totalSteps, Util.Status.UNDEFINED); } @@ -317,7 +329,7 @@ public class FeatureReportGenerator { return skipped; } - private int getTotalTagPending(){ + private int getTotalTagPending() { int pending = 0; for (TagObject tag : allTags) { pending += tag.getNumberOfPending(); @@ -328,9 +340,13 @@ public class FeatureReportGenerator { private List getAllStepStatuses() { List steps = new ArrayList(); for (Feature feature : allFeatures) { - for (Element scenario : feature.getElements()) { - for (Step step : scenario.getSteps()) { - steps.add(step.getStatus()); + if (Util.hasScenarios(feature)) { + for (Element scenario : feature.getElements()) { + if (Util.hasSteps(scenario)) { + for (Step step : scenario.getSteps()) { + steps.add(step.getStatus()); + } + } } } } diff --git a/src/main/java/net/masterthought/jenkins/Runner.java b/src/main/java/net/masterthought/jenkins/Runner.java index dd72111..30c789e 100644 --- a/src/main/java/net/masterthought/jenkins/Runner.java +++ b/src/main/java/net/masterthought/jenkins/Runner.java @@ -1,26 +1,27 @@ -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/cucumber-jvm/builds/7/cucumber-html-reports"); - List list = new ArrayList(); +//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/15/cucumber-html-reports"); +// List list = new ArrayList(); // list.add("/Users/kings/.jenkins/jobs/aaaaa/builds/15/cucumber-html-reports/french.json"); // list.add("/Users/kings/.jenkins/jobs/aaaaa/builds/15/cucumber-html-reports/co_cucumber.json"); // list.add("/Users/kings/.jenkins/jobs/aaaaa/builds/15/cucumber-html-reports/ccp_cucumber.json"); // list.add("/Users/kings/.jenkins/jobs/aaaaa/builds/15/cucumber-html-reports/ss_cucumber.json"); - list.add("/Users/kings/.jenkins/jobs/cucumber-jvm/builds/7/cucumber-html-reports/cukes.json"); - list.add("/Users/kings/.jenkins/jobs/cucumber-jvm/builds/7/cucumber-html-reports/cucumber.json"); - - FeatureReportGenerator featureReportGenerator = new FeatureReportGenerator(list,rd,"","7","cucumber-jvm",false,true); - featureReportGenerator.generateReports(); -// boolean result = featureReportGenerator.getBuildStatus(); -// System.out.println("status: " + result); - - } -} +//// list.add("/Users/kings/.jenkins/jobs/cucumber-jvm/builds/7/cucumber-html-reports/cukes.json"); +//// list.add("/Users/kings/.jenkins/jobs/cucumber-jvm/builds/7/cucumber-html-reports/cucumber.json"); +// list.add("/Users/kings/.jenkins/jobs/aaaaa/builds/15/cucumber-html-reports/result.json"); +// +// FeatureReportGenerator featureReportGenerator = new FeatureReportGenerator(list,rd,"","15","aaaaa",false,true); +// featureReportGenerator.generateReports(); +//// boolean result = featureReportGenerator.getBuildStatus(); +//// System.out.println("status: " + result); +// +// } +//} diff --git a/src/main/java/net/masterthought/jenkins/TagObject.java b/src/main/java/net/masterthought/jenkins/TagObject.java index d09b19f..e18e047 100644 --- a/src/main/java/net/masterthought/jenkins/TagObject.java +++ b/src/main/java/net/masterthought/jenkins/TagObject.java @@ -10,7 +10,7 @@ import java.util.List; public class TagObject { - + private String tagName; private List scenarios = new ArrayList(); private List elements = new ArrayList(); @@ -19,47 +19,51 @@ public class TagObject { return tagName; } - public String getFileName(){ - return tagName.replace("@","").trim() + ".html"; + public String getFileName() { + return tagName.replace("@", "").trim() + ".html"; } public List getScenarios() { return scenarios; } - - public void setScenarios(List scenarioTagList){ + + public void setScenarios(List scenarioTagList) { this.scenarios = scenarioTagList; } - public TagObject(String tagName, List scenarios){ + public TagObject(String tagName, List scenarios) { this.tagName = tagName; this.scenarios = scenarios; } private void getElements() { - for(ScenarioTag scenarioTag : scenarios){ + for (ScenarioTag scenarioTag : scenarios) { elements.add(scenarioTag.getScenario()); } } - public Integer getNumberOfScenarios(){ + public Integer getNumberOfScenarios() { return this.scenarios.size(); } public String getDurationOfSteps() { Long duration = 0L; for (ScenarioTag scenarioTag : scenarios) { - for (Step step : scenarioTag.getScenario().getSteps()) { - duration = duration + step.getDuration(); - } + if (Util.hasSteps(scenarioTag)) { + for (Step step : scenarioTag.getScenario().getSteps()) { + duration = duration + step.getDuration(); + } + } } return Util.formatDuration(duration); } - public int getNumberOfSteps(){ + public int getNumberOfSteps() { int totalSteps = 0; - for(ScenarioTag scenario : scenarios){ - totalSteps += scenario.getScenario().getSteps().length; + for (ScenarioTag scenario : scenarios) { + if (Util.hasSteps(scenario)) { + totalSteps += scenario.getScenario().getSteps().length; + } } return totalSteps; } @@ -72,22 +76,23 @@ public class TagObject { return Util.findStatusCount(getStatuses(), Util.Status.FAILED); } - public int getNumberOfSkipped() { + public int getNumberOfSkipped() { return Util.findStatusCount(getStatuses(), Util.Status.SKIPPED); } - public int getNumberOfPending() { - return Util.findStatusCount(getStatuses(), Util.Status.UNDEFINED); - } - + public int getNumberOfPending() { + return Util.findStatusCount(getStatuses(), Util.Status.UNDEFINED); + } + private List getStatuses() { List statuses = new ArrayList(); - for(ScenarioTag scenarioTag : scenarios){ - - for (Step step : scenarioTag.getScenario().getSteps()) { - statuses.add(step.getStatus()); - } - } + for (ScenarioTag scenarioTag : scenarios) { + if (Util.hasSteps(scenarioTag)) { + for (Step step : scenarioTag.getScenario().getSteps()) { + statuses.add(step.getStatus()); + } + } + } return statuses; } @@ -98,7 +103,7 @@ public class TagObject { return step.getStatus(); } }; - + Element[] elementList = new Element[elements.size()]; List results = Util.collectScenarios(elements.toArray(elementList), scenarioStatus); return results.contains(Util.Status.FAILED) ? Util.Status.FAILED : Util.Status.PASSED; @@ -107,5 +112,5 @@ public class TagObject { public String getRawStatus() { return getStatus().toString().toLowerCase(); } - + } diff --git a/src/main/java/net/masterthought/jenkins/json/Feature.java b/src/main/java/net/masterthought/jenkins/json/Feature.java index 7e0ecab..c81e365 100644 --- a/src/main/java/net/masterthought/jenkins/json/Feature.java +++ b/src/main/java/net/masterthought/jenkins/json/Feature.java @@ -62,9 +62,13 @@ public class Feature { private List lookUpSteps() { List stepStatuses = new ArrayList(); - for (Element element : elements) { - for (Step step : element.getSteps()) { - stepStatuses.add(step.getStatus()); + if (Util.itemExists(elements)) { + for (Element element : elements) { + if (Util.hasSteps(element)) { + for (Step step : element.getSteps()) { + stepStatuses.add(step.getStatus()); + } + } } } return stepStatuses; @@ -106,7 +110,7 @@ public class Feature { } public int getNumberOfScenarios() { - return elements.length; + return Util.itemExists(elements) ? elements.length : 0; } public int getNumberOfSteps() { @@ -135,9 +139,13 @@ public class Feature { public String getDurationOfSteps() { Long totalDuration = 0L; - for (Element element : elements) { - for (Step step : element.getSteps()) { - totalDuration = totalDuration + step.getDuration(); + if (Util.itemExists(elements)) { + for (Element element : elements) { + if (Util.hasSteps(element)) { + for (Step step : element.getSteps()) { + totalDuration = totalDuration + step.getDuration(); + } + } } } return Util.formatDuration(totalDuration); diff --git a/src/main/java/net/masterthought/jenkins/json/Util.java b/src/main/java/net/masterthought/jenkins/json/Util.java index 1e3a9d3..b1fed4c 100644 --- a/src/main/java/net/masterthought/jenkins/json/Util.java +++ b/src/main/java/net/masterthought/jenkins/json/Util.java @@ -1,5 +1,6 @@ package net.masterthought.jenkins.json; +import net.masterthought.jenkins.ScenarioTag; import org.joda.time.Period; import org.joda.time.format.PeriodFormatter; import org.joda.time.format.PeriodFormatterBuilder; @@ -19,7 +20,7 @@ public class Util { return listItem.size() != 0; } - public static boolean itemExists(Tag[] tags) { + public static boolean itemExists(T[] tags) { boolean result = false; if (tags != null) { result = tags.length != 0; @@ -59,22 +60,49 @@ public class Util { return result; } + public static boolean hasSteps(Element element) { + boolean result = element.getSteps() == null || element.getSteps().length == 0; + if(result){ + System.out.println("[WARNING] scenario has no steps: " + element.getName()); + } + return !result; + } + + public static boolean hasSteps(ScenarioTag scenario) { + boolean result = scenario.getScenario().getSteps() == null || scenario.getScenario().getSteps().length == 0; + if(result){ + System.out.println("[WARNING] scenario tag has no steps: " + scenario.getScenario().getName()); + } + return !result; + } + + public static boolean hasScenarios(Feature feature) { + boolean result = feature.getElements() == null || feature.getElements().length == 0; + if(result){ + System.out.println("[WARNING] feature has no scenarios: " + feature.getName()); + } + return !result; + } + public static enum Status { PASSED, FAILED, SKIPPED, UNDEFINED, MISSING } public static List collectScenarios(Element[] list, Closure clo) { List res = new ArrayList(); + if(Util.itemExists(list)){ for (final Element t : list) { res.add((R) clo.call(t)); - } + } } return res; } public static List collectSteps(Step[] list, Closure clo) { List res = new ArrayList(); - for (final Step t : list) { + if(Util.itemExists(list)){ + for (final Step t : list) { res.add((R) clo.call(t)); + } } return res; } diff --git a/velocity.log b/velocity.log index bfd1596..454c560 100644 --- a/velocity.log +++ b/velocity.log @@ -1,28 +1,28 @@ -Wed Jun 06 17:10:56 BST 2012 [debug] AvalonLogChute initialized using file 'velocity.log' -Wed Jun 06 17:10:56 BST 2012 [trace] ******************************************************************* -Wed Jun 06 17:10:56 BST 2012 [debug] Starting Jakarta Velocity v1.5-SNAPSHOT (compiled: 2006-07-21 06:25:35) -Wed Jun 06 17:10:56 BST 2012 [trace] RuntimeInstance initializing. -Wed Jun 06 17:10:56 BST 2012 [debug] Default Properties File: org/apache/velocity/runtime/defaults/velocity.properties -Wed Jun 06 17:10:56 BST 2012 [debug] Trying to use logger class org.apache.velocity.runtime.log.AvalonLogChute -Wed Jun 06 17:10:56 BST 2012 [debug] Using logger class org.apache.velocity.runtime.log.AvalonLogChute -Wed Jun 06 17:10:56 BST 2012 [debug] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl) -Wed Jun 06 17:10:56 BST 2012 [debug] ResourceLoader instantiated: org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader -Wed Jun 06 17:10:56 BST 2012 [trace] ClasspathResourceLoader : initialization complete. -Wed Jun 06 17:10:56 BST 2012 [debug] ResourceCache: initialized (class org.apache.velocity.runtime.resource.ResourceCacheImpl) -Wed Jun 06 17:10:56 BST 2012 [trace] Default ResourceManager initialization complete. -Wed Jun 06 17:10:56 BST 2012 [debug] Loaded System Directive: org.apache.velocity.runtime.directive.Literal -Wed Jun 06 17:10:56 BST 2012 [debug] Loaded System Directive: org.apache.velocity.runtime.directive.Macro -Wed Jun 06 17:10:56 BST 2012 [debug] Loaded System Directive: org.apache.velocity.runtime.directive.Parse -Wed Jun 06 17:10:56 BST 2012 [debug] Loaded System Directive: org.apache.velocity.runtime.directive.Include -Wed Jun 06 17:10:56 BST 2012 [debug] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach -Wed Jun 06 17:10:56 BST 2012 [debug] Created '20' parsers. -Wed Jun 06 17:10:56 BST 2012 [trace] Velocimacro : initialization starting. -Wed Jun 06 17:10:56 BST 2012 [debug] Velocimacro : "velocimacro.library" is not set. Trying default library: VM_global_library.vm -Wed Jun 06 17:10:56 BST 2012 [debug] Velocimacro : Default library not found. -Wed Jun 06 17:10:56 BST 2012 [debug] Velocimacro : allowInline = true : VMs can be defined inline in templates -Wed Jun 06 17:10:56 BST 2012 [debug] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions -Wed Jun 06 17:10:56 BST 2012 [debug] Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed. -Wed Jun 06 17:10:56 BST 2012 [debug] Velocimacro : autoload off : VM system will not automatically reload global library macros -Wed Jun 06 17:10:56 BST 2012 [trace] Velocimacro : initialization complete. -Wed Jun 06 17:10:56 BST 2012 [trace] RuntimeInstance successfully initialized. -Wed Jun 06 17:10:56 BST 2012 [debug] ResourceManager : found templates/tagOverview.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader +Fri Jun 15 15:15:17 BST 2012 [debug] AvalonLogChute initialized using file 'velocity.log' +Fri Jun 15 15:15:17 BST 2012 [trace] ******************************************************************* +Fri Jun 15 15:15:17 BST 2012 [debug] Starting Jakarta Velocity v1.5-SNAPSHOT (compiled: 2006-07-21 06:25:35) +Fri Jun 15 15:15:17 BST 2012 [trace] RuntimeInstance initializing. +Fri Jun 15 15:15:17 BST 2012 [debug] Default Properties File: org/apache/velocity/runtime/defaults/velocity.properties +Fri Jun 15 15:15:17 BST 2012 [debug] Trying to use logger class org.apache.velocity.runtime.log.AvalonLogChute +Fri Jun 15 15:15:17 BST 2012 [debug] Using logger class org.apache.velocity.runtime.log.AvalonLogChute +Fri Jun 15 15:15:17 BST 2012 [debug] Default ResourceManager initializing. (class org.apache.velocity.runtime.resource.ResourceManagerImpl) +Fri Jun 15 15:15:17 BST 2012 [debug] ResourceLoader instantiated: org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader +Fri Jun 15 15:15:17 BST 2012 [trace] ClasspathResourceLoader : initialization complete. +Fri Jun 15 15:15:17 BST 2012 [debug] ResourceCache: initialized (class org.apache.velocity.runtime.resource.ResourceCacheImpl) +Fri Jun 15 15:15:17 BST 2012 [trace] Default ResourceManager initialization complete. +Fri Jun 15 15:15:17 BST 2012 [debug] Loaded System Directive: org.apache.velocity.runtime.directive.Literal +Fri Jun 15 15:15:17 BST 2012 [debug] Loaded System Directive: org.apache.velocity.runtime.directive.Macro +Fri Jun 15 15:15:17 BST 2012 [debug] Loaded System Directive: org.apache.velocity.runtime.directive.Parse +Fri Jun 15 15:15:17 BST 2012 [debug] Loaded System Directive: org.apache.velocity.runtime.directive.Include +Fri Jun 15 15:15:17 BST 2012 [debug] Loaded System Directive: org.apache.velocity.runtime.directive.Foreach +Fri Jun 15 15:15:17 BST 2012 [debug] Created '20' parsers. +Fri Jun 15 15:15:17 BST 2012 [trace] Velocimacro : initialization starting. +Fri Jun 15 15:15:17 BST 2012 [debug] Velocimacro : "velocimacro.library" is not set. Trying default library: VM_global_library.vm +Fri Jun 15 15:15:17 BST 2012 [debug] Velocimacro : Default library not found. +Fri Jun 15 15:15:17 BST 2012 [debug] Velocimacro : allowInline = true : VMs can be defined inline in templates +Fri Jun 15 15:15:17 BST 2012 [debug] Velocimacro : allowInlineToOverride = false : VMs defined inline may NOT replace previous VM definitions +Fri Jun 15 15:15:17 BST 2012 [debug] Velocimacro : allowInlineLocal = false : VMs defined inline will be global in scope if allowed. +Fri Jun 15 15:15:17 BST 2012 [debug] Velocimacro : autoload off : VM system will not automatically reload global library macros +Fri Jun 15 15:15:17 BST 2012 [trace] Velocimacro : initialization complete. +Fri Jun 15 15:15:17 BST 2012 [trace] RuntimeInstance successfully initialized. +Fri Jun 15 15:15:17 BST 2012 [debug] ResourceManager : found templates/tagOverview.vm with loader org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader