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

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-12424] Pulled up build result summary message to BuildResult.
  • Loading branch information
uhafner committed May 8, 2012
1 parent 0d18935 commit 882d057
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 1 deletion.
106 changes: 106 additions & 0 deletions src/main/java/hudson/plugins/analysis/core/BuildResult.java
Expand Up @@ -1177,6 +1177,112 @@ public String getReason() {
return reason;
}

/**
* Creates a default summary message for the build result. Typically, you
* can call this method in {@link #getSummary()} to create the actual
* visible user message.
*
* @param url
* the URL to the build results
* @param warnings
* number of warnings
* @param modules
* number of modules
* @return the summary message
*/
protected static String createDefaultSummary(final String url, final int warnings, final int modules) {
HtmlPrinter summary = new HtmlPrinter();

String message = createWarningsMessage(warnings);
if (warnings > 0) {
summary.append(summary.link(url, message));
}
else {
summary.append(message);
}
if (modules > 0) {
summary.append(" ");
summary.append(createAnalysesMessage(modules));
}
else {
summary.append(".");
}
return summary.toString();
}

private static String createAnalysesMessage(final int modules) {
if (modules == 1) {
return Messages.ResultAction_OneFile();
}
else {
return Messages.ResultAction_MultipleFiles(modules);
}
}

private static String createWarningsMessage(final int warnings) {
if (warnings == 1) {
return Messages.ResultAction_OneWarning();
}
else {
return Messages.ResultAction_MultipleWarnings(warnings);
}
}

/**
* Creates an HTML URL reference start tag.
*
* @param url the URL
* @return the HTML tag
*/
protected static String createUrl(final String url) {
return String.format("<a href=\"%s\">", url);
}

/**
* Creates a default delta message for the build result. Typically, you can
* call this method in {@link #createDeltaMessage()} to create the actual
* visible user message.
*
* @param url
* the URL to the build results
* @param newWarnings
* number of new warnings
* @param fixedWarnings
* number of fixed warnings
* @return the summary message
*/
protected static String createDefaultDeltaMessage(final String url, final int newWarnings, final int fixedWarnings) {
HtmlPrinter summary = new HtmlPrinter();
if (newWarnings > 0) {
summary.append(summary.item(
summary.link(url + "/new", createNewWarningsLinkName(newWarnings))));
}
if (fixedWarnings > 0) {
summary.append(summary.item(
summary.link(url + "/fixed", createFixedWarningsLinkName(fixedWarnings))));
}

return summary.toString();
}

private static String createNewWarningsLinkName(final int newWarnings) {
if (newWarnings == 1) {
return Messages.ResultAction_OneNewWarning();
}
else {
return Messages.ResultAction_MultipleNewWarnings(newWarnings);
}
}

private static String createFixedWarningsLinkName(final int fixedWarnings) {
if (fixedWarnings == 1) {
return Messages.ResultAction_OneFixedWarning();
}
else {
return Messages.ResultAction_MultipleFixedWarnings(fixedWarnings);
}
}

