Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade trends and detail views to Bootstrap 5 #272

Merged
merged 20 commits into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 44 additions & 30 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -16,14 +16,14 @@
<revision>1.52</revision>
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<jenkins.version>2.222.4</jenkins.version>
<jenkins.version>2.263.1</jenkins.version>
<java.level>8</java.level>
<no-test-jar>false</no-test-jar>
</properties>
<licenses>
<license>
<name>MIT</name>
<url>http://opensource.org/licenses/MIT</url>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>
<scm>
Expand All @@ -48,16 +48,7 @@
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>echarts-api</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>checks-api</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>checks-api</artifactId>
<scope>test</scope>
<classifier>tests</classifier>
<version>5.1.2-6-rc504.fd62772631c3</version>
timja marked this conversation as resolved.
Show resolved Hide resolved
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
Expand All @@ -69,13 +60,18 @@
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>github-checks</artifactId>
<version>1.0.9</version>
<scope>test</scope>
<artifactId>bootstrap5-api</artifactId>
<version>5.1.0-1</version>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>font-awesome-api</artifactId>
<version>5.15.3-4</version> <!-- TODO merged but not released in bom -->
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>bootstrap4-api</artifactId>
<artifactId>jquery3-api</artifactId>
<version>3.6.0-2</version> <!-- TODO merged but not released in bom -->
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand All @@ -89,6 +85,28 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jackson2-api</artifactId>
</dependency>
<!-- Checks API -->
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>checks-api</artifactId>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>checks-api</artifactId>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>io.jenkins.plugins</groupId>
<artifactId>github-checks</artifactId>
<version>1.0.9</version>
<scope>test</scope>
</dependency>
<!-- End Checks API -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand All @@ -98,6 +116,12 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>junit</artifactId>
<groupId>org.jenkins-ci.plugins</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
Expand Down Expand Up @@ -150,14 +174,8 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>database</artifactId>
<version>1.9</version>
<version>114.v0e004e100040</version>
<scope>test</scope>
<exclusions>
<exclusion> <!-- TODO move to bom in Jenkins core -->
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
Expand All @@ -182,17 +200,13 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>jackson2-api</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.222.x</artifactId>
<version>26</version>
<artifactId>bom-2.263.x</artifactId>
<version>919.v3c802a29576e</version>
<scope>import</scope>
<type>pom</type>
</dependency>
Expand Down
33 changes: 19 additions & 14 deletions src/main/java/hudson/tasks/junit/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
import edu.hm.hafner.echarts.ChartModelConfiguration;
import edu.hm.hafner.echarts.JacksonFacade;
import edu.hm.hafner.echarts.LinesChartModel;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.bind.JavaScriptMethod;
import hudson.tasks.test.TestObject;
import hudson.tasks.test.TestObjectIterable;
import hudson.tasks.test.TestResultDurationChart;
import hudson.tasks.test.TestResultTrendChart;

import io.jenkins.plugins.junit.storage.TestResultImpl;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.bind.JavaScriptMethod;

