Skip to content
Permalink
Browse files

Remove Joda Time dependency (JENKINS-43103). (#87)

Removed dependency to Joda Time (JENKINS-43103)
  • Loading branch information...
veita authored and centic9 committed May 2, 2017
1 parent a729cfa commit f24f927000a65a12103c4d2f5d3094eda9b76969
@@ -29,21 +29,20 @@
*/
package hudson.plugins.jacoco.portlet;

import hudson.model.Job;
import hudson.model.Run;
import hudson.plugins.jacoco.JacocoBuildAction;
import hudson.plugins.jacoco.portlet.bean.JacocoCoverageResultSummary;
import hudson.plugins.jacoco.portlet.utils.Utils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import org.joda.time.LocalDate;
import hudson.model.Job;
import hudson.model.Run;
import hudson.plugins.jacoco.JacocoBuildAction;
import hudson.plugins.jacoco.portlet.bean.JacocoCoverageResultSummary;
import hudson.plugins.jacoco.portlet.utils.Utils;

/**
* Load data of JaCoCo coverage results used by chart or grid.
@@ -66,20 +65,20 @@ private JacocoLoadData() {
* number of days
* @return Map The sorted summaries
*/
public static Map<LocalDate, JacocoCoverageResultSummary> loadChartDataWithinRange(List<Job<?,?>> jobs, int daysNumber) {
public static Map<Calendar, JacocoCoverageResultSummary> loadChartDataWithinRange(List<Job<?,?>> jobs, int daysNumber) {

Map<LocalDate, JacocoCoverageResultSummary> summaries = new HashMap<>();
Map<Calendar, JacocoCoverageResultSummary> summaries = new HashMap<>();

// Get the last build (last date) of the all jobs
LocalDate lastDate = Utils.getLastDate(jobs);
Calendar firstDate = Utils.getLastDate(jobs);

// No builds
if (lastDate == null) {
if (firstDate == null) {
return null;
}

// Get the first date from last build date minus number of days
LocalDate firstDate = lastDate.minusDays(daysNumber);
// Adjust for the given date range
firstDate.add(Calendar.DAY_OF_MONTH, -daysNumber);

// For each job, get JaCoCo coverage results according with
// date range (last build date minus number of days)
@@ -88,9 +87,9 @@ private JacocoLoadData() {
Run<?,?> run = job.getLastCompletedBuild();

if (null != run) {
LocalDate runDate = new LocalDate(run.getTimestamp());
Calendar runDate = run.getTimestamp();

while (runDate.isAfter(firstDate)) {
while (runDate.after(firstDate)) {

summarize(summaries, run, runDate, job);

@@ -103,8 +102,7 @@ private JacocoLoadData() {
break;
}

runDate = new LocalDate(run.getTimestamp());

runDate = run.getTimestamp();
}
}
}
@@ -128,7 +126,7 @@ private JacocoLoadData() {
* @param job
* job from the DashBoard Portlet view
*/
private static void summarize(Map<LocalDate, JacocoCoverageResultSummary> summaries, Run<?,?> run, LocalDate runDate, Job<?,?> job) {
private static void summarize(Map<Calendar, JacocoCoverageResultSummary> summaries, Run<?,?> run, Calendar runDate, Job<?,?> job) {

JacocoCoverageResultSummary jacocoCoverageResult = getResult(run);

@@ -29,14 +29,9 @@
*/
package hudson.plugins.jacoco.portlet.chart;

import hudson.plugins.jacoco.portlet.Messages;
import hudson.plugins.jacoco.portlet.JacocoLoadData;
import hudson.plugins.jacoco.portlet.bean.JacocoCoverageResultSummary;
import hudson.plugins.jacoco.portlet.utils.Constants;
import hudson.plugins.jacoco.portlet.utils.Utils;

import java.awt.BasicStroke;
import java.awt.Color;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

@@ -49,16 +44,20 @@
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.joda.time.LocalDate;
import org.kohsuke.stapler.DataBoundConstructor;

import hudson.Extension;
import hudson.model.Descriptor;
import hudson.model.Job;
import hudson.plugins.jacoco.portlet.JacocoLoadData;
import hudson.plugins.jacoco.portlet.Messages;
import hudson.plugins.jacoco.portlet.bean.JacocoCoverageResultSummary;
import hudson.plugins.jacoco.portlet.utils.Constants;
import hudson.plugins.jacoco.portlet.utils.Utils;
import hudson.plugins.view.dashboard.DashboardPortlet;
import hudson.util.DataSetBuilder;
import hudson.util.Graph;
import hudson.util.ShiftedCategoryAxis;
import org.kohsuke.stapler.DataBoundConstructor;

/**
* A portlet for JaCoCo coverage results - Trend Chart.
@@ -117,7 +116,7 @@ public Graph getSummaryGraph() {
List<Job<?,?>> jobs = (List) getDashboard().getJobs();

// Fill a HashMap with the data will be showed in the chart
Map<LocalDate, JacocoCoverageResultSummary> summaries =
Map<Calendar, JacocoCoverageResultSummary> summaries =
JacocoLoadData.loadChartDataWithinRange(jobs, daysNumber);

return createTrendChart(summaries, width, height);
@@ -135,7 +134,7 @@ public Graph getSummaryGraph() {
* the chart height
* @return Graph (JFreeChart)
*/
private static Graph createTrendChart(final Map<LocalDate, JacocoCoverageResultSummary> summaries, int widthParam,
private static Graph createTrendChart(final Map<Calendar, JacocoCoverageResultSummary> summaries, int widthParam,
int heightParam) {

return new Graph(-1, widthParam, heightParam) {
@@ -198,11 +197,11 @@ protected JFreeChart createGraph() {
* @return CategoryDataset Interface for a dataset with one or more
* series, and values associated with categories.
*/
private static CategoryDataset buildDataSet(Map<LocalDate, JacocoCoverageResultSummary> summaries) {
private static CategoryDataset buildDataSet(Map<Calendar, JacocoCoverageResultSummary> summaries) {

DataSetBuilder<String, LocalDate> dataSetBuilder = new DataSetBuilder<>();
DataSetBuilder<String, Calendar> dataSetBuilder = new DataSetBuilder<>();

for (Map.Entry<LocalDate, JacocoCoverageResultSummary> entry : summaries.entrySet()) {
for (Map.Entry<Calendar, JacocoCoverageResultSummary> entry : summaries.entrySet()) {
float classCoverage = 0;
float lineCoverage = 0;
float methodCoverage = 0;
@@ -230,7 +229,7 @@ private static CategoryDataset buildDataSet(Map<LocalDate, JacocoCoverageResultS
dataSetBuilder.add((methodCoverage / count), "method", entry.getKey());
dataSetBuilder.add((branchCoverage / count), "branch", entry.getKey());
dataSetBuilder.add((instructionCoverage / count), "instruction", entry.getKey());

// XXX this should be a separate chart. the range axis is different.
dataSetBuilder.add((complexityScore / count), "complexity", entry.getKey());
}
@@ -29,15 +29,14 @@
*/
package hudson.plugins.jacoco.portlet.utils;

import hudson.model.Job;
import hudson.model.Result;
import hudson.model.Run;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;
import java.util.List;

import org.joda.time.LocalDate;
import hudson.model.Job;
import hudson.model.Result;
import hudson.model.Run;

/**
* Defines common methods that are used for the whole project.
@@ -68,7 +67,7 @@ public static int validateChartAttributes(String attribute, int defaultValue) {
if (attribute != null) {
if (attribute.equals("") || attribute.equals("0")) {
return defaultValue;
}
}

// Check if attribute value is a number
try {
@@ -81,7 +80,7 @@ public static int validateChartAttributes(String attribute, int defaultValue) {
} catch (NumberFormatException exception) {
return defaultValue;
}
}
}

return defaultValue;
}
@@ -95,16 +94,16 @@ public static int validateChartAttributes(String attribute, int defaultValue) {
* @return LocalDate the last date of all jobs that belogs to
* Dashboard View.
*/
public static LocalDate getLastDate(List<Job<?,?>> jobs) {
LocalDate lastDate = null;
public static Calendar getLastDate(List<Job<?,?>> jobs) {
Calendar lastDate = null;
for (Job<?,?> job : jobs) {
Run<?,?> lastRun = job.getLastCompletedBuild();
if (lastRun != null) {
LocalDate date = new LocalDate(lastRun.getTimestamp());
Calendar date = lastRun.getTimestamp();
if (lastDate == null) {
lastDate = date;
}
if (date.isAfter(lastDate)) {
if (date.after(lastDate)) {
lastDate = date;
}
}
@@ -128,8 +127,8 @@ public static float roundFloat(int scale, RoundingMode roundingMode, float value
bigDecimal = bigDecimal.setScale(scale, roundingMode);
return bigDecimal.floatValue();
}


public static int nthOccurrence(String str, char c, int n) {
int pos = str.indexOf(c, 0);
while (n-- > 0 && pos != -1)
@@ -158,5 +157,5 @@ public static Result applyLogicalAnd(Result op1, Result op2){
return Result.FAILURE;

}

}
@@ -1,15 +1,15 @@
package hudson.plugins.jacoco.portlet.utils;

import hudson.model.FreeStyleProject;
import hudson.model.Job;

import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.joda.time.LocalDate;
import org.jvnet.hudson.test.HudsonTestCase;

import hudson.model.FreeStyleProject;
import hudson.model.Job;

/**
* Test {@link hudson.plugins.jacoco.portlet.utils.Utils}
* through HudsonTestCase extension.
@@ -33,7 +33,7 @@ public void testGetLastDate() throws Exception {
jobs.add(prj);
jobs.add(prj2);

LocalDate lastDate = Utils.getLastDate(jobs);
Calendar lastDate = Utils.getLastDate(jobs);
assertNotNull(lastDate);
}

0 comments on commit f24f927

Please sign in to comment.
You can’t perform that action at this time.