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

Replace joda-time dependency with java.time #125

Merged
merged 3 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.12</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package hudson.plugins.view.dashboard.test;

import org.joda.time.LocalDate;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
* Graph label showing the build date.
*
* @author Ulli Hafner
*/
public class LocalDateLabel implements Comparable<LocalDateLabel> {

private static final DateTimeFormatter format = DateTimeFormatter.ofPattern("MM-dd");

private final LocalDate date;

/**
Expand All @@ -28,7 +32,7 @@ public int compareTo(final LocalDateLabel o) {
/** {@inheritDoc} */
@Override
public String toString() {
return date.toString("MM-dd");
return format.format(date);
}

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
import hudson.util.ListBoxModel;
import hudson.util.ShiftedCategoryAxis;
import hudson.util.StackedAreaRenderer2;
import java.awt.Color;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
Expand All @@ -25,16 +34,9 @@
import org.jfree.chart.renderer.category.StackedAreaRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.ui.RectangleInsets;
import org.joda.time.LocalDate;
import org.joda.time.chrono.GregorianChronology;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.Stapler;

import java.awt.Color;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

public class TestTrendChart extends DashboardPortlet {

public enum DisplayStatus {
Expand Down Expand Up @@ -70,7 +72,12 @@ public String getName() {

@DataBoundConstructor
public TestTrendChart(
String name, int graphWidth, int graphHeight, DisplayStatus displayStatus, int dateRange, int dateShift) {
String name,
int graphWidth,
int graphHeight,
DisplayStatus displayStatus,
int dateRange,
int dateShift) {
super(name);
this.graphWidth = graphWidth;
this.graphHeight = graphHeight;
Expand Down Expand Up @@ -123,37 +130,40 @@ public int compare(LocalDate d1, LocalDate d2) {
// We need a custom comparator for LocalDate objects
final Map<LocalDate, TestResultSummary> summaries =
new TreeMap<LocalDate, TestResultSummary>(localDateComparator);
LocalDate today =
new LocalDate(
System.currentTimeMillis() - dateShift * 6000, GregorianChronology.getInstanceUTC());
LocalDate today = LocalDateTime.now().minus(dateShift * 6000, ChronoUnit.MILLIS).toLocalDate();

// for each job, for each day, add last build of the day to summary
for (Job job : getDashboard().getJobs()) {
Run run = job.getFirstBuild();

if (run != null) { // execute only if job has builds
LocalDate runDay =
new LocalDate(
run.getTimeInMillis() - dateShift * 60000L, GregorianChronology.getInstanceUTC());
Instant.ofEpochMilli(run.getTimeInMillis())
.atZone(ZoneId.systemDefault())
.minus(dateShift * 60000L, ChronoUnit.MILLIS)
.toLocalDate();
LocalDate firstDay =
(dateRange != 0)
? new LocalDate(
System.currentTimeMillis() - dateShift * 6000L,
GregorianChronology.getInstanceUTC())
? LocalDateTime.now()
.minus(dateShift * 6000, ChronoUnit.MILLIS)
.toLocalDate()
.minusDays(dateRange)
: runDay;

while (run != null) {
runDay =
new LocalDate(
run.getTimeInMillis() - dateShift * 60000L, GregorianChronology.getInstanceUTC());
Instant.ofEpochMilli(run.getTimeInMillis())
.atZone(ZoneId.systemDefault())
.minus(dateShift * 60000L, ChronoUnit.MILLIS)
.toLocalDate();
Run nextRun = run.getNextBuild();

if (nextRun != null) {
LocalDate nextRunDay =
new LocalDate(
nextRun.getTimeInMillis() - dateShift * 60000L,
GregorianChronology.getInstanceUTC());
Instant.ofEpochMilli(nextRun.getTimeInMillis())
.atZone(ZoneId.systemDefault())
.minus(dateShift * 60000L, ChronoUnit.MILLIS)
.toLocalDate();
// skip run before firstDay, but keep if next build is
// after start date
if (!runDay.isBefore(firstDay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import hudson.maven.MavenModuleSet;
import hudson.model.Result;
import hudson.plugins.view.dashboard.Dashboard;
import java.time.LocalDate;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import org.hamcrest.Matchers;
import org.joda.time.LocalDate;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.ExtractResourceSCM;
Expand Down