BlueGit

timfa birdcourier

CI: JUnit-tests en automatische release bij een tag

Voeg tests toe voor plugin.yml, config.yml, koerierstypes en cleanup-tags.
Op master draaien test en build zonder manual-job; een gepushte tag
publiceert de jar automatisch als beide slagen.

timfa Grok Bot · pushed by timfa

Authored 2026-11-17 · 8 hours ago

Hash
de26594e804ec563b9cded3a14f43000374c12ef
Parent
2a19b3da
Pipeline
Failed
11 files changed +267 −51
.gitlab-ci.yml +11 −13
@@ -1,16 +1,6 @@
1 # Release pipeline: runs when a version tag is created (e.g. v1.8.0 or 1.8.0).
2 #
3 # Required CI/CD variable:
4 # CI_PUSH_TOKEN — Project Access Token (Maintainer) with scopes:
5 # `write_repository`, `self_rotate` (or `api`), and `api`
6 # (api is required to write the rotated token back to this variable).
7 #
8 # Flow:
9 # 1. validate — reject invalid or non-increasing versions
10 # 2. bump — update version in project files and push commit (ci.skip; tag unchanged)
11 # 3. build — produce BirdCourier-<version>.jar and upload to Package Registry
12 # 4. release — publish a GitLab Release with the jar attached
13 # 5. rotate-token — self-rotate CI_PUSH_TOKEN and update the CI/CD variable
1 # GitLab-backup van de BlueGit-pipeline.
2 # Draait op een tag: test, daarna build en automatische GitLab-release
3 # (geen manual-stap). BlueGit zelf gebruikt blue-ci-cd.yml.
14 4
15 5 workflow:
16 6 rules:
@@ -22,12 +12,19 @@ variables:
22 12 GRADLE_OPTS: "-Dorg.gradle.daemon=false"
23 13
24 14 stages:
15 - test
25 16 - validate
26 17 - bump
27 18 - build
28 19 - release
29 20 - rotate
30 21
22 test:
23 stage: test
24 image: gradle:jdk25
25 script:
26 - gradle --no-daemon test
27
31 28 .validate_image:
32 29 image: alpine:3.20
33 30 before_script:
@@ -38,6 +35,7 @@ stages:
38 35 validate:version:
39 36 extends: .validate_image
40 37 stage: validate
38 needs: [test]
41 39 script:
42 40 - ./scripts/release.sh validate
43 41 artifacts:
@@ -1,16 +1,6 @@
1# Release pipeline: runs when a version tag is created (e.g. v1.8.0 or 1.8.0).
1# GitLab-backup van de BlueGit-pipeline.
2#
2# Draait op een tag: test, daarna build en automatische GitLab-release
3# Required CI/CD variable:
3# (geen manual-stap). BlueGit zelf gebruikt blue-ci-cd.yml.
4# CI_PUSH_TOKEN — Project Access Token (Maintainer) with scopes:
5# `write_repository`, `self_rotate` (or `api`), and `api`
6# (api is required to write the rotated token back to this variable).
7#
8# Flow:
9# 1. validate — reject invalid or non-increasing versions
10# 2. bump — update version in project files and push commit (ci.skip; tag unchanged)
11# 3. build — produce BirdCourier-<version>.jar and upload to Package Registry
12# 4. release — publish a GitLab Release with the jar attached
13# 5. rotate-token — self-rotate CI_PUSH_TOKEN and update the CI/CD variable
14
4
15workflow:
5workflow:
16 rules:
6 rules:
@@ -22,12 +12,19 @@ variables:
22 GRADLE_OPTS: "-Dorg.gradle.daemon=false"
12 GRADLE_OPTS: "-Dorg.gradle.daemon=false"
23
13
24stages:
14stages:
15 - test
25 - validate
16 - validate
26 - bump
17 - bump
27 - build
18 - build
28 - release
19 - release
29 - rotate
20 - rotate
30
21
22test:
23 stage: test
24 image: gradle:jdk25
25 script:
26 - gradle --no-daemon test
27
31.validate_image:
28.validate_image:
32 image: alpine:3.20
29 image: alpine:3.20
33 before_script:
30 before_script:
@@ -38,6 +35,7 @@ stages:
38validate:version:
35validate:version:
39 extends: .validate_image
36 extends: .validate_image
40 stage: validate
37 stage: validate
38 needs: [test]
41 script:
39 script:
42 - ./scripts/release.sh validate
40 - ./scripts/release.sh validate
43 artifacts:
41 artifacts:
README.md +14 −0
@@ -64,6 +64,20 @@ gradle build
64 64
65 65 The resulting JAR is `build/libs/BirdCourier-<version>.jar`.
66 66
67 Run the unit tests with:
68
69 ```bash
70 gradle test
71 ```
72
73 ## Releases
74
75 On BlueGit, a master push runs the tests and builds the jar (no manual job).
76 Push a version tag (for example `1.1.4` or `v1.1.4`) to publish a release
77 automatically: the pipeline runs the tests, builds the jar, and attaches
78 `BirdCourier-<version>.jar` to the tag. A leading `v` on the tag is stripped
79 from the version and file name.
80
67 81 ## Changelog
68 82
69 83 ### 1.1.3
@@ -64,6 +64,20 @@ gradle build
64
64
65The resulting JAR is `build/libs/BirdCourier-<version>.jar`.
65The resulting JAR is `build/libs/BirdCourier-<version>.jar`.
66
66
67Run the unit tests with:
68
69```bash
70gradle test
71```
72
73## Releases
74
75On BlueGit, a master push runs the tests and builds the jar (no manual job).
76Push a version tag (for example `1.1.4` or `v1.1.4`) to publish a release
77automatically: the pipeline runs the tests, builds the jar, and attaches
78`BirdCourier-<version>.jar` to the tag. A leading `v` on the tag is stripped
79from the version and file name.
80
67## Changelog
81## Changelog
68
82
69### 1.1.3
83### 1.1.3
blue-ci-cd.yml +22 −18
@@ -1,32 +1,38 @@
1 # BlueGit CI (vertaald uit .gitlab-ci.yml; GitLab is alleen nog backup).
1 # BlueGit CI voor BirdCourier.
2 2 #
3 # Op GitLab startte een nieuwe tag de release (validate, bump-commit terug naar
4 # master met CI_PUSH_TOKEN, build, GitLab-release, token roteren). Op BlueGit
5 # maakt de release-API de tag zelf, dus:
6 # master-push: version (hoogste tag + 1 patch, of RELEASE_VERSION) en build.
7 # Zonder tags blijft de versie die al in de projectbestanden staat (1.1.3).
8 # release: HANDMATIG (zoals op GitLab een bewuste tag), maakt tag + release
9 # met de jar. Nooit automatisch, nooit dubbel.
10 # De versie wordt alleen in de build gezet (zelfde bump als scripts/release.sh),
11 # er wordt geen bump-commit teruggepusht; CI_PUSH_TOKEN is niet meer nodig.
12 # Tag-pushes starten geen pipeline.
3 # master-push: test + build (geen release-job, zodat de pipeline op success
4 # eindigt in plaats van manual).
5 # tag-push: test + build, daarna automatisch release (geen manual-stap).
6 # De release-API voor bestaande tags maakt de tag niet aan of verplaatst die
7 # niet; de zip/jar komt uit dezelfde pipeline. Een leidende v op de tag wordt
8 # in de versie en jar-naam gestript.
13 9
14 10 workflow:
15 11 rules:
16 12 - if: $CI_COMMIT_TAG != ""
17 when: never
18 - if: $CI_COMMIT_BRANCH == "master"
13 - if: $CI_COMMIT_BRANCH
19 14 - if: $CI_PIPELINE_SOURCE == "web"
20 15 - if: $CI_PIPELINE_SOURCE == "api"
21 16
22 17 variables:
23 18 GRADLE_OPTS: "-Dorg.gradle.daemon=false"
24 19
25 stages: [build, release]
20 stages: [test, build, release]
21
22 test:
23 stage: test
24 image: gradle:jdk25
25 script:
26 - gradle --no-daemon test
27 artifacts:
28 when: always
29 paths: [build/reports/tests/test/]
30 expire_in: 14d
26 31
27 32 build:artifacts:
28 33 stage: build
29 34 image: gradle:jdk25
35 needs: [test]
30 36 script:
31 37 - bash scripts/ci/build.sh
32 38 artifacts:
@@ -36,11 +42,9 @@ build:artifacts:
36 42 release:
37 43 stage: release
38 44 image: bluegit/base
39 needs: [build:artifacts]
40 when: manual
45 needs: [test, build:artifacts]
41 46 resource_group: release
42 47 rules:
43 - if: $CI_COMMIT_BRANCH == "master"
44 when: manual
48 - if: $CI_COMMIT_TAG != ""
45 49 script:
46 50 - bash scripts/ci/bluegit-release.sh
@@ -1,32 +1,38 @@
1# BlueGit CI (vertaald uit .gitlab-ci.yml; GitLab is alleen nog backup).
1# BlueGit CI voor BirdCourier.
2#
2#
3# Op GitLab startte een nieuwe tag de release (validate, bump-commit terug naar
3# master-push: test + build (geen release-job, zodat de pipeline op success
4# master met CI_PUSH_TOKEN, build, GitLab-release, token roteren). Op BlueGit
4# eindigt in plaats van manual).
5# maakt de release-API de tag zelf, dus:
5# tag-push: test + build, daarna automatisch release (geen manual-stap).
6# master-push: version (hoogste tag + 1 patch, of RELEASE_VERSION) en build.
6# De release-API voor bestaande tags maakt de tag niet aan of verplaatst die
7# Zonder tags blijft de versie die al in de projectbestanden staat (1.1.3).
7# niet; de zip/jar komt uit dezelfde pipeline. Een leidende v op de tag wordt
8# release: HANDMATIG (zoals op GitLab een bewuste tag), maakt tag + release
8# in de versie en jar-naam gestript.
9# met de jar. Nooit automatisch, nooit dubbel.
10# De versie wordt alleen in de build gezet (zelfde bump als scripts/release.sh),
11# er wordt geen bump-commit teruggepusht; CI_PUSH_TOKEN is niet meer nodig.
12# Tag-pushes starten geen pipeline.
13
9
14workflow:
10workflow:
15 rules:
11 rules:
16 - if: $CI_COMMIT_TAG != ""
12 - if: $CI_COMMIT_TAG != ""
17 when: never
13 - if: $CI_COMMIT_BRANCH
18 - if: $CI_COMMIT_BRANCH == "master"
19 - if: $CI_PIPELINE_SOURCE == "web"
14 - if: $CI_PIPELINE_SOURCE == "web"
20 - if: $CI_PIPELINE_SOURCE == "api"
15 - if: $CI_PIPELINE_SOURCE == "api"
21
16
22variables:
17variables:
23 GRADLE_OPTS: "-Dorg.gradle.daemon=false"
18 GRADLE_OPTS: "-Dorg.gradle.daemon=false"
24
19
25stages: [build, release]
20stages: [test, build, release]
21
22test:
23 stage: test
24 image: gradle:jdk25
25 script:
26 - gradle --no-daemon test
27 artifacts:
28 when: always
29 paths: [build/reports/tests/test/]
30 expire_in: 14d
26
31
27build:artifacts:
32build:artifacts:
28 stage: build
33 stage: build
29 image: gradle:jdk25
34 image: gradle:jdk25
35 needs: [test]
30 script:
36 script:
31 - bash scripts/ci/build.sh
37 - bash scripts/ci/build.sh
32 artifacts:
38 artifacts:
@@ -36,11 +42,9 @@ build:artifacts:
36release:
42release:
37 stage: release
43 stage: release
38 image: bluegit/base
44 image: bluegit/base
39 needs: [build:artifacts]
45 needs: [test, build:artifacts]
40 when: manual
41 resource_group: release
46 resource_group: release
42 rules:
47 rules:
43 - if: $CI_COMMIT_BRANCH == "master"
48 - if: $CI_COMMIT_TAG != ""
44 when: manual
45 script:
49 script:
46 - bash scripts/ci/bluegit-release.sh
50 - bash scripts/ci/bluegit-release.sh
build.gradle.kts +7 −0
@@ -15,6 +15,9 @@ repositories {
15 15
16 16 dependencies {
17 17 compileOnly("io.papermc.paper:paper-api:26.2.build.112-stable")
18 testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
19 testImplementation("org.yaml:snakeyaml:2.4")
20 testRuntimeOnly("org.junit.platform:junit-platform-launcher")
18 21 }
19 22
20 23 java {
@@ -25,3 +28,7 @@ tasks.withType<JavaCompile>().configureEach {
25 28 options.encoding = "UTF-8"
26 29 options.release.set(25)
27 30 }
31
32 tasks.test {
33 useJUnitPlatform()
34 }
@@ -15,6 +15,9 @@ repositories {
15
15
16dependencies {
16dependencies {
17 compileOnly("io.papermc.paper:paper-api:26.2.build.112-stable")
17 compileOnly("io.papermc.paper:paper-api:26.2.build.112-stable")
18 testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
19 testImplementation("org.yaml:snakeyaml:2.4")
20 testRuntimeOnly("org.junit.platform:junit-platform-launcher")
18}
21}
19
22
20java {
23java {
@@ -25,3 +28,7 @@ tasks.withType<JavaCompile>().configureEach {
25 options.encoding = "UTF-8"
28 options.encoding = "UTF-8"
26 options.release.set(25)
29 options.release.set(25)
27}
30}
31
32tasks.test {
33 useJUnitPlatform()
34}
scripts/ci/bluegit-release.sh +21 −10
@@ -1,15 +1,26 @@
1 1 #!/usr/bin/env bash
2 # BlueGit: release maken met de jar als asset.
3 # De release-API maakt de tag zelf aan en weigert een bestaande tag, dus een
4 # release kan nooit twee keer ontstaan. Overslaan als HEAD al een tag heeft.
2 # BlueGit: publicatie van een bestaande tag (de tag is al gepusht).
3 # POST .../releases/$TAG/assets maakt de release met de jar als asset en
4 # wijzigt de tag niet. Alleen job-token, alleen in de tag-pipeline.
5 5 set -euo pipefail
6 : "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}"
7 v="$(cat build/version.txt)"
8 git fetch -q --tags origin 2>/dev/null || true
9 if [[ -n "$(git tag --points-at HEAD)" ]]; then echo "Geen release: HEAD heeft al een tag."; exit 0; fi
10 if git rev-parse -q --verify "refs/tags/$v" >/dev/null; then echo "Tag $v bestaat al" >&2; exit 1; fi
11 body="$(printf '{"tag":"%s","commit":"%s","name":"BirdCourier %s","body":"Release %s of BirdCourier.","assets":[{"job":"build:artifacts","path":"build/out/BirdCourier.jar","name":"BirdCourier-%s.jar"}]}' "$v" "$CI_COMMIT_SHA" "$v" "$v" "$v")"
6 : "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}" "${CI_COMMIT_TAG:?}"
7 v="${CI_COMMIT_TAG#v}"
8 path="build/out/BirdCourier.jar"
9 name="BirdCourier-${v}.jar"
10 [[ -f "$path" ]] || { echo "ontbreekt: $path" >&2; ls -la build/out >&2 || true; exit 1; }
11
12 body="$(python3 -c 'import json,sys; print(json.dumps({
13 "commit": sys.argv[1],
14 "name": "BirdCourier "+sys.argv[2],
15 "body": "Release "+sys.argv[2]+" of BirdCourier.",
16 "assets": [{"job": "build:artifacts", "path": sys.argv[3], "name": sys.argv[4]}],
17 }))' "$CI_COMMIT_SHA" "$v" "$path" "$name")"
18
12 19 resp="$(mktemp)"
13 code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" -H "Authorization: Bearer $CI_JOB_TOKEN" -H "Content-Type: application/json" -d "$body")" || code=000
20 code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST \
21 "$CI_API_URL/repos/$CI_PROJECT_PATH/releases/${CI_COMMIT_TAG}/assets" \
22 -H "Authorization: Bearer $CI_JOB_TOKEN" \
23 -H "Content-Type: application/json" \
24 --data-binary "$body")" || code=000
14 25 cat "$resp"; echo
15 26 [[ "$code" == 2* ]] || { echo "Release-API gaf HTTP $code" >&2; exit 1; }
@@ -1,15 +1,26 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2# BlueGit: release maken met de jar als asset.
2# BlueGit: publicatie van een bestaande tag (de tag is al gepusht).
3# De release-API maakt de tag zelf aan en weigert een bestaande tag, dus een
3# POST .../releases/$TAG/assets maakt de release met de jar als asset en
4# release kan nooit twee keer ontstaan. Overslaan als HEAD al een tag heeft.
4# wijzigt de tag niet. Alleen job-token, alleen in de tag-pipeline.
5set -euo pipefail
5set -euo pipefail
6: "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}"
6: "${CI_API_URL:?}" "${CI_JOB_TOKEN:?}" "${CI_COMMIT_SHA:?}" "${CI_PROJECT_PATH:?}" "${CI_COMMIT_TAG:?}"
7v="$(cat build/version.txt)"
7v="${CI_COMMIT_TAG#v}"
8git fetch -q --tags origin 2>/dev/null || true
8path="build/out/BirdCourier.jar"
9if [[ -n "$(git tag --points-at HEAD)" ]]; then echo "Geen release: HEAD heeft al een tag."; exit 0; fi
9name="BirdCourier-${v}.jar"
10if git rev-parse -q --verify "refs/tags/$v" >/dev/null; then echo "Tag $v bestaat al" >&2; exit 1; fi
10[[ -f "$path" ]] || { echo "ontbreekt: $path" >&2; ls -la build/out >&2 || true; exit 1; }
11body="$(printf '{"tag":"%s","commit":"%s","name":"BirdCourier %s","body":"Release %s of BirdCourier.","assets":[{"job":"build:artifacts","path":"build/out/BirdCourier.jar","name":"BirdCourier-%s.jar"}]}' "$v" "$CI_COMMIT_SHA" "$v" "$v" "$v")"
11
12body="$(python3 -c 'import json,sys; print(json.dumps({
13 "commit": sys.argv[1],
14 "name": "BirdCourier "+sys.argv[2],
15 "body": "Release "+sys.argv[2]+" of BirdCourier.",
16 "assets": [{"job": "build:artifacts", "path": sys.argv[3], "name": sys.argv[4]}],
17}))' "$CI_COMMIT_SHA" "$v" "$path" "$name")"
18
12resp="$(mktemp)"
19resp="$(mktemp)"
13code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST "$CI_API_URL/repos/$CI_PROJECT_PATH/releases" -H "Authorization: Bearer $CI_JOB_TOKEN" -H "Content-Type: application/json" -d "$body")" || code=000
20code="$(curl -sS -o "$resp" -w '%{http_code}' -X POST \
21 "$CI_API_URL/repos/$CI_PROJECT_PATH/releases/${CI_COMMIT_TAG}/assets" \
22 -H "Authorization: Bearer $CI_JOB_TOKEN" \
23 -H "Content-Type: application/json" \
24 --data-binary "$body")" || code=000
14cat "$resp"; echo
25cat "$resp"; echo
15[[ "$code" == 2* ]] || { echo "Release-API gaf HTTP $code" >&2; exit 1; }
26[[ "$code" == 2* ]] || { echo "Release-API gaf HTTP $code" >&2; exit 1; }
scripts/ci/build.sh +6 −5
@@ -1,10 +1,11 @@
1 1 #!/usr/bin/env bash
2 # Versie bepalen (hoogste tag + 1 patch of RELEASE_VERSION), zelfde bump als
3 # scripts/release.sh (alleen lokaal in de build, geen commit), jar bouwen.
4 # Zonder tags: de versie die al in build.gradle.kts staat, zodat de eerste
5 # import van 1.1.3 niet als 0.0.1 wordt gebouwd.
2 # Versie bepalen (tag, RELEASE_VERSION, hoogste tag + 1 patch, of de versie
3 # die al in build.gradle.kts staat), zelfde bump als scripts/release.sh
4 # (alleen lokaal in de build, geen commit), jar bouwen.
6 5 set -euo pipefail
7 if [ -n "${RELEASE_VERSION:-}" ]; then v="${RELEASE_VERSION#v}"; else
6 if [ -n "${RELEASE_VERSION:-}" ]; then v="${RELEASE_VERSION#v}"
7 elif [ -n "${CI_COMMIT_TAG:-}" ]; then v="${CI_COMMIT_TAG#v}"
8 else
8 9 last="$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' | sort -V | tail -n1 || true)"
9 10 if [ -z "$last" ]; then
10 11 v="$(sed -n 's/^version = "\(.*\)"/\1/p' build.gradle.kts)"
@@ -1,10 +1,11 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2# Versie bepalen (hoogste tag + 1 patch of RELEASE_VERSION), zelfde bump als
2# Versie bepalen (tag, RELEASE_VERSION, hoogste tag + 1 patch, of de versie
3# scripts/release.sh (alleen lokaal in de build, geen commit), jar bouwen.
3# die al in build.gradle.kts staat), zelfde bump als scripts/release.sh
4# Zonder tags: de versie die al in build.gradle.kts staat, zodat de eerste
4# (alleen lokaal in de build, geen commit), jar bouwen.
5# import van 1.1.3 niet als 0.0.1 wordt gebouwd.
6set -euo pipefail
5set -euo pipefail
7if [ -n "${RELEASE_VERSION:-}" ]; then v="${RELEASE_VERSION#v}"; else
6if [ -n "${RELEASE_VERSION:-}" ]; then v="${RELEASE_VERSION#v}"
7elif [ -n "${CI_COMMIT_TAG:-}" ]; then v="${CI_COMMIT_TAG#v}"
8else
8 last="$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' | sort -V | tail -n1 || true)"
9 last="$(git tag -l | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' | sort -V | tail -n1 || true)"
9 if [ -z "$last" ]; then
10 if [ -z "$last" ]; then
10 v="$(sed -n 's/^version = "\(.*\)"/\1/p' build.gradle.kts)"
11 v="$(sed -n 's/^version = "\(.*\)"/\1/p' build.gradle.kts)"
src/main/java/nl/timfalken/birdcourier/CleanupPatch.java +2 −2
@@ -134,7 +134,7 @@ public final class CleanupPatch {
134 134 } catch (Throwable ignored) { return false; }
135 135 }
136 136
137 private static boolean isCourierTagged(Set<String> tags) {
137 static boolean isCourierTagged(Set<String> tags) {
138 138 for (String tag : tags) if (tag.equals("birdcourier") || tag.equals("bird_courier")
139 139 || tag.equals("birdcourier-visual") || tag.equals("birdcourier_visual")
140 140 || tag.startsWith("birdcourier-shipment:") || tag.startsWith("birdcourier_shipment:")
@@ -142,7 +142,7 @@ public final class CleanupPatch {
142 142 return false;
143 143 }
144 144
145 private static Long shipmentId(Set<String> tags) {
145 static Long shipmentId(Set<String> tags) {
146 146 String[] prefixes = {"birdcourier-shipment:", "birdcourier_shipment:", "birdcourier:"};
147 147 for (String tag : tags) for (String prefix : prefixes) if (tag.startsWith(prefix)) {
148 148 try { return Long.parseLong(tag.substring(prefix.length())); }
@@ -134,7 +134,7 @@ public final class CleanupPatch {
134 } catch (Throwable ignored) { return false; }
134 } catch (Throwable ignored) { return false; }
135 }
135 }
136
136
137 private static boolean isCourierTagged(Set<String> tags) {
137 static boolean isCourierTagged(Set<String> tags) {
138 for (String tag : tags) if (tag.equals("birdcourier") || tag.equals("bird_courier")
138 for (String tag : tags) if (tag.equals("birdcourier") || tag.equals("bird_courier")
139 || tag.equals("birdcourier-visual") || tag.equals("birdcourier_visual")
139 || tag.equals("birdcourier-visual") || tag.equals("birdcourier_visual")
140 || tag.startsWith("birdcourier-shipment:") || tag.startsWith("birdcourier_shipment:")
140 || tag.startsWith("birdcourier-shipment:") || tag.startsWith("birdcourier_shipment:")
@@ -142,7 +142,7 @@ public final class CleanupPatch {
142 return false;
142 return false;
143 }
143 }
144
144
145 private static Long shipmentId(Set<String> tags) {
145 static Long shipmentId(Set<String> tags) {
146 String[] prefixes = {"birdcourier-shipment:", "birdcourier_shipment:", "birdcourier:"};
146 String[] prefixes = {"birdcourier-shipment:", "birdcourier_shipment:", "birdcourier:"};
147 for (String tag : tags) for (String prefix : prefixes) if (tag.startsWith(prefix)) {
147 for (String tag : tags) for (String prefix : prefixes) if (tag.startsWith(prefix)) {
148 try { return Long.parseLong(tag.substring(prefix.length())); }
148 try { return Long.parseLong(tag.substring(prefix.length())); }
src/main/java/nl/timfalken/birdcourier/CourierChoicePatch.java +3 −3
@@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicLong;
9 9
10 10 /** Runtime compatibility layer for per-player courier selection and visual setup. */
11 11 public final class CourierChoicePatch {
12 private static final List<String> ALLOWED = List.of("allay", "bat", "bee", "blaze", "chicken", "baby_chicken", "ghast", "parrot", "vex");
12 static final List<String> ALLOWED = List.of("allay", "bat", "bee", "blaze", "chicken", "baby_chicken", "ghast", "parrot", "vex");
13 13 private static final Map<UUID, String> CHOICES = new HashMap<>();
14 14 private static Path choicesFile;
15 15
@@ -206,8 +206,8 @@ public final class CourierChoicePatch {
206 206 }
207 207 }
208 208
209 private static String storageType(String choice) { if ("ghast".equals(choice)) return "HAPPY_GHAST"; if ("baby_chicken".equals(choice)) return "CHICKEN"; return choice.toUpperCase(Locale.ROOT); }
210 private static String displayChoice(String choice) { if ("ghast".equals(choice)) return "Ghastling"; if ("baby_chicken".equals(choice)) return "Baby Chicken"; return Character.toUpperCase(choice.charAt(0)) + choice.substring(1); }
209 static String storageType(String choice) { if ("ghast".equals(choice)) return "HAPPY_GHAST"; if ("baby_chicken".equals(choice)) return "CHICKEN"; return choice.toUpperCase(Locale.ROOT); }
210 static String displayChoice(String choice) { if ("ghast".equals(choice)) return "Ghastling"; if ("baby_chicken".equals(choice)) return "Baby Chicken"; return Character.toUpperCase(choice.charAt(0)) + choice.substring(1); }
211 211
212 212 private static void loadChoices() {
213 213 CHOICES.clear();
@@ -9,7 +9,7 @@ import java.util.concurrent.atomic.AtomicLong;
9
9
10/** Runtime compatibility layer for per-player courier selection and visual setup. */
10/** Runtime compatibility layer for per-player courier selection and visual setup. */
11public final class CourierChoicePatch {
11public final class CourierChoicePatch {
12 private static final List<String> ALLOWED = List.of("allay", "bat", "bee", "blaze", "chicken", "baby_chicken", "ghast", "parrot", "vex");
12 static final List<String> ALLOWED = List.of("allay", "bat", "bee", "blaze", "chicken", "baby_chicken", "ghast", "parrot", "vex");
13 private static final Map<UUID, String> CHOICES = new HashMap<>();
13 private static final Map<UUID, String> CHOICES = new HashMap<>();
14 private static Path choicesFile;
14 private static Path choicesFile;
15
15
@@ -206,8 +206,8 @@ public final class CourierChoicePatch {
206 }
206 }
207 }
207 }
208
208
209 private static String storageType(String choice) { if ("ghast".equals(choice)) return "HAPPY_GHAST"; if ("baby_chicken".equals(choice)) return "CHICKEN"; return choice.toUpperCase(Locale.ROOT); }
209 static String storageType(String choice) { if ("ghast".equals(choice)) return "HAPPY_GHAST"; if ("baby_chicken".equals(choice)) return "CHICKEN"; return choice.toUpperCase(Locale.ROOT); }
210 private static String displayChoice(String choice) { if ("ghast".equals(choice)) return "Ghastling"; if ("baby_chicken".equals(choice)) return "Baby Chicken"; return Character.toUpperCase(choice.charAt(0)) + choice.substring(1); }
210 static String displayChoice(String choice) { if ("ghast".equals(choice)) return "Ghastling"; if ("baby_chicken".equals(choice)) return "Baby Chicken"; return Character.toUpperCase(choice.charAt(0)) + choice.substring(1); }
211
211
212 private static void loadChoices() {
212 private static void loadChoices() {
213 CHOICES.clear();
213 CHOICES.clear();
src/test/java/nl/timfalken/birdcourier/CleanupTagTest.java added +36 −0
@@ -0,0 +1,36 @@
1 package nl.timfalken.birdcourier;
2
3 import java.util.Set;
4
5 import org.junit.jupiter.api.Test;
6
7 import static org.junit.jupiter.api.Assertions.assertEquals;
8 import static org.junit.jupiter.api.Assertions.assertFalse;
9 import static org.junit.jupiter.api.Assertions.assertNull;
10 import static org.junit.jupiter.api.Assertions.assertTrue;
11
12 class CleanupTagTest {
13
14 @Test
15 void courierTagsAreRecognisedAndOrdinaryTagsAreNot() {
16 assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier")));
17 assertTrue(CleanupPatch.isCourierTagged(Set.of("bird_courier")));
18 assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier-visual")));
19 assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier_visual")));
20 assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier-shipment:7")));
21 assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier_shipment:7")));
22 assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier:7")));
23 assertFalse(CleanupPatch.isCourierTagged(Set.of()));
24 assertFalse(CleanupPatch.isCourierTagged(Set.of("invulnerable", "parrot")));
25 }
26
27 @Test
28 void shipmentIdIsReadFromKnownPrefixesOnly() {
29 assertEquals(42L, CleanupPatch.shipmentId(Set.of("birdcourier-shipment:42")));
30 assertEquals(9L, CleanupPatch.shipmentId(Set.of("other", "birdcourier_shipment:9")));
31 assertEquals(3L, CleanupPatch.shipmentId(Set.of("birdcourier:3")));
32 assertNull(CleanupPatch.shipmentId(Set.of("birdcourier")));
33 assertNull(CleanupPatch.shipmentId(Set.of("birdcourier-shipment:nope")));
34 assertNull(CleanupPatch.shipmentId(Set.of()));
35 }
36 }
@@ -0,0 +1,36 @@
1package nl.timfalken.birdcourier;
2
3import java.util.Set;
4
5import org.junit.jupiter.api.Test;
6
7import static org.junit.jupiter.api.Assertions.assertEquals;
8import static org.junit.jupiter.api.Assertions.assertFalse;
9import static org.junit.jupiter.api.Assertions.assertNull;
10import static org.junit.jupiter.api.Assertions.assertTrue;
11
12class CleanupTagTest {
13
14 @Test
15 void courierTagsAreRecognisedAndOrdinaryTagsAreNot() {
16 assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier")));
17 assertTrue(CleanupPatch.isCourierTagged(Set.of("bird_courier")));
18 assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier-visual")));
19 assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier_visual")));
20 assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier-shipment:7")));
21 assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier_shipment:7")));
22 assertTrue(CleanupPatch.isCourierTagged(Set.of("birdcourier:7")));
23 assertFalse(CleanupPatch.isCourierTagged(Set.of()));
24 assertFalse(CleanupPatch.isCourierTagged(Set.of("invulnerable", "parrot")));
25 }
26
27 @Test
28 void shipmentIdIsReadFromKnownPrefixesOnly() {
29 assertEquals(42L, CleanupPatch.shipmentId(Set.of("birdcourier-shipment:42")));
30 assertEquals(9L, CleanupPatch.shipmentId(Set.of("other", "birdcourier_shipment:9")));
31 assertEquals(3L, CleanupPatch.shipmentId(Set.of("birdcourier:3")));
32 assertNull(CleanupPatch.shipmentId(Set.of("birdcourier")));
33 assertNull(CleanupPatch.shipmentId(Set.of("birdcourier-shipment:nope")));
34 assertNull(CleanupPatch.shipmentId(Set.of()));
35 }
36}
src/test/java/nl/timfalken/birdcourier/CourierChoiceTest.java added +52 −0
@@ -0,0 +1,52 @@
1 package nl.timfalken.birdcourier;
2
3 import java.util.List;
4
5 import org.junit.jupiter.api.Test;
6 import org.junit.jupiter.params.ParameterizedTest;
7 import org.junit.jupiter.params.provider.CsvSource;
8
9 import static org.junit.jupiter.api.Assertions.assertEquals;
10 import static org.junit.jupiter.api.Assertions.assertFalse;
11 import static org.junit.jupiter.api.Assertions.assertTrue;
12
13 class CourierChoiceTest {
14
15 @Test
16 void allowedTypesMatchThePublicCourierCommand() {
17 assertEquals(
18 List.of("allay", "bat", "bee", "blaze", "chicken", "baby_chicken", "ghast", "parrot", "vex"),
19 CourierChoicePatch.ALLOWED);
20 assertFalse(CourierChoicePatch.ALLOWED.contains("phantom"));
21 }
22
23 @ParameterizedTest
24 @CsvSource({
25 "parrot,PARROT",
26 "allay,ALLAY",
27 "ghast,HAPPY_GHAST",
28 "baby_chicken,CHICKEN",
29 "bat,BAT"
30 })
31 void storageTypeMapsChoiceToEntityType(String choice, String stored) {
32 assertEquals(stored, CourierChoicePatch.storageType(choice));
33 }
34
35 @ParameterizedTest
36 @CsvSource({
37 "parrot,Parrot",
38 "allay,Allay",
39 "ghast,Ghastling",
40 "baby_chicken,Baby Chicken",
41 "vex,Vex"
42 })
43 void displayChoiceUsesFriendlyNames(String choice, String shown) {
44 assertEquals(shown, CourierChoicePatch.displayChoice(choice));
45 }
46
47 @Test
48 void defaultVisualFallbackStaysInTheAllowedList() {
49 String configured = "PARROT".toLowerCase();
50 assertTrue(CourierChoicePatch.ALLOWED.contains(configured));
51 }
52 }
@@ -0,0 +1,52 @@
1package nl.timfalken.birdcourier;
2
3import java.util.List;
4
5import org.junit.jupiter.api.Test;
6import org.junit.jupiter.params.ParameterizedTest;
7import org.junit.jupiter.params.provider.CsvSource;
8
9import static org.junit.jupiter.api.Assertions.assertEquals;
10import static org.junit.jupiter.api.Assertions.assertFalse;
11import static org.junit.jupiter.api.Assertions.assertTrue;
12
13class CourierChoiceTest {
14
15 @Test
16 void allowedTypesMatchThePublicCourierCommand() {
17 assertEquals(
18 List.of("allay", "bat", "bee", "blaze", "chicken", "baby_chicken", "ghast", "parrot", "vex"),
19 CourierChoicePatch.ALLOWED);
20 assertFalse(CourierChoicePatch.ALLOWED.contains("phantom"));
21 }
22
23 @ParameterizedTest
24 @CsvSource({
25 "parrot,PARROT",
26 "allay,ALLAY",
27 "ghast,HAPPY_GHAST",
28 "baby_chicken,CHICKEN",
29 "bat,BAT"
30 })
31 void storageTypeMapsChoiceToEntityType(String choice, String stored) {
32 assertEquals(stored, CourierChoicePatch.storageType(choice));
33 }
34
35 @ParameterizedTest
36 @CsvSource({
37 "parrot,Parrot",
38 "allay,Allay",
39 "ghast,Ghastling",
40 "baby_chicken,Baby Chicken",
41 "vex,Vex"
42 })
43 void displayChoiceUsesFriendlyNames(String choice, String shown) {
44 assertEquals(shown, CourierChoicePatch.displayChoice(choice));
45 }
46
47 @Test
48 void defaultVisualFallbackStaysInTheAllowedList() {
49 String configured = "PARROT".toLowerCase();
50 assertTrue(CourierChoicePatch.ALLOWED.contains(configured));
51 }
52}
src/test/java/nl/timfalken/birdcourier/PluginConfigTest.java added +93 −0
@@ -0,0 +1,93 @@
1 package nl.timfalken.birdcourier;
2
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.nio.charset.StandardCharsets;
6 import java.nio.file.Files;
7 import java.nio.file.Path;
8 import java.util.Map;
9 import java.util.Set;
10
11 import org.junit.jupiter.api.Test;
12 import org.yaml.snakeyaml.Yaml;
13
14 import static org.junit.jupiter.api.Assertions.assertEquals;
15 import static org.junit.jupiter.api.Assertions.assertFalse;
16 import static org.junit.jupiter.api.Assertions.assertNotNull;
17 import static org.junit.jupiter.api.Assertions.assertTrue;
18
19 class PluginConfigTest {
20
21 @Test
22 @SuppressWarnings("unchecked")
23 void pluginYmlDeclaresCommandsAndPermissions() throws IOException {
24 Map<String, Object> yaml = loadYaml("plugin.yml");
25 assertEquals("BirdCourier", yaml.get("name"));
26 assertEquals("nl.timfalken.birdcourier.BirdCourierPlugin", yaml.get("main"));
27 assertEquals("26.2", String.valueOf(yaml.get("api-version")).replace("'", ""));
28 assertEquals(gradleVersion(), String.valueOf(yaml.get("version")));
29
30 Map<String, Object> commands = (Map<String, Object>) yaml.get("commands");
31 assertNotNull(commands);
32 assertEquals(Set.of("send", "courier", "birdcourier"), commands.keySet());
33 assertEquals("birdcourier.send", ((Map<String, Object>) commands.get("send")).get("permission"));
34 assertEquals("birdcourier.courier", ((Map<String, Object>) commands.get("courier")).get("permission"));
35 assertEquals("birdcourier.admin", ((Map<String, Object>) commands.get("birdcourier")).get("permission"));
36
37 Map<String, Object> permissions = (Map<String, Object>) yaml.get("permissions");
38 assertNotNull(permissions);
39 assertEquals(true, ((Map<String, Object>) permissions.get("birdcourier.send")).get("default"));
40 assertEquals(true, ((Map<String, Object>) permissions.get("birdcourier.courier")).get("default"));
41 assertEquals("op", ((Map<String, Object>) permissions.get("birdcourier.admin")).get("default"));
42 }
43
44 @Test
45 @SuppressWarnings("unchecked")
46 void configYmlHasFlightVisualAndCleanupDefaults() throws IOException {
47 Map<String, Object> yaml = loadYaml("config.yml");
48
49 Map<String, Object> visual = (Map<String, Object>) yaml.get("visual");
50 assertEquals("PARROT", visual.get("entity-type"));
51
52 Map<String, Object> flight = (Map<String, Object>) yaml.get("flight");
53 assertEquals(10.0, ((Number) flight.get("speed-blocks-per-second")).doubleValue(), 0.001);
54 assertEquals(5.0, ((Number) flight.get("unloaded-speed-multiplier")).doubleValue(), 0.001);
55 assertEquals(10, ((Number) flight.get("preferred-height-above-ground")).intValue());
56
57 Map<String, Object> messages = (Map<String, Object>) yaml.get("messages");
58 assertTrue(messages.containsKey("sent"));
59 assertTrue(messages.containsKey("delivered"));
60 assertTrue(messages.containsKey("target-offline"));
61
62 Map<String, Object> cleanup = (Map<String, Object>) yaml.get("cleanup");
63 assertEquals(true, cleanup.get("remove-all-ai-disabled-configured-type"));
64 assertEquals(false, cleanup.get("remove-configured-type-with-any-courier-flag"));
65 assertEquals(false, cleanup.get("remove-untagged-courier-like-entities"));
66 }
67
68 private static Map<String, Object> loadYaml(String name) throws IOException {
69 try (InputStream in = PluginConfigTest.class.getClassLoader().getResourceAsStream(name)) {
70 assertNotNull(in, name + " missing on the test classpath");
71 Object loaded = new Yaml().load(in);
72 assertTrue(loaded instanceof Map, name + " should be a mapping");
73 @SuppressWarnings("unchecked")
74 Map<String, Object> map = (Map<String, Object>) loaded;
75 assertFalse(map.isEmpty());
76 return map;
77 }
78 }
79
80 private static String gradleVersion() throws IOException {
81 Path gradle = Path.of("build.gradle.kts");
82 if (!Files.isRegularFile(gradle)) {
83 gradle = Path.of("..", "build.gradle.kts");
84 }
85 for (String line : Files.readAllLines(gradle, StandardCharsets.UTF_8)) {
86 line = line.trim();
87 if (line.startsWith("version = \"")) {
88 return line.substring("version = \"".length(), line.length() - 1);
89 }
90 }
91 throw new IOException("version not found in build.gradle.kts");
92 }
93 }
@@ -0,0 +1,93 @@
1package nl.timfalken.birdcourier;
2
3import java.io.IOException;
4import java.io.InputStream;
5import java.nio.charset.StandardCharsets;
6import java.nio.file.Files;
7import java.nio.file.Path;
8import java.util.Map;
9import java.util.Set;
10
11import org.junit.jupiter.api.Test;
12import org.yaml.snakeyaml.Yaml;
13
14import static org.junit.jupiter.api.Assertions.assertEquals;
15import static org.junit.jupiter.api.Assertions.assertFalse;
16import static org.junit.jupiter.api.Assertions.assertNotNull;
17import static org.junit.jupiter.api.Assertions.assertTrue;
18
19class PluginConfigTest {
20
21 @Test
22 @SuppressWarnings("unchecked")
23 void pluginYmlDeclaresCommandsAndPermissions() throws IOException {
24 Map<String, Object> yaml = loadYaml("plugin.yml");
25 assertEquals("BirdCourier", yaml.get("name"));
26 assertEquals("nl.timfalken.birdcourier.BirdCourierPlugin", yaml.get("main"));
27 assertEquals("26.2", String.valueOf(yaml.get("api-version")).replace("'", ""));
28 assertEquals(gradleVersion(), String.valueOf(yaml.get("version")));
29
30 Map<String, Object> commands = (Map<String, Object>) yaml.get("commands");
31 assertNotNull(commands);
32 assertEquals(Set.of("send", "courier", "birdcourier"), commands.keySet());
33 assertEquals("birdcourier.send", ((Map<String, Object>) commands.get("send")).get("permission"));
34 assertEquals("birdcourier.courier", ((Map<String, Object>) commands.get("courier")).get("permission"));
35 assertEquals("birdcourier.admin", ((Map<String, Object>) commands.get("birdcourier")).get("permission"));
36
37 Map<String, Object> permissions = (Map<String, Object>) yaml.get("permissions");
38 assertNotNull(permissions);
39 assertEquals(true, ((Map<String, Object>) permissions.get("birdcourier.send")).get("default"));
40 assertEquals(true, ((Map<String, Object>) permissions.get("birdcourier.courier")).get("default"));
41 assertEquals("op", ((Map<String, Object>) permissions.get("birdcourier.admin")).get("default"));
42 }
43
44 @Test
45 @SuppressWarnings("unchecked")
46 void configYmlHasFlightVisualAndCleanupDefaults() throws IOException {
47 Map<String, Object> yaml = loadYaml("config.yml");
48
49 Map<String, Object> visual = (Map<String, Object>) yaml.get("visual");
50 assertEquals("PARROT", visual.get("entity-type"));
51
52 Map<String, Object> flight = (Map<String, Object>) yaml.get("flight");
53 assertEquals(10.0, ((Number) flight.get("speed-blocks-per-second")).doubleValue(), 0.001);
54 assertEquals(5.0, ((Number) flight.get("unloaded-speed-multiplier")).doubleValue(), 0.001);
55 assertEquals(10, ((Number) flight.get("preferred-height-above-ground")).intValue());
56
57 Map<String, Object> messages = (Map<String, Object>) yaml.get("messages");
58 assertTrue(messages.containsKey("sent"));
59 assertTrue(messages.containsKey("delivered"));
60 assertTrue(messages.containsKey("target-offline"));
61
62 Map<String, Object> cleanup = (Map<String, Object>) yaml.get("cleanup");
63 assertEquals(true, cleanup.get("remove-all-ai-disabled-configured-type"));
64 assertEquals(false, cleanup.get("remove-configured-type-with-any-courier-flag"));
65 assertEquals(false, cleanup.get("remove-untagged-courier-like-entities"));
66 }
67
68 private static Map<String, Object> loadYaml(String name) throws IOException {
69 try (InputStream in = PluginConfigTest.class.getClassLoader().getResourceAsStream(name)) {
70 assertNotNull(in, name + " missing on the test classpath");
71 Object loaded = new Yaml().load(in);
72 assertTrue(loaded instanceof Map, name + " should be a mapping");
73 @SuppressWarnings("unchecked")
74 Map<String, Object> map = (Map<String, Object>) loaded;
75 assertFalse(map.isEmpty());
76 return map;
77 }
78 }
79
80 private static String gradleVersion() throws IOException {
81 Path gradle = Path.of("build.gradle.kts");
82 if (!Files.isRegularFile(gradle)) {
83 gradle = Path.of("..", "build.gradle.kts");
84 }
85 for (String line : Files.readAllLines(gradle, StandardCharsets.UTF_8)) {
86 line = line.trim();
87 if (line.startsWith("version = \"")) {
88 return line.substring("version = \"".length(), line.length() - 1);
89 }
90 }
91 throw new IOException("version not found in build.gradle.kts");
92 }
93}