Skip to content

Commit

Permalink
Search through builds now can discard old builds by yymmddhhmm limit
Browse files Browse the repository at this point in the history
  • Loading branch information
judovana committed Mar 23, 2023
1 parent 0171554 commit 77d7769
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 13 deletions.
15 changes: 11 additions & 4 deletions src/main/java/hudson/plugins/nested_view/NestedViewsSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException,
}
}
putToHistory(query, hits.size(), new Date());
switch (this.query.getSort()){
case 2: Collections.sort(hits, new NestedViewsSearchResult.DateComparator()); break;
case 3: Collections.sort(hits, new NestedViewsSearchResult.NameComparator()); break;
default: Collections.sort(hits, new NestedViewsSearchResult.LenghtComparator()); break;
switch (this.query.getSort()) {
case 2:
Collections.sort(hits, new NestedViewsSearchResult.DateComparator());
break;
case 3:
Collections.sort(hits, new NestedViewsSearchResult.NameComparator());
break;
default:
Collections.sort(hits, new NestedViewsSearchResult.LenghtComparator());
break;
}
} else {
Collections.sort(hits, new NestedViewsSearchResult.LenghtComparator());
Expand Down Expand Up @@ -161,6 +167,7 @@ public List<HelpItem> getSearchHelp() throws IOException {
r.add(new HelpItem("1", "default - by lenght of items"));
r.add(new HelpItem("2", "by date - requires B and/or L"));
r.add(new HelpItem("3", "alphabetically"));
r.add(new HelpItem("Tyymmddhhmm", "with B/S, will discard builds older then yymmddhhmm. Good with -t2"));
r.add(new HelpItem("Xn", "for NEXTn searches Nested View search will be turned off. n is optional number 1-9"));
r.add(new HelpItem("eg \"-Rjo: dacapo sp[ei]c\"", "will find all Jobs which Matches .*dacapo.* or .*sp[ei]c.* "));
r.add(new HelpItem(" Project/build details in search: ", ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -31,6 +30,8 @@ public class ProjectWrapper {
private final Collection<String> matched;
private int matchedBuildsCount;
private Date dateTime = new Date(Integer.MIN_VALUE);
private final Date upperTimeLimit;
private final Date lowerTimeLimit;

public ProjectWrapper(Optional<AbstractProject> project, boolean multiline, boolean projectInfo, int stats, int last, int builds, Query nvrSearch, Collection<String> matched) {
this.project = project;
Expand All @@ -41,6 +42,17 @@ public ProjectWrapper(Optional<AbstractProject> project, boolean multiline, bool
this.builds = builds;
this.nvrSearch = nvrSearch;
this.matched = matched;
if (isTimeLimit()) {
this.upperTimeLimit = nvrSearch.getTimeLimit();
this.lowerTimeLimit = this.upperTimeLimit;
} else {
upperTimeLimit = new Date(Long.MAX_VALUE);
lowerTimeLimit = new Date(Integer.MIN_VALUE);
}
}

private boolean isTimeLimit() {
return this.nvrSearch != null && this.nvrSearch.getTimeLimit() != null;
}

public List<LinkableCandidate> getDetails() {
Expand Down Expand Up @@ -140,26 +152,34 @@ public List<LinkableCandidate> createDetailsImpl() {
if (matches) {
BuildDetails bb = buildToString(b);
setDateTime(bb);
buildsList.add(bb);
if (isBuildTimeValid(b)) {
buildsList.add(bb);
}
}
} else {
if (!matches) {
BuildDetails bb = buildToString(b);
setDateTime(bb);
buildsList.add(bb);
if (isBuildTimeValid(b)) {
buildsList.add(bb);
}
}
}
}
} else {
BuildDetails bb = buildToString(b);
setDateTime(bb);
buildsList.add(bb);
if (isBuildTimeValid(b)) {
buildsList.add(bb);
}
}
}
if (i2 > 0) {
Integer counter = summ.getOrDefault(b.getResult(), 0);
counter = counter + 1;
summ.put(b.getResult(), counter);
if (isBuildTimeValid(b)) {
summ.put(b.getResult(), counter);
}
}
}
i1--;
Expand Down Expand Up @@ -187,6 +207,10 @@ public List<LinkableCandidate> createDetailsImpl() {
}
}

private boolean isBuildTimeValid(AbstractBuild b) {
return b.getTime().getTime() >= lowerTimeLimit.getTime();
}

private String resultToString(Result r) {
return (r == null) ? "RUNNING" : r.toString();
}
Expand Down
39 changes: 35 additions & 4 deletions src/main/java/hudson/plugins/nested_view/search/Query.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package hudson.plugins.nested_view.search;

import hudson.plugins.nested_view.NestedViewsSearch;
import hudson.plugins.nested_view.NestedViewsSearchFactory;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -22,6 +26,8 @@ public class Query {
private int last = -1;
private int sort = 1;

private String yymmddhhmm = null;

public String getOriginal() {
return original;
}
Expand Down Expand Up @@ -81,7 +87,7 @@ public Query(boolean search, String ooriginal) {
NestedViewsSearchFactory.setTmpSkip(n);
}
if ((query.contains("D") || query.contains("d"))) {
if(search) {
if (search) {
if (query.contains("D")) {
finalFilter = true;
searchByNvr = getNumber(query, "D", 1);
Expand All @@ -105,7 +111,7 @@ public Query(boolean search, String ooriginal) {
}
if (query.contains("S") && search) {
if (query.contains("SS")) {
statsTable = true;
statsTable = true;
}
stats = getNumber(query, "S", 10);
}
Expand All @@ -120,6 +126,15 @@ public Query(boolean search, String ooriginal) {
} else {
last = -1;
}
if (query.contains("T") && search) {
long time = getLongNumber(query, "T", 0);
String stime = "" + time;
if (stime.length() == 10) {
yymmddhhmm = stime;
} else {
NestedViewsSearch.LOGGER.log(Level.WARNING, "T have invlaid argument - " + stime + "; is not 10 chars of yymmddhhmm long");
}
}
if (query.contains("t")) {
sort = getNumber(query, "t", 1);
}
Expand Down Expand Up @@ -192,12 +207,16 @@ public String[] getWithoutArgumentsSplit() {


private int getNumber(String query, String switcher, int n) {
return (int) getLongNumber(query, switcher, n);
}

private long getLongNumber(String query, String switcher, long n) {
String l = query.replaceAll(".*" + switcher, "");
l = l.replaceAll("[^0-9].*", "");
try {
n = Integer.parseInt(l);
n = Long.parseLong(l);
} catch (Exception ex) {
//ok
NestedViewsSearch.LOGGER.log(Level.WARNING, "no reasonabl enumber from " + l, ex);
}
return n;
}
Expand Down Expand Up @@ -242,6 +261,18 @@ public boolean isInvert() {
return invert;
}

public Date getTimeLimit() {
try {
if (yymmddhhmm == null) {
return null;
}
return new SimpleDateFormat("yyMMddHHmm").parse(yymmddhhmm);
} catch (Exception ex) {
NestedViewsSearch.LOGGER.log(Level.WARNING, ex.toString(), ex);
return null;
}
}

public boolean isNonTrivial(boolean suggesting) {
final String loriginal;
if (original == null) {
Expand Down

0 comments on commit 77d7769

Please sign in to comment.