import static org.sonar.api.rule.Severity.INFO;
import static org.sonar.api.rule.Severity.MAJOR;
import static org.sonar.api.rule.Severity.MINOR;
+import static org.sonar.api.utils.DateUtils.truncateToSeconds;
/**
* For each component, computes the measures related to number of issues:
}
Period period = periodHolder.getPeriod();
// Add one second to not take into account issues created during current analysis
- if (issue.creationDate().getTime() >= period.getSnapshotDate() + 1000L) {
+ if (issue.creationDate().getTime() > truncateToSeconds(period.getSnapshotDate())) {
currentCounters.addOnPeriod(issue);
}
}
import com.google.common.base.Predicate;
import com.google.common.collect.Lists;
import com.google.common.collect.Ordering;
-import java.util.Calendar;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import org.apache.commons.lang.time.DateUtils;
import org.sonar.core.issue.DefaultIssue;
import org.sonar.core.issue.FieldDiffs;
import org.sonar.db.issue.IssueChangeDto;
import org.sonar.server.issue.IssueFieldsSetter;
import static com.google.common.collect.FluentIterable.from;
+import static org.sonar.api.utils.DateUtils.truncateToSeconds;
/**
* Gets the issue debt that was introduced on a period. The algorithm
* Changelog have to be sorted from newest to oldest.
* Null date should be the first as this happen when technical debt has changed since previous analysis.
*/
- private static final Comparator<FieldDiffs> CHANGE_ORDERING = Ordering.natural().reverse().nullsFirst().onResultOf(new Function<FieldDiffs, Date>() {
- @Override
- public Date apply(@Nonnull FieldDiffs dto) {
- return dto.creationDate();
- }
- });
+ private static final Comparator<FieldDiffs> CHANGE_ORDERING = Ordering.natural().reverse().nullsFirst().onResultOf((Function<FieldDiffs, Date>) dto -> dto.creationDate());
public long calculate(DefaultIssue issue, Collection<IssueChangeDto> debtChangelog, Period period) {
- if (issue.creationDate().getTime() > period.getSnapshotDate() + 1000L) {
+ if (issue.creationDate().getTime() > truncateToSeconds(period.getSnapshotDate())) {
return MoreObjects.firstNonNull(issue.effortInMinutes(), 0L);
}
return calculateFromChangelog(issue, debtChangelog, period.getSnapshotDate());
}
private static boolean isBeforeOrEqual(@Nullable Date changeDate, Date periodDate) {
- return (changeDate != null) && (DateUtils.truncatedCompareTo(changeDate, periodDate, Calendar.SECOND) <= 0);
+ return (changeDate != null) && (truncateToSeconds(changeDate.getTime()) <= truncateToSeconds(periodDate.getTime()));
}
private static FieldDiffs.Diff debtDiff(FieldDiffs diffs) {
import static org.sonar.api.rule.Severity.MINOR;
import static org.sonar.api.rules.RuleType.BUG;
import static org.sonar.api.rules.RuleType.VULNERABILITY;
+import static org.sonar.api.utils.DateUtils.truncateToSeconds;
import static org.sonar.server.computation.task.projectanalysis.component.ComponentVisitor.Order.POST_ORDER;
import static org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit.LEAVES;
import static org.sonar.server.computation.task.projectanalysis.measure.Measure.newMeasureBuilder;
private static boolean isOnPeriod(DefaultIssue issue, Period period) {
// Add one second to not take into account issues created during current analysis
- return issue.creationDate().getTime() >= period.getSnapshotDate() + 1000L;
+ return issue.creationDate().getTime() > truncateToSeconds(period.getSnapshotDate());
}
}
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import java.io.Serializable;
-import java.time.Instant;
-import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.sonar.core.issue.tracking.Trackable;
import static java.lang.String.format;
+import static org.sonar.api.utils.DateUtils.truncateToSeconds;
public class DefaultIssue implements Issue, Trackable, org.sonar.api.ce.measure.Issue {
return this;
}
- @CheckForNull
- private static Date truncateToSeconds(@Nullable Date d) {
- if (d == null) {
- return null;
- }
- Instant instant = d.toInstant();
- instant = instant.truncatedTo(ChronoUnit.SECONDS);
- return Date.from(instant);
- }
-
@Override
@CheckForNull
public Date updateDate() {
return Date.from(date.toInstant().plus(numberOfDays, ChronoUnit.DAYS));
}
+ @CheckForNull
+ public static Date truncateToSeconds(@Nullable Date d) {
+ if (d == null) {
+ return null;
+ }
+ return truncateToSecondsImpl(d);
+ }
+
+ public static long truncateToSeconds(long dateTime) {
+ return truncateToSecondsImpl(new Date(dateTime)).getTime();
+ }
+
+ private static Date truncateToSecondsImpl(Date d) {
+ Instant instant = d.toInstant();
+ instant = instant.truncatedTo(ChronoUnit.SECONDS);
+ return Date.from(instant);
+ }
+
}