#!/usr/bin/env bash # gen-bulk.sh # Writes classes into the package that @SpringBootApplication already scans. # # 'plain' classes carry no stereotype annotation at all. They are still opened, read and # have their annotation metadata parsed by the scanner -- which is the point: it separates # the cost of *scanning* from the cost of *creating beans*. set -euo pipefail COUNT="${1:-5000}" KIND="${2:-plain}" ROOT="$(cd "$(dirname "$0")/.." && pwd)" DIR="$ROOT/src/main/java/com/ankurm/startup/bulk" rm -rf "$DIR"; mkdir -p "$DIR" for i in $(seq 1 "$COUNT"); do if [ "$KIND" = "component" ]; then printf 'package com.ankurm.startup.bulk;\nimport org.springframework.stereotype.Component;\n@Component\npublic class Bulk%d { public int id() { return %d; } }\n' "$i" "$i" > "$DIR/Bulk$i.java" else printf 'package com.ankurm.startup.bulk;\npublic class Bulk%d { public int id() { return %d; } }\n' "$i" "$i" > "$DIR/Bulk$i.java" fi done echo "generated $COUNT $KIND classes in src/main/java/com/ankurm/startup/bulk"