Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

[Feature] Category filtering #93

Merged
merged 7 commits into from May 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -118,7 +118,7 @@
<connection>scm:git:git://github.com/jenkinsci/${project.artifactId}-plugin.git</connection>
<developerConnection>scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git</developerConnection>
<url>https://github.com/jenkinsci/${project.artifactId}-plugin</url>
<tag>HEAD</tag>
<tag>warnings-4.61</tag>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this required?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check if the ATH test still is running after the UI changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, I might have changed the tag to be able to create an installable hpi for our server. Should I leave it as HEAD?
I will also check the test suite again.

</scm>

<repositories>
Expand Down
25 changes: 23 additions & 2 deletions src/main/java/hudson/plugins/warnings/WarningsPublisher.java
Expand Up @@ -63,6 +63,8 @@ public class WarningsPublisher extends HealthAwarePublisher implements SimpleBui
private String excludePattern;
/** warning messages to exclude from report */
private String messagesPattern;
/** warning categories to exclude from report */
private String categoriesPattern;

/** File pattern and parser configurations. @since 3.19 */
@SuppressFBWarnings("SE")
Expand Down Expand Up @@ -170,6 +172,15 @@ public String getMessagesPattern() {
return messagesPattern;
}

/**
* Returns the Java regex pattern of warning categories to exclude from report.
*
* @return the Java regex pattern of warning categories to exclude from report
*/
public String getCategoriesPattern() {
return categoriesPattern;
}

/**
* Sets the Java regex pattern of warning messages to exclude from report.
*
Expand All @@ -180,6 +191,16 @@ public void setMessagesPattern(final String pattern) {
messagesPattern = pattern;
}

/**
* Sets the Java regex pattern of warning categories to exclude from report.
*
* @param pattern the pattern to exclude
*/
@DataBoundSetter
public void setCategoriesPattern(final String pattern) {
categoriesPattern = pattern;
}

