Skip to content

Commit

Permalink
search now can see into artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
judovana committed Apr 20, 2023
1 parent 4331930 commit 64c8a5c
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 26 deletions.
14 changes: 10 additions & 4 deletions src/main/java/hudson/plugins/nested_view/NestedViewsSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,16 @@ public List<HelpItem> getSearchHelp() throws IOException {
r.add(new HelpItem("S x B x L", "S and B switches are iterating to the past. This may have significant performance impact! L should be fast always"));
r.add(new HelpItem("d",
"will search also in DisplayName. In addition it sets `-oB` as OR and Build details are required for it to work. The OR is enforcing you to filter jobs first and name as second"));
r.add(new HelpItem("D",
"Same as -d, but only projects with at least one matching build will be shown. -d/-D do not affect suggestions and can be acompanied by number - algorithm: "));
r.add(new HelpItem("1: ", "default, what mathced project name, is not used in displayName search. -! is weird here, not sure what to do better"));
r.add(new HelpItem("2: ", "all yor expressions are used used in displayName search"));
r.add(new HelpItem("i",
"will search also in artifacts. In addition it sets `-oB` as OR and Build details are required for it to work. The OR is enforcing you to filter jobs first and name as second"));
r.add(new HelpItem("A",
"is controlling, how many artifacts in most to search through. Default 10. Reasonable numbers ends in some 100. Without i/I useless"));
r.add(new HelpItem("D/I",
"Same as -d/-i, but only projects with at least one matching build will be shown. -d/-D -i/-I do not affect suggestions and can be acompanied by number - algorithm: "));
r.add(new HelpItem("1: ", "default, what mathced project name, is not used in displayName/artifact search. -! is weird here, not sure what to do better"));
r.add(new HelpItem("2: ", "all yor expressions are used used in displayName/artifact search"));
r.add(new HelpItem("note",
"Algortihm is shared between i/I/d/D if you set it once, yo can not unset it."));
return r;
}

Expand Down
19 changes: 15 additions & 4 deletions src/main/java/hudson/plugins/nested_view/search/BuildDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import hudson.model.Run;
import jenkins.model.Jenkins;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

