From bc8430f468c13339f24e5b479a574111108c5e69 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Wed, 2 Aug 2017 15:49:46 -0700 Subject: [PATCH 01/28] JENKINS-39284_Set_build_description_to_failure_cause JENKINS-39284 Add an option to the BFA configuration that, when enabled, sets the build description to the failure cause. --- .../jenkins/plugins/bfa/BuildFailureScanner.java | 13 +++++++++++++ .../jenkins/plugins/bfa/PluginImpl.java | 15 +++++++++++++++ .../jenkins/plugins/bfa/PluginImpl/config.jelly | 5 +++++ 3 files changed, 33 insertions(+) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index 56053e0f..51c09352 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -175,6 +175,19 @@ public static void scan(Run build, PrintStream buildLog) { printDownstream(buildLog, downstreamFailureCauses); } + if (PluginImpl.getInstance().isEnableBuildDescription() && !foundCauseList.isEmpty()) { + // create a build description text from the list of failures. + String buildDescription = ""; + if (foundCauseList.get(0).getCategories() != null) { + buildDescription = buildDescription.concat(foundCauseList.get(0).getCategories().get(0)); + buildDescription = buildDescription.concat(": "); + } + buildDescription = buildDescription.concat(" "); + buildDescription = buildDescription.concat(foundCauseList.get(0).getDescription()); + buildDescription = buildDescription.concat(""); + build.setDescription(buildDescription); + } + StatisticsLogger.getInstance().log(build, foundCauseListToLog); } catch (Exception e) { logger.log(Level.SEVERE, "Could not scan build " + build, e); diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java index ec41b6d7..3f4435d8 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java @@ -133,6 +133,7 @@ public class PluginImpl extends Plugin { private int nrOfScanThreads; private int maxLogSize; + private Boolean enableBuildDescription; private Boolean graphsEnabled; @@ -484,6 +485,19 @@ public int getMaxLogSize() { } + /** + * If enableBuildDescription is enabled or not. Build Descriptions will be set to a concatenated + * list of the failure descriptions as a convenience. + * @return True if enabled. + */ + public boolean isEnableBuildDescription() { + if (enableBuildDescription == null) { + return false; + } else { + return enableBuildDescription; + } + } + /** * Checks if the build with certain result should be analyzed or not. * @@ -584,6 +598,7 @@ public void configure(StaplerRequest req, JSONObject o) throws Descriptor.FormEx testResultParsingEnabled = o.getBoolean("testResultParsingEnabled"); testResultCategories = o.getString("testResultCategories"); maxLogSize = o.optInt("maxLogSize"); + enableBuildDescription = o.getBoolean("enableBuildDescription"); int scanThreads = o.getInt("nrOfScanThreads"); int minSodWorkerThreads = o.getInt("minimumNumberOfWorkerThreads"); int maxSodWorkerThreads = o.getInt("maximumNumberOfWorkerThreads"); diff --git a/src/main/resources/com/sonyericsson/jenkins/plugins/bfa/PluginImpl/config.jelly b/src/main/resources/com/sonyericsson/jenkins/plugins/bfa/PluginImpl/config.jelly index 103e440a..d56fe1f7 100644 --- a/src/main/resources/com/sonyericsson/jenkins/plugins/bfa/PluginImpl/config.jelly +++ b/src/main/resources/com/sonyericsson/jenkins/plugins/bfa/PluginImpl/config.jelly @@ -121,5 +121,10 @@ value="${it.maxLogSize}" default="${it.DEFAULT_MAX_LOG_SIZE}"/> + + + From 82fa4622cf352f9852271692c53ad133897ee298 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Fri, 11 Aug 2017 15:02:40 -0700 Subject: [PATCH 02/28] Add a setter for the enableBuildDescription option. --- .../com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java index 3f4435d8..5f35e4fe 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java @@ -485,6 +485,15 @@ public int getMaxLogSize() { } + /** + * Set option to append failure causes to job's build description + * + * @param enableBuildDescription should build description option be turned on + */ + public void setEnableBuildDescription(Boolean enableBuildDescription) { + this.enableBuildDescription = enableBuildDescription; + } + /** * If enableBuildDescription is enabled or not. Build Descriptions will be set to a concatenated * list of the failure descriptions as a convenience. From cae89da2f55a5e1b3aaaa126396026ac7cc3680e Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Fri, 11 Aug 2017 15:23:49 -0700 Subject: [PATCH 03/28] Refactor with a method specific to creating the build description using BFA categories and causes. --- .../plugins/bfa/BuildFailureScanner.java | 51 +++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index 51c09352..22002d02 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -176,16 +176,7 @@ public static void scan(Run build, PrintStream buildLog) { } if (PluginImpl.getInstance().isEnableBuildDescription() && !foundCauseList.isEmpty()) { - // create a build description text from the list of failures. - String buildDescription = ""; - if (foundCauseList.get(0).getCategories() != null) { - buildDescription = buildDescription.concat(foundCauseList.get(0).getCategories().get(0)); - buildDescription = buildDescription.concat(": "); - } - buildDescription = buildDescription.concat(" "); - buildDescription = buildDescription.concat(foundCauseList.get(0).getDescription()); - buildDescription = buildDescription.concat(""); - build.setDescription(buildDescription); + build.setDescription(generateDescriptionString(build, foundCauseList)); } StatisticsLogger.getInstance().log(build, foundCauseListToLog); @@ -479,4 +470,44 @@ private static List findFailedTests(final Run build, final Pr return failedTestList; } + + /** + * Generate text that can be used for the build description using categories and failure causes + * + * @param build to get current build description + * @param foundCauseList list of failure causes + * @return A String of the BFA categories and causes appended to the build's description. + */ + public static String generateDescriptionString(Run build, List foundCauseList) { + String buildDescription = ""; + // Append all of the categories. + if (foundCauseList.get(0) != null) { + for (int j = 0; j < foundCauseList.get(0).getCategories().size(); j++) { + buildDescription += ""; + buildDescription += foundCauseList.get(0).getCategories().get(j).toString(); + buildDescription += " "; + } + if (foundCauseList.get(0).getCategories().size() > 0) { + buildDescription += ": "; + } + } + + // Append all failure causes. + for (int i = 0; i < foundCauseList.size(); i++) { + buildDescription = buildDescription.concat(""); + buildDescription = buildDescription.concat(foundCauseList.get(i).getDescription()); + buildDescription = buildDescription.concat(""); + if (i < (foundCauseList.size() - 1)) { + buildDescription += " "; + } + } + buildDescription = buildDescription.concat(""); + + // Append this build description to any pre-existing build description + if (!(build.getDescription() == null) && !build.getDescription().isEmpty()) { + buildDescription = build.getDescription().concat("
\n"); + } + buildDescription.concat(buildDescription); + return buildDescription; + } } From c6a005c821131c2f13bf257f62b36f87e6d6d64a Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Fri, 11 Aug 2017 15:26:19 -0700 Subject: [PATCH 04/28] Add unit tests for the enableBuildDescription option. The tests are not as complete as I'd like because I'm not sure how to manipulate the build description before BFA scans the build. I'd like to test functionality with a build description already set such as might happen from another plugin. --- .../bfa/BuildFailureScannerHudsonTest.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java index f33e4e40..805f1bfc 100644 --- a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java +++ b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java @@ -102,6 +102,7 @@ public class BuildFailureScannerHudsonTest { private static final String BUILD_LOG = "ERROR: brief\n detail\n"; private static final String BUILD_LOG_FIRST_LINE = "ERROR: brief"; + private static final String BUILD_DESCRIPTION = "This is a build description."; private static final String DESCRIPTION = "The error was: ${1,1}${2,1}"; private static final String REGEX = "ERROR: (.*?)$"; private static final String MULTILINE_REGEX = "ERROR: (.*?)$.*? detail"; @@ -608,6 +609,116 @@ public boolean perform(AbstractBuild build, Launcher launcher, assertEquals("Amount of failure causes does not match.", 0, causeListFromAction.size()); } + /** + * Test enableBuildDescription = false does not append failure cause to build description + */ + @Test + public void testTestEnableBuildDescriptionIfDisabled() throws Exception { + PluginImpl.getInstance().setTestResultParsingEnabled(true); + PluginImpl.getInstance().setEnableBuildDescription(false); + FreeStyleProject project = jenkins.createFreeStyleProject(); + + project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); + project.getBuildersList().add(new TestBuilder() { + public boolean perform(AbstractBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, IOException { + build.getWorkspace().child("junit.xml").copyFrom( + this.getClass().getResource("junit.xml")); + return true; + } + }); + + project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); + + Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); + FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); + jenkins.assertBuildStatus(Result.UNSTABLE, build); + + FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); + assertNotNull(action); + + List causeListFromAction = action.getFoundFailureCauses(); + assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); + + // Start with some build description not assigned by BFA and run another scan. + action.getFoundFailureCauses(); + assertEquals(build.getDescription(), null); + } + + /** + * Test enableBuildDescription = true does append failure cause to existing build description + * without categories set + */ + @Test + public void testTestEnableBuildDescriptionWithoutCategoriesIfEnabled() throws Exception { + PluginImpl.getInstance().setTestResultParsingEnabled(true); + PluginImpl.getInstance().setEnableBuildDescription(true); + FreeStyleProject project = jenkins.createFreeStyleProject(); + + project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); + project.getBuildersList().add(new TestBuilder() { + public boolean perform(AbstractBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, IOException { + build.getWorkspace().child("junit.xml").copyFrom( + this.getClass().getResource("junit.xml")); + return true; + } + }); + + project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); + + Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); + FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); + jenkins.assertBuildStatus(Result.UNSTABLE, build); + + FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); + assertNotNull(action); + + List causeListFromAction = action.getFoundFailureCauses(); + assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); + String testDescription = "Here are details of the failure... More details"; + + assertEquals(testDescription, build.getDescription()); + } + + /** + * Test enableBuildDescription = true does append failure cause to existing build description + * with categories set + */ + @Test + public void testTestEnableBuildDescriptionWithCategoriesIfEnabled() throws Exception { + PluginImpl.getInstance().setTestResultParsingEnabled(true); + PluginImpl.getInstance().setEnableBuildDescription(true); + String categories = "foo bar"; + PluginImpl.getInstance().setTestResultCategories(categories); + FreeStyleProject project = jenkins.createFreeStyleProject(); + + project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); + project.getBuildersList().add(new TestBuilder() { + public boolean perform(AbstractBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, IOException { + build.getWorkspace().child("junit.xml").copyFrom( + this.getClass().getResource("junit.xml")); + return true; + } + }); + + project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); + + Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); + FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); + jenkins.assertBuildStatus(Result.UNSTABLE, build); + + FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); + assertNotNull(action); + + List causeListFromAction = action.getFoundFailureCauses(); + assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); + + String testDescription = "foo bar : Here are details of the failure... More details"; + assertEquals(build.getDescription(), testDescription); + } + /** * ArgumentMatcher for a Statistics object. */ From 764d9f34a1eb4c3473e9ad23e4946a8e34c92ac5 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Thu, 17 Aug 2017 15:10:41 -0700 Subject: [PATCH 05/28] Fix how BFA description gets concatenated to existing build description. --- .../sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index 22002d02..2f54e545 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -505,9 +505,8 @@ public static String generateDescriptionString(Run build, List\n"); + buildDescription = build.getDescription().concat("
\n").concat(buildDescription); } - buildDescription.concat(buildDescription); return buildDescription; } } From f4ebd34b5738f0c7f069c26d71643206faa1fc6e Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Thu, 17 Aug 2017 15:12:19 -0700 Subject: [PATCH 06/28] Change tests to include a pre-set build description. --- .../bfa/BuildFailureScannerHudsonTest.java | 98 ++++++++++--------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java index 805f1bfc..a0077d87 100644 --- a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java +++ b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java @@ -647,22 +647,63 @@ public boolean perform(AbstractBuild build, Launcher launcher, /** * Test enableBuildDescription = true does append failure cause to existing build description - * without categories set + * without categories set. */ @Test public void testTestEnableBuildDescriptionWithoutCategoriesIfEnabled() throws Exception { + PluginImpl.getInstance().setTestResultParsingEnabled(true); + PluginImpl.getInstance().setEnableBuildDescription(true); + FreeStyleProject project = jenkins.createFreeStyleProject(); + + // Test with a preset build description + project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); + project.getBuildersList().add(new TestBuilder() { + public boolean perform(AbstractBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, IOException { + build.getWorkspace().child("junit.xml").copyFrom(this.getClass().getResource("junit.xml")); + build.setDescription("Hello World"); + return true; + } + }); + + project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); + + Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); + FreeStyleBuild build = future.get(120, TimeUnit.SECONDS); + jenkins.assertBuildStatus(Result.UNSTABLE, build); + + FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); + assertNotNull(action); + + List causeListFromAction = action.getFoundFailureCauses(); + assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); + String testDescription = "Hello World
\n" + + "Here are details of the failure... More details"; + + assertEquals(testDescription, build.getDescription()); + } + + /** + * Test enableBuildDescription = true does append failure cause to existing build description + * with categories set + */ + @Test + public void testTestEnableBuildDescriptionWithCategoriesIfEnabled() throws Exception { PluginImpl.getInstance().setTestResultParsingEnabled(true); PluginImpl.getInstance().setEnableBuildDescription(true); + String categories = "foo bar"; + PluginImpl.getInstance().setTestResultCategories(categories); FreeStyleProject project = jenkins.createFreeStyleProject(); + // Test with a preset build description project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); project.getBuildersList().add(new TestBuilder() { - public boolean perform(AbstractBuild build, Launcher launcher, - BuildListener listener) throws InterruptedException, IOException { - build.getWorkspace().child("junit.xml").copyFrom( - this.getClass().getResource("junit.xml")); - return true; - } + public boolean perform(AbstractBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, IOException { + build.getWorkspace().child("junit.xml").copyFrom(this.getClass().getResource("junit.xml")); + build.setDescription("Hello World"); + return true; + } }); project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); @@ -676,47 +717,10 @@ public boolean perform(AbstractBuild build, Launcher launcher, List causeListFromAction = action.getFoundFailureCauses(); assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); - String testDescription = "Here are details of the failure... More details"; - assertEquals(testDescription, build.getDescription()); - } - - /** - * Test enableBuildDescription = true does append failure cause to existing build description - * with categories set - */ - @Test - public void testTestEnableBuildDescriptionWithCategoriesIfEnabled() throws Exception { - PluginImpl.getInstance().setTestResultParsingEnabled(true); - PluginImpl.getInstance().setEnableBuildDescription(true); - String categories = "foo bar"; - PluginImpl.getInstance().setTestResultCategories(categories); - FreeStyleProject project = jenkins.createFreeStyleProject(); - - project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); - project.getBuildersList().add(new TestBuilder() { - public boolean perform(AbstractBuild build, Launcher launcher, - BuildListener listener) throws InterruptedException, IOException { - build.getWorkspace().child("junit.xml").copyFrom( - this.getClass().getResource("junit.xml")); - return true; - } - }); - - project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); - - Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); - FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); - jenkins.assertBuildStatus(Result.UNSTABLE, build); - - FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); - assertNotNull(action); - - List causeListFromAction = action.getFoundFailureCauses(); - assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); - - String testDescription = "foo bar : Here are details of the failure... More details"; - assertEquals(build.getDescription(), testDescription); + String testDescription = "Hello World
\n" + + "foo bar : Here are details of the failure... More details"; + assertEquals(build.getDescription(), testDescription); } /** From 7412511364b59d2ea1b212f1045faab503876a51 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Wed, 2 Aug 2017 15:49:46 -0700 Subject: [PATCH 07/28] JENKINS-39284_Set_build_description_to_failure_cause JENKINS-39284 Add an option to the BFA configuration that, when enabled, sets the build description to the failure cause. --- .../jenkins/plugins/bfa/BuildFailureScanner.java | 13 +++++++++++++ .../jenkins/plugins/bfa/PluginImpl.java | 15 +++++++++++++++ .../jenkins/plugins/bfa/PluginImpl/config.jelly | 5 +++++ 3 files changed, 33 insertions(+) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index 87553f57..c478354f 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -187,6 +187,19 @@ public static void scan(Run build, PrintStream buildLog) { printDownstream(buildLog, downstreamFailureCauses); } + if (PluginImpl.getInstance().isEnableBuildDescription() && !foundCauseList.isEmpty()) { + // create a build description text from the list of failures. + String buildDescription = ""; + if (foundCauseList.get(0).getCategories() != null) { + buildDescription = buildDescription.concat(foundCauseList.get(0).getCategories().get(0)); + buildDescription = buildDescription.concat(": "); + } + buildDescription = buildDescription.concat(" "); + buildDescription = buildDescription.concat(foundCauseList.get(0).getDescription()); + buildDescription = buildDescription.concat(""); + build.setDescription(buildDescription); + } + StatisticsLogger.getInstance().log(build, foundCauseListToLog); } catch (Exception e) { logger.log(Level.SEVERE, "Could not scan build " + build, e); diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java index 656bb4f8..eb489219 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java @@ -133,6 +133,7 @@ public class PluginImpl extends Plugin { private int nrOfScanThreads; private int maxLogSize; + private Boolean enableBuildDescription; private Boolean graphsEnabled; @@ -485,6 +486,19 @@ public int getMaxLogSize() { } + /** + * If enableBuildDescription is enabled or not. Build Descriptions will be set to a concatenated + * list of the failure descriptions as a convenience. + * @return True if enabled. + */ + public boolean isEnableBuildDescription() { + if (enableBuildDescription == null) { + return false; + } else { + return enableBuildDescription; + } + } + /** * Checks if the build with certain result should be analyzed or not. * @@ -585,6 +599,7 @@ public void configure(StaplerRequest req, JSONObject o) throws Descriptor.FormEx testResultParsingEnabled = o.getBoolean("testResultParsingEnabled"); testResultCategories = o.getString("testResultCategories"); maxLogSize = o.optInt("maxLogSize"); + enableBuildDescription = o.getBoolean("enableBuildDescription"); int scanThreads = o.getInt("nrOfScanThreads"); int minSodWorkerThreads = o.getInt("minimumNumberOfWorkerThreads"); int maxSodWorkerThreads = o.getInt("maximumNumberOfWorkerThreads"); diff --git a/src/main/resources/com/sonyericsson/jenkins/plugins/bfa/PluginImpl/config.jelly b/src/main/resources/com/sonyericsson/jenkins/plugins/bfa/PluginImpl/config.jelly index b6dad645..1af9584e 100644 --- a/src/main/resources/com/sonyericsson/jenkins/plugins/bfa/PluginImpl/config.jelly +++ b/src/main/resources/com/sonyericsson/jenkins/plugins/bfa/PluginImpl/config.jelly @@ -122,5 +122,10 @@ value="${it.maxLogSize}" default="${it.DEFAULT_MAX_LOG_SIZE}"/> + + + From f57029df7ccc06764fb3db0c1238311592cb3c2c Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Fri, 11 Aug 2017 15:02:40 -0700 Subject: [PATCH 08/28] Add a setter for the enableBuildDescription option. --- .../com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java index eb489219..207548ef 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java @@ -486,6 +486,15 @@ public int getMaxLogSize() { } + /** + * Set option to append failure causes to job's build description + * + * @param enableBuildDescription should build description option be turned on + */ + public void setEnableBuildDescription(Boolean enableBuildDescription) { + this.enableBuildDescription = enableBuildDescription; + } + /** * If enableBuildDescription is enabled or not. Build Descriptions will be set to a concatenated * list of the failure descriptions as a convenience. From f3b2cab76ca517a1bd544b73020769545d2f37ac Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Fri, 11 Aug 2017 15:23:49 -0700 Subject: [PATCH 09/28] Refactor with a method specific to creating the build description using BFA categories and causes. --- .../plugins/bfa/BuildFailureScanner.java | 51 +++++++++++++++---- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index c478354f..453d67ce 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -188,16 +188,7 @@ public static void scan(Run build, PrintStream buildLog) { } if (PluginImpl.getInstance().isEnableBuildDescription() && !foundCauseList.isEmpty()) { - // create a build description text from the list of failures. - String buildDescription = ""; - if (foundCauseList.get(0).getCategories() != null) { - buildDescription = buildDescription.concat(foundCauseList.get(0).getCategories().get(0)); - buildDescription = buildDescription.concat(": "); - } - buildDescription = buildDescription.concat(" "); - buildDescription = buildDescription.concat(foundCauseList.get(0).getDescription()); - buildDescription = buildDescription.concat(""); - build.setDescription(buildDescription); + build.setDescription(generateDescriptionString(build, foundCauseList)); } StatisticsLogger.getInstance().log(build, foundCauseListToLog); @@ -491,4 +482,44 @@ private static List findFailedTests(final Run build, final Pr return failedTestList; } + + /** + * Generate text that can be used for the build description using categories and failure causes + * + * @param build to get current build description + * @param foundCauseList list of failure causes + * @return A String of the BFA categories and causes appended to the build's description. + */ + public static String generateDescriptionString(Run build, List foundCauseList) { + String buildDescription = ""; + // Append all of the categories. + if (foundCauseList.get(0) != null) { + for (int j = 0; j < foundCauseList.get(0).getCategories().size(); j++) { + buildDescription += ""; + buildDescription += foundCauseList.get(0).getCategories().get(j).toString(); + buildDescription += " "; + } + if (foundCauseList.get(0).getCategories().size() > 0) { + buildDescription += ": "; + } + } + + // Append all failure causes. + for (int i = 0; i < foundCauseList.size(); i++) { + buildDescription = buildDescription.concat(""); + buildDescription = buildDescription.concat(foundCauseList.get(i).getDescription()); + buildDescription = buildDescription.concat(""); + if (i < (foundCauseList.size() - 1)) { + buildDescription += " "; + } + } + buildDescription = buildDescription.concat(""); + + // Append this build description to any pre-existing build description + if (!(build.getDescription() == null) && !build.getDescription().isEmpty()) { + buildDescription = build.getDescription().concat("
\n"); + } + buildDescription.concat(buildDescription); + return buildDescription; + } } From 2c4ab5e80d6a09e260654baf20106f90c81ae20c Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Fri, 11 Aug 2017 15:26:19 -0700 Subject: [PATCH 10/28] Add unit tests for the enableBuildDescription option. The tests are not as complete as I'd like because I'm not sure how to manipulate the build description before BFA scans the build. I'd like to test functionality with a build description already set such as might happen from another plugin. --- .../bfa/BuildFailureScannerHudsonTest.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java index ac13b0c7..ec6feb3e 100644 --- a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java +++ b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java @@ -103,6 +103,7 @@ public class BuildFailureScannerHudsonTest { private static final String BUILD_LOG = "ERROR: brief\n detail\n"; private static final String BUILD_LOG_FIRST_LINE = "ERROR: brief"; + private static final String BUILD_DESCRIPTION = "This is a build description."; private static final String DESCRIPTION = "The error was: ${1,1}${2,1}"; private static final String REGEX = "ERROR: (.*?)$"; private static final String MULTILINE_REGEX = "ERROR: (.*?)$.*? detail"; @@ -609,6 +610,116 @@ public boolean perform(AbstractBuild build, Launcher launcher, assertEquals("Amount of failure causes does not match.", 0, causeListFromAction.size()); } + /** + * Test enableBuildDescription = false does not append failure cause to build description + */ + @Test + public void testTestEnableBuildDescriptionIfDisabled() throws Exception { + PluginImpl.getInstance().setTestResultParsingEnabled(true); + PluginImpl.getInstance().setEnableBuildDescription(false); + FreeStyleProject project = jenkins.createFreeStyleProject(); + + project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); + project.getBuildersList().add(new TestBuilder() { + public boolean perform(AbstractBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, IOException { + build.getWorkspace().child("junit.xml").copyFrom( + this.getClass().getResource("junit.xml")); + return true; + } + }); + + project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); + + Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); + FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); + jenkins.assertBuildStatus(Result.UNSTABLE, build); + + FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); + assertNotNull(action); + + List causeListFromAction = action.getFoundFailureCauses(); + assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); + + // Start with some build description not assigned by BFA and run another scan. + action.getFoundFailureCauses(); + assertEquals(build.getDescription(), null); + } + + /** + * Test enableBuildDescription = true does append failure cause to existing build description + * without categories set + */ + @Test + public void testTestEnableBuildDescriptionWithoutCategoriesIfEnabled() throws Exception { + PluginImpl.getInstance().setTestResultParsingEnabled(true); + PluginImpl.getInstance().setEnableBuildDescription(true); + FreeStyleProject project = jenkins.createFreeStyleProject(); + + project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); + project.getBuildersList().add(new TestBuilder() { + public boolean perform(AbstractBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, IOException { + build.getWorkspace().child("junit.xml").copyFrom( + this.getClass().getResource("junit.xml")); + return true; + } + }); + + project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); + + Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); + FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); + jenkins.assertBuildStatus(Result.UNSTABLE, build); + + FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); + assertNotNull(action); + + List causeListFromAction = action.getFoundFailureCauses(); + assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); + String testDescription = "Here are details of the failure... More details"; + + assertEquals(testDescription, build.getDescription()); + } + + /** + * Test enableBuildDescription = true does append failure cause to existing build description + * with categories set + */ + @Test + public void testTestEnableBuildDescriptionWithCategoriesIfEnabled() throws Exception { + PluginImpl.getInstance().setTestResultParsingEnabled(true); + PluginImpl.getInstance().setEnableBuildDescription(true); + String categories = "foo bar"; + PluginImpl.getInstance().setTestResultCategories(categories); + FreeStyleProject project = jenkins.createFreeStyleProject(); + + project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); + project.getBuildersList().add(new TestBuilder() { + public boolean perform(AbstractBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, IOException { + build.getWorkspace().child("junit.xml").copyFrom( + this.getClass().getResource("junit.xml")); + return true; + } + }); + + project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); + + Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); + FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); + jenkins.assertBuildStatus(Result.UNSTABLE, build); + + FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); + assertNotNull(action); + + List causeListFromAction = action.getFoundFailureCauses(); + assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); + + String testDescription = "foo bar : Here are details of the failure... More details"; + assertEquals(build.getDescription(), testDescription); + } + /** * ArgumentMatcher for a Statistics object. */ From 9d86903260045c90175cdeeb1abe549eb0fbbe3a Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Thu, 17 Aug 2017 15:10:41 -0700 Subject: [PATCH 11/28] Fix how BFA description gets concatenated to existing build description. --- .../sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index 453d67ce..8350bb72 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -517,9 +517,8 @@ public static String generateDescriptionString(Run build, List\n"); + buildDescription = build.getDescription().concat("
\n").concat(buildDescription); } - buildDescription.concat(buildDescription); return buildDescription; } } From 03e03c76cde968761a2f98f92d79b7448ddb1f16 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Thu, 17 Aug 2017 15:12:19 -0700 Subject: [PATCH 12/28] Change tests to include a pre-set build description. --- .../bfa/BuildFailureScannerHudsonTest.java | 98 ++++++++++--------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java index ec6feb3e..e4a63631 100644 --- a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java +++ b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java @@ -648,22 +648,63 @@ public boolean perform(AbstractBuild build, Launcher launcher, /** * Test enableBuildDescription = true does append failure cause to existing build description - * without categories set + * without categories set. */ @Test public void testTestEnableBuildDescriptionWithoutCategoriesIfEnabled() throws Exception { + PluginImpl.getInstance().setTestResultParsingEnabled(true); + PluginImpl.getInstance().setEnableBuildDescription(true); + FreeStyleProject project = jenkins.createFreeStyleProject(); + + // Test with a preset build description + project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); + project.getBuildersList().add(new TestBuilder() { + public boolean perform(AbstractBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, IOException { + build.getWorkspace().child("junit.xml").copyFrom(this.getClass().getResource("junit.xml")); + build.setDescription("Hello World"); + return true; + } + }); + + project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); + + Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); + FreeStyleBuild build = future.get(120, TimeUnit.SECONDS); + jenkins.assertBuildStatus(Result.UNSTABLE, build); + + FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); + assertNotNull(action); + + List causeListFromAction = action.getFoundFailureCauses(); + assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); + String testDescription = "Hello World
\n" + + "Here are details of the failure... More details"; + + assertEquals(testDescription, build.getDescription()); + } + + /** + * Test enableBuildDescription = true does append failure cause to existing build description + * with categories set + */ + @Test + public void testTestEnableBuildDescriptionWithCategoriesIfEnabled() throws Exception { PluginImpl.getInstance().setTestResultParsingEnabled(true); PluginImpl.getInstance().setEnableBuildDescription(true); + String categories = "foo bar"; + PluginImpl.getInstance().setTestResultCategories(categories); FreeStyleProject project = jenkins.createFreeStyleProject(); + // Test with a preset build description project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); project.getBuildersList().add(new TestBuilder() { - public boolean perform(AbstractBuild build, Launcher launcher, - BuildListener listener) throws InterruptedException, IOException { - build.getWorkspace().child("junit.xml").copyFrom( - this.getClass().getResource("junit.xml")); - return true; - } + public boolean perform(AbstractBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, IOException { + build.getWorkspace().child("junit.xml").copyFrom(this.getClass().getResource("junit.xml")); + build.setDescription("Hello World"); + return true; + } }); project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); @@ -677,47 +718,10 @@ public boolean perform(AbstractBuild build, Launcher launcher, List causeListFromAction = action.getFoundFailureCauses(); assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); - String testDescription = "Here are details of the failure... More details"; - assertEquals(testDescription, build.getDescription()); - } - - /** - * Test enableBuildDescription = true does append failure cause to existing build description - * with categories set - */ - @Test - public void testTestEnableBuildDescriptionWithCategoriesIfEnabled() throws Exception { - PluginImpl.getInstance().setTestResultParsingEnabled(true); - PluginImpl.getInstance().setEnableBuildDescription(true); - String categories = "foo bar"; - PluginImpl.getInstance().setTestResultCategories(categories); - FreeStyleProject project = jenkins.createFreeStyleProject(); - - project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); - project.getBuildersList().add(new TestBuilder() { - public boolean perform(AbstractBuild build, Launcher launcher, - BuildListener listener) throws InterruptedException, IOException { - build.getWorkspace().child("junit.xml").copyFrom( - this.getClass().getResource("junit.xml")); - return true; - } - }); - - project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); - - Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); - FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); - jenkins.assertBuildStatus(Result.UNSTABLE, build); - - FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); - assertNotNull(action); - - List causeListFromAction = action.getFoundFailureCauses(); - assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); - - String testDescription = "foo bar : Here are details of the failure... More details"; - assertEquals(build.getDescription(), testDescription); + String testDescription = "Hello World
\n" + + "foo bar : Here are details of the failure... More details"; + assertEquals(build.getDescription(), testDescription); } /** From 1bd3035e7a8336c1628d18939a8ad656208eecf8 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm <822454+TreverW@users.noreply.github.com> Date: Wed, 19 Feb 2020 17:25:53 -0800 Subject: [PATCH 13/28] Change tests to include a pre-set build description. --- .../jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java index 60e2425d..cda3c7fc 100644 --- a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java +++ b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java @@ -701,7 +701,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, */ @Test public void testTestEnableBuildDescriptionIfDisabled() throws Exception { -// PluginImpl.getInstance().setTestResultParsingEnabled(true); + PluginImpl.getInstance().setTestResultParsingEnabled(true); PluginImpl.getInstance().setEnableBuildDescription(false); FreeStyleProject project = jenkins.createFreeStyleProject(); @@ -721,7 +721,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); jenkins.assertBuildStatus(Result.UNSTABLE, build); - FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); + FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); assertNotNull(action); List causeListFromAction = action.getFoundFailureCauses(); From 1e3912a9933bd6220b7f12e6c5404e2092242a1b Mon Sep 17 00:00:00 2001 From: Trever Wilhelm <822454+TreverW@users.noreply.github.com> Date: Mon, 9 Mar 2020 15:58:58 -0700 Subject: [PATCH 14/28] Fix test expected files. --- .../jenkins/plugins/bfa/jcasc/jcasc-local-expected.yml | 1 + .../jenkins/plugins/bfa/jcasc/jcasc-mongo-expected.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-local-expected.yml b/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-local-expected.yml index d7e07b2e..bfd3b3dd 100644 --- a/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-local-expected.yml +++ b/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-local-expected.yml @@ -1,4 +1,5 @@ doNotAnalyzeAbortedJob: true +enableBuildDescription: false gerritTriggerEnabled: true globalEnabled: true graphsEnabled: false diff --git a/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-mongo-expected.yml b/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-mongo-expected.yml index c45d0da7..c823b95d 100644 --- a/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-mongo-expected.yml +++ b/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-mongo-expected.yml @@ -1,4 +1,5 @@ doNotAnalyzeAbortedJob: true +enableBuildDescription: false gerritTriggerEnabled: true globalEnabled: true graphsEnabled: false From 554f8a1db624a5331197572f875cd9e1237edfe0 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm <822454+TreverW@users.noreply.github.com> Date: Mon, 9 Mar 2020 16:10:09 -0700 Subject: [PATCH 15/28] Update Javadocs per checkstyle recommendations. --- .../plugins/bfa/BuildFailureScanner.java | 2 +- .../jenkins/plugins/bfa/PluginImpl.java | 2 +- .../bfa/BuildFailureScannerHudsonTest.java | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index 6966172a..68ca890f 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -540,7 +540,7 @@ private static List findFailedTests(final Run build, final Pr } /** - * Generate text that can be used for the build description using categories and failure causes + * Generate text that can be used for the build description using categories and failure causes. * * @param build to get current build description * @param foundCauseList list of failure causes diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java index 5d42a992..c29a59b4 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java @@ -596,7 +596,7 @@ public int getMaxLogSize() { /** - * Set option to append failure causes to job's build description + * Set option to append failure causes to job's build description. * * @param enableBuildDescription should build description option be turned on */ diff --git a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java index 92c01a23..00f5f428 100644 --- a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java +++ b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java @@ -697,7 +697,9 @@ public boolean perform(AbstractBuild build, Launcher launcher, } /** - * Test enableBuildDescription = false does not append failure cause to build description + * Test enableBuildDescription = false does not append failure cause to build description. + * + * @throws Exception if a build description is appended when the setting is set to false. */ @Test public void testTestEnableBuildDescriptionIfDisabled() throws Exception { @@ -735,6 +737,8 @@ public boolean perform(AbstractBuild build, Launcher launcher, /** * Test enableBuildDescription = true does append failure cause to existing build description * without categories set. + * + * @throws Exception if the build description is not appended when the setting is true. */ @Test public void testTestEnableBuildDescriptionWithoutCategoriesIfEnabled() throws Exception { @@ -764,15 +768,17 @@ public boolean perform(AbstractBuild build, Launcher launcher, List causeListFromAction = action.getFoundFailureCauses(); assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); - String testDescription = "Hello World
\n" + - "Here are details of the failure... More details"; + String testDescription = "Hello World
\n" + + "Here are details of the failure... More details"; assertEquals(testDescription, build.getDescription()); } /** - * Test enableBuildDescription = true does append failure cause to existing build description + * Test enableBuildDescription = true does append failure cause to existing build description. * with categories set + * + * @throws Exception if description is not appended correctly. */ @Test public void testTestEnableBuildDescriptionWithCategoriesIfEnabled() throws Exception { @@ -805,8 +811,8 @@ public boolean perform(AbstractBuild build, Launcher launcher, List causeListFromAction = action.getFoundFailureCauses(); assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); - String testDescription = "Hello World
\n" + - "foo bar : Here are details of the failure... More details"; + String testDescription = "Hello World
\n" + + "foo bar : Here are details of the failure... More details"; assertEquals(build.getDescription(), testDescription); } From 9a5ba0688ff794ed7b3cfac41bd6426b9964ecf4 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm <822454+TreverW@users.noreply.github.com> Date: Tue, 10 Mar 2020 16:15:02 -0700 Subject: [PATCH 16/28] Refactored naming to be consistent with rest of code. --- .../plugins/bfa/BuildFailureScanner.java | 2 +- .../jenkins/plugins/bfa/PluginImpl.java | 16 ++++++++-------- .../plugins/bfa/PluginImpl/config.jelly | 2 +- .../bfa/BuildFailureScannerHudsonTest.java | 18 +++++++++--------- .../plugins/bfa/jcasc/jcasc-local-expected.yml | 2 +- .../plugins/bfa/jcasc/jcasc-mongo-expected.yml | 2 +- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index 68ca890f..c6f10da5 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -240,7 +240,7 @@ public static void scan(Run build, PrintStream scanLog) { printDownstream(scanLog, downstreamFailureCauses); } - if (PluginImpl.getInstance().isEnableBuildDescription() && !foundCauseList.isEmpty()) { + if (PluginImpl.getInstance().isBuildDescriptionEnabled() && !foundCauseList.isEmpty()) { build.setDescription(generateDescriptionString(build, foundCauseList)); } diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java index c29a59b4..6bc737be 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java @@ -148,7 +148,7 @@ public class PluginImpl extends GlobalConfiguration { private int nrOfScanThreads; private int maxLogSize; - private Boolean enableBuildDescription; + private Boolean buildDescriptionEnabled; private Boolean graphsEnabled; @@ -598,22 +598,22 @@ public int getMaxLogSize() { /** * Set option to append failure causes to job's build description. * - * @param enableBuildDescription should build description option be turned on + * @param buildDescriptionEnabled should build description option be turned on */ - public void setEnableBuildDescription(Boolean enableBuildDescription) { - this.enableBuildDescription = enableBuildDescription; + public void setBuildDescriptionEnabled(Boolean buildDescriptionEnabled) { + this.buildDescriptionEnabled = buildDescriptionEnabled; } /** - * If enableBuildDescription is enabled or not. Build Descriptions will be set to a concatenated + * If buildDescriptionEnabled is enabled or not. Build Descriptions will be set to a concatenated * list of the failure descriptions as a convenience. * @return True if enabled. */ - public boolean isEnableBuildDescription() { - if (enableBuildDescription == null) { + public boolean isBuildDescriptionEnabled() { + if (buildDescriptionEnabled == null) { return false; } else { - return enableBuildDescription; + return buildDescriptionEnabled; } } diff --git a/src/main/resources/com/sonyericsson/jenkins/plugins/bfa/PluginImpl/config.jelly b/src/main/resources/com/sonyericsson/jenkins/plugins/bfa/PluginImpl/config.jelly index 4ee46506..eeadbcdb 100644 --- a/src/main/resources/com/sonyericsson/jenkins/plugins/bfa/PluginImpl/config.jelly +++ b/src/main/resources/com/sonyericsson/jenkins/plugins/bfa/PluginImpl/config.jelly @@ -89,7 +89,7 @@ - diff --git a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java index 00f5f428..b740da55 100644 --- a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java +++ b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java @@ -697,14 +697,14 @@ public boolean perform(AbstractBuild build, Launcher launcher, } /** - * Test enableBuildDescription = false does not append failure cause to build description. + * Test buildDescriptionEnabled = false does not append failure cause to build description. * * @throws Exception if a build description is appended when the setting is set to false. */ @Test - public void testTestEnableBuildDescriptionIfDisabled() throws Exception { + public void testTestBuildDescriptionEnabledIfDisabled() throws Exception { PluginImpl.getInstance().setTestResultParsingEnabled(true); - PluginImpl.getInstance().setEnableBuildDescription(false); + PluginImpl.getInstance().setBuildDescriptionEnabled(false); FreeStyleProject project = jenkins.createFreeStyleProject(); project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); @@ -735,15 +735,15 @@ public boolean perform(AbstractBuild build, Launcher launcher, } /** - * Test enableBuildDescription = true does append failure cause to existing build description + * Test buildDescriptionEnabled = true does append failure cause to existing build description * without categories set. * * @throws Exception if the build description is not appended when the setting is true. */ @Test - public void testTestEnableBuildDescriptionWithoutCategoriesIfEnabled() throws Exception { + public void testTestBuildDescriptionEnabledWithoutCategoriesIfEnabled() throws Exception { PluginImpl.getInstance().setTestResultParsingEnabled(true); - PluginImpl.getInstance().setEnableBuildDescription(true); + PluginImpl.getInstance().setBuildDescriptionEnabled(true); FreeStyleProject project = jenkins.createFreeStyleProject(); // Test with a preset build description @@ -775,15 +775,15 @@ public boolean perform(AbstractBuild build, Launcher launcher, } /** - * Test enableBuildDescription = true does append failure cause to existing build description. + * Test buildDescriptionEnabled = true does append failure cause to existing build description. * with categories set * * @throws Exception if description is not appended correctly. */ @Test - public void testTestEnableBuildDescriptionWithCategoriesIfEnabled() throws Exception { + public void testTestBuildDescriptionEnabledWithCategoriesIfEnabled() throws Exception { PluginImpl.getInstance().setTestResultParsingEnabled(true); - PluginImpl.getInstance().setEnableBuildDescription(true); + PluginImpl.getInstance().setBuildDescriptionEnabled(true); String categories = "foo bar"; PluginImpl.getInstance().setTestResultCategories(categories); FreeStyleProject project = jenkins.createFreeStyleProject(); diff --git a/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-local-expected.yml b/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-local-expected.yml index bfd3b3dd..25804386 100644 --- a/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-local-expected.yml +++ b/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-local-expected.yml @@ -1,5 +1,5 @@ +buildDescriptionEnabled: false doNotAnalyzeAbortedJob: true -enableBuildDescription: false gerritTriggerEnabled: true globalEnabled: true graphsEnabled: false diff --git a/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-mongo-expected.yml b/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-mongo-expected.yml index c823b95d..4781abec 100644 --- a/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-mongo-expected.yml +++ b/src/test/resources/com/sonyericsson/jenkins/plugins/bfa/jcasc/jcasc-mongo-expected.yml @@ -1,5 +1,5 @@ +buildDescriptionEnabled: false doNotAnalyzeAbortedJob: true -enableBuildDescription: false gerritTriggerEnabled: true globalEnabled: true graphsEnabled: false From 782c996a98b451128d1ebff9cc737ca8c9afe387 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Sun, 6 Sep 2020 23:28:41 -0700 Subject: [PATCH 17/28] Add suppression for MagicNumber Checkstyle check in test file. --- checkstyle-suppressions.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml index 72976b17..4bc5370b 100644 --- a/checkstyle-suppressions.xml +++ b/checkstyle-suppressions.xml @@ -12,4 +12,7 @@ + From 8d7b3fd14808fac6e8969508d746e8d63bd50f1c Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Sun, 6 Sep 2020 23:51:08 -0700 Subject: [PATCH 18/28] Refactor Boolean to boolean --- .../sonyericsson/jenkins/plugins/bfa/PluginImpl.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java index 44663910..a99cff5d 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java @@ -161,7 +161,7 @@ public class PluginImpl extends GlobalConfiguration { private int nrOfScanThreads; private int maxLogSize; - private Boolean buildDescriptionEnabled; + private boolean buildDescriptionEnabled; private Boolean graphsEnabled; @@ -686,8 +686,8 @@ public int getMaxLogSize() { * * @param buildDescriptionEnabled should build description option be turned on */ - public void setBuildDescriptionEnabled(Boolean buildDescriptionEnabled) { - this.buildDescriptionEnabled = buildDescriptionEnabled; + public void setBuildDescriptionEnabled(boolean buildDescriptionEnabled) { + this.buildDescriptionEnabled = buildDescriptionEnabled; } /** @@ -696,11 +696,7 @@ public void setBuildDescriptionEnabled(Boolean buildDescriptionEnabled) { * @return True if enabled. */ public boolean isBuildDescriptionEnabled() { - if (buildDescriptionEnabled == null) { - return false; - } else { return buildDescriptionEnabled; - } } /** From 848b9d14302fd4cdba5537df8094cb467503a6f1 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Sun, 6 Sep 2020 23:56:15 -0700 Subject: [PATCH 19/28] Test for null. https://github.com/jenkinsci/build-failure-analyzer-plugin/pull/72#discussion_r140747975 --- .../jenkins/plugins/bfa/BuildFailureScanner.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index c555c202..30548eb0 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -252,7 +252,6 @@ public static void scan(Run build, PrintStream scanLog) { notifySlackAllFail = true; } - if (PluginImpl.getInstance().isEnableBuildDescription() && !foundCauseList.isEmpty()) { if (PluginImpl.getInstance().isBuildDescriptionEnabled() && !foundCauseList.isEmpty()) { build.setDescription(generateDescriptionString(build, foundCauseList)); } @@ -677,12 +676,14 @@ public static String generateDescriptionString(Run build, List"); - buildDescription = buildDescription.concat(foundCauseList.get(i).getDescription()); - buildDescription = buildDescription.concat(""); - if (i < (foundCauseList.size() - 1)) { - buildDescription += " "; + if (foundCauseList.get(0) != null) { + for (int i = 0; i < foundCauseList.size(); i++) { + buildDescription = buildDescription.concat(""); + buildDescription = buildDescription.concat(foundCauseList.get(i).getDescription()); + buildDescription = buildDescription.concat(""); + if (i < (foundCauseList.size() - 1)) { + buildDescription += " "; + } } } buildDescription = buildDescription.concat(""); From de4785f2c035d128ab6f52557d2eb6b20d36603a Mon Sep 17 00:00:00 2001 From: Trever Wilhelm Date: Mon, 7 Sep 2020 00:11:44 -0700 Subject: [PATCH 20/28] Change type of test builder to QueueTaskFuture --- .../jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java index 4a894a6f..e7cff1bc 100644 --- a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java +++ b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java @@ -1055,7 +1055,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); - Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); + QueueTaskFuture future = project.scheduleBuild2(0, new Cause.UserIdCause()); FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); jenkins.assertBuildStatus(Result.UNSTABLE, build); @@ -1095,7 +1095,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); - Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); + QueueTaskFuture future = project.scheduleBuild2(0, new Cause.UserIdCause()); FreeStyleBuild build = future.get(120, TimeUnit.SECONDS); jenkins.assertBuildStatus(Result.UNSTABLE, build); @@ -1137,7 +1137,7 @@ public boolean perform(AbstractBuild build, Launcher launcher, project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); - Future future = project.scheduleBuild2(0, new Cause.UserIdCause()); + QueueTaskFuture future = project.scheduleBuild2(0, new Cause.UserIdCause()); FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); jenkins.assertBuildStatus(Result.UNSTABLE, build); From e483810184fe6d75ffd1e0b298c9019eb068a4e5 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm <822454+TreverW@users.noreply.github.com> Date: Mon, 7 Sep 2020 00:29:02 -0700 Subject: [PATCH 21/28] Update src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java Co-authored-by: Robert Sandell --- .../java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java index 6bc737be..77f95c46 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/PluginImpl.java @@ -600,6 +600,7 @@ public int getMaxLogSize() { * * @param buildDescriptionEnabled should build description option be turned on */ + @DataBoundSetter public void setBuildDescriptionEnabled(Boolean buildDescriptionEnabled) { this.buildDescriptionEnabled = buildDescriptionEnabled; } From bf9461cfe827cc2bfd5525a43b846e1ea0f11b7c Mon Sep 17 00:00:00 2001 From: Trever Wilhelm <822454+TreverW@users.noreply.github.com> Date: Mon, 7 Sep 2020 00:29:55 -0700 Subject: [PATCH 22/28] Update src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java Co-authored-by: Robert Sandell --- .../sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index c6f10da5..fb40c594 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -572,7 +572,7 @@ public static String generateDescriptionString(Run build, List"); // Append this build description to any pre-existing build description - if (!(build.getDescription() == null) && !build.getDescription().isEmpty()) { + if (StringUtilities.isNotEmpty(build.getDescription()) { buildDescription = build.getDescription().concat("
\n").concat(buildDescription); } return buildDescription; From 8df48d58c449b4254b9f021a302a95a3b2fb0783 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm <822454+TreverW@users.noreply.github.com> Date: Mon, 7 Sep 2020 00:35:51 -0700 Subject: [PATCH 23/28] Add suppression for MagicNumber Checkstyle check in test file. Remove line numbers as they may change frequently. --- checkstyle-suppressions.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml index 4bc5370b..87e3c4c7 100644 --- a/checkstyle-suppressions.xml +++ b/checkstyle-suppressions.xml @@ -13,6 +13,5 @@ files="InjectedTest.java"/> + files="BuildFailureScannerHudsonTest.java"/> From 2d3e9acf6c7c67290f91f18c348a6a4ece2ecbc0 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm <822454+TreverW@users.noreply.github.com> Date: Mon, 7 Sep 2020 00:49:50 -0700 Subject: [PATCH 24/28] Change to StringUtils --- .../sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index 04646036..50386023 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -50,6 +50,7 @@ import hudson.tasks.test.AbstractTestResultAction; import hudson.tasks.test.TestResult; import jenkins.model.Jenkins; +import org.apache.commons.lang.StringUtils; import javax.annotation.Nonnull; import java.io.BufferedReader; @@ -689,7 +690,7 @@ public static String generateDescriptionString(Run build, List"); // Append this build description to any pre-existing build description - if (StringUtilities.isNotEmpty(build.getDescription()) { + if (StringUtils.isNotEmpty(build.getDescription())) { buildDescription = build.getDescription().concat("
\n").concat(buildDescription); } return buildDescription; From 7dbb5719fdde1964a11223d7887796da3429bdaa Mon Sep 17 00:00:00 2001 From: Trever Wilhelm <822454+TreverW@users.noreply.github.com> Date: Mon, 7 Sep 2020 01:02:07 -0700 Subject: [PATCH 25/28] Removing unnecessary items per feedback to pull request. --- .../bfa/BuildFailureScannerHudsonTest.java | 41 ------------------- 1 file changed, 41 deletions(-) diff --git a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java index e7cff1bc..241acd46 100644 --- a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java +++ b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java @@ -1039,7 +1039,6 @@ public boolean perform(AbstractBuild build, Launcher launcher, */ @Test public void testTestBuildDescriptionEnabledIfDisabled() throws Exception { - PluginImpl.getInstance().setTestResultParsingEnabled(true); PluginImpl.getInstance().setBuildDescriptionEnabled(false); FreeStyleProject project = jenkins.createFreeStyleProject(); @@ -1070,46 +1069,6 @@ public boolean perform(AbstractBuild build, Launcher launcher, assertEquals(build.getDescription(), null); } - /** - * Test buildDescriptionEnabled = true does append failure cause to existing build description - * without categories set. - * - * @throws Exception if the build description is not appended when the setting is true. - */ - @Test - public void testTestBuildDescriptionEnabledWithoutCategoriesIfEnabled() throws Exception { - PluginImpl.getInstance().setTestResultParsingEnabled(true); - PluginImpl.getInstance().setBuildDescriptionEnabled(true); - FreeStyleProject project = jenkins.createFreeStyleProject(); - - // Test with a preset build description - project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); - project.getBuildersList().add(new TestBuilder() { - public boolean perform(AbstractBuild build, Launcher launcher, - BuildListener listener) throws InterruptedException, IOException { - build.getWorkspace().child("junit.xml").copyFrom(this.getClass().getResource("junit.xml")); - build.setDescription("Hello World"); - return true; - } - }); - - project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); - - QueueTaskFuture future = project.scheduleBuild2(0, new Cause.UserIdCause()); - FreeStyleBuild build = future.get(120, TimeUnit.SECONDS); - jenkins.assertBuildStatus(Result.UNSTABLE, build); - - FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); - assertNotNull(action); - - List causeListFromAction = action.getFoundFailureCauses(); - assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); - String testDescription = "Hello World
\n" - + "Here are details of the failure... More details"; - - assertEquals(testDescription, build.getDescription()); - } - /** * Test buildDescriptionEnabled = true does append failure cause to existing build description. * with categories set From 79774870bba6fccb05a916a17295eecffb136aba Mon Sep 17 00:00:00 2001 From: Trever Wilhelm <822454+TreverW@users.noreply.github.com> Date: Wed, 9 Sep 2020 13:22:15 -0700 Subject: [PATCH 26/28] Enable parsing test results in test method. Results are required in order to have an unstable build with failure causes identified in order to make sure the Build Description is not applied if the setting is disabled. --- .../bfa/BuildFailureScannerHudsonTest.java | 129 +++++++++--------- 1 file changed, 65 insertions(+), 64 deletions(-) diff --git a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java index 241acd46..eb5ac21c 100644 --- a/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java +++ b/src/test/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScannerHudsonTest.java @@ -1039,77 +1039,78 @@ public boolean perform(AbstractBuild build, Launcher launcher, */ @Test public void testTestBuildDescriptionEnabledIfDisabled() throws Exception { - PluginImpl.getInstance().setBuildDescriptionEnabled(false); - FreeStyleProject project = jenkins.createFreeStyleProject(); - - project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); - project.getBuildersList().add(new TestBuilder() { - public boolean perform(AbstractBuild build, Launcher launcher, - BuildListener listener) throws InterruptedException, IOException { - build.getWorkspace().child("junit.xml").copyFrom( - this.getClass().getResource("junit.xml")); - return true; - } - }); + PluginImpl.getInstance().setTestResultParsingEnabled(true); + PluginImpl.getInstance().setBuildDescriptionEnabled(false); + FreeStyleProject project = jenkins.createFreeStyleProject(); + + project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); + project.getBuildersList().add(new TestBuilder() { + public boolean perform(AbstractBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, IOException { + build.getWorkspace().child("junit.xml").copyFrom( + this.getClass().getResource("junit.xml")); + return true; + } + }); - project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); + project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); - QueueTaskFuture future = project.scheduleBuild2(0, new Cause.UserIdCause()); - FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); - jenkins.assertBuildStatus(Result.UNSTABLE, build); + QueueTaskFuture future = project.scheduleBuild2(0, new Cause.UserIdCause()); + FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); + jenkins.assertBuildStatus(Result.UNSTABLE, build); - FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); - assertNotNull(action); + FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); + assertNotNull(action); - List causeListFromAction = action.getFoundFailureCauses(); - assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); + List causeListFromAction = action.getFoundFailureCauses(); + assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); - // Start with some build description not assigned by BFA and run another scan. - action.getFoundFailureCauses(); - assertEquals(build.getDescription(), null); + // Start with some build description not assigned by BFA and run another scan. + action.getFoundFailureCauses(); + assertEquals(build.getDescription(), null); } - /** - * Test buildDescriptionEnabled = true does append failure cause to existing build description. - * with categories set - * - * @throws Exception if description is not appended correctly. - */ - @Test - public void testTestBuildDescriptionEnabledWithCategoriesIfEnabled() throws Exception { - PluginImpl.getInstance().setTestResultParsingEnabled(true); - PluginImpl.getInstance().setBuildDescriptionEnabled(true); - String categories = "foo bar"; - PluginImpl.getInstance().setTestResultCategories(categories); - FreeStyleProject project = jenkins.createFreeStyleProject(); - - // Test with a preset build description - project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); - project.getBuildersList().add(new TestBuilder() { - public boolean perform(AbstractBuild build, Launcher launcher, - BuildListener listener) throws InterruptedException, IOException { - build.getWorkspace().child("junit.xml").copyFrom(this.getClass().getResource("junit.xml")); - build.setDescription("Hello World"); - return true; - } - }); - - project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); - - QueueTaskFuture future = project.scheduleBuild2(0, new Cause.UserIdCause()); - FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); - jenkins.assertBuildStatus(Result.UNSTABLE, build); - - FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); - assertNotNull(action); - - List causeListFromAction = action.getFoundFailureCauses(); - assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); - - String testDescription = "Hello World
\n" - + "foo bar : Here are details of the failure... More details"; - assertEquals(build.getDescription(), testDescription); - } + /** + * Test buildDescriptionEnabled = true does append failure cause to existing build description. + * with categories set + * + * @throws Exception if description is not appended correctly. + */ + @Test + public void testTestBuildDescriptionEnabledWithCategoriesIfEnabled() throws Exception { + PluginImpl.getInstance().setTestResultParsingEnabled(true); + PluginImpl.getInstance().setBuildDescriptionEnabled(true); + String categories = "foo bar"; + PluginImpl.getInstance().setTestResultCategories(categories); + FreeStyleProject project = jenkins.createFreeStyleProject(); + + // Test with a preset build description + project.getBuildersList().add(new PrintToLogBuilder(BUILD_LOG)); + project.getBuildersList().add(new TestBuilder() { + public boolean perform(AbstractBuild build, Launcher launcher, + BuildListener listener) throws InterruptedException, IOException { + build.getWorkspace().child("junit.xml").copyFrom(this.getClass().getResource("junit.xml")); + build.setDescription("Hello World"); + return true; + } + }); + + project.getPublishersList().add(new JUnitResultArchiver("junit.xml", false, null)); + + QueueTaskFuture future = project.scheduleBuild2(0, new Cause.UserIdCause()); + FreeStyleBuild build = future.get(10, TimeUnit.SECONDS); + jenkins.assertBuildStatus(Result.UNSTABLE, build); + + FailureCauseBuildAction action = build.getAction(FailureCauseBuildAction.class); + assertNotNull(action); + + List causeListFromAction = action.getFoundFailureCauses(); + assertEquals("Amount of failure causes does not match.", 2, causeListFromAction.size()); + + String testDescription = "Hello World
\n" + + "foo bar : Here are details of the failure... More details"; + assertEquals(build.getDescription(), testDescription); + } /** * ArgumentMatcher for a Statistics object. From 9673b4752f1dccb93ec38030923d17dbce1585ee Mon Sep 17 00:00:00 2001 From: Trever Wilhelm <822454+TreverW@users.noreply.github.com> Date: Wed, 9 Sep 2020 15:35:36 -0700 Subject: [PATCH 27/28] Refactor string concatenation to eliminate spotbugs issue. --- .../plugins/bfa/BuildFailureScanner.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index 50386023..f805fead 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -663,36 +663,38 @@ private static List findFailedTests(final Run build, final Pr * @return A String of the BFA categories and causes appended to the build's description. */ public static String generateDescriptionString(Run build, List foundCauseList) { - String buildDescription = ""; - // Append all of the categories. + StringBuffer buildDescription = new StringBuffer(); + buildDescription.append(""); + if (foundCauseList.get(0) != null) { + for (int j = 0; j < foundCauseList.get(0).getCategories().size(); j++) { - buildDescription += ""; - buildDescription += foundCauseList.get(0).getCategories().get(j).toString(); - buildDescription += " "; + buildDescription.append(""); + buildDescription.append(foundCauseList.get(0).getCategories().get(j)); + buildDescription.append(" "); } if (foundCauseList.get(0).getCategories().size() > 0) { - buildDescription += ": "; + buildDescription.append(": "); } } // Append all failure causes. if (foundCauseList.get(0) != null) { for (int i = 0; i < foundCauseList.size(); i++) { - buildDescription = buildDescription.concat(""); - buildDescription = buildDescription.concat(foundCauseList.get(i).getDescription()); - buildDescription = buildDescription.concat(""); + buildDescription.append(""); + buildDescription.append(foundCauseList.get(i).getDescription()); + buildDescription.append(""); if (i < (foundCauseList.size() - 1)) { - buildDescription += " "; + buildDescription.append(" "); } } } - buildDescription = buildDescription.concat(""); + buildDescription.append(""); // Append this build description to any pre-existing build description if (StringUtils.isNotEmpty(build.getDescription())) { - buildDescription = build.getDescription().concat("
\n").concat(buildDescription); + buildDescription.insert(0,(build.getDescription().concat("
\n"))); } - return buildDescription; + return buildDescription.toString(); } } From 3ac164f32bfcdf728cdb1d36e4531b02f9883237 Mon Sep 17 00:00:00 2001 From: Trever Wilhelm <822454+TreverW@users.noreply.github.com> Date: Wed, 9 Sep 2020 16:09:49 -0700 Subject: [PATCH 28/28] Add space to fix another SpotBug isssue. --- .../sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java index f805fead..e8166993 100644 --- a/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java +++ b/src/main/java/com/sonyericsson/jenkins/plugins/bfa/BuildFailureScanner.java @@ -693,7 +693,7 @@ public static String generateDescriptionString(Run build, List\n"))); + buildDescription.insert(0, (build.getDescription().concat("
\n"))); } return buildDescription.toString(); }