/**
* Upgrade for release 4.5 or older.
*
Expand Down Expand Up @@ -374,9 +395,9 @@ private void handleRejectedException(final PluginLogger logger, final String par

private ParserResult filterWarnings(final ParserResult project, final PluginLogger logger) {
WarningsFilter filter = new WarningsFilter();
if (filter.isActive(getIncludePattern(), getExcludePattern(), getMessagesPattern())) {
if (filter.isActive(getIncludePattern(), getExcludePattern(), getMessagesPattern(), getCategoriesPattern())) {
Collection<FileAnnotation> filtered = filter.apply(project.getAnnotations(),
getIncludePattern(), getExcludePattern(), getMessagesPattern(), logger);
getIncludePattern(), getExcludePattern(), getMessagesPattern(), getCategoriesPattern(), logger);
return new ParserResult(filtered);
}
return project;
Expand Down
33 changes: 26 additions & 7 deletions src/main/java/hudson/plugins/warnings/parser/WarningsFilter.java
Expand Up @@ -21,7 +21,7 @@ public class WarningsFilter {
private final Set<Pattern> includePatterns = Sets.newHashSet();
private final Set<Pattern> excludePatterns = Sets.newHashSet();

private Set<Pattern> addPatterns(final @CheckForNull String pattern) {
private Set<Pattern> addFilePatterns(final @CheckForNull String pattern) {
Set<Pattern> patterns = Sets.newHashSet();
if (StringUtils.isNotBlank(pattern)) {
String[] split = StringUtils.split(pattern, ',');
Expand All @@ -34,6 +34,18 @@ private Set<Pattern> addPatterns(final @CheckForNull String pattern) {
return patterns;
}

private Set<Pattern> addStringPatterns(final @CheckForNull String pattern) {
Set<Pattern> patterns = Sets.newHashSet();
if (StringUtils.isNotBlank(pattern)) {
String[] split = StringUtils.split(pattern, '\n');
for (String singlePattern : split) {
String trimmed = StringUtils.trim(singlePattern);
patterns.add(Pattern.compile(trimmed)); // NOCHECKSTYLE
}
}
return patterns;
}

/**
* Filters te specified warnings by exclude and include patterns.
*
Expand All @@ -54,10 +66,12 @@ public Collection<FileAnnotation> apply(final Collection<FileAnnotation> allAnno
final @CheckForNull String includePattern,
final @CheckForNull String excludePattern,
final @CheckForNull String messagesPattern,
final @CheckForNull String categoriesPattern,
final PluginLogger logger) {
Collection<Pattern> includePatterns = addPatterns(includePattern);
Collection<Pattern> excludePatterns = addPatterns(excludePattern);
Collection<Pattern> messagesPatterns = addPatterns(messagesPattern);
Collection<Pattern> includePatterns = addFilePatterns(includePattern);
Collection<Pattern> excludePatterns = addFilePatterns(excludePattern);
Collection<Pattern> messagesPatterns = addStringPatterns(messagesPattern);
Collection<Pattern> categoriesPatterns = addStringPatterns(categoriesPattern);

Collection<FileAnnotation> includedAnnotations;
if (includePatterns.isEmpty()) {
Expand All @@ -73,7 +87,7 @@ public Collection<FileAnnotation> apply(final Collection<FileAnnotation> allAnno
}
}
}
if (excludePatterns.isEmpty() && messagesPatterns.isEmpty()) {
if (excludePatterns.isEmpty() && messagesPatterns.isEmpty() && categoriesPatterns.isEmpty()) {
return includedAnnotations;
}
else {
Expand All @@ -89,13 +103,18 @@ public Collection<FileAnnotation> apply(final Collection<FileAnnotation> allAnno
excludedAnnotations.remove(annotation);
}
}
for (Pattern exclude : categoriesPatterns) {
if (exclude.matcher(annotation.getCategory()).matches()) {
excludedAnnotations.remove(annotation);
}
}
}
logger.log(String.format("Found %d warnings after exclusion.", excludedAnnotations.size()));
return excludedAnnotations;
}
}

public boolean isActive(final String includePattern, final String excludePattern, final String messagesPattern) {
return StringUtils.isNotBlank(includePattern) || StringUtils.isNotBlank(excludePattern) || StringUtils.isNotBlank(messagesPattern);
public boolean isActive(final String includePattern, final String excludePattern, final String messagesPattern, final String categoriesPattern) {
return StringUtils.isNotBlank(includePattern) || StringUtils.isNotBlank(excludePattern) || StringUtils.isNotBlank(messagesPattern) || StringUtils.isNotBlank(categoriesPattern);
}
}
Expand Up @@ -21,7 +21,10 @@
<f:textbox />
</f:entry>
<f:entry title="${%Messages to ignore}" field="messagesPattern" description="${%description.messagesPattern}">
<f:textbox />
<f:expandableTextbox />
</f:entry>
<f:entry title="${%Categories to ignore}" field="categoriesPattern" description="${%description.categoriesPattern}">
<f:expandableTextbox />
</f:entry>

<u:failed />
Expand Down
Expand Up @@ -7,17 +7,21 @@ description.consoleLogParsers=The parsers to use when scanning the console log o
description.logFilesParsers=Workspace files to scan for compiler warnings using a predefined parser. \
If none of the parsers fits your project then you can create your own parser in the \
<a href="../../configure">system configuration</a> section.
description.includePattern=Comma separated list of \
<a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html">regular expressions</a> \
that specifies the files to include in the report (based on their absolute filename). \
description.includePattern=List of \
<a href="http://download.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">regular expressions</a> \
(one per line) that specifies the files to include in the report (based on their absolute filename). \
If this field is empty then all files are included.
description.excludePattern=Comma separated list of \
<a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html">regular expressions</a> \
that specifies the files to exclude from the report (based on their absolute filename).
description.messagesPattern=Comma separated list of \
<a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html">regular expressions</a>, \
that specifies the warning messages to exclude form the report (based on the warning messages). \
description.excludePattern=List of \
<a href="http://download.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">regular expressions</a> \
(one per line) that specifies the files to exclude from the report (based on their absolute filename).
description.messagesPattern=List of \
<a href="http://download.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">regular expressions</a>, \
(one per line) that specifies the warning messages to exclude form the report (based on the warning messages). \
If this field is empty then all warning messages are included.
description.categoriesPattern=List of \
<a href="http://download.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">regular expressions</a>, \
(one per line) that specifies the warning messages to exclude form the report (based on the warning categories). \
If this field is empty then all warning categories are included.

description.detectModules=Determines if Ant or Maven modules should be detected for all files that contain \
warnings. Activating this option may increase your build time since the detector scans the whole \
Expand Down
Expand Up @@ -2,31 +2,36 @@ description.consoleLogParsers=Diese Parser werden zum Analysieren der Konsolenau
Falls kein Parser ausgew�hlt wird, wird die Konsolenausgabe nicht untersucht.
description.logFilesParsers=Dateien aus dem Arbeitsbereich, die mit einem festdefiniertem Parser durchsucht werden sollen.

description.includePattern=Komma separierte Liste von \
<a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html">regul�ren Ausdr�cken</a>, \
description.includePattern=Liste von \
<a href="http://download.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">regul�ren Ausdr�cken</a>, \
die die Warnungen festlegt, die im Warnungsbericht erscheinen sollen (basierend auf deren Dateinamen). \
Bleibt das Feld leer, so werden alle gefundenen Warnungen �bernommen.
description.excludePattern=Komma separierte Liste von \
<a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html">regul�ren Ausdr�cken</a>, \
<a href="http://download.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">regul�ren Ausdr�cken</a>, \
die die Warnungen festlegt, die nicht im Warnungsbericht erscheinen sollen (basierend auf deren Dateinamen). \
Bleibt das Feld leer, so werden alle gefundenen Warnungen �bernommen.
description.messagesPattern=Komma separierte Liste von \
<a href="http://download.oracle.com/javase/1.5.0/docs/api/java/util/regex/Pattern.html">regul�ren Ausdr�cken</a>, \
die die Warnungen festlegt, die nicht im Warnungsbericht erscheinen sollen (basierend auf deren Warnmeldungen). \
description.messagesPattern=Liste von \
<a href="http://download.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">regul�ren Ausdr�cken</a>, \
(einer pro Zeile) die die Warnungen festlegt, die nicht im Warnungsbericht erscheinen sollen (basierend auf deren Warnmeldungen). \
Bleibt das Feld leer, so werden alle gefundenen Warnungen �bernommen.

description.categoriesPattern=Liste von \
<a href="http://download.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">regul�ren Ausdr�cken</a>, \
(einer pro Zeile) die die Warnungen festlegt, die nicht im Warnungsbericht erscheinen sollen (basierend auf deren Kategorien). \
Bleibt das Feld leer, so werden alle gefundenen Warnungen �bernommen.

Categories\ to\ ignore=Zu ignorierende Warnungskategorien
Messages\ to\ ignore=Zu ignorierende Warnmeldungen
Warnings\ to\ ignore=Zu ignorierende Warnungen
Warnings\ to\ include=Zu ber�cksichtigende Warnungen
Scan\ console\ log=Konsole durchsuchen
Scan\ workspace\ files=Dateien durchsuchen
Warnings\ to\ ignore=Zu ignorierende Warnungen
Warnings\ to\ include=Zu ber�cksichtigende Warnungen
Scan\ console\ log=Konsole durchsuchen
Scan\ workspace\ files=Dateien durchsuchen
Trend\ graph=Trend Graph
configure=Die Defaultwerte f�r die Konfiguration des Trends Graphen werden in einem eigenen Formular festgelegt.
description.detectModules=Bestimmt ob Dateien, die Warnungen enthalten, nach Projekten gruppiert werden sollen. \
Die Projektnamen werden aus den Ant oder Maven Konfigurationsdateien ermittelt und den Warnungen zugeordnet. \
Da dazu der gesamte Arbeitsbereich nach ''build.xml'' oder ''pom.xml'' Dateien durchsucht wird, kann je \
nach Gr��e des Arbeitsbereichs die Dauer eines Builds erheblich erh�ht werden.
Detect\ modules=Projekte automatisch erkennen
Resolve\ relative\ paths=Relative Pfade aufl�sen
Resolve\ relative\ paths=Relative Pfade aufl�sen
description.resolveRelativePaths=Falls aktiviert, werden relative Pfade f�r betroffene Dateien durch absolute Pfade ersetzt. \
Diese Operation ben�tigt viel Zeit in gro�en Arbeitsbereichen und sollte daher bei Performanceproblemen deaktiviert werden.
Diese Operation ben�tigt viel Zeit in gro�en Arbeitsbereichen und sollte daher bei Performanceproblemen deaktiviert werden.
Expand Up @@ -113,7 +113,8 @@ private Collection<FileAnnotation> parseAndFilter(final ParserRegistry parserReg
final String includePattern, final String excludePattern) throws IOException {
Collection<FileAnnotation> annotations = parserRegistry.parse(file);
final String messagesPattern = null;
return new WarningsFilter().apply(annotations, includePattern, excludePattern, messagesPattern, new NullLogger());
final String categoriesPattern = null;
return new WarningsFilter().apply(annotations, includePattern, excludePattern, messagesPattern, categoriesPattern, new NullLogger());
}

/**
Expand Down
Expand Up @@ -31,7 +31,27 @@ public void testMessagesPattern() {
WarningsFilter filter = new WarningsFilter();
// exclude warnings with this warning message from the report
final String excludeMessage = "Javadoc: Missing tag for parameter arg1";
warnings = filter.apply(warnings, null, null, excludeMessage, new NullLogger());
warnings = filter.apply(warnings, null, null, excludeMessage, null, new NullLogger());

assertFalse(warnings.contains(w1));
assertTrue(warnings.contains(w2));
}

/**
* Tests the exclusion of certain warning messages from the report (based on category).
*/
@Test
public void testCategoriesPattern() {
Warning w1 = new Warning("dummyFile.java", 0, "warningType", "-W#pragma-messages", "Warning. But ok.", Priority.LOW);
Warning w2 = new Warning("dummyFile.java", 0, "warningType", "-WWhatever", "Warning. Not ok!", Priority.LOW);
Collection<FileAnnotation> warnings = new LinkedList<FileAnnotation>();
warnings.add(w1);
warnings.add(w2);

WarningsFilter filter = new WarningsFilter();
// exclude warnings with this warning message from the report
final String excludeCategory = "-W#pragma-messages";
warnings = filter.apply(warnings, null, null, null, excludeCategory, new NullLogger());

assertFalse(warnings.contains(w1));
assertTrue(warnings.contains(w2));
Expand All @@ -40,5 +60,6 @@ public void testMessagesPattern() {
private Warning createDummyWarning(final String message) {
return new Warning("dummyFile.java", 0, "warningType", "warningCategory", message, Priority.LOW);
}

}