Skip to content

Commit

Permalink
Initial idea of artifacts filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
judovana committed Apr 20, 2023
1 parent 979787c commit c3162d2
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 11 deletions.
43 changes: 41 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 @@ -6,6 +6,7 @@
import jenkins.model.Jenkins;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -50,7 +51,7 @@ public String toString() {
}
}

public LinkableCandidate toLinkable(String projectName) {
public LinkableCandidate toLinkable(String projectName, SearchArtifactsOptions searchArtifactsOptions) {
if (id != null) {
String pre = "";
String link;
Expand All @@ -65,7 +66,29 @@ public LinkableCandidate toLinkable(String projectName) {
if (artifacts.size()>0) {
post += " ("+artifacts.size()+" artifacts)";
}
return new LinkableCandidate(pre, link, post, getJenkinsUrl() + "/job/" + projectName + "/" + id);
List<LinkableCandidate> sublinks = new ArrayList<>(artifacts.size());
if(searchArtifactsOptions != null) {
for (Run.Artifact artifact : artifacts) {
for (String candidate : searchArtifactsOptions.query) {
if (searchArtifactsOptions.algorithm == 1 && searchArtifactsOptions.matched != null && searchArtifactsOptions.matched.contains(candidate)) {
continue;
}
boolean matches = NamableWithClass.matchSingle(artifact.relativePath, candidate, searchArtifactsOptions.how);
if (!searchArtifactsOptions.invert) {
if (matches) {
sublinks.add(new LinkableCandidate("", artifact.relativePath, "", getJenkinsUrl() + "/job/" + projectName + "/" + id + "/artifact/" + artifact.relativePath, new ArrayList<>(0)));
}
} else {
if (!matches) {
sublinks.add(new LinkableCandidate("", artifact.relativePath, "", getJenkinsUrl() + "/job/" + projectName + "/" + id + "/artifact/" + artifact.relativePath, new ArrayList<>(0)));
}
}


}
}
}
return new LinkableCandidate(pre, link, post, getJenkinsUrl() + "/job/" + projectName + "/" + id, sublinks);
} else {
return new LinkableCandidate(prefix + "n/a");
}
Expand All @@ -78,4 +101,20 @@ public static String getJenkinsUrl() {
public long getDateTime() {
return dateTime.getTime();
}

static class SearchArtifactsOptions {
private final String[] query;
private final int algorithm;
private final Collection<String> matched;
private final String how;
private final boolean invert;

public SearchArtifactsOptions(String[] query, int algorithm, Collection<String> matched, String how, boolean invert) {
this.query = query;
this.algorithm = algorithm;
this.matched = matched;
this.how = how;
this.invert = invert;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package hudson.plugins.nested_view.search;

import java.util.ArrayList;
import java.util.List;

public class LinkableCandidate {
private final String plainText;
private final boolean canLink;
private final String prefix;
private final String suffix;
private final String url;
private final List<LinkableCandidate> sublinks;

public LinkableCandidate(String prefix, String link, String suffix, String url) {
public LinkableCandidate(String prefix, String link, String suffix, String url, List<LinkableCandidate> sublinks) {
this.plainText = link;
this.canLink = true;
this.prefix = prefix;
this.suffix = suffix;
this.url = url;
this.sublinks = sublinks;
}

public LinkableCandidate(String plainText) {
Expand All @@ -21,6 +26,7 @@ public LinkableCandidate(String plainText) {
this.prefix = null;
this.suffix = null;
this.url = null;
this.sublinks = new ArrayList<LinkableCandidate>(0);
}

public String getPlainText() {
Expand All @@ -43,4 +49,7 @@ public boolean isCanLink() {
return canLink;
}

public List<LinkableCandidate> getSublinks() {
return sublinks;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ProjectWrapper {
private final int last;
private final int builds;
private final Query query;
private final BuildDetails.SearchArtifactsOptions artifactSearch;
private List<LinkableCandidate> details;
private final Collection<String> matched;
private int matchedBuildsCount;
Expand All @@ -42,6 +43,17 @@ public ProjectWrapper(Optional<AbstractProject> project, boolean multiline, bool
this.builds = builds;
this.query = query;
this.matched = matched;
if (query!=null) {
artifactSearch = new BuildDetails.SearchArtifactsOptions(
query.getWithoutArgumentsSplit(),
query.isSearchByArtifacts(),
matched,
query.getHow(),
query.isInvert()
);
} else {
artifactSearch = null;
}
if (isTimeLimit()) {
this.upperTimeLimit = query.getTimeLimit();
this.lowerTimeLimit = this.upperTimeLimit;
Expand Down Expand Up @@ -82,36 +94,36 @@ public List<LinkableCandidate> createDetailsImpl() {
if (s.contains("1")) {//-L1
BuildDetails lastBuild = specifiedBuild(" last build : ", project.get().getLastBuild());
setDateTime(lastBuild);
result.add(lastBuild.toLinkable(project.get().getName()));
result.add(lastBuild.toLinkable(project.get().getName(), artifactSearch));
}
if (s.contains("2")) {//-L2
BuildDetails lastStable = specifiedBuild(" last stable build : ", project.get().getLastStableBuild());
setDateTime(lastStable);
result.add(lastStable.toLinkable(project.get().getName()));
result.add(lastStable.toLinkable(project.get().getName(), artifactSearch));
}
if (s.contains("3")) {//-L3
BuildDetails lastSuc = specifiedBuild(" last success build : ", project.get().getLastSuccessfulBuild());
setDateTime(lastSuc);
result.add(lastSuc.toLinkable(project.get().getName()));
result.add(lastSuc.toLinkable(project.get().getName(), artifactSearch));
}
if (s.contains("4")) {//-L4
BuildDetails lastUnst = specifiedBuild(" last unstable build : ", project.get().getLastUnstableBuild());
result.add(lastUnst.toLinkable(project.get().getName()));
result.add(lastUnst.toLinkable(project.get().getName(), artifactSearch));
}
if (s.contains("5")) {//-L5
BuildDetails lastFail = specifiedBuild(" last failed build : ", project.get().getLastFailedBuild());
setDateTime(lastFail);
result.add(lastFail.toLinkable(project.get().getName()));
result.add(lastFail.toLinkable(project.get().getName(), artifactSearch));
}
if (s.contains("6")) {//-L6
BuildDetails lastUnsuc = specifiedBuild(" last unsuccess build : ", project.get().getLastUnsuccessfulBuild());
setDateTime(lastUnsuc);
result.add(lastUnsuc.toLinkable(project.get().getName()));
result.add(lastUnsuc.toLinkable(project.get().getName(), artifactSearch));
}
if (s.contains("7")) {//-L7
BuildDetails lastComp = specifiedBuild(" last completed build : ", project.get().getLastCompletedBuild());
setDateTime(lastComp);
result.add(lastComp.toLinkable(project.get().getName()));
result.add(lastComp.toLinkable(project.get().getName(), artifactSearch));
}
}

Expand Down Expand Up @@ -194,7 +206,7 @@ public List<LinkableCandidate> createDetailsImpl() {
}
if (builds >= 0) {
for (BuildDetails a : buildsList) {
LinkableCandidate linkableCandidate = a.toLinkable(project.get().getName());
LinkableCandidate linkableCandidate = a.toLinkable(project.get().getName(), artifactSearch);
result.add(linkableCandidate);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@
${detail.getPlainText()}
</j:otherwise>
</j:choose>
<j:if test="${detail.getSublinks().size() > 0}">
<j:if test="${hit.project.isMultiline()}">
<br/>
</j:if>
<j:forEach var="sublink" items="${detail.getSublinks()}" varStatus="status"> <!-- LinkableCandidate -->
<j:if test="${hit.project.isMultiline()}">
<st:nbsp/>*<st:nbsp/>
</j:if>
(${sublink.getPrefix()}<a href="${sublink.getUrl()}">${sublink.getPlainText()}</a>${sublink.getSuffix()})
<j:if test="${hit.project.isMultiline()}">
<j:if test="${!status.last}">
<br/>
</j:if>
</j:if>
</j:forEach>
</j:if>
<j:choose>
<j:when test="${hit.project.isMultiline()}">
<br/>
Expand Down

0 comments on commit c3162d2

Please sign in to comment.