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

Commit

Permalink
[JENKINS-17225] Provide a field to validate the task tags definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Sep 10, 2014
1 parent f24c281 commit 95eed9a
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 5 deletions.
56 changes: 56 additions & 0 deletions src/main/java/hudson/plugins/tasks/TasksDescriptor.java
@@ -1,7 +1,17 @@
package hudson.plugins.tasks;

import java.io.IOException;
import java.io.StringReader;
import java.util.Collection;

import org.apache.commons.lang3.StringUtils;
import org.kohsuke.stapler.QueryParameter;

import hudson.Extension;
import hudson.plugins.analysis.core.PluginDescriptor;
import hudson.plugins.tasks.parser.Task;
import hudson.plugins.tasks.parser.TaskScanner;
import hudson.util.FormValidation;

/**
* Descriptor for the class {@link TasksPublisher}. Used as a singleton. The
Expand Down Expand Up @@ -45,4 +55,50 @@ public String getIconUrl() {
public String getSummaryIconUrl() {
return ICONS_PREFIX + "tasks-48x48.png";
}

/**
* Validates the example text that will be scanned for open tasks.
*
* @param example the text to be scanned for open tasks
* @param high
* tag identifiers indicating high priority
* @param normal
* tag identifiers indicating normal priority
* @param low
* tag identifiers indicating low priority
* @param ignoreCase
* if case should be ignored during matching
* @param asRegexp
* if the identifiers should be treated as regular expression
* @return validation result
* @throws IOException if an error occurs
*/
public FormValidation doCheckExample(@QueryParameter final String example,
@QueryParameter final String high,
@QueryParameter final String normal,
@QueryParameter final String low,
@QueryParameter final boolean ignoreCase,
@QueryParameter final boolean asRegexp) throws IOException {
if (StringUtils.isEmpty(example)) {
return FormValidation.ok();
}

TaskScanner scanner = new TaskScanner(high, normal, low, ignoreCase, asRegexp);
if (scanner.isInvalidPattern()) {
return FormValidation.error(scanner.getErrorMessage());
}

Collection<Task> tasks = scanner.scan(new StringReader(example));
if (tasks.isEmpty()) {
return FormValidation.warning(Messages.Validation_NoTask());
}
else if (tasks.size() != 1) {
return FormValidation.warning(Messages.Validation_MultipleTasks(tasks.size()));
}
else {
Task task = tasks.iterator().next();
return FormValidation.ok(Messages.Validation_OneTask(task.getType(),
task.getDetailMessage()));
}
}
}
8 changes: 8 additions & 0 deletions src/main/java/hudson/plugins/tasks/parser/TaskScanner.java
Expand Up @@ -71,6 +71,14 @@ public TaskScanner(final String high, final String normal, final String low,
}
}

public boolean isInvalidPattern() {
return isInvalidPattern;
}

public String getErrorMessage() {
return errorMessage.toString();
}

/**
* Compiles a regular expression pattern to scan for tag identifiers.
*
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/hudson/plugins/tasks/Messages.properties
Expand Up @@ -34,3 +34,7 @@ Portlet.WarningsTable=Open tasks per project
Portlet.WarningsPriorityGraph=Open tasks trend graph (priority distribution)
Portlet.WarningsNewVsFixedGraph=Open tasks trend graph (new vs. fixed)
Portlet.WarningsTotalsGraph=Open tasks trend graph (totals)

Validation.NoTask=No open task!
Validation.OneTask=One open task: {0} - {1}
Validation.MultipleTasks={0} open tasks!
Expand Up @@ -28,4 +28,8 @@ NewTasksDetail.Name=Neue Offene Punkte
Portlet.WarningsTable=Offene Punkte pro Projekt
Portlet.WarningsPriorityGraph=Offene Punkte Trend Graph (Verteilung nach Priorität)
Portlet.WarningsNewVsFixedGraph=Offene Punkte Trend Graph (Verhältnis von neu zu behoben)
Portlet.WarningsTotalsGraph=Offene Punkte Trend Graph (Gesamtanzahl)
Portlet.WarningsTotalsGraph=Offene Punkte Trend Graph (Gesamtanzahl)

Validation.NoTask=Kein offener Punkt gefunden!
Validation.OneTask=Ein offener Punkt gefunden: {0} - {1}!
Validation.MultipleTasks={0} offene Punkte gefunden!
Expand Up @@ -3,7 +3,7 @@
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:u="/util" xmlns:c="/hudson/plugins/tasks/config">

<c:patterns />
<c:tasks descriptor="TasksPublisher"/>
<c:tasks />
<f:advanced>
<u:advanced id="tasks"/>
</f:advanced>
Expand Down
8 changes: 5 additions & 3 deletions src/main/resources/hudson/plugins/tasks/config/tasks.jelly
@@ -1,10 +1,9 @@
<!--
Section header
<%@attribute name="descriptor" required="true" %>
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define"
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<f:entry title="${%Tasks tags}" description="${%description.tags}">
<table>
<thead>
Expand Down Expand Up @@ -35,5 +34,8 @@
<f:entry title="${%Regular expression}" field="asRegexp" description="${%description.asRegexp}">
<f:checkbox name="asRegexp" checked="${instance.asRegexp}"/>
</f:entry>
<f:entry title="${%Example Text}" field="example" description="${%description.example}">
<f:textarea />
</f:entry>

</j:jelly>
Expand Up @@ -7,3 +7,5 @@ description.asRegexp=Treat the tag identifiers as regular expression. Note that
two capturing groups, the first one is interpreted as tag name, the second one as message. An example \
of such a regular expression would be ''^.*(TODO(?:[0-9]*))(.*)$''.
description.ignoreCase=Ignore the case of the the tag identifiers.
description.example=Enter an example message that will be scanned for open tasks with the \
properties specified in the entries above.
Expand Up @@ -4,6 +4,7 @@ Normal\ priority=Normale Priorit
Low\ priority=Niedrige Priorität
Ignore\ case=Groß-/Kleinschreibung ignorieren
Regular\ expression=Regulärer Ausdruck
Example\ Text=Beispieltext

description.tags=Konfiguriere die Texte, nach denen in den angegebenen Dateien gesucht werden soll. \
Für jede Priorität kann eine durch Kommas getrennte Liste von Texten definiert werden, z.B. TODO, FIXME, o.a. \
Expand All @@ -13,6 +14,8 @@ description.asRegexp=Interpretiere die Texte als regul
enthalten, die erste Gruppe enthält den zu suchenden Text, die zweite die Meldung des offenen Punktes. \
Ein Beispiel für solch einen regulären Ausdruck wäre ''^.*(TODO(?:[0-9]*))(.*)$''.
description.ignoreCase=Die Texte werden unabhängig von Groß-/Kleinschreibung analysiert.?
description.example=Hier kann ein Beispieltext eingegeben werden, um zu sehen, ob mit den \
oben angegebenen Parametern tatsächlich ein offener Punkt gefunden wird.



0 comments on commit 95eed9a

Please sign in to comment.