Skip to content

Commit 77d7769

Browse files
committed
Search through builds now can discard old builds by yymmddhhmm limit
1 parent 0171554 commit 77d7769

File tree

3 files changed

+75
-13
lines changed

3 files changed

+75
-13
lines changed

Diff for: src/main/java/hudson/plugins/nested_view/NestedViewsSearch.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,16 @@ public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException,
9898
}
9999
}
100100
putToHistory(query, hits.size(), new Date());
101-
switch (this.query.getSort()){
102-
case 2: Collections.sort(hits, new NestedViewsSearchResult.DateComparator()); break;
103-
case 3: Collections.sort(hits, new NestedViewsSearchResult.NameComparator()); break;
104-
default: Collections.sort(hits, new NestedViewsSearchResult.LenghtComparator()); break;
101+
switch (this.query.getSort()) {
102+
case 2:
103+
Collections.sort(hits, new NestedViewsSearchResult.DateComparator());
104+
break;
105+
case 3:
106+
Collections.sort(hits, new NestedViewsSearchResult.NameComparator());
107+
break;
108+
default:
109+
Collections.sort(hits, new NestedViewsSearchResult.LenghtComparator());
110+
break;
105111
}
106112
} else {
107113
Collections.sort(hits, new NestedViewsSearchResult.LenghtComparator());
@@ -161,6 +167,7 @@ public List<HelpItem> getSearchHelp() throws IOException {
161167
r.add(new HelpItem("1", "default - by lenght of items"));
162168
r.add(new HelpItem("2", "by date - requires B and/or L"));
163169
r.add(new HelpItem("3", "alphabetically"));
170+
r.add(new HelpItem("Tyymmddhhmm", "with B/S, will discard builds older then yymmddhhmm. Good with -t2"));
164171
r.add(new HelpItem("Xn", "for NEXTn searches Nested View search will be turned off. n is optional number 1-9"));
165172
r.add(new HelpItem("eg \"-Rjo: dacapo sp[ei]c\"", "will find all Jobs which Matches .*dacapo.* or .*sp[ei]c.* "));
166173
r.add(new HelpItem(" Project/build details in search: ", ""));

Diff for: src/main/java/hudson/plugins/nested_view/search/ProjectWrapper.java

+29-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.util.ArrayList;
44
import java.util.Arrays;
55
import java.util.Collection;
6-
import java.util.Comparator;
76
import java.util.Date;
87
import java.util.HashMap;
98
import java.util.Iterator;
@@ -31,6 +30,8 @@ public class ProjectWrapper {
3130
private final Collection<String> matched;
3231
private int matchedBuildsCount;
3332
private Date dateTime = new Date(Integer.MIN_VALUE);
33+
private final Date upperTimeLimit;
34+
private final Date lowerTimeLimit;
3435

3536
public ProjectWrapper(Optional<AbstractProject> project, boolean multiline, boolean projectInfo, int stats, int last, int builds, Query nvrSearch, Collection<String> matched) {
3637
this.project = project;
@@ -41,6 +42,17 @@ public ProjectWrapper(Optional<AbstractProject> project, boolean multiline, bool
4142
this.builds = builds;
4243
this.nvrSearch = nvrSearch;
4344
this.matched = matched;
45+
if (isTimeLimit()) {
46+
this.upperTimeLimit = nvrSearch.getTimeLimit();
47+
this.lowerTimeLimit = this.upperTimeLimit;
48+
} else {
49+
upperTimeLimit = new Date(Long.MAX_VALUE);
50+
lowerTimeLimit = new Date(Integer.MIN_VALUE);
51+
}
52+
}
53+
54+
private boolean isTimeLimit() {
55+
return this.nvrSearch != null && this.nvrSearch.getTimeLimit() != null;
4456
}
4557

4658
public List<LinkableCandidate> getDetails() {
@@ -140,26 +152,34 @@ public List<LinkableCandidate> createDetailsImpl() {
140152
if (matches) {
141153
BuildDetails bb = buildToString(b);
142154
setDateTime(bb);
143-
buildsList.add(bb);
155+
if (isBuildTimeValid(b)) {
156+
buildsList.add(bb);
157+
}
144158
}
145159
} else {
146160
if (!matches) {
147161
BuildDetails bb = buildToString(b);
148162
setDateTime(bb);
149-
buildsList.add(bb);
163+
if (isBuildTimeValid(b)) {
164+
buildsList.add(bb);
165+
}
150166
}
151167
}
152168
}
153169
} else {
154170
BuildDetails bb = buildToString(b);
155171
setDateTime(bb);
156-
buildsList.add(bb);
172+
if (isBuildTimeValid(b)) {
173+
buildsList.add(bb);
174+
}
157175
}
158176
}
159177
if (i2 > 0) {
160178
Integer counter = summ.getOrDefault(b.getResult(), 0);
161179
counter = counter + 1;
162-
summ.put(b.getResult(), counter);
180+
if (isBuildTimeValid(b)) {
181+
summ.put(b.getResult(), counter);
182+
}
163183
}
164184
}
165185
i1--;
@@ -187,6 +207,10 @@ public List<LinkableCandidate> createDetailsImpl() {
187207
}
188208
}
189209

