Skip to content

Commit

Permalink
Time is now recorded
Browse files Browse the repository at this point in the history
  • Loading branch information
judovana committed Mar 15, 2023
1 parent d931083 commit 1439fbe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/main/java/hudson/plugins/nested_view/search/BuildDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@
import hudson.model.Run;
import jenkins.model.Jenkins;

import java.util.Date;

public class BuildDetails {

private final String id;
private final String displayName;
private final String result;
private final String timeStampString;
private final String prefix;
private final Date dateTime;

public BuildDetails(String prefix, Run run) {
this(prefix, run.getId(), run.getDisplayName(), run.getResult(), run.getTimestampString());
this(prefix, run.getId(), run.getDisplayName(), run.getResult(), run.getTimestampString(), run.getTime());
}

public BuildDetails(String prefix, String id, String displayName, Result result, String timeStampString) {
public BuildDetails(String prefix, String id, String displayName, Result result, String timeStampString, Date dateTime) {
this.prefix = prefix;
this.id = id;
this.displayName = displayName;
this.result = result == null ? "RUNNING" : result.toString();
this.timeStampString = timeStampString;
this.dateTime = dateTime;
}

public String toString() {
Expand Down Expand Up @@ -57,4 +61,8 @@ public LinkableCandidate toLinkable(String projectName) {
public static String getJenkinsUrl() {
return Jenkins.get().getRootUrl().replaceAll("[\\/]+$", "");
}

public Date getDateTime() {
return dateTime;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand All @@ -28,6 +29,7 @@ public class ProjectWrapper {
private List<LinkableCandidate> details;
private final Collection<String> matched;
private int matchedBuildsCount;
private Date dateTime = new Date(Integer.MIN_VALUE);

public ProjectWrapper(Optional<AbstractProject> project, boolean multiline, boolean projectInfo, int stats, int last, int builds, Query nvrSearch, Collection<String> matched) {
this.project = project;
Expand Down Expand Up @@ -66,14 +68,17 @@ public List<LinkableCandidate> createDetailsImpl() {
//-L/L0 -all
if (s.contains("1")) {//-L1
BuildDetails lastBuild = specifiedBuild(" last build : ", project.get().getLastBuild());
setDateTime(lastBuild);
result.add(lastBuild.toLinkable(project.get().getName()));
}
if (s.contains("2")) {//-L2
BuildDetails lastStable = specifiedBuild(" last stable build : ", project.get().getLastStableBuild());
setDateTime(lastStable);
result.add(lastStable.toLinkable(project.get().getName()));
}
if (s.contains("3")) {//-L3
BuildDetails lastSuc = specifiedBuild(" last success build : ", project.get().getLastSuccessfulBuild());
setDateTime(lastSuc);
result.add(lastSuc.toLinkable(project.get().getName()));
}
if (s.contains("4")) {//-L4
Expand All @@ -82,14 +87,17 @@ public List<LinkableCandidate> createDetailsImpl() {
}
if (s.contains("5")) {//-L5
BuildDetails lastFail = specifiedBuild(" last failed build : ", project.get().getLastFailedBuild());
setDateTime(lastFail);
result.add(lastFail.toLinkable(project.get().getName()));
}
if (s.contains("6")) {//-L6
BuildDetails lastUnsuc = specifiedBuild(" last unsuccess build : ", project.get().getLastUnsuccessfulBuild());
setDateTime(lastUnsuc);
result.add(lastUnsuc.toLinkable(project.get().getName()));
}
if (s.contains("7")) {//-L7
BuildDetails lastComp = specifiedBuild(" last completed build : ", project.get().getLastCompletedBuild());
setDateTime(lastComp);
result.add(lastComp.toLinkable(project.get().getName()));
}
}
Expand Down Expand Up @@ -119,16 +127,22 @@ public List<LinkableCandidate> createDetailsImpl() {
boolean matches = NamableWithClass.matchSingle(displayName, candidate, nvrSearch.getHow());
if (!nvrSearch.isInvert()) {
if (matches) {
buildsList.add(buildToString(b));
BuildDetails bb = buildToString(b);
setDateTime(bb);
buildsList.add(bb);
}
} else {
if (!matches) {
buildsList.add(buildToString(b));
BuildDetails bb = buildToString(b);
setDateTime(bb);
buildsList.add(bb);
}
}
}
} else {
buildsList.add(buildToString(b));
BuildDetails bb = buildToString(b);
setDateTime(bb);
buildsList.add(bb);
}
}
if (i2 > 0) {
Expand Down Expand Up @@ -161,12 +175,20 @@ public List<LinkableCandidate> createDetailsImpl() {
}
}

private void setDateTime(BuildDetails build) {
dateTime = new Date(Math.max(dateTime.getTime(), build.getDateTime().getTime()));
}

public Date getDateTime() {
return dateTime;
}

public boolean isMultiline() {
return multiline;
}

private BuildDetails specifiedBuild(String s, Run lastBuild) {
return lastBuild != null ? new BuildDetails(s, lastBuild) : new BuildDetails(s, null, null, null, null);
return lastBuild != null ? new BuildDetails(s, lastBuild) : new BuildDetails(s, null, null, null, null, new Date(0));
}

private BuildDetails buildToString(Run ab) {
Expand Down

0 comments on commit 1439fbe

Please sign in to comment.