From 775c805b3112417ad32392696188ed19d6d0be80 Mon Sep 17 00:00:00 2001 From: KaIsa9 Date: Wed, 11 Jan 2023 19:10:13 +0200 Subject: [PATCH 01/12] Checkstyle pmd cpd and findbugs reports were added --- Jenkinsfile | 37 ++++++++++++++++++++++------ api/pom.xml | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 97 insertions(+), 10 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index eb1f9aec..4c9373f0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -16,16 +16,37 @@ pipeline { } stage('Test'){ steps{ - echo 'Test' - sh "pwd\n\ - cd api\n\ - mvn test" - } + script{ + echo 'Test' + sh "pwd\n\ + cd api\n\ + mvn test" + } + } } - stage('Deploy'){ + stage('Static code analysis'){ steps{ - echo 'Deploy' + script{ + echo 'Static code analysis' + sh "cd api\n\ + echo \"static code analysis finished\"\n\ + mvn -X clean pmd:pmd pmd:cpd findbugs:findbugs checkstyle:checkstyle \n\ + echo \"static code analysis finished\"" + } + + echo "Reading static analysis report" + recordIssues enabledForFailure: true, failOnError: false, tool:checkStyle(pattern: "**/target/checkstyle-result.xml") + recordIssues enabledForFailure: true, failOnError: false, tool:findBugs(pattern: "**/target/findbugs*.xml") + recordIssues enabledForFailure: true, failOnError: false, tool:cpd(pattern: "**/target/cpd.xml") + recordIssues enabledForFailure: true, failOnError: false, tool:pmdParser(pattern: "**/target/pmd.xml") } } } - } \ No newline at end of file + } +// def runStaticCodeAnalysis(){ +// withMaven(maven: "maven-387", publisherStrategy: 'EXPLICIT'){ +// sh "cd api\n\ +// echo \"static code analysis finished\"\n\ +// mvn -X clean checkstyle:checkstyle\n\ +// echo \"static code analysis finished\""} +// } \ No newline at end of file diff --git a/api/pom.xml b/api/pom.xml index 503a0d18..18e0820c 100755 --- a/api/pom.xml +++ b/api/pom.xml @@ -1,11 +1,12 @@ - + 4.0.0 org.springframework.boot spring-boot-starter-parent 2.7.3 - + com.github.throyer.common.spring-boot api @@ -19,6 +20,36 @@ 17 + + + + org.codehaus.mojo + findbugs-maven-plugin + 3.0.2 + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.2.0 + + + + checkstyle + + + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.17.0 + + 17 + + + + + @@ -192,6 +223,16 @@ spring-security-test test + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.2.0 + + + com.google.code.findbugs + jsr305 + 3.0.2 + @@ -246,6 +287,31 @@ + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.2.0 + + + verify-style + process-classes + + check + + + + + true + false + + + + com.puppycrawl.tools + checkstyle + 9.3 + + + \ No newline at end of file From 30c4203528c0944385892d92848a4a49a3f31aa4 Mon Sep 17 00:00:00 2001 From: KaIsa9 Date: Thu, 12 Jan 2023 12:50:50 +0200 Subject: [PATCH 02/12] jacoco report added --- Jenkinsfile | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 4c9373f0..98327507 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -20,8 +20,16 @@ pipeline { echo 'Test' sh "pwd\n\ cd api\n\ - mvn test" + mvn test jacoco:report" } + + publishHTML([ + allowMissing: true, + keepAll:true, + alwaysLinkToLastBuild: true, + reportDir: 'api/target/site/jacoco', + reportFiles: 'index.html', + reportName: 'Jacoco coverage HTML report']) } } stage('Static code analysis'){ From 51fc514c7b9ca429cd781866b4ab2bf752d431d1 Mon Sep 17 00:00:00 2001 From: kaisa9 Date: Fri, 3 Feb 2023 12:23:54 +0000 Subject: [PATCH 03/12] Jenkinsfile moved to the jenkins directory --- Jenkinsfile => .jenkins/Jenkinsfile | 49 +++++++++++------------------ 1 file changed, 19 insertions(+), 30 deletions(-) rename Jenkinsfile => .jenkins/Jenkinsfile (78%) diff --git a/Jenkinsfile b/.jenkins/Jenkinsfile similarity index 78% rename from Jenkinsfile rename to .jenkins/Jenkinsfile index 98327507..3e18e5b1 100644 --- a/Jenkinsfile +++ b/.jenkins/Jenkinsfile @@ -7,37 +7,16 @@ pipeline { steps{ echo 'Download dependencies' withMaven(maven:"maven-387", publisherStrategy: 'EXPLICIT'){ - sh "pwd\n\ - cd api \n\ - ls -la\n\ + sh "cd api \n\ mvn install -DskipTests" } } } - stage('Test'){ - steps{ - script{ - echo 'Test' - sh "pwd\n\ - cd api\n\ - mvn test jacoco:report" - } - - publishHTML([ - allowMissing: true, - keepAll:true, - alwaysLinkToLastBuild: true, - reportDir: 'api/target/site/jacoco', - reportFiles: 'index.html', - reportName: 'Jacoco coverage HTML report']) - } - } stage('Static code analysis'){ steps{ script{ echo 'Static code analysis' sh "cd api\n\ - echo \"static code analysis finished\"\n\ mvn -X clean pmd:pmd pmd:cpd findbugs:findbugs checkstyle:checkstyle \n\ echo \"static code analysis finished\"" } @@ -50,11 +29,21 @@ pipeline { } } } - } -// def runStaticCodeAnalysis(){ -// withMaven(maven: "maven-387", publisherStrategy: 'EXPLICIT'){ -// sh "cd api\n\ -// echo \"static code analysis finished\"\n\ -// mvn -X clean checkstyle:checkstyle\n\ -// echo \"static code analysis finished\""} -// } \ No newline at end of file + stage('Test'){ + steps{ + script{ + echo 'Test' + sh "cd api\n\ + mvn test jacoco:report" + } + + publishHTML([ + allowMissing: true, + keepAll:true, + alwaysLinkToLastBuild: true, + reportDir: 'api/target/site/jacoco', + reportFiles: 'index.html', + reportName: 'Jacoco coverage HTML report']) + } + } + } \ No newline at end of file From 05b991ba821f04996def706372a5089e81c69fd9 Mon Sep 17 00:00:00 2001 From: kaisa9 Date: Mon, 6 Feb 2023 12:41:33 +0000 Subject: [PATCH 04/12] maven profiles: default, tests, checkstyle were created --- api/pom.xml | 224 +++++++++++++++++++++--------- {.jenkins => jenkins}/Jenkinsfile | 13 +- 2 files changed, 167 insertions(+), 70 deletions(-) rename {.jenkins => jenkins}/Jenkinsfile (82%) diff --git a/api/pom.xml b/api/pom.xml index 18e0820c..2c8ebb42 100755 --- a/api/pom.xml +++ b/api/pom.xml @@ -20,35 +20,7 @@ 17 - - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.2 - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.2.0 - - - - checkstyle - - - - - - org.apache.maven.plugins - maven-pmd-plugin - 3.17.0 - - 17 - - - - + @@ -223,16 +195,6 @@ spring-security-test test - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.2.0 - - - com.google.code.findbugs - jsr305 - 3.0.2 - @@ -287,31 +249,165 @@ - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.2.0 - - - verify-style - process-classes - - check - - - - - true - false - - - - com.puppycrawl.tools - checkstyle - 9.3 - - - + + + default + + true + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.2.0 + + true + true + + + + + + + tests + + false + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.2.0 + + true + true + + + + org.jacoco + jacoco-maven-plugin + 0.8.8 + + + + + + + static-code-analysis + + true + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.2.0 + + + com.google.code.findbugs + jsr305 + 3.0.2 + + + + + + org.codehaus.mojo + findbugs-maven-plugin + 3.0.2 + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.2.0 + + + + checkstyle + + + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.20.0 + + 17 + + + + + cpd + pmd + + + + + + + + + + org.apache.maven.plugins + maven-pmd-plugin + 3.20.0 + + false + 17 + + + + pmd-break + prepare-package + + check + cpd + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 3.2.0 + + + verify-style + process-classes + + check + + + + verify-cpd + verify + + checkstyle + + + + + false + true + false + + + + com.puppycrawl.tools + checkstyle + 9.3 + + + + + + + \ No newline at end of file diff --git a/.jenkins/Jenkinsfile b/jenkins/Jenkinsfile similarity index 82% rename from .jenkins/Jenkinsfile rename to jenkins/Jenkinsfile index 3e18e5b1..d32992f2 100644 --- a/.jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -8,7 +8,7 @@ pipeline { echo 'Download dependencies' withMaven(maven:"maven-387", publisherStrategy: 'EXPLICIT'){ sh "cd api \n\ - mvn install -DskipTests" + mvn install -P default" } } } @@ -17,24 +17,24 @@ pipeline { script{ echo 'Static code analysis' sh "cd api\n\ - mvn -X clean pmd:pmd pmd:cpd findbugs:findbugs checkstyle:checkstyle \n\ + mvn install -P static-code-analysis\n\ echo \"static code analysis finished\"" } echo "Reading static analysis report" recordIssues enabledForFailure: true, failOnError: false, tool:checkStyle(pattern: "**/target/checkstyle-result.xml") - recordIssues enabledForFailure: true, failOnError: false, tool:findBugs(pattern: "**/target/findbugs*.xml") +// recordIssues enabledForFailure: true, failOnError: false, tool:findBugs(pattern: "**/target/findbugs*.xml") recordIssues enabledForFailure: true, failOnError: false, tool:cpd(pattern: "**/target/cpd.xml") recordIssues enabledForFailure: true, failOnError: false, tool:pmdParser(pattern: "**/target/pmd.xml") } } - } + stage('Test'){ steps{ script{ echo 'Test' sh "cd api\n\ - mvn test jacoco:report" + mvn install -P tests" } publishHTML([ @@ -46,4 +46,5 @@ pipeline { reportName: 'Jacoco coverage HTML report']) } } - } \ No newline at end of file + } +} \ No newline at end of file From 4fa9f96024b397706a018f17a9963d94d7cbeece Mon Sep 17 00:00:00 2001 From: kaisa9 Date: Tue, 7 Feb 2023 10:31:04 +0000 Subject: [PATCH 05/12] findbugs plugin was changed to the spotbugs one --- api/pom.xml | 67 ++++++++++++++++++++++++++++++++++++++------- jenkins/Jenkinsfile | 2 +- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/api/pom.xml b/api/pom.xml index 2c8ebb42..78ef43d4 100755 --- a/api/pom.xml +++ b/api/pom.xml @@ -277,7 +277,23 @@ false - + + + + + + + + + + + + com.github.spotbugs + spotbugs-maven-plugin + 4.7.3.0 + + + @@ -293,7 +309,6 @@ org.jacoco jacoco-maven-plugin 0.8.8 - @@ -309,18 +324,20 @@ maven-checkstyle-plugin 3.2.0 - - com.google.code.findbugs - jsr305 - 3.0.2 - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.2 + com.github.spotbugs + spotbugs-maven-plugin + 4.7.3.0 + + + + spotbugs + + + org.apache.maven.plugins @@ -354,6 +371,36 @@ + + com.github.spotbugs + spotbugs-maven-plugin + 4.7.3.0 + + + com.github.spotbugs + spotbugs + 4.7.3 + + + + true + false + target + false + true + Max + Low + + + + spotbugs + + spotbugs + check + + + + org.apache.maven.plugins maven-pmd-plugin diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index d32992f2..f2418a3e 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -23,7 +23,7 @@ pipeline { echo "Reading static analysis report" recordIssues enabledForFailure: true, failOnError: false, tool:checkStyle(pattern: "**/target/checkstyle-result.xml") -// recordIssues enabledForFailure: true, failOnError: false, tool:findBugs(pattern: "**/target/findbugs*.xml") + recordIssues enabledForFailure: true, failOnError: false, tool:spotBugs(pattern: "**/target/spotbugs*.xml") recordIssues enabledForFailure: true, failOnError: false, tool:cpd(pattern: "**/target/cpd.xml") recordIssues enabledForFailure: true, failOnError: false, tool:pmdParser(pattern: "**/target/pmd.xml") } From 9ef2fb072acb3ad1eed12c74d63b888de413fbcd Mon Sep 17 00:00:00 2001 From: kaisa9 Date: Thu, 16 Feb 2023 10:59:00 +0000 Subject: [PATCH 06/12] checkstyle uses custom settings, javadoc warnings excluded --- api/codestyle/checkstyle-suppressions.xml | 7 + api/codestyle/checkstyle_checks.xml | 915 ++++++++++++++++++++++ api/codestyle/sun_checks.xml | 186 +++++ api/pom.xml | 7 + 4 files changed, 1115 insertions(+) create mode 100644 api/codestyle/checkstyle-suppressions.xml create mode 100644 api/codestyle/checkstyle_checks.xml create mode 100644 api/codestyle/sun_checks.xml diff --git a/api/codestyle/checkstyle-suppressions.xml b/api/codestyle/checkstyle-suppressions.xml new file mode 100644 index 00000000..40f4001a --- /dev/null +++ b/api/codestyle/checkstyle-suppressions.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/api/codestyle/checkstyle_checks.xml b/api/codestyle/checkstyle_checks.xml new file mode 100644 index 00000000..b92d5ea5 --- /dev/null +++ b/api/codestyle/checkstyle_checks.xml @@ -0,0 +1,915 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/codestyle/sun_checks.xml b/api/codestyle/sun_checks.xml new file mode 100644 index 00000000..9448e1b0 --- /dev/null +++ b/api/codestyle/sun_checks.xml @@ -0,0 +1,186 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/pom.xml b/api/pom.xml index 78ef43d4..ddc0cf16 100755 --- a/api/pom.xml +++ b/api/pom.xml @@ -342,6 +342,10 @@ org.apache.maven.plugins maven-checkstyle-plugin + + + + 3.2.0 @@ -443,6 +447,9 @@ false true + /codestyle/checkstyle_checks.xml + /codestyle/checkstyle-suppressions.xml + false From c87ac3625e2ecf01557a42f21f011c1ed64bf576 Mon Sep 17 00:00:00 2001 From: kaisa9 Date: Thu, 16 Feb 2023 15:37:01 +0000 Subject: [PATCH 07/12] Codestyle rules added as a parameter of the Jenkins build --- api/codestyle/checkstyle_checks.xml | 979 ++++------------------------ api/pom.xml | 20 +- jenkins/Jenkinsfile | 86 ++- 3 files changed, 194 insertions(+), 891 deletions(-) diff --git a/api/codestyle/checkstyle_checks.xml b/api/codestyle/checkstyle_checks.xml index b92d5ea5..7f7559c1 100644 --- a/api/codestyle/checkstyle_checks.xml +++ b/api/codestyle/checkstyle_checks.xml @@ -3,6 +3,23 @@ "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd"> + + - - - - - - - + - + + - + - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - + + + - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - + + @@ -223,693 +70,125 @@ value="^( *\* *([^ ]+|\{@code .*|<a href="[^"]+">)|(package|import) .*)$"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - + - - - - - - - - - - + + + + + + + + + + + - - - - - - - + + - - - - - - - - - - - - - - + + - - - - - - - - - - - - - + + + + + + + - - - - - - - - - + + - - - - + + - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/api/pom.xml b/api/pom.xml index ddc0cf16..4436e4cb 100755 --- a/api/pom.xml +++ b/api/pom.xml @@ -18,6 +18,8 @@ 1.6.11 17 + + codestyle/checkstyle-suppressions.xml @@ -257,7 +259,6 @@ true - @@ -277,14 +278,6 @@ false - - - - - - - - @@ -342,10 +335,6 @@ org.apache.maven.plugins maven-checkstyle-plugin - - - - 3.2.0 @@ -447,9 +436,8 @@ false true - /codestyle/checkstyle_checks.xml - /codestyle/checkstyle-suppressions.xml - + ${codestyle.checks.file} + ${codestyle.suppressions.file} false diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index f2418a3e..81998196 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -1,9 +1,15 @@ - - pipeline { agent any + parameters { + choice( + choices: ['sun_checks', 'sun_checks_with_suppressions', 'custom_checks', 'custom_checks_with_suppressions'], + description: 'Select xml file with checkstyle rules', + name: 'CHECKSTYLE_RULES_SET')} stages { stage('Build'){ + options { + timeout(time:10, unit: 'MINUTES' ) + } steps{ echo 'Download dependencies' withMaven(maven:"maven-387", publisherStrategy: 'EXPLICIT'){ @@ -13,38 +19,68 @@ pipeline { } } stage('Static code analysis'){ + options { + timeout(time:10, unit: 'MINUTES' ) + } steps{ - script{ + script{ echo 'Static code analysis' - sh "cd api\n\ - mvn install -P static-code-analysis\n\ + currentCheckstyleRulesStr = getCheckstyleRules(params.CHECKSTYLE_RULES_SET) + sh "echo ${currentCheckstyleRulesStr} \n\ + cd api\n\ + mvn -X install -P static-code-analysis ${currentCheckstyleRulesStr}\n\ echo \"static code analysis finished\"" - } + } echo "Reading static analysis report" recordIssues enabledForFailure: true, failOnError: false, tool:checkStyle(pattern: "**/target/checkstyle-result.xml") recordIssues enabledForFailure: true, failOnError: false, tool:spotBugs(pattern: "**/target/spotbugs*.xml") recordIssues enabledForFailure: true, failOnError: false, tool:cpd(pattern: "**/target/cpd.xml") recordIssues enabledForFailure: true, failOnError: false, tool:pmdParser(pattern: "**/target/pmd.xml") - } - } + } + } - stage('Test'){ - steps{ - script{ - echo 'Test' - sh "cd api\n\ - mvn install -P tests" - } - - publishHTML([ - allowMissing: true, - keepAll:true, - alwaysLinkToLastBuild: true, - reportDir: 'api/target/site/jacoco', - reportFiles: 'index.html', - reportName: 'Jacoco coverage HTML report']) - } - } + stage('Test'){ + options { + timeout(time:10, unit: 'MINUTES' ) + } + steps{ + script{ + echo 'Test' + sh "cd api\n\ + mvn install -P tests" + } + + publishHTML([ + allowMissing: true, + keepAll:true, + alwaysLinkToLastBuild: true, + reportDir: 'api/target/site/jacoco', + reportFiles: 'index.html', + reportName: 'Jacoco coverage HTML report']) + } + } } +} + +def getCheckstyleRules(String selectedCheckstyleRules) { + String mvnOptions = '' + switch(selectedCheckstyleRules){ + case "sun_checks": + mvnOptions = '-Dcodestyle.checks.file=./codestyle/sun_checks.xml' + break + case "sun_checks_with_suppressions": + mvnOptions = '-Dcodestyle.checks.file=./codestyle/sun_checks.xml -Dcodestyle.suppressions.file=./codestylecheckstyle-suppressions.xml' + break + case "custom_checks": + mvnOptions = '-Dcodestyle.checks.file=./codestyle/checkstyle_checks.xml' + break + case "custom_checks_with_suppressions": + mvnOptions = '-Dcodestyle.checks.file=./codestyle/checkstyle_checks.xml -Dcodestyle.suppressions.file=./codestylecheckstyle-suppressions.xml' + break + default: + mvnOptions = ' h lkjh lkjhjlkhjklhjklhlhkjkjkjkj ;kj jk;' + break + } + return mvnOptions } \ No newline at end of file From ce82eb34b6fe3a3c7fb4b2b37d2a802d908c1800 Mon Sep 17 00:00:00 2001 From: kaisa9 Date: Tue, 7 Mar 2023 16:23:26 +0000 Subject: [PATCH 08/12] Jenkins/Readme.md is added --- jenkins/README.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 jenkins/README.md diff --git a/jenkins/README.md b/jenkins/README.md new file mode 100644 index 00000000..2204b70d --- /dev/null +++ b/jenkins/README.md @@ -0,0 +1,31 @@ +#Prerequisites. +The Jenkins is installed and set up with ansible playbook from [project](https://github.com/Alliedium/awesome-jenkins/) +[multibranchpipelines](https://www.jenkins.io/doc/book/pipeline/multibranch/) + +#Jenkinsfile description + +Here we created Jenkinsfile to run our staged build on Jenkins. [How to run pipeline](https://www.jenkins.io/doc/book/pipeline/running-pipelines/) +We used declarative pipeline. +Please see reference about [Jenkinsfile](https://www.jenkins.io/doc/book/pipeline/jenkinsfile/) and [pipeline syntax](https://www.jenkins.io/doc/book/pipeline/syntax/) +Our Jenkinsfile has 3 stages: _Build_, _Static code analysis_ and _Test_. +We have 3 different maven [profiles](https://maven.apache.org/guides/introduction/introduction-to-profiles.html) in the pom.xml file, which are used for these three stages respectively: default, static-code-analysis and test + +1. In the _Build_ stage maven dependencies are downloaded and jar file is build: 'mvn install -P default' + +2. The static code analysis is performed during the _Static code analysis_ stage. +We used [spotbugs](https://spotbugs.github.io/spotbugs-maven-plugin/), [pmd/cpd](https://pmd.github.io/latest/pmd_userdocs_tools_maven.html) and [checkstyle](https://checkstyle.org/) plugins. +Analysis is run by maven command 'mvn -X install -P static-code-analysis'. In addition, we add checkstyle rules file as an option to our command. +We have 2 files with rules: sun_checks.xml - the standard file, downloaded from internet [github source](https://github.com/checkstyle/checkstyle/blob/52728d750690867f252e9312e1347a5b0010d9a4/src/main/resources/sun_checks.xml), checkstyle_checks.xml - with customized rules (here we changed maximum line length), +and 1 file with check suppression - we have suppressed Javadoc checks. +You also can use [google style standards](https://github.com/checkstyle/checkstyle/tree/52728d750690867f252e9312e1347a5b0010d9a4/src/main/resources/google_checks.xml) checks or customize your own style checks. +In Jenkinsfile we added 4 options/combinations for codestyle checks which can be selected before the build: 'sun_checks', 'sun_checks_with_suppressions', +'custom_checks', 'custom_checks_with_suppressions'. +Static code analysis reports are published on Jenkins for all our tools using [WarningNG plugin](https://plugins.jenkins.io/warnings-ng/). +We disabled build failure in the case if number of bugs or/and warnings will exceed predefined values by setting 'failOnError: false'. +_**NB:** If you prefer to **fail** your build in the case of not passing static code analysis quality gate please set this parameter to **_true_**._ +This parameter can be set separately for each of your tools + +3. In the third stage _Test_ the unit tests are running and the test coverage report is provided. +We used [Jacoco maven plugin](https://www.eclemma.org/jacoco/trunk/doc/maven.html) to do test coverage analysis. +The report is published in Jenkins by the means of the [HTML publisher Jenkins plugin](https://plugins.jenkins.io/htmlpublisher/). + From 2af080f1728d439100d860f32693d93134284dd3 Mon Sep 17 00:00:00 2001 From: kaisa9 Date: Tue, 14 Mar 2023 17:24:43 +0000 Subject: [PATCH 09/12] Draft 1 after review. Intermediate results. --- api/codestyle/checkstyle_checks.xml | 4 +-- ...ssions.xml => checkstyle_suppressions.xml} | 0 api/codestyle/sun_checks.xml | 2 +- api/pom.xml | 34 ++----------------- jenkins/Jenkinsfile | 6 ++-- jenkins/README.md | 5 ++- 6 files changed, 10 insertions(+), 41 deletions(-) rename api/codestyle/{checkstyle-suppressions.xml => checkstyle_suppressions.xml} (100%) diff --git a/api/codestyle/checkstyle_checks.xml b/api/codestyle/checkstyle_checks.xml index 7f7559c1..807b80c7 100644 --- a/api/codestyle/checkstyle_checks.xml +++ b/api/codestyle/checkstyle_checks.xml @@ -39,8 +39,8 @@ - + diff --git a/api/codestyle/checkstyle-suppressions.xml b/api/codestyle/checkstyle_suppressions.xml similarity index 100% rename from api/codestyle/checkstyle-suppressions.xml rename to api/codestyle/checkstyle_suppressions.xml diff --git a/api/codestyle/sun_checks.xml b/api/codestyle/sun_checks.xml index 9448e1b0..4b0114e7 100644 --- a/api/codestyle/sun_checks.xml +++ b/api/codestyle/sun_checks.xml @@ -40,7 +40,7 @@ + default="checkstyle_suppressions.xml" /> diff --git a/api/pom.xml b/api/pom.xml index 4436e4cb..77509d5d 100755 --- a/api/pom.xml +++ b/api/pom.xml @@ -19,7 +19,7 @@ 1.6.11 17 - codestyle/checkstyle-suppressions.xml + @@ -259,45 +259,15 @@ true - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.2.0 - - true - true - - - - + tests false - - - - com.github.spotbugs - spotbugs-maven-plugin - 4.7.3.0 - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 3.2.0 - - true - true - - org.jacoco jacoco-maven-plugin diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 81998196..0f783945 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -70,16 +70,16 @@ def getCheckstyleRules(String selectedCheckstyleRules) { mvnOptions = '-Dcodestyle.checks.file=./codestyle/sun_checks.xml' break case "sun_checks_with_suppressions": - mvnOptions = '-Dcodestyle.checks.file=./codestyle/sun_checks.xml -Dcodestyle.suppressions.file=./codestylecheckstyle-suppressions.xml' + mvnOptions = '-Dcodestyle.checks.file=./codestyle/sun_checks.xml -Dcodestyle.suppressions.file=./codestyle/checkstyle_suppressions.xml' break case "custom_checks": mvnOptions = '-Dcodestyle.checks.file=./codestyle/checkstyle_checks.xml' break case "custom_checks_with_suppressions": - mvnOptions = '-Dcodestyle.checks.file=./codestyle/checkstyle_checks.xml -Dcodestyle.suppressions.file=./codestylecheckstyle-suppressions.xml' + mvnOptions = '-Dcodestyle.checks.file=./codestyle/checkstyle_checks.xml -Dcodestyle.suppressions.file=./codestyle/checkstyle_suppressions.xml' break default: - mvnOptions = ' h lkjh lkjhjlkhjklhjklhlhkjkjkjkj ;kj jk;' + mvnOptions = '-Dcodestyle.checks.file=./codestyle/sun_checks.xml' break } return mvnOptions diff --git a/jenkins/README.md b/jenkins/README.md index 2204b70d..e94ad5b6 100644 --- a/jenkins/README.md +++ b/jenkins/README.md @@ -1,8 +1,7 @@ -#Prerequisites. +# Prerequisites. The Jenkins is installed and set up with ansible playbook from [project](https://github.com/Alliedium/awesome-jenkins/) -[multibranchpipelines](https://www.jenkins.io/doc/book/pipeline/multibranch/) -#Jenkinsfile description +# Jenkinsfile description Here we created Jenkinsfile to run our staged build on Jenkins. [How to run pipeline](https://www.jenkins.io/doc/book/pipeline/running-pipelines/) We used declarative pipeline. From 8204c8f16216e5bb4e16a29d8e5040fbaf7307ea Mon Sep 17 00:00:00 2001 From: kaisa9 Date: Thu, 16 Mar 2023 11:29:57 +0000 Subject: [PATCH 10/12] draft 1 after review --- jenkins/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile index 0f783945..e61a634b 100644 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -12,7 +12,7 @@ pipeline { } steps{ echo 'Download dependencies' - withMaven(maven:"maven-387", publisherStrategy: 'EXPLICIT'){ + withMaven(maven:"maven", publisherStrategy: 'EXPLICIT'){ sh "cd api \n\ mvn install -P default" } From 66100382fb80e7aa0de4f8a75890ae5c5269e6a5 Mon Sep 17 00:00:00 2001 From: kaisa9 Date: Mon, 27 Mar 2023 17:48:44 +0000 Subject: [PATCH 11/12] Jenkins/Readme.md is added --- jenkins/README.md | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/jenkins/README.md b/jenkins/README.md index e94ad5b6..d3ab8f27 100644 --- a/jenkins/README.md +++ b/jenkins/README.md @@ -4,27 +4,40 @@ The Jenkins is installed and set up with ansible playbook from [project](https:/ # Jenkinsfile description Here we created Jenkinsfile to run our staged build on Jenkins. [How to run pipeline](https://www.jenkins.io/doc/book/pipeline/running-pipelines/) -We used declarative pipeline. -Please see reference about [Jenkinsfile](https://www.jenkins.io/doc/book/pipeline/jenkinsfile/) and [pipeline syntax](https://www.jenkins.io/doc/book/pipeline/syntax/) +We used declarative pipeline. Our Jenkinsfile has 3 stages: _Build_, _Static code analysis_ and _Test_. We have 3 different maven [profiles](https://maven.apache.org/guides/introduction/introduction-to-profiles.html) in the pom.xml file, which are used for these three stages respectively: default, static-code-analysis and test 1. In the _Build_ stage maven dependencies are downloaded and jar file is build: 'mvn install -P default' -2. The static code analysis is performed during the _Static code analysis_ stage. -We used [spotbugs](https://spotbugs.github.io/spotbugs-maven-plugin/), [pmd/cpd](https://pmd.github.io/latest/pmd_userdocs_tools_maven.html) and [checkstyle](https://checkstyle.org/) plugins. -Analysis is run by maven command 'mvn -X install -P static-code-analysis'. In addition, we add checkstyle rules file as an option to our command. -We have 2 files with rules: sun_checks.xml - the standard file, downloaded from internet [github source](https://github.com/checkstyle/checkstyle/blob/52728d750690867f252e9312e1347a5b0010d9a4/src/main/resources/sun_checks.xml), checkstyle_checks.xml - with customized rules (here we changed maximum line length), -and 1 file with check suppression - we have suppressed Javadoc checks. -You also can use [google style standards](https://github.com/checkstyle/checkstyle/tree/52728d750690867f252e9312e1347a5b0010d9a4/src/main/resources/google_checks.xml) checks or customize your own style checks. -In Jenkinsfile we added 4 options/combinations for codestyle checks which can be selected before the build: 'sun_checks', 'sun_checks_with_suppressions', -'custom_checks', 'custom_checks_with_suppressions'. +2. The static code analysis is performed during the _Static code analysis_ stage. + We used the following maven plugins: +* [spotbugs](https://spotbugs.github.io/spotbugs-maven-plugin/) +* [pmd/cpd](https://pmd.github.io/latest/pmd_userdocs_tools_maven.html) +* [checkstyle](https://checkstyle.org/) + Analysis is run via maven command + `mvn -X install -P static-code-analysis`. +Checkstyle analysis is performed according the convention standards. By default, checkstyle is performed using sun style standards described in the [sun_checks.xml file](https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/sun_checks.xml). +The [google style standards](https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml) or custom rules can be used as an option. +One can customize the rules by written its own file or/and by adding file with suppression rules. +In our profile we can switch between sun standards and customized rules. +We have 2 files with rules: _sun_checks.xml_, _checkstyle_checks.xml_ - here we changed maximum line length, +and 1 suppression file _checkstyle_suppressions.xml_ here we have suppressed Javadoc checks. +In Jenkinsfile we added 4 options/combinations for codestyle checks which can be selected before the build: + * 'sun_checks' + * 'sun_checks_with_suppressions' + * 'custom_checks' + * 'custom_checks_with_suppressions'. Static code analysis reports are published on Jenkins for all our tools using [WarningNG plugin](https://plugins.jenkins.io/warnings-ng/). -We disabled build failure in the case if number of bugs or/and warnings will exceed predefined values by setting 'failOnError: false'. -_**NB:** If you prefer to **fail** your build in the case of not passing static code analysis quality gate please set this parameter to **_true_**._ -This parameter can be set separately for each of your tools + We disabled build failure in the case if number of bugs or/and warnings will exceed predefined values by setting 'failOnError: false'. + If you prefer to _fail_ your build you can set cut-off number of bugs and warnings for successful build and set 'failOnError: true'. + This parameter, as well as cut-off numbers, can be [set](https://www.jenkins.io/doc/pipeline/steps/warnings-ng/) separately for each static analysis tools supported by WarningNG plugin 3. In the third stage _Test_ the unit tests are running and the test coverage report is provided. We used [Jacoco maven plugin](https://www.eclemma.org/jacoco/trunk/doc/maven.html) to do test coverage analysis. The report is published in Jenkins by the means of the [HTML publisher Jenkins plugin](https://plugins.jenkins.io/htmlpublisher/). +### References +1. [Jenkinsfile](https://www.jenkins.io/doc/book/pipeline/jenkinsfile/) +2. [Pipeline syntax](https://www.jenkins.io/doc/book/pipeline/syntax/) +3. [Comparison of findbugs, pmd and checkstyle plugins](https://www.sw-engineering-candies.com/blog-1/comparison-of-findbugs-pmd-and-checkstyle) \ No newline at end of file From 3c78029a7e298d6a89adfb05141986c298499c0c Mon Sep 17 00:00:00 2001 From: KaIsa9 Date: Tue, 28 Mar 2023 12:55:45 +0000 Subject: [PATCH 12/12] Jenkins/Jenkinsfile --- jenkins/Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 jenkins/Jenkinsfile diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile old mode 100644 new mode 100755 index e61a634b..3768a909 --- a/jenkins/Jenkinsfile +++ b/jenkins/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { echo 'Download dependencies' withMaven(maven:"maven", publisherStrategy: 'EXPLICIT'){ sh "cd api \n\ - mvn install -P default" + mvn -X -ntp install -P default" } } }