-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-interactive.sh
More file actions
84 lines (74 loc) · 3.92 KB
/
Copy pathtest-interactive.sh
File metadata and controls
84 lines (74 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────────────────
# Interactive smoke test for java-service-archetype.
#
# Installs the archetype to the local Maven repo, then runs
# mvn archetype:generate in interactive mode by piping answers to each prompt
# via stdin. The generated project is written to a temp directory and removed
# on exit.
#
# Prerequisites: mvn (system Maven) must be on PATH for the generate step.
# Usage: ./test-interactive.sh [--verify]
# --verify also run `mvn verify -f parent/pom.xml` on the generated project
# ─────────────────────────────────────────────────────────────────────────────
set -euo pipefail
ARCHETYPE_GROUP_ID="io.github.jeffjensen"
ARCHETYPE_ARTIFACT_ID="java-service-archetype"
# ARCHETYPE_VERSION is read from the project pom.xml at runtime (after install),
# so this script needs no edits when the project version changes.
RUN_VERIFY=false
for arg in "$@"; do
case "$arg" in
--verify) RUN_VERIFY=true ;;
*) echo "Unknown argument: $arg" >&2; exit 1 ;;
esac
done
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OUT_DIR="$(mktemp -d)"
trap 'echo "==> Cleaning up $OUT_DIR"; rm -rf "$OUT_DIR"' EXIT
# ── 1. Install ─────────────────────────────────────────────────────────────
echo "==> Installing archetype to local repo..."
(cd "$SCRIPT_DIR" && ./mvnw install -q)
# ── Read the archetype version straight from the project POM, so this script
# needs no maintenance when the project version changes ──────────────────
ARCHETYPE_VERSION="$(cd "$SCRIPT_DIR" && ./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout --no-transfer-progress)"
echo "==> Using archetype version: $ARCHETYPE_VERSION"
# ── 2. Generate ────────────────────────────────────────────────────────────
echo "==> Generating project interactively in $OUT_DIR..."
cd "$OUT_DIR"
# Answers fed to each Maven prompt, in the exact order maven-archetype-plugin
# 3.4.x prompts. Required properties WITHOUT a non-empty default are prompted
# first, in archetype-metadata.xml order, THEN groupId / artifactId / package.
# Properties with a non-empty default are NOT prompted, so they get no answer
# line here: version (1.0.0-SNAPSHOT), serviceAreas (",") and presentationTypes
# (rest). The "," default makes serviceAreas resolve to a single "service" module.
#
# integrations → database:main
# groupId → com.example
# artifactId → my-service
# package → (Enter: accept default derived from groupId)
# confirm → Y
printf '%s\n' \
"database:main" \
"com.example" \
"my-service" \
"" \
"Y" \
| mvn archetype:generate \
--no-transfer-progress \
-DarchetypeGroupId="$ARCHETYPE_GROUP_ID" \
-DarchetypeArtifactId="$ARCHETYPE_ARTIFACT_ID" \
-DarchetypeVersion="$ARCHETYPE_VERSION"
# ── 3. Show generated layout ───────────────────────────────────────────────
echo ""
echo "==> Generated project layout:"
find "my-service" -type f | sort
# ── 4. Optionally verify the generated project compiles and tests pass ─────
if [ "$RUN_VERIFY" = "true" ]; then
echo ""
echo "==> Running mvn verify on generated project..."
(cd "my-service" && mvn verify -f parent/pom.xml --no-transfer-progress)
echo "==> Build: PASSED"
fi
echo ""
echo "==> SUCCESS"