/**
* History of {@link hudson.tasks.test.TestObject} over time.
Expand All @@ -43,9 +45,10 @@
@Restricted(NoExternalUse.class)
public class History {
private static final JacksonFacade JACKSON_FACADE = new JacksonFacade();
private static final String EMPTY_CONFIGURATION = "{}";
private final TestObject testObject;

public History(TestObject testObject) {
public History(final TestObject testObject) {
this.testObject = testObject;
}

Expand All @@ -68,44 +71,46 @@ public boolean historyAvailable() {

@JavaScriptMethod
@SuppressWarnings("unused") // Called by jelly view
public String getTestResultTrend() {
return JACKSON_FACADE.toJson(createTestResultTrend());
public String getTestResultTrend(final String configuration) {
return JACKSON_FACADE.toJson(createTestResultTrend(ChartModelConfiguration.fromJson(configuration)));
}

private LinesChartModel createTestResultTrend() {
private LinesChartModel createTestResultTrend(
final ChartModelConfiguration chartModelConfiguration) {
if (testObject instanceof hudson.tasks.junit.TestResult) {
TestResultImpl pluggableStorage = ((hudson.tasks.junit.TestResult) testObject).getPluggableStorage();
if (pluggableStorage != null) {
return new TestResultTrendChart().create(pluggableStorage.getTrendTestResultSummary());
}
}

return new TestResultTrendChart().createFromTestObject(createBuildHistory(testObject), new ChartModelConfiguration());
return new TestResultTrendChart().createFromTestObject(createBuildHistory(testObject), chartModelConfiguration);
}

@JavaScriptMethod
@SuppressWarnings("unused") // Called by jelly view
public String getTestDurationTrend() {
return JACKSON_FACADE.toJson(createTestDurationResultTrend());
public String getTestDurationTrend(final String configuration) {
return JACKSON_FACADE.toJson(createTestDurationResultTrend(ChartModelConfiguration.fromJson(configuration)));
}

private LinesChartModel createTestDurationResultTrend() {
private LinesChartModel createTestDurationResultTrend(
final ChartModelConfiguration chartModelConfiguration) {
if (testObject instanceof hudson.tasks.junit.TestResult) {
TestResultImpl pluggableStorage = ((hudson.tasks.junit.TestResult) testObject).getPluggableStorage();
if (pluggableStorage != null) {
return new TestResultDurationChart().create(pluggableStorage.getTestDurationResultSummary());
}
}

return new TestResultDurationChart().create(createBuildHistory(testObject), new ChartModelConfiguration());
return new TestResultDurationChart().create(createBuildHistory(testObject), chartModelConfiguration);
}

private TestObjectIterable createBuildHistory(TestObject testObject) {
private TestObjectIterable createBuildHistory(final TestObject testObject) {
return new TestObjectIterable(testObject);
}

@SuppressWarnings("unused") // Called by jelly view
public static int asInt(String s, int defaultValue) {
public static int asInt(final String s, final int defaultValue) {
if (s == null) return defaultValue;
try {
return Integer.parseInt(s);
Expand Down
25 changes: 10 additions & 15 deletions src/main/java/hudson/tasks/test/TestResultDurationChart.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
package hudson.tasks.test;

import java.util.List;

import edu.hm.hafner.echarts.ChartModelConfiguration;
import edu.hm.hafner.echarts.LineSeries;
import edu.hm.hafner.echarts.LinesChartModel;
import edu.hm.hafner.echarts.LinesDataSet;
import edu.hm.hafner.echarts.Palette;

import hudson.tasks.junit.TestDurationResultSummary;
import hudson.tasks.junit.TrendTestResultSummary;
import java.util.List;

import static hudson.tasks.test.TestDurationTrendSeriesBuilder.SECONDS;
import static hudson.tasks.test.TestResultTrendSeriesBuilder.FAILED_KEY;
import static hudson.tasks.test.TestResultTrendSeriesBuilder.PASSED_KEY;
import static hudson.tasks.test.TestResultTrendSeriesBuilder.SKIPPED_KEY;
import static hudson.tasks.test.TestDurationTrendSeriesBuilder.*;

public class TestResultDurationChart {
public LinesChartModel create(List<TestDurationResultSummary> results) {

public LinesChartModel create(final List<TestDurationResultSummary> results) {
LinesDataSet dataset = new LinesDataSet();
results.forEach(result -> dataset.add(result.getDisplayName(), result.toMap(), result.getBuildNumber()));

return getLinesChartModel(dataset);
}

Expand All @@ -31,16 +29,13 @@ public LinesChartModel create(final Iterable results,
return getLinesChartModel(dataSet);
}

private LinesChartModel getLinesChartModel(LinesDataSet dataSet) {
LinesChartModel model = new LinesChartModel();
model.setDomainAxisLabels(dataSet.getDomainAxisLabels());
model.setBuildNumbers(dataSet.getBuildNumbers());

private LinesChartModel getLinesChartModel(final LinesDataSet dataSet) {
LinesChartModel model = new LinesChartModel(dataSet);
LineSeries duration = new LineSeries(SECONDS, Palette.GREEN.getNormal(),
LineSeries.StackedMode.STACKED, LineSeries.FilledMode.FILLED);
duration.addAll(dataSet.getSeries(SECONDS));
model.addSeries(duration);

return model;
}
}
Loading