From f07c2e04a68daed0ca2673ebed3f6e92fd663b08 Mon Sep 17 00:00:00 2001
From: Carl Jones <jonesc162@cardiff.ac.uk>
Date: Tue, 4 Jul 2023 09:49:15 +0100
Subject: [PATCH] Update CI and Gradle build to Java 17.

Add pitest for mutation testing.

Separate build into many phases.
---
 .gitlab-ci.yml  | 57 ++++++++++++++++++++++++++++++++++++++++++++-----
 build.gradle    | 20 +++++++++++++++++
 settings.gradle |  2 +-
 3 files changed, 73 insertions(+), 6 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0fcd4f8..5950f51 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -8,8 +8,12 @@ default:
 
 
 stages:
+  - compile
+  - analyse
   - assemble
   - build
+  - code-coverage
+  - mutate
   - publish
 
 before_script:
@@ -24,12 +28,36 @@ cache:
     - .gradle/wrapper
     - .gradle/caches
 
+compile:gradle:
+  stage: compile
+  only:
+    - tags
+  script:
+    - ./gradlew --continue compileJava
+  artifacts:
+    name: "$CI_JOB_NAME"
+    paths:
+      - ./build/classes/java/main
+    expire_in: 4 week
+
+analyse:gradle:
+  stage: analyse
+  only:
+    - tags
+  script:
+    - ./gradlew --continue checkstyleMain
+  artifacts:
+    name: "$CI_JOB_NAME"
+    paths:
+      - ./build/reports/checkstyle/
+    expire_in: 4 week
+
 assemble:gradle:
   stage: assemble
   only:
     - tags
   script:
-    - ./gradlew shadowJar
+    - ./gradlew  --continue shadowJar
   artifacts:
     name: "$CI_JOB_NAME"
     paths:
@@ -42,16 +70,36 @@ build:gradle:
   only:
     - tags
   script:
-    - ./gradlew buildAndReport
+    - ./gradlew  --continue build
   artifacts:
     name: "$CI_JOB_NAME"
     paths:
       - ./build/reports/tests/
-      - ./build/reports/checkstyle/
-      - ./build/jacocoHtml
       - ./build/libs/*.jar
+      - ./build/jacoco/test.exec
+    expire_in: 4 week
+
+
+code-coverage:gradle:
+  stage: code-coverage
+  only:
+    - tags
+  script:
+    - ./gradlew  --continue jacocoTestReport
+    - ./gradlew  --continue jacocoTestCoverageVerification
+  artifacts:
+    name: "$CI_JOB_NAME"
+    paths:
+      - ./build/jacocoHtml/
     expire_in: 4 week
 
+mutate:gradle:
+  stage: mutate
+  only:
+    - tags
+  script:
+    - ./gradlew --continue pitest
+
 
 pages:
 
@@ -73,4 +121,3 @@ pages:
     paths:
       - public
 
-
diff --git a/build.gradle b/build.gradle
index f4174dd..aa6be3a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,9 +4,13 @@ plugins {
     id 'checkstyle'
     id 'idea'
     id 'application'
+    id 'info.solidsoft.pitest' version '1.9.11'
     id 'com.github.johnrengelman.shadow' version '7.1.0'
 
 }
+
+apply plugin: 'info.solidsoft.pitest.aggregator' // to 'pitestReportAggregate' appear
+
 group 'com.nsa.cm6123-6623'
 version '1.0-SNAPSHOT'
 
@@ -104,3 +108,19 @@ task buildAndReport {
 rootProject.tasks.named("jar") {
     duplicatesStrategy = 'include'
 }
+
+pitest {
+    targetClasses = ['uk.ac.cf.cm6123.cardgames.*']  //by default "${project.group}.*"
+    //pitestVersion = '1.9.0' //not needed when a default PIT version should be used
+    threads = 4
+    outputFormats = ['XML', 'HTML']
+    timestampedReports = false
+    junit5PluginVersion = '1.0.0'
+
+    reportAggregator {
+        testStrengthThreshold.set(50)
+        mutationThreshold.set(40)
+        maxSurviving.set(3)
+    }
+
+}
diff --git a/settings.gradle b/settings.gradle
index 2a5bb20..81e509b 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -1,2 +1,2 @@
-rootProject.name = 'assessment-2023-starter-monopoly'
+rootProject.name = 'assessment-2024-starter-monopoly'
 
-- 
GitLab