Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #21 from mixalturek/master
[JENKINS-23888] Add query parameter support for filtering errors based o...
  • Loading branch information
mixalturek committed Jul 27, 2014
2 parents 87401a0 + d48f4da commit 2a17c35
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 20 deletions.
Expand Up @@ -3,10 +3,10 @@
/**
* Status of comparison of two reports.
*
* Implementation note: The declaration order of the constants is significant,
* it's used in sorting.
* Implementation note: The upper case of the constants and declaration order
* are significant, the second one is used in sorting.
*
* @see CppcheckResult#diffCurrentAndPrevious()
* @see CppcheckResult#diffCurrentAndPrevious(java.util.Set)
* @author Michal Turek
*/
public enum CppcheckDiffState {
Expand Down
73 changes: 61 additions & 12 deletions src/main/java/org/jenkinsci/plugins/cppcheck/CppcheckResult.java
Expand Up @@ -18,13 +18,7 @@
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;

/**
* @author Gregory Boissinot
Expand Down Expand Up @@ -142,7 +136,8 @@ public Object getDynamic(final String link, final StaplerRequest request,
return null;
}

Collection<CppcheckWorkspaceFile> files = diffCurrentAndPrevious();
Set<CppcheckDiffState> filter = parseStatesFilter(request.getParameter("states"));
Collection<CppcheckWorkspaceFile> files = diffCurrentAndPrevious(filter);
int before = parseIntWithDefault(request.getParameter("before"), 5);
int after = parseIntWithDefault(request.getParameter("after"), 5);

Expand Down Expand Up @@ -170,6 +165,31 @@ public Object getDynamic(final String link, final StaplerRequest request,
return null;
}

/**
* Parse list of states.
*
* @param states
* comma separated list of states (will be transformed to uppercase)
* @return the parsed value or null if input is null
*/
private Set<CppcheckDiffState> parseStatesFilter(String states) {
if (states == null) {
return null;
}

Set<CppcheckDiffState> result = new HashSet<CppcheckDiffState>();

for (String state: states.toUpperCase().split(",")) {
try {
result.add(CppcheckDiffState.valueOf(state));
} catch (IllegalArgumentException e) {
// Ignore, input was broken
}
}

return result;
}

/**
* Parse integer.
*
Expand Down Expand Up @@ -340,10 +360,13 @@ public int getNumberErrorsAccordingConfiguration(
* a developer updates the source code somewhere above the issue. Move of
* the code to a different file e.g. during refactoring is not considered
* and one solved and one new issue will be highlighted in such case.
*
*
* @param filter
* put only issues of these types to the output, null for all
* @return the result of the comparison
*/
public Collection<CppcheckWorkspaceFile> diffCurrentAndPrevious() {
public Collection<CppcheckWorkspaceFile> diffCurrentAndPrevious(
Set<CppcheckDiffState> filter) {
CppcheckSourceContainer cur = getCppcheckSourceContainer();
CppcheckResult prevResult = getPreviousResult();
List<CppcheckWorkspaceFile> curValues
Expand All @@ -354,7 +377,7 @@ public Collection<CppcheckWorkspaceFile> diffCurrentAndPrevious() {
file.setDiffState(CppcheckDiffState.UNCHANGED);
}

return curValues;
return filterDiffOutput(curValues, filter);
}

CppcheckSourceContainer prev = prevResult.getCppcheckSourceContainer();
Expand Down Expand Up @@ -428,7 +451,33 @@ public int compare(CppcheckWorkspaceFile a, CppcheckWorkspaceFile b) {
}
});

return curValues;
return filterDiffOutput(curValues, filter);
}

/**
* Filter result of comparison.
*
* @param files
* input issues
* @param filter
* put only issues of these types to the output, null for all
* @return
*/
private Collection<CppcheckWorkspaceFile> filterDiffOutput(List<CppcheckWorkspaceFile> files,
Set<CppcheckDiffState> filter) {
if (filter == null) {
return files;
}

Collection<CppcheckWorkspaceFile> result = new ArrayList<CppcheckWorkspaceFile>();

for (CppcheckWorkspaceFile file: files) {
if (filter.contains(file.getDiffState())) {
result.add(file);
}
}

return result;
}

/**
Expand Down
@@ -1,7 +1,7 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:g="/jelly/cppcheck">
<st:header name="Content-Type" value="text/html;charset=UTF-8"/>

<j:set var="cachedContainer" value="${it.diffCurrentAndPrevious()}"/>
<j:set var="cachedContainer" value="${it.diffCurrentAndPrevious(null)}"/>

<h2>${%Details}</h2>

Expand All @@ -13,10 +13,15 @@
#cppcheckDetails .unchanged { }
#cppcheckDetails .inconclusive { color: #555555; }
</style>

<p><a href="source.all?before=5&amp;after=5">
${%Show all violations highlighted on a single page.}
</a></p>

<p>Show issues highlighted on a single page</p>
<ul>
<li><a href="source.all?before=5&amp;after=5">${%all}</a></li>
<li><a href="source.all?before=5&amp;after=5&amp;states=new,solved">${%new and solved}</a></li>
<li><a href="source.all?before=5&amp;after=5&amp;states=new">${%new}</a></li>
<li><a href="source.all?before=5&amp;after=5&amp;states=solved">${%solved}</a></li>
<li><a href="source.all?before=5&amp;after=5&amp;states=unchanged">${%unchanged}</a></li>
</ul>

<table class="pane sortable" id="cppcheckDetails">
<thead>
Expand Down
Expand Up @@ -23,6 +23,10 @@

<h1>${%Cppcheck Results}</h1>

<j:if test="${it.files.isEmpty()}">
<p>${%The result set is empty.}</p>
</j:if>

<j:forEach var="file" items="${it.files}">
<j:set var="inconclusiveCss" value=""/>
<j:if test="${file.cppcheckFile.inconclusive}">
Expand Down

0 comments on commit 2a17c35

Please sign in to comment.