210+
private boolean isBuildTimeValid(AbstractBuild b) {
211+
return b.getTime().getTime() >= lowerTimeLimit.getTime();
212+
}
213+
190214
private String resultToString(Result r) {
191215
return (r == null) ? "RUNNING" : r.toString();
192216
}

Diff for: src/main/java/hudson/plugins/nested_view/search/Query.java

+35-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package hudson.plugins.nested_view.search;
22

3+
import hudson.plugins.nested_view.NestedViewsSearch;
34
import hudson.plugins.nested_view.NestedViewsSearchFactory;
45

6+
import java.text.SimpleDateFormat;
7+
import java.util.Date;
8+
import java.util.logging.Level;
59
import java.util.regex.Matcher;
610
import java.util.regex.Pattern;
711

@@ -22,6 +26,8 @@ public class Query {
2226
private int last = -1;
2327
private int sort = 1;
2428

29+
private String yymmddhhmm = null;
30+
2531
public String getOriginal() {
2632
return original;
2733
}
@@ -81,7 +87,7 @@ public Query(boolean search, String ooriginal) {
8187
NestedViewsSearchFactory.setTmpSkip(n);
8288
}
8389
if ((query.contains("D") || query.contains("d"))) {
84-
if(search) {
90+
if (search) {
8591
if (query.contains("D")) {
8692
finalFilter = true;
8793
searchByNvr = getNumber(query, "D", 1);
@@ -105,7 +111,7 @@ public Query(boolean search, String ooriginal) {
105111
}
106112
if (query.contains("S") && search) {
107113
if (query.contains("SS")) {
108-
statsTable = true;
114+
statsTable = true;
109115
}
110116
stats = getNumber(query, "S", 10);
111117
}
@@ -120,6 +126,15 @@ public Query(boolean search, String ooriginal) {
120126
} else {
121127
last = -1;
122128
}
129+
if (query.contains("T") && search) {
130+
long time = getLongNumber(query, "T", 0);
131+
String stime = "" + time;
132+
if (stime.length() == 10) {
133+
yymmddhhmm = stime;
134+
} else {
135+
NestedViewsSearch.LOGGER.log(Level.WARNING, "T have invlaid argument - " + stime + "; is not 10 chars of yymmddhhmm long");
136+
}
137+
}
123138
if (query.contains("t")) {
124139
sort = getNumber(query, "t", 1);
125140
}
@@ -192,12 +207,16 @@ public String[] getWithoutArgumentsSplit() {
192207

193208

194209
private int getNumber(String query, String switcher, int n) {
210+
return (int) getLongNumber(query, switcher, n);
211+
}
212+
213+
private long getLongNumber(String query, String switcher, long n) {
195214
String l = query.replaceAll(".*" + switcher, "");
196215
l = l.replaceAll("[^0-9].*", "");
197216
try {
198-
n = Integer.parseInt(l);
217+
n = Long.parseLong(l);
199218
} catch (Exception ex) {
200-
//ok
219+
NestedViewsSearch.LOGGER.log(Level.WARNING, "no reasonabl enumber from " + l, ex);
201220
}
202221
return n;
203222
}
@@ -242,6 +261,18 @@ public boolean isInvert() {
242261
return invert;
243262
}
244263

264+
public Date getTimeLimit() {
265+
try {
266+
if (yymmddhhmm == null) {
267+
return null;
268+
}
269+
return new SimpleDateFormat("yyMMddHHmm").parse(yymmddhhmm);
270+
} catch (Exception ex) {
271+
NestedViewsSearch.LOGGER.log(Level.WARNING, ex.toString(), ex);
272+
return null;
273+
}
274+
}
275+
245276
public boolean isNonTrivial(boolean suggesting) {
246277
final String loriginal;
247278
if (original == null) {

0 commit comments

Comments
 (0)