diff --git a/src/main/java/hudson/tasks/test/TestResultProjectAction.java b/src/main/java/hudson/tasks/test/TestResultProjectAction.java index ee3ceb07d..b88d4665a 100644 --- a/src/main/java/hudson/tasks/test/TestResultProjectAction.java +++ b/src/main/java/hudson/tasks/test/TestResultProjectAction.java @@ -43,6 +43,7 @@ import hudson.model.Job; import hudson.model.Run; import hudson.tasks.junit.JUnitResultArchiver; +import hudson.tasks.test.TestResultTrendChart.PassedColor; import io.jenkins.plugins.echarts.AsyncConfigurableTrendChart; import io.jenkins.plugins.echarts.AsyncTrendChart; @@ -60,6 +61,8 @@ * @author Kohsuke Kawaguchi */ public class TestResultProjectAction implements Action, AsyncTrendChart, AsyncConfigurableTrendChart { + private static final JacksonFacade JACKSON_FACADE = new JacksonFacade(); + /** * Project that owns this action. * @since 1.2-beta-1 @@ -119,23 +122,23 @@ public AbstractTestResultAction getLastTestResultAction() { @Deprecated protected LinesChartModel createChartModel() { - return createChartModel(new ChartModelConfiguration()); + return createChartModel(new ChartModelConfiguration(), PassedColor.BLUE); } - private LinesChartModel createChartModel(final ChartModelConfiguration configuration) { + private LinesChartModel createChartModel(ChartModelConfiguration configuration, PassedColor passedColor) { Run lastCompletedBuild = job.getLastCompletedBuild(); JunitTestResultStorage storage = JunitTestResultStorage.find(); if (!(storage instanceof FileJunitTestResultStorage)) { TestResultImpl pluggableStorage = storage.load(lastCompletedBuild.getParent().getFullName(), lastCompletedBuild.getNumber()); - return new TestResultTrendChart().create(pluggableStorage.getTrendTestResultSummary()); + return new TestResultTrendChart().create(pluggableStorage.getTrendTestResultSummary(), passedColor); } TestResultActionIterable buildHistory = createBuildHistory(lastCompletedBuild); if (buildHistory == null) { return new LinesChartModel(); } - return new TestResultTrendChart().create(buildHistory, configuration); + return new TestResultTrendChart().create(buildHistory, configuration, passedColor); } @CheckForNull @@ -227,7 +230,8 @@ public String getBuildTrendModel() { @JavaScriptMethod @Override public String getConfigurableBuildTrendModel(final String configuration) { - return new JacksonFacade().toJson(createChartModel(ChartModelConfiguration.fromJson(configuration))); + PassedColor useBlue = JACKSON_FACADE.getBoolean(configuration, "useBlue", false) ? PassedColor.BLUE : PassedColor.GREEN; + return new JacksonFacade().toJson(createChartModel(ChartModelConfiguration.fromJson(configuration), useBlue)); } @Override diff --git a/src/main/java/hudson/tasks/test/TestResultTrendChart.java b/src/main/java/hudson/tasks/test/TestResultTrendChart.java index 3f0011c3d..7556522b5 100644 --- a/src/main/java/hudson/tasks/test/TestResultTrendChart.java +++ b/src/main/java/hudson/tasks/test/TestResultTrendChart.java @@ -14,46 +14,62 @@ import static hudson.tasks.test.TestResultTrendSeriesBuilder.*; public class TestResultTrendChart { + enum PassedColor {GREEN, BLUE} public LinesChartModel create(final List results) { + return create(results, PassedColor.BLUE); + } + + public LinesChartModel create(final List results, final PassedColor passedColor) { LinesDataSet dataset = new LinesDataSet(); results.forEach(result -> dataset.add(result.getDisplayName(), result.toMap(), result.getBuildNumber())); - return getLinesChartModel(dataset); + return getLinesChartModel(dataset, passedColor); } - public LinesChartModel create(@NonNull final Iterable results, - final ChartModelConfiguration configuration) { + public LinesChartModel create(@NonNull final Iterable results, final ChartModelConfiguration configuration) { + return create(results, configuration, PassedColor.GREEN); + } + + public LinesChartModel create(@NonNull final Iterable results, final ChartModelConfiguration configuration, + final PassedColor passedColor) { TestResultTrendSeriesBuilder builder = new TestResultTrendSeriesBuilder(); LinesDataSet dataSet = builder.createDataSet(configuration, results); - return getLinesChartModel(dataSet); + return getLinesChartModel(dataSet, passedColor); } public LinesChartModel createFromTestObject(final Iterable results, - final ChartModelConfiguration configuration) { + final ChartModelConfiguration configuration) { + return createFromTestObject(results, configuration, PassedColor.GREEN); + } + + public LinesChartModel createFromTestObject(final Iterable results, final ChartModelConfiguration configuration, + final PassedColor passedColor) { TestObjectTrendSeriesBuilder builder = new TestObjectTrendSeriesBuilder(); LinesDataSet dataSet = builder.createDataSet(configuration, results); - return getLinesChartModel(dataSet); + return getLinesChartModel(dataSet, passedColor); } - private LinesChartModel getLinesChartModel(final LinesDataSet dataSet) { + private LinesChartModel getLinesChartModel(final LinesDataSet dataSet, final PassedColor passedColor) { LinesChartModel model = new LinesChartModel(dataSet); - LineSeries failed = new LineSeries("Failed", Palette.RED.getNormal(), + + LineSeries passed = new LineSeries("Passed", + passedColor == PassedColor.BLUE ? Palette.BLUE.getNormal() : Palette.GREEN.getNormal(), LineSeries.StackedMode.STACKED, LineSeries.FilledMode.FILLED); - failed.addAll(dataSet.getSeries(FAILED_KEY)); - model.addSeries(failed); + passed.addAll(dataSet.getSeries(PASSED_KEY)); + model.addSeries(passed); LineSeries skipped = new LineSeries("Skipped", Palette.GRAY.getNormal(), LineSeries.StackedMode.STACKED, LineSeries.FilledMode.FILLED); skipped.addAll(dataSet.getSeries(SKIPPED_KEY)); model.addSeries(skipped); - LineSeries passed = new LineSeries("Passed", Palette.BLUE.getNormal(), + LineSeries failed = new LineSeries("Failed", Palette.RED.getNormal(), LineSeries.StackedMode.STACKED, LineSeries.FilledMode.FILLED); - passed.addAll(dataSet.getSeries(PASSED_KEY)); - model.addSeries(passed); + failed.addAll(dataSet.getSeries(FAILED_KEY)); + model.addSeries(failed); return model; } diff --git a/src/main/resources/hudson/tasks/test/TestResultProjectAction/floatingBox.jelly b/src/main/resources/hudson/tasks/test/TestResultProjectAction/floatingBox.jelly index 993b4f528..605a50a7d 100644 --- a/src/main/resources/hudson/tasks/test/TestResultProjectAction/floatingBox.jelly +++ b/src/main/resources/hudson/tasks/test/TestResultProjectAction/floatingBox.jelly @@ -23,7 +23,36 @@ THE SOFTWARE. --> - - + + +
+ + +
+
+ +
+
+ + + + +