diff --git a/Jenkinsfile b/Jenkinsfile
deleted file mode 100644
index eb1f9aec..00000000
--- a/Jenkinsfile
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-pipeline {
- agent any
- stages {
- stage('Build'){
- steps{
- echo 'Download dependencies'
- withMaven(maven:"maven-387", publisherStrategy: 'EXPLICIT'){
- sh "pwd\n\
- cd api \n\
- ls -la\n\
- mvn install -DskipTests"
- }
- }
- }
- stage('Test'){
- steps{
- echo 'Test'
- sh "pwd\n\
- cd api\n\
- mvn test"
- }
- }
- stage('Deploy'){
- steps{
- echo 'Deploy'
- }
- }
- }
- }
\ 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..807b80c7
--- /dev/null
+++ b/api/codestyle/checkstyle_checks.xml
@@ -0,0 +1,194 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
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/sun_checks.xml b/api/codestyle/sun_checks.xml
new file mode 100644
index 00000000..4b0114e7
--- /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 503a0d18..77509d5d 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
@@ -17,8 +18,12 @@
1.6.11
17
+
+
+
+
@@ -248,4 +253,173 @@
+
+
+ default
+
+ true
+
+
+
+
+ tests
+
+ false
+
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ 0.8.8
+
+
+
+
+
+ static-code-analysis
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 3.2.0
+
+
+
+
+
+ com.github.spotbugs
+ spotbugs-maven-plugin
+ 4.7.3.0
+
+
+
+ spotbugs
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-checkstyle-plugin
+ 3.2.0
+
+
+
+ checkstyle
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-pmd-plugin
+ 3.20.0
+
+ 17
+
+
+
+
+ cpd
+ pmd
+
+
+
+
+
+
+
+
+
+ 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
+ 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
+ ${codestyle.checks.file}
+ ${codestyle.suppressions.file}
+ false
+
+
+
+ com.puppycrawl.tools
+ checkstyle
+ 9.3
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/jenkins/Jenkinsfile b/jenkins/Jenkinsfile
new file mode 100755
index 00000000..3768a909
--- /dev/null
+++ b/jenkins/Jenkinsfile
@@ -0,0 +1,86 @@
+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", publisherStrategy: 'EXPLICIT'){
+ sh "cd api \n\
+ mvn -X -ntp install -P default"
+ }
+ }
+ }
+ stage('Static code analysis'){
+ options {
+ timeout(time:10, unit: 'MINUTES' )
+ }
+ steps{
+ script{
+ echo 'Static code analysis'
+ 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'){
+ 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=./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=./codestyle/checkstyle_suppressions.xml'
+ break
+ default:
+ mvnOptions = '-Dcodestyle.checks.file=./codestyle/sun_checks.xml'
+ break
+ }
+ return mvnOptions
+}
\ No newline at end of file
diff --git a/jenkins/README.md b/jenkins/README.md
new file mode 100644
index 00000000..d3ab8f27
--- /dev/null
+++ b/jenkins/README.md
@@ -0,0 +1,43 @@
+# Prerequisites.
+The Jenkins is installed and set up with ansible playbook from [project](https://github.com/Alliedium/awesome-jenkins/)
+
+# 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.
+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 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'.
+ 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