public class BuildDetails {

Expand All @@ -15,19 +18,25 @@ public class BuildDetails {
private final String timeStampString;
private final String prefix;
private final Date dateTime;
private final List<Run.Artifact> artifacts;

public BuildDetails(String prefix, Run run) {
this(prefix, run.getId(), run.getDisplayName(), run.getResult(), run.getTimestampString(), run.getTime());
public BuildDetails(String prefix, Run run, int archives) {
this(prefix, run.getId(), run.getDisplayName(), run.getResult(), run.getTimestampString(), run.getTime(), archives>0?run.getArtifactsUpTo(archives):new ArrayList<Run.Artifact>(0));
}

@SuppressFBWarnings(value = {"EI_EXPOSE_REP2"}, justification = "date is not cared")
public BuildDetails(String prefix, String id, String displayName, Result result, String timeStampString, Date dateTime) {
public BuildDetails(String prefix, String id, String displayName, Result result, String timeStampString, Date dateTime, List<Run.Artifact> list) {
this.prefix = prefix;
this.id = id;
this.displayName = displayName;
this.result = result == null ? "RUNNING" : result.toString();
this.timeStampString = timeStampString;
this.dateTime = dateTime;
this.artifacts = (list==null?new ArrayList<>():list);
}

public List<String> getArtifacts() {
return artifacts.stream().map(a->a.relativePath).collect(Collectors.toList());
}

public String toString() {
Expand All @@ -53,7 +62,9 @@ public LinkableCandidate toLinkable(String projectName) {
post = id + "/" + displayName;
}
post = post + "/" + result + "/" + timeStampString + " ago";
;
if (artifacts.size()>0) {
post += " ("+artifacts.size()+" artifacts)";
}
return new LinkableCandidate(pre, link, post, getJenkinsUrl() + "/job/" + projectName + "/" + id);
} else {
return new LinkableCandidate(prefix + "n/a");
Expand Down
37 changes: 22 additions & 15 deletions src/main/java/hudson/plugins/nested_view/search/ProjectWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ public class ProjectWrapper {
private final int stats;
private final int last;
private final int builds;
private final Query nvrSearch;
private final Query query;
private List<LinkableCandidate> details;
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) {
public ProjectWrapper(Optional<AbstractProject> project, boolean multiline, boolean projectInfo, int stats, int last, int builds, Query query, Collection<String> matched) {
this.project = project;
this.multiline = multiline;
this.projectInfo = projectInfo;
this.stats = stats;
this.last = last;
this.builds = builds;
this.nvrSearch = nvrSearch;
this.query = query;
this.matched = matched;
if (isTimeLimit()) {
this.upperTimeLimit = nvrSearch.getTimeLimit();
this.upperTimeLimit = query.getTimeLimit();
this.lowerTimeLimit = this.upperTimeLimit;
} else {
upperTimeLimit = new Date(Long.MAX_VALUE);
Expand All @@ -52,7 +52,7 @@ public ProjectWrapper(Optional<AbstractProject> project, boolean multiline, bool
}

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

public List<LinkableCandidate> getDetails() {
Expand Down Expand Up @@ -122,7 +122,7 @@ public List<LinkableCandidate> createDetailsImpl() {
//-S, -Sn - stats ; we want to include also thsoe with 0 occurences, so the order is table like
Map<Result, Integer> summ = new HashMap<>();
//SS, prepopulate map
if (nvrSearch != null && nvrSearch.isStatsTable()) {
if (query != null && query.isStatsTable()) {
summ.put(Result.ABORTED, 0);
summ.put(Result.FAILURE, 0);
summ.put(Result.NOT_BUILT, 0);
Expand All @@ -141,14 +141,14 @@ public List<LinkableCandidate> createDetailsImpl() {
if (q instanceof AbstractBuild) {
AbstractBuild b = (AbstractBuild) q;
if (i1 > 0) {
if (nvrSearch != null && nvrSearch.isSearchByNvr() >= 0) {
for (String candidate : nvrSearch.getWithoutArgumentsSplit()) {
if (nvrSearch.isSearchByNvr() == 1 && matched != null && matched.contains(candidate)) {
if (query != null && query.isSearchByNvr() >= 0) {
for (String candidate : query.getWithoutArgumentsSplit()) {
if (query.isSearchByNvr() == 1 && matched != null && matched.contains(candidate)) {
continue;
}
String displayName = b.getDisplayName();
boolean matches = NamableWithClass.matchSingle(displayName, candidate, nvrSearch.getHow());
if (!nvrSearch.isInvert()) {
boolean matches = NamableWithClass.matchSingle(displayName, candidate, query.getHow());
if (!query.isInvert()) {
if (matches) {
BuildDetails bb = buildToString(b);
setDateTime(bb);
Expand Down Expand Up @@ -193,7 +193,10 @@ public List<LinkableCandidate> createDetailsImpl() {
}).map(a -> resultToString(a.getKey()) + ": " + a.getValue() + "x").collect(Collectors.joining(", "))));
}
if (builds >= 0) {
result.addAll(buildsList.stream().map(a -> a.toLinkable(project.get().getName())).collect(Collectors.toList()));
for (BuildDetails a : buildsList) {
LinkableCandidate linkableCandidate = a.toLinkable(project.get().getName());
result.add(linkableCandidate);
}
}
matchedBuildsCount = buildsList.size();
}
Expand Down Expand Up @@ -228,7 +231,11 @@ public boolean isMultiline() {
}

private BuildDetails specifiedBuild(String s, Run lastBuild) {
return lastBuild != null ? new BuildDetails(s, lastBuild) : new BuildDetails(s, null, null, null, null, new Date(0));
int archives = 0;
if (query.isSearchByArtifacts() > 0) {
archives = Math.max(0, query.getMaxArtifacts());
}
return lastBuild != null ? new BuildDetails(s, lastBuild, archives) : new BuildDetails(s, null, null, null, null, new Date(0), new ArrayList<>(0));
}

private BuildDetails buildToString(Run ab) {
Expand All @@ -237,10 +244,10 @@ private BuildDetails buildToString(Run ab) {

public boolean isStillValid() {
if (project.isPresent()) {
if (nvrSearch == null) {
if (query == null) {
return true;
} else {
if (nvrSearch.isFinalFilter() && matchedBuildsCount <= 0) {
if (query.isFinalFilter() && matchedBuildsCount <= 0) {
return false;
} else {
return true;
Expand Down
35 changes: 32 additions & 3 deletions src/main/java/hudson/plugins/nested_view/search/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class Query {

private boolean multiline;
private int searchByNvr = -1;
private int searchByArtifacts = -1;
private int maxArtifacts = -1;
private boolean finalFilter;
private boolean projectInfo;
private int stats = -1;
Expand Down Expand Up @@ -91,18 +93,37 @@ public Query(boolean search, String ooriginal) {
if (query.contains("D")) {
finalFilter = true;
searchByNvr = getNumber(query, "D", 1);
;
} else {
searchByNvr = getNumber(query, "d", 1);
;
}
}
bool = "o";
if (builds <= 0) { //maybe it was already set
builds = 10;
}
}

if ((query.contains("I") || query.contains("i"))) {
if (search) {
if (query.contains("I")) {
finalFilter = true;
searchByArtifacts = getNumber(query, "I", 1);
} else {
searchByArtifacts = getNumber(query, "i", 1);
}
}
bool = "o";
if (builds <= 0) { //maybe it was already set
builds = 10;
}
if (maxArtifacts <= 0) { //maybe it was already set
maxArtifacts = 10;
}
}
if (query.contains("A")) {
if (search) {
maxArtifacts = getNumber(query, "A", 10);
}
}
if (query.contains("m") && search) {
multiline = true;
}
Expand Down Expand Up @@ -253,6 +274,14 @@ public int isSearchByNvr() {
return searchByNvr;
}

public int isSearchByArtifacts() {
return searchByArtifacts;
}

public int getMaxArtifacts() {
return maxArtifacts;
}

public boolean isFinalFilter() {
return finalFilter;
}
Expand Down

0 comments on commit 64c8a5c

Please sign in to comment.