/**
* Returns a summary message for the summary.jelly file.
*
Expand Down
Expand Up @@ -26,7 +26,7 @@ public String toString() {
}

/**
* Adds a list item.
* Adds a hyperlink.
*
* @param url
* the link URL
Expand Down
Expand Up @@ -72,6 +72,15 @@ ResultAction.SuccessfulMultipleHighScore=New highscore: only successful builds f
ResultAction.SuccessfulOneNoHighScore=Still one day before reaching the previous successful builds highscore.
ResultAction.SuccessfulMultipleNoHighScore=Still {0} days before reaching the previous successful builds highscore.

ResultAction.OneWarning=1 warning
ResultAction.MultipleWarnings={0} warnings
ResultAction.OneNewWarning=1 new warning
ResultAction.MultipleNewWarnings={0} new warnings
ResultAction.OneFixedWarning=1 fixed warning
ResultAction.MultipleFixedWarnings={0} fixed warnings
ResultAction.OneFile=from one analysis.
ResultAction.MultipleFiles=from {0} analyses.

BuildResultEvaluator.success=no threshold has been exceeded
BuildResultEvaluator.failure.new.priority={0} new warnings of priority {3} exceed the threshold of {1} by {2}
BuildResultEvaluator.failure.all.priority={0} warnings of priority {3} exceed the threshold of {1} by {2}
Expand Down
Expand Up @@ -74,6 +74,15 @@ ResultAction.SuccessfulMultipleHighScore=Neuer Rekord: seit {0} Tagen gibt es nu
ResultAction.SuccessfulOneNoHighScore=Noch ein Tag, bis der alte "erfolgreiche Builds" Rekord gebrochen wird.
ResultAction.SuccessfulMultipleNoHighScore=Noch {0} Tage, bis der alte "erfolgreiche Builds" Rekord gebrochen wird.

ResultAction.OneWarning=eine Warnung
ResultAction.MultipleWarnings={0} Warnungen
ResultAction.OneNewWarning=eine neue Warnung
ResultAction.MultipleNewWarnings={0} neue Warnungen
ResultAction.OneFixedWarning=eine behobene Warnung
ResultAction.MultipleFixedWarnings={0} behobene Warnungen
ResultAction.OneFile=aus einer Analyse.
ResultAction.MultipleFiles=aus {0} Analysen.

BuildResultEvaluator.success=Kein Grenzwert wurde überschritten
BuildResultEvaluator.failure.new.priority={0} neue Warnungen der Priorität {3} haben die erlaubte Obergrenze von {1} um {2} überschritten
BuildResultEvaluator.failure.all.priority={0} Warnungen der Priorität {3} haben die erlaubte Obergrenze von {1} um {2} überschritten
Expand Down
Expand Up @@ -15,3 +15,12 @@ NewWarningsDetail.Name=Nouveaux Warnings

FilesParser.Error.NoPermission=Le fichier {0} est ignoré parce que nous n''avons pas les permissions pour le lire.
FilesParser.Error.EmptyFile=Le fichier {0} est ignoré parce qu''il est vide.

ResultAction.NoWarningsSince=Pas de warnings depuis le build {0}
ResultAction.OneWarning=1 warning
ResultAction.MultipleWarnings={0} warnings
ResultAction.OneNewWarning=1 nouveau warning
ResultAction.MultipleNewWarnings={0} nouveaux warnings
ResultAction.OneFixedWarning=1 warning corrigé
ResultAction.MultipleFixedWarnings={0} warnings corrigés

Expand Up @@ -73,6 +73,13 @@ ResultAction.SuccessfulMultipleHighScore=\u65b0\u8a18\u9332: {0}\u65e5\u9593\u30
ResultAction.SuccessfulOneNoHighScore=\u524d\u56de\u306e\u8a18\u9332\u307e\u3067\u3042\u30681\u65e5\u3067\u3059\u3002
ResultAction.SuccessfulMultipleNoHighScore=\u524d\u56de\u306e\u8a18\u9332\u307e\u3067\u3042\u3068{0}\u65e5\u3067\u3059\u3002

ResultAction.OneWarning=1\u500b\u306e\u8b66\u544a
ResultAction.MultipleWarnings={0}\u500b\u306e\u8b66\u544a
ResultAction.OneNewWarning=1\u500b\u306e\u65b0\u3057\u3044\u8b66\u544a
ResultAction.MultipleNewWarnings={0}\u500b\u306e\u65b0\u3057\u3044\u8b66\u544a
ResultAction.OneFixedWarning=1\u500b\u306e\u4fee\u6b63\u3055\u308c\u305f\u8b66\u544a
ResultAction.MultipleFixedWarnings={0}\u500b\u306e\u4fee\u6b63\u3055\u308c\u305f\u8b66\u544a

BuildResultEvaluator.success=\u95be\u5024\u3092\u8d85\u3048\u3066\u3044\u307e\u305b\u3093\u3002
BuildResultEvaluator.failure.new.priority={0} new warnings of priority {3} exceed the threshold of {1} by {2}
BuildResultEvaluator.failure.all.priority={0} warnings of priority {3} exceed the threshold of {1} by {2}
Expand Down
184 changes: 184 additions & 0 deletions src/test/java/hudson/plugins/analysis/core/BuildResultTest.java
@@ -0,0 +1,184 @@
package hudson.plugins.analysis.core;

import java.util.Locale;

import junit.framework.Assert;

import org.junit.Before;
import org.junit.Test;

/**
* Tests the class {@link BuildResult}.
*
* @author Ulli Hafner
*/
public class BuildResultTest {
/**
* Initializes the locale to English.
*/
@Before
public void initializeLocale() {
Locale.setDefault(Locale.ENGLISH);
}

/**
* Checks the text for no warnings from 0 files.
*/
@Test
public void test0WarningsIn0File() {
checkSummaryText(0, 0, "0 warnings.");
}

/**
* Checks the text for no warnings from 1 file.
*/
@Test
public void test0WarningsIn1File() {
checkSummaryText(0, 1, "0 warnings from one analysis.");
}

/**
* Checks the text for no warnings from 5 files.
*/
@Test
public void test0WarningsIn5Files() {
checkSummaryText(0, 5, "0 warnings from 5 analyses.");
}

/**
* Checks the text for 1 warning from 2 files.
*/
@Test
public void test1WarningIn2Files() {
checkSummaryText(1, 2, "<a href=\"findbugsResult\">1 warning</a> from 2 analyses.");
}

/**
* Checks the text for 5 warnings from 1 file.
*/
@Test
public void test5WarningsIn1File() {
checkSummaryText(5, 1, "<a href=\"findbugsResult\">5 warnings</a> from one analysis.");
}

/**
* Checks the text for 5 warnings from 0 file.
*/
@Test
public void test5WarningsIn0File() {
checkSummaryText(5, 0, "<a href=\"findbugsResult\">5 warnings</a>.");
}

/**
* Parameterized test case to check the message text for the specified
* number of warnings and files.
*
* @param numberOfWarnings
* the number of warnings
* @param numberOfFiles
* the number of files
* @param expectedMessage
* the expected message
*/
private void checkSummaryText(final int numberOfWarnings, final int numberOfFiles, final String expectedMessage) {
Assert.assertEquals("Wrong summary message created.", expectedMessage,
BuildResult.createDefaultSummary("findbugsResult", numberOfWarnings, numberOfFiles));
}

/**
* Checks the delta message for no new and no fixed warnings.
*/
@Test
public void testNoDelta() {
checkDeltaText(0, 0, "");
}

/**
* Checks the delta message for 1 new and no fixed warnings.
*/
@Test
public void testOnly1New() {
checkDeltaText(0, 1, "<li><a href=\"findbugsResult/new\">1 new warning</a></li>");
}

/**
* Checks the delta message for 5 new and no fixed warnings.
*/
@Test
public void testOnly5New() {
checkDeltaText(0, 5, "<li><a href=\"findbugsResult/new\">5 new warnings</a></li>");
}

/**
* Checks the delta message for 1 fixed and no new warnings.
*/
@Test
public void testOnly1Fixed() {
checkDeltaText(1, 0, "<li><a href=\"findbugsResult/fixed\">1 fixed warning</a></li>");
}

/**
* Checks the delta message for 5 fixed and no new warnings.
*/
@Test
public void testOnly5Fixed() {
checkDeltaText(5, 0, "<li><a href=\"findbugsResult/fixed\">5 fixed warnings</a></li>");
}

/**
* Checks the delta message for 5 fixed and 5 new warnings.
*/
@Test
public void test5New5Fixed() {
checkDeltaText(5, 5,
"<li><a href=\"findbugsResult/new\">5 new warnings</a></li>"
+ "<li><a href=\"findbugsResult/fixed\">5 fixed warnings</a></li>");
}

/**
* Checks the delta message for 5 fixed and 5 new warnings.
*/
@Test
public void test5New1Fixed() {
checkDeltaText(1, 5,
"<li><a href=\"findbugsResult/new\">5 new warnings</a></li>"
+ "<li><a href=\"findbugsResult/fixed\">1 fixed warning</a></li>");
}

/**
* Checks the delta message for 5 fixed and 5 new warnings.
*/
@Test
public void test1New5Fixed() {
checkDeltaText(5, 1,
"<li><a href=\"findbugsResult/new\">1 new warning</a></li>"
+ "<li><a href=\"findbugsResult/fixed\">5 fixed warnings</a></li>");
}

/**
* Checks the delta message for 5 fixed and 5 new warnings.
*/
@Test
public void test1New1Fixed() {
checkDeltaText(1, 1,
"<li><a href=\"findbugsResult/new\">1 new warning</a></li>"
+ "<li><a href=\"findbugsResult/fixed\">1 fixed warning</a></li>");
}

/**
* Parameterized test case to check the message text for the specified
* number of warnings and files.
*
* @param numberOfFixedWarnings
* the number of fixed warnings
* @param numberOfNewWarnings
* the number of new warnings
* @param expectedMessage
* the expected message
*/
private void checkDeltaText(final int numberOfFixedWarnings, final int numberOfNewWarnings, final String expectedMessage) {
Assert.assertEquals("Wrong delta message created.", expectedMessage,
BuildResult.createDefaultDeltaMessage("findbugsResult", numberOfNewWarnings, numberOfFixedWarnings));
}
}

0 comments on commit 882d057

Please sign in to comment.