From 6e5acf6550979976b31307204de1b780cf10144f Mon Sep 17 00:00:00 2001 From: Aleksi Simell Date: Wed, 23 Dec 2020 12:07:25 +0200 Subject: [PATCH 1/5] Add new field for overwriting x axis label per build --- .../java/hudson/plugins/robot/RobotPublisher.java | 12 +++++++++++- src/main/java/hudson/plugins/robot/RobotStep.java | 10 ++++++++++ .../hudson/plugins/robot/RobotStepExecution.java | 2 +- .../hudson/plugins/robot/RobotPublisher/config.jelly | 3 +++ .../plugins/robot/RobotPublisher/config.properties | 3 +++ .../plugins/robot/RobotPublisherSystemTest.java | 4 ++-- .../hudson/plugins/robot/RobotPublisherTest.java | 2 +- 7 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/main/java/hudson/plugins/robot/RobotPublisher.java b/src/main/java/hudson/plugins/robot/RobotPublisher.java index af4bf29..08a827b 100755 --- a/src/main/java/hudson/plugins/robot/RobotPublisher.java +++ b/src/main/java/hudson/plugins/robot/RobotPublisher.java @@ -62,6 +62,7 @@ public class RobotPublisher extends Recorder implements Serializable, final private double passThreshold; final private double unstableThreshold; private String[] otherFiles; + final private String overwriteXAxisLabel; final private boolean enableCache; //Default to true @@ -95,7 +96,7 @@ public class RobotPublisher extends Recorder implements Serializable, public RobotPublisher(String outputPath, String outputFileName, boolean disableArchiveOutput, String reportFileName, String logFileName, double passThreshold, double unstableThreshold, - boolean onlyCritical, String otherFiles, boolean enableCache) { + boolean onlyCritical, String otherFiles, boolean enableCache, String overwriteXAxisLabel) { this.outputPath = outputPath; this.outputFileName = outputFileName; this.disableArchiveOutput = disableArchiveOutput; @@ -105,6 +106,7 @@ public RobotPublisher(String outputPath, String outputFileName, this.logFileName = logFileName; this.onlyCritical = onlyCritical; this.enableCache = enableCache; + this.overwriteXAxisLabel = overwriteXAxisLabel; if (otherFiles != null) { String[] filemasks = otherFiles.split(","); @@ -203,6 +205,14 @@ public String getOtherFiles() { return StringUtils.join(otherFiles, ","); } + /** + * Gets the value of overwriteXAxisLabel + * @return X axis label for the trend + */ + public String getOverwriteXAxisLabel() { + return overwriteXAxisLabel; + } + /** * {@inheritDoc} */ diff --git a/src/main/java/hudson/plugins/robot/RobotStep.java b/src/main/java/hudson/plugins/robot/RobotStep.java index 2343874..fbf9d3f 100644 --- a/src/main/java/hudson/plugins/robot/RobotStep.java +++ b/src/main/java/hudson/plugins/robot/RobotStep.java @@ -38,6 +38,7 @@ public class RobotStep extends Step { private @CheckForNull String[] otherFiles; private boolean enableCache = true; private boolean onlyCritical = true; + private @CheckForNull String overwriteXAxisLabel; @@ -89,6 +90,10 @@ public boolean getEnableCache() { public boolean getOnlyCritical() { return this.onlyCritical; } + + public String getOverwriteXAxisLabel() { + return this.overwriteXAxisLabel; + } @DataBoundSetter public void setReportFileName(String reportFileName) { @@ -142,6 +147,11 @@ public void setOtherFiles(String otherFiles) { } } + @DataBoundSetter + public void setOverwriteXAxisLabel(String overwriteXAxisLabel) { + this.overwriteXAxisLabel = overwriteXAxisLabel; + } + @Override public StepExecution start(StepContext context) throws Exception { return new RobotStepExecution(this, context); diff --git a/src/main/java/hudson/plugins/robot/RobotStepExecution.java b/src/main/java/hudson/plugins/robot/RobotStepExecution.java index 702ea2b..ca64ee0 100644 --- a/src/main/java/hudson/plugins/robot/RobotStepExecution.java +++ b/src/main/java/hudson/plugins/robot/RobotStepExecution.java @@ -28,7 +28,7 @@ public class RobotStepExecution extends SynchronousNonBlockingStepExecution + + + diff --git a/src/main/resources/hudson/plugins/robot/RobotPublisher/config.properties b/src/main/resources/hudson/plugins/robot/RobotPublisher/config.properties index bcb46f4..9ca4aea 100644 --- a/src/main/resources/hudson/plugins/robot/RobotPublisher/config.properties +++ b/src/main/resources/hudson/plugins/robot/RobotPublisher/config.properties @@ -14,6 +14,9 @@ advanced.otherfiles=Other files to copy advanced.otherfiles.description=Comma separated list of robot related artifacts to be saved advanced.enableCache=Enable cache advanced.enableCache.description=Enable cache for test results +advanced.overwriteXAxisLabel=X-axis label +advanced.overwriteXAxisLabel.description=Overwrite default x-axis label for publish trend + thresholds.label=Thresholds for build result thresholds.onlycritical=Use thresholds for critical tests only \ No newline at end of file diff --git a/src/test/java/hudson/plugins/robot/RobotPublisherSystemTest.java b/src/test/java/hudson/plugins/robot/RobotPublisherSystemTest.java index 2b121d4..fc82472 100644 --- a/src/test/java/hudson/plugins/robot/RobotPublisherSystemTest.java +++ b/src/test/java/hudson/plugins/robot/RobotPublisherSystemTest.java @@ -57,7 +57,7 @@ public class RobotPublisherSystemTest { public void testRoundTripConfig() throws Exception { FreeStyleProject p = j.jenkins.createProject(FreeStyleProject.class, "testRoundTripConfig"); RobotPublisher before = new RobotPublisher("a", "b", false, "c", "d", 11, 27, true, "dir1/*.jpg, dir2/*.png", - false); + false, ""); p.getPublishersList().add(before); j.configRoundtrip(p); RobotPublisher after = p.getPublishersList().get(RobotPublisher.class); @@ -70,7 +70,7 @@ public void testRoundTripConfig() throws Exception { public void testConfigView() throws Exception { FreeStyleProject p = j.jenkins.createProject(FreeStyleProject.class, "testConfigView"); RobotPublisher before = new RobotPublisher("a", "b", false, "c", "d", 11, 27, true, "dir1/*.jpg, dir2/*.png", - false); + false, ""); p.getPublishersList().add(before); HtmlPage page = j.createWebClient().getPage(p, "configure"); WebAssert.assertTextPresent(page, "Publish Robot Framework"); diff --git a/src/test/java/hudson/plugins/robot/RobotPublisherTest.java b/src/test/java/hudson/plugins/robot/RobotPublisherTest.java index e2a9cdb..78a28ab 100644 --- a/src/test/java/hudson/plugins/robot/RobotPublisherTest.java +++ b/src/test/java/hudson/plugins/robot/RobotPublisherTest.java @@ -38,7 +38,7 @@ public void setUp() throws Exception { } private RobotPublisher getRobotPublisher(double passThreshold, double unstableThreshold) { - return new RobotPublisher("", "", false, "", "", passThreshold, unstableThreshold, onlyCritical, "", false); + return new RobotPublisher("", "", false, "", "", passThreshold, unstableThreshold, onlyCritical, "", false, ""); } @Test From 69a5f75af1a5fd7b2e849bfff9976017db58950c Mon Sep 17 00:00:00 2001 From: Aleksi Simell Date: Wed, 23 Dec 2020 12:44:22 +0200 Subject: [PATCH 2/5] Add xAxisLabel to projectAction --- src/main/java/hudson/plugins/robot/RobotBuildAction.java | 4 +++- src/main/java/hudson/plugins/robot/RobotPublisher.java | 2 +- .../java/hudson/plugins/robot/RobotProjectActionTest.java | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/hudson/plugins/robot/RobotBuildAction.java b/src/main/java/hudson/plugins/robot/RobotBuildAction.java index 14539d8..a4ad801 100755 --- a/src/main/java/hudson/plugins/robot/RobotBuildAction.java +++ b/src/main/java/hudson/plugins/robot/RobotBuildAction.java @@ -63,6 +63,7 @@ public class RobotBuildAction extends AbstractTestResultAction private final boolean enableCache; private Run build; private RobotResult result; + private String xAxisLabel; static { XSTREAM.alias("result",RobotResult.class); @@ -82,7 +83,7 @@ public class RobotBuildAction extends AbstractTestResultAction * @param enableCache Whether we want to enable caching or not */ public RobotBuildAction(Run build, RobotResult result, - String outputPath, TaskListener listener, String logFileLink, String logHtmlLink, boolean enableCache) { + String outputPath, TaskListener listener, String logFileLink, String logHtmlLink, boolean enableCache, String xAxisLabel) { super(); super.onAttached(build); this.build = build; @@ -90,6 +91,7 @@ public RobotBuildAction(Run build, RobotResult result, this.logFileLink = logFileLink; this.logHtmlLink = logHtmlLink; this.enableCache = enableCache; + this.xAxisLabel = xAxisLabel; setResult(result, listener); } diff --git a/src/main/java/hudson/plugins/robot/RobotPublisher.java b/src/main/java/hudson/plugins/robot/RobotPublisher.java index 08a827b..def3746 100755 --- a/src/main/java/hudson/plugins/robot/RobotPublisher.java +++ b/src/main/java/hudson/plugins/robot/RobotPublisher.java @@ -270,7 +270,7 @@ public void perform(Run build, FilePath workspace, Launcher launcher, Task logger.println(Messages.robot_publisher_done()); logger.println(Messages.robot_publisher_assigning()); - RobotBuildAction action = new RobotBuildAction(build, result, FILE_ARCHIVE_DIR, listener, expandedReportFileName, expandedLogFileName, enableCache); + RobotBuildAction action = new RobotBuildAction(build, result, FILE_ARCHIVE_DIR, listener, expandedReportFileName, expandedLogFileName, enableCache, overwriteXAxisLabel); build.addAction(action); // set RobotProjectAction as project action for Blue Ocean diff --git a/src/test/java/hudson/plugins/robot/RobotProjectActionTest.java b/src/test/java/hudson/plugins/robot/RobotProjectActionTest.java index b5cd9df..93574b7 100644 --- a/src/test/java/hudson/plugins/robot/RobotProjectActionTest.java +++ b/src/test/java/hudson/plugins/robot/RobotProjectActionTest.java @@ -60,7 +60,7 @@ public void testShouldDisplayGraph() throws IOException { when(build.getProject()).thenReturn(p); when(build.getRootDir()).thenReturn(tmpDir); RobotResult result = mock(RobotResult.class); - RobotBuildAction buildAction = new RobotBuildAction(build, result, "", null, null, null, false); + RobotBuildAction buildAction = new RobotBuildAction(build, result, "", null, null, null, false, ""); when(build.getAction(RobotBuildAction.class)).thenReturn(buildAction); when(p.getLastBuild()).thenReturn(build); @@ -76,7 +76,7 @@ public void testShouldGetLastBuildAction() throws IOException{ when(buildWithAction.getProject()).thenReturn(p); when(buildWithAction.getRootDir()).thenReturn(tmpDir); RobotResult result = mock(RobotResult.class); - RobotBuildAction buildAction = new RobotBuildAction(buildWithAction, result, "", null, null, null, false); + RobotBuildAction buildAction = new RobotBuildAction(buildWithAction, result, "", null, null, null, false, ""); when(buildWithAction.getAction(RobotBuildAction.class)).thenReturn(buildAction); when(p.getLastBuild()).thenReturn(lastBuild); From c06aa5f5f6cf7b24901d000c918f06c43fc92503 Mon Sep 17 00:00:00 2001 From: Aleksi Simell Date: Wed, 23 Dec 2020 13:55:50 +0200 Subject: [PATCH 3/5] Add x axis label for robot step --- src/main/resources/hudson/plugins/robot/RobotStep/config.jelly | 3 +++ .../resources/hudson/plugins/robot/RobotStep/config.properties | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/main/resources/hudson/plugins/robot/RobotStep/config.jelly b/src/main/resources/hudson/plugins/robot/RobotStep/config.jelly index f71e1a7..bf4a164 100755 --- a/src/main/resources/hudson/plugins/robot/RobotStep/config.jelly +++ b/src/main/resources/hudson/plugins/robot/RobotStep/config.jelly @@ -38,6 +38,9 @@ limitations under the License. + + +
diff --git a/src/main/resources/hudson/plugins/robot/RobotStep/config.properties b/src/main/resources/hudson/plugins/robot/RobotStep/config.properties index bcb46f4..e427760 100644 --- a/src/main/resources/hudson/plugins/robot/RobotStep/config.properties +++ b/src/main/resources/hudson/plugins/robot/RobotStep/config.properties @@ -14,6 +14,8 @@ advanced.otherfiles=Other files to copy advanced.otherfiles.description=Comma separated list of robot related artifacts to be saved advanced.enableCache=Enable cache advanced.enableCache.description=Enable cache for test results +advanced.overwriteXAxisLabel=X-axis label +advanced.overwriteXAxisLabel.description=Overwrite default x-axis label for publish trend thresholds.label=Thresholds for build result thresholds.onlycritical=Use thresholds for critical tests only \ No newline at end of file From 906bcd47a8a5257690e35d63d1c4ecc01d38ff5a Mon Sep 17 00:00:00 2001 From: Aleksi Simell Date: Wed, 23 Dec 2020 13:56:04 +0200 Subject: [PATCH 4/5] Check if build overwrites x axis label --- .../java/hudson/plugins/robot/AggregatedRobotAction.java | 5 +++-- src/main/java/hudson/plugins/robot/RobotBuildAction.java | 6 +++++- .../java/hudson/plugins/robot/model/RobotCaseResult.java | 4 +++- .../java/hudson/plugins/robot/model/RobotTestObject.java | 6 ++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/hudson/plugins/robot/AggregatedRobotAction.java b/src/main/java/hudson/plugins/robot/AggregatedRobotAction.java index 62616bf..87863f2 100644 --- a/src/main/java/hudson/plugins/robot/AggregatedRobotAction.java +++ b/src/main/java/hudson/plugins/robot/AggregatedRobotAction.java @@ -23,6 +23,7 @@ import hudson.plugins.robot.model.RobotResult; import hudson.util.ChartUtil; import hudson.util.Graph; +import org.apache.commons.lang.StringUtils; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -92,8 +93,8 @@ public void doGraph(StaplerRequest req, StaplerResponse rsp) if (req.checkIfModified(t, rsp)) return; - - String labelFormat = RobotConfig.getInstance().getXAxisLabelFormat(); + String label = getChildBuildAction(build).getxAxisLabel(); + String labelFormat = StringUtils.isBlank(label) ? RobotConfig.getInstance().getXAxisLabelFormat() : label; Graph g = RobotGraphHelper.createTestResultsGraphForTestObject(getResult(), Boolean.valueOf(req.getParameter("zoomSignificant")), false, Boolean.valueOf(req.getParameter("hd")), diff --git a/src/main/java/hudson/plugins/robot/RobotBuildAction.java b/src/main/java/hudson/plugins/robot/RobotBuildAction.java index a4ad801..72b9d1b 100755 --- a/src/main/java/hudson/plugins/robot/RobotBuildAction.java +++ b/src/main/java/hudson/plugins/robot/RobotBuildAction.java @@ -221,6 +221,10 @@ public Object getTarget(){ return getResult(); } + public String getxAxisLabel() { + return xAxisLabel; + } + /** * Serves Robot html report via robot url. Shows not found page if file is missing. * @param req StaplerRequest @@ -270,7 +274,7 @@ public void doGraph(StaplerRequest req, StaplerResponse rsp) if (maxBuildsReq == null || maxBuildsReq.isEmpty()) maxBuildsReq = "0"; // show all builds by default - String labelFormat = RobotConfig.getInstance().getXAxisLabelFormat(); + String labelFormat = StringUtils.isBlank(xAxisLabel) ? RobotConfig.getInstance().getXAxisLabelFormat() : xAxisLabel; Graph g = RobotGraphHelper.createTestResultsGraphForTestObject(getResult(), Boolean.valueOf(req.getParameter("zoomSignificant")), false, Boolean.valueOf(req.getParameter("hd")), diff --git a/src/main/java/hudson/plugins/robot/model/RobotCaseResult.java b/src/main/java/hudson/plugins/robot/model/RobotCaseResult.java index c54449b..eb70b5f 100644 --- a/src/main/java/hudson/plugins/robot/model/RobotCaseResult.java +++ b/src/main/java/hudson/plugins/robot/model/RobotCaseResult.java @@ -28,6 +28,7 @@ import java.util.Date; import java.util.List; +import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.kohsuke.stapler.StaplerRequest; import org.kohsuke.stapler.StaplerResponse; @@ -265,7 +266,8 @@ public int getAge(){ public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException { if(!isNeedToGenerate(req, rsp)) return; - String labelFormat = RobotConfig.getInstance().getXAxisLabelFormat(); + String label = getParentAction().getxAxisLabel(); + String labelFormat = StringUtils.isBlank(label) ? RobotConfig.getInstance().getXAxisLabelFormat() : label; Graph g = RobotGraphHelper.createTestResultsGraphForTestObject(this, false, true, Boolean.parseBoolean(req.getParameter("hd")), false, false, labelFormat, Integer.parseInt(req.getParameter("maxBuildsToShow"))); diff --git a/src/main/java/hudson/plugins/robot/model/RobotTestObject.java b/src/main/java/hudson/plugins/robot/model/RobotTestObject.java index e7f43bc..28270ca 100644 --- a/src/main/java/hudson/plugins/robot/model/RobotTestObject.java +++ b/src/main/java/hudson/plugins/robot/model/RobotTestObject.java @@ -253,7 +253,8 @@ public String getDurationDiff(RobotTestObject comparable){ public void doGraph(StaplerRequest req, StaplerResponse rsp) throws IOException { if(!isNeedToGenerate(req, rsp)) return; - String labelFormat = RobotConfig.getInstance().getXAxisLabelFormat(); + String label = parentAction.getxAxisLabel(); + String labelFormat = StringUtils.isBlank(label) ? RobotConfig.getInstance().getXAxisLabelFormat() : label; Graph g = RobotGraphHelper.createTestResultsGraphForTestObject(this, Boolean.parseBoolean(req.getParameter("zoomSignificant")), false, Boolean.parseBoolean(req.getParameter("hd")), @@ -273,7 +274,8 @@ public void doGraph(StaplerRequest req, StaplerResponse rsp) public void doDurationGraph(StaplerRequest req, StaplerResponse rsp) throws IOException { if(!isNeedToGenerate(req, rsp)) return; - String labelFormat = RobotConfig.getInstance().getXAxisLabelFormat(); + String label = parentAction.getxAxisLabel(); + String labelFormat = StringUtils.isBlank(label) ? RobotConfig.getInstance().getXAxisLabelFormat() : label; Graph g = RobotGraphHelper.createDurationGraphForTestObject(this, req.hasParameter("hd"), Integer.parseInt(req.getParameter("maxBuildsToShow")), From 07c6be3891b48a72f257d707c311b5edc5b323f0 Mon Sep 17 00:00:00 2001 From: Aleksi Simell Date: Wed, 23 Dec 2020 14:51:34 +0200 Subject: [PATCH 5/5] Add help texts for overwriting x axis --- .../help-overwriteXAxisLabel.html | 18 ++++++++++++++++++ .../RobotStep/help-overwriteXAxisLabel.html | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/main/resources/hudson/plugins/robot/RobotPublisher/help-overwriteXAxisLabel.html create mode 100644 src/main/resources/hudson/plugins/robot/RobotStep/help-overwriteXAxisLabel.html diff --git a/src/main/resources/hudson/plugins/robot/RobotPublisher/help-overwriteXAxisLabel.html b/src/main/resources/hudson/plugins/robot/RobotPublisher/help-overwriteXAxisLabel.html new file mode 100644 index 0000000..69a8b18 --- /dev/null +++ b/src/main/resources/hudson/plugins/robot/RobotPublisher/help-overwriteXAxisLabel.html @@ -0,0 +1,18 @@ + +
+

Pattern to format x axis label in trend graphs. You can use $build for build number beside all letters from java class DateTimeFormatter (e.g. MM-dd HH:mm). Already created and cached images are not affected

+
diff --git a/src/main/resources/hudson/plugins/robot/RobotStep/help-overwriteXAxisLabel.html b/src/main/resources/hudson/plugins/robot/RobotStep/help-overwriteXAxisLabel.html new file mode 100644 index 0000000..69a8b18 --- /dev/null +++ b/src/main/resources/hudson/plugins/robot/RobotStep/help-overwriteXAxisLabel.html @@ -0,0 +1,18 @@ + +
+

Pattern to format x axis label in trend graphs. You can use $build for build number beside all letters from java class DateTimeFormatter (e.g. MM-dd HH:mm). Already created and cached images are not affected

+