From fd78eeece6fcea23c6a09fd3225e64c7aabde67e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Thu, 8 Mar 2018 22:25:39 +0000 Subject: [PATCH 01/10] jenkins: report environment, no snapshots in PRs to master and only deploy from https repos --- Jenkinsfile.groovy | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index e799493..02c109f 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -3,12 +3,16 @@ final String mvn = "mvn --batch-mode --update-snapshots" pipeline { agent any stages { + stage('Environment') { + steps { + sh 'set' + } + } stage('no SNAPSHOT in master') { - // checks that the pom version is not a snapshot when the current branch is master - // TODO: also check for SNAPSHOT when is a pull request with master as the target branch + // checks that the pom version is not a snapshot when the current or target branch is master when { expression { - (env.GIT_BRANCH == 'master') && + (env.GIT_BRANCH == 'master' || env.CHANGE_TARGET == 'master') && (readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT") } } steps { @@ -60,7 +64,7 @@ pipeline { } } stage('Deploy') { - when { expression { (env.GIT_BRANCH == 'master') } } + when { expression { (env.GIT_BRANCH == 'master' && env.GIT_URL.startsWith('https://')) } } steps { withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { sh "${mvn} deploy --activate-profiles release -DskipTests=true" From 02ab4eaada6f8fb8935d88d94b20115c704c5d0c Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 10 Mar 2018 08:09:27 +0000 Subject: [PATCH 02/10] jenkins: Don't build java in parallel and only enter stages when suitable files found --- Jenkinsfile.groovy | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index 02c109f..268e49c 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -13,13 +13,15 @@ pipeline { when { expression { (env.GIT_BRANCH == 'master' || env.CHANGE_TARGET == 'master') && - (readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT") } + (readMavenPom(file: 'pom.xml').version).contains("SNAPSHOT") + } } steps { error("Build failed because SNAPSHOT version") } } stage('Static Code Analysis') { + when { expression { findFiles(glob: '**/src/main/java/*.java').length > 0 } } steps { withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { sh "${mvn} compile checkstyle:checkstyle pmd:pmd" @@ -27,25 +29,22 @@ pipeline { pmd canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '', unHealthy: '' } } - stage('Build') { - parallel { - stage('Java 8') { - steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { - sh "${mvn} clean install" - } - } + stage('Build Java 9') { + steps { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { + sh "${mvn} clean install" } - stage('Java 9') { - steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { - sh "${mvn} clean install" - } - } + } + } + stage('Build Java 8') { + steps { + withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + sh "${mvn} clean install" } } } stage('Test Results') { + when { expression { findFiles(glob: '**/target/surefire-reports/*.xml').length > 0 } } steps { junit '**/target/surefire-reports/*.xml' jacoco exclusionPattern: '**/*{Test|IT|Main|Application|Immutable}.class' @@ -59,6 +58,7 @@ pipeline { } } stage('Archiving') { + when { expression { findFiles(glob: '**/target/*.jar').length > 0 } } steps { archiveArtifacts '**/target/*.jar' } From 1439dcdb5e566d8f3dfaa89448d7732c87aeb323 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 10 Mar 2018 17:02:25 +0000 Subject: [PATCH 03/10] jenkins: check code with sonarqube --- Jenkinsfile.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index 268e49c..298e7de 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -24,7 +24,9 @@ pipeline { when { expression { findFiles(glob: '**/src/main/java/*.java').length > 0 } } steps { withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { - sh "${mvn} compile checkstyle:checkstyle pmd:pmd" + withSonarQubeEnv('sonarqube') { + sh "${mvn} compile checkstyle:checkstyle pmd:pmd org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar" + } } pmd canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '', unHealthy: '' } From 8619824c41546c1fa4343d58ffe20ea41bc2281c Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 10 Mar 2018 17:04:56 +0000 Subject: [PATCH 04/10] jenkins: try to log java files --- Jenkinsfile.groovy | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index 298e7de..fcc9346 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -21,14 +21,17 @@ pipeline { } } stage('Static Code Analysis') { - when { expression { findFiles(glob: '**/src/main/java/*.java').length > 0 } } + when { expression { findFiles(glob: '**/src/main/java/**/*.java').length > 0 } } steps { withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + sh "${mvn} compile" + sh "${mvn} checkstyle:checkstyle" + sh "${mvn} pmd:pmd" + pmd canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '', unHealthy: '' withSonarQubeEnv('sonarqube') { - sh "${mvn} compile checkstyle:checkstyle pmd:pmd org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar" + sh "${mvn} org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar" } } - pmd canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '', unHealthy: '' } } stage('Build Java 9') { From 12f314396dc40d9a409f97b6487d6bf8dc2028ff Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 10 Mar 2018 18:09:03 +0000 Subject: [PATCH 05/10] jenkins: Use jeneric maven and jdk names --- Jenkinsfile.groovy | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index fcc9346..7198d71 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -23,7 +23,7 @@ pipeline { stage('Static Code Analysis') { when { expression { findFiles(glob: '**/src/main/java/**/*.java').length > 0 } } steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + withMaven(maven: 'maven', jdk: 'JDK LTS') { sh "${mvn} compile" sh "${mvn} checkstyle:checkstyle" sh "${mvn} pmd:pmd" @@ -34,16 +34,16 @@ pipeline { } } } - stage('Build Java 9') { + stage('Build Java Next') { steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 9') { + withMaven(maven: 'maven', jdk: 'JDK Next') { sh "${mvn} clean install" } } } - stage('Build Java 8') { + stage('Build Java LTS') { steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + withMaven(maven: 'maven', jdk: 'JDK LTS') { sh "${mvn} clean install" } } @@ -53,7 +53,7 @@ pipeline { steps { junit '**/target/surefire-reports/*.xml' jacoco exclusionPattern: '**/*{Test|IT|Main|Application|Immutable}.class' - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + withMaven(maven: 'maven', jdk: 'JDK LTS') { sh "${mvn} com.gavinmogan:codacy-maven-plugin:coverage " + "-DcoverageReportFile=target/site/jacoco/jacoco.xml " + "-DprojectToken=`$JENKINS_HOME/codacy/token` " + @@ -71,7 +71,7 @@ pipeline { stage('Deploy') { when { expression { (env.GIT_BRANCH == 'master' && env.GIT_URL.startsWith('https://')) } } steps { - withMaven(maven: 'maven 3.5.2', jdk: 'JDK 1.8') { + withMaven(maven: 'maven', jdk: 'JDK LTS') { sh "${mvn} deploy --activate-profiles release -DskipTests=true" } } From 0430d8a26e70f8a1497f345044bef1911b600985 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 10 Mar 2018 18:13:19 +0000 Subject: [PATCH 06/10] Remove circleci and werker config --- circle.yml | 3 --- wercker.yml | 6 ------ 2 files changed, 9 deletions(-) delete mode 100644 circle.yml delete mode 100644 wercker.yml diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 280d970..0000000 --- a/circle.yml +++ /dev/null @@ -1,3 +0,0 @@ -test: - override: - - ./mvnw clean install diff --git a/wercker.yml b/wercker.yml deleted file mode 100644 index b152705..0000000 --- a/wercker.yml +++ /dev/null @@ -1,6 +0,0 @@ -box: maven:3.5.0-jdk-8 - -build: - steps: - - xenoterracide/maven: - goals: clean install From 1830db4476fbaede01e274e8154c008a44a40578 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 11 Mar 2018 19:25:50 +0000 Subject: [PATCH 07/10] jenkins: update to template --- Jenkinsfile.groovy | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Jenkinsfile.groovy b/Jenkinsfile.groovy index 7198d71..9207dae 100644 --- a/Jenkinsfile.groovy +++ b/Jenkinsfile.groovy @@ -28,7 +28,14 @@ pipeline { sh "${mvn} checkstyle:checkstyle" sh "${mvn} pmd:pmd" pmd canComputeNew: false, defaultEncoding: '', healthy: '', pattern: '', unHealthy: '' - withSonarQubeEnv('sonarqube') { + } + } + } + stage('SonarQube (develop only)') { + when { expression { env.GIT_BRANCH == 'develop' && env.GIT_URL.startsWith('https://') } } + steps { + withSonarQubeEnv('sonarqube') { + withMaven(maven: 'maven', jdk: 'JDK LTS') { sh "${mvn} org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar" } } @@ -37,7 +44,7 @@ pipeline { stage('Build Java Next') { steps { withMaven(maven: 'maven', jdk: 'JDK Next') { - sh "${mvn} clean install" + sh "${mvn} clean install -Djava.version=9" } } } From 7b0dc90d55ed54d3fe9ab104e6e90135bd963b7d Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 12 Mar 2018 20:08:04 +0000 Subject: [PATCH 08/10] Add missing generic types --- .../java/net/kemitix/conditional/TrueValueClause.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/kemitix/conditional/TrueValueClause.java b/src/main/java/net/kemitix/conditional/TrueValueClause.java index 9d3fbcc..c8e7143 100644 --- a/src/main/java/net/kemitix/conditional/TrueValueClause.java +++ b/src/main/java/net/kemitix/conditional/TrueValueClause.java @@ -34,11 +34,11 @@ import java.util.function.Supplier; */ class TrueValueClause implements Value.ValueClause { - protected static final Value.ValueClause TRUE = new TrueValueClause(); + protected static final Value.ValueClause TRUE = new TrueValueClause<>(); @Override public ValueSupplier then(final Supplier trueSupplier) { - return new TrueValueSupplier(trueSupplier); + return new TrueValueSupplier<>(trueSupplier); } @Override @@ -54,11 +54,13 @@ class TrueValueClause implements Value.ValueClause { /** * An intermediate result of the {@link Value} where the clause has evaluated to true. + * + * @param the type of the value */ @RequiredArgsConstructor - private class TrueValueSupplier implements ValueSupplier { + private static final class TrueValueSupplier implements ValueSupplier { - private final transient Supplier valueSupplier; + private final Supplier valueSupplier; @Override public T otherwise(final Supplier falseSupplier) { From e45246e2b727834fd3031d322493548ba0df6b71 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 12 Mar 2018 20:08:25 +0000 Subject: [PATCH 09/10] Suppress false-positive PMD error --- src/main/java/net/kemitix/conditional/TrueValueClause.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/net/kemitix/conditional/TrueValueClause.java b/src/main/java/net/kemitix/conditional/TrueValueClause.java index c8e7143..8179e27 100644 --- a/src/main/java/net/kemitix/conditional/TrueValueClause.java +++ b/src/main/java/net/kemitix/conditional/TrueValueClause.java @@ -60,6 +60,7 @@ class TrueValueClause implements Value.ValueClause { @RequiredArgsConstructor private static final class TrueValueSupplier implements ValueSupplier { + @SuppressWarnings("PMD.BeanMembersShouldSerialize") private final Supplier valueSupplier; @Override From f5f51cf347df17246879d9f498872ab723a2f8dd Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 12 Mar 2018 20:09:34 +0000 Subject: [PATCH 10/10] Add missing generic types --- src/main/java/net/kemitix/conditional/FalseValueClause.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/kemitix/conditional/FalseValueClause.java b/src/main/java/net/kemitix/conditional/FalseValueClause.java index 672d285..3f6be53 100644 --- a/src/main/java/net/kemitix/conditional/FalseValueClause.java +++ b/src/main/java/net/kemitix/conditional/FalseValueClause.java @@ -52,8 +52,10 @@ class FalseValueClause implements Value.ValueClause { /** * An intermediate result of the {@link Value} where the clause has evaluated to false. + * + * @param the type of the value */ - private class FalseValueSupplier implements ValueSupplier { + private static final class FalseValueSupplier implements ValueSupplier { @Override public T otherwise(final Supplier falseSupplier) {