From babb012edfbe697c9605dc092ae535198e217b08 Mon Sep 17 00:00:00 2001 From: tobias Date: Sun, 12 Jun 2022 21:01:26 +0200 Subject: [PATCH] JENKINS-68740: Support ansible lint warning format Add optional additional colon after linting rule name to regex to support old format (prior ansible-lint 6.1.0) and new format --- .../hm/hafner/analysis/parser/AnsibleLintParser.java | 2 +- .../hafner/analysis/parser/AnsibleLintParserTest.java | 10 +++++++++- .../edu/hm/hafner/analysis/registry/ParsersTest.java | 2 +- .../edu/hm/hafner/analysis/parser/ansibleLint.txt | 2 ++ 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/hm/hafner/analysis/parser/AnsibleLintParser.java b/src/main/java/edu/hm/hafner/analysis/parser/AnsibleLintParser.java index 8a68ea65e..f5369e5f6 100644 --- a/src/main/java/edu/hm/hafner/analysis/parser/AnsibleLintParser.java +++ b/src/main/java/edu/hm/hafner/analysis/parser/AnsibleLintParser.java @@ -21,7 +21,7 @@ public class AnsibleLintParser extends LookaheadParser { private static final long serialVersionUID = 8481090596321427484L; - private static final String ANSIBLE_LINT_WARNING_PATTERN = "(.*)\\:([0-9]*)\\:\\s*\\[?([a-zA-Z0-9\\-]+)\\]?\\s(.*)"; + private static final String ANSIBLE_LINT_WARNING_PATTERN = "(.*)\\:([0-9]*)\\:\\s*\\[?([a-zA-Z0-9\\-]+)\\]?:?\\s(.*)"; /** * Creates a new instance of {@link AnsibleLintParser}. diff --git a/src/test/java/edu/hm/hafner/analysis/parser/AnsibleLintParserTest.java b/src/test/java/edu/hm/hafner/analysis/parser/AnsibleLintParserTest.java index aa00c8555..c0b9ae05a 100644 --- a/src/test/java/edu/hm/hafner/analysis/parser/AnsibleLintParserTest.java +++ b/src/test/java/edu/hm/hafner/analysis/parser/AnsibleLintParserTest.java @@ -20,7 +20,7 @@ class AnsibleLintParserTest extends AbstractParserTest { @Override protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) { - assertThat(report).hasSize(9); + assertThat(report).hasSize(10); Iterator iterator = report.iterator(); softly.assertThat(iterator.next()) @@ -86,6 +86,14 @@ protected void assertThatIssuesArePresent(final Report report, final SoftAsserti .hasLineEnd(11) .hasMessage("File permissions unset or incorrect") .hasFileName("/workspace/templates.yml"); + + softly.assertThat(iterator.next()) + .hasSeverity(Severity.WARNING_NORMAL) + .hasCategory("no-changed-when") + .hasLineStart(41) + .hasLineEnd(41) + .hasMessage("Commands should not change things if nothing needs doing.") + .hasFileName("/workspace/roles/create_service/tasks/main.yml"); } @Override diff --git a/src/test/java/edu/hm/hafner/analysis/registry/ParsersTest.java b/src/test/java/edu/hm/hafner/analysis/registry/ParsersTest.java index 88980eb91..b2d681190 100644 --- a/src/test/java/edu/hm/hafner/analysis/registry/ParsersTest.java +++ b/src/test/java/edu/hm/hafner/analysis/registry/ParsersTest.java @@ -624,7 +624,7 @@ void shouldFindAllAjcIssues() { /** Runs the AnsibleLint parser on an output file that contains 9 issues. */ @Test void shouldFindAllAnsibleLintIssues() { - findIssuesOfTool(9, "ansiblelint", "ansibleLint.txt"); + findIssuesOfTool(10, "ansiblelint", "ansibleLint.txt"); } /** diff --git a/src/test/resources/edu/hm/hafner/analysis/parser/ansibleLint.txt b/src/test/resources/edu/hm/hafner/analysis/parser/ansibleLint.txt index bda7d26f6..557d5eb91 100644 --- a/src/test/resources/edu/hm/hafner/analysis/parser/ansibleLint.txt +++ b/src/test/resources/edu/hm/hafner/analysis/parser/ansibleLint.txt @@ -9,3 +9,5 @@ /workspace/system.yml:20: risky-file-permissions File permissions unset or incorrect /workspace/upgrade.yml:38: no-handler Tasks that run when changed should likely be handlers /workspace/templates.yml:11: risky-file-permissions File permissions unset or incorrect + +/workspace/roles/create_service/tasks/main.yml:41: no-changed-when: Commands should not change things if nothing needs doing.