#!/usr/bin/env bash # # make-spi-assets.sh — stage the plugin author's compile-time artifacts next to the release files. # # A third-party plugin compiles against mx.quest:runway-spi (provided) and tests against # mx.quest:runway-spi-testkit (test). No Maven repository serves them: they travel as assets of the kernel # release (on the project's releases page), and an author installs them into ~/.m2 with `mvn install:install-file` # (docs/PLUGIN-DEVELOPMENT.md §3). So every release carries, for VERSION = the kernel release version: # # runway-spi-.jar runway-spi--sources.jar runway-spi-.pom # runway-spi-testkit-.jar runway-spi-testkit--sources.jar runway-spi-testkit-.pom # # The jars are copied byte-for-byte from the reactor modules' target/ (both modules attach a sources jar; all # four honour project.build.outputTimestamp, so they are reproducible). The poms are CONSUMER poms, generated # here: the module poms inherit their groupId and version from the reactor parent (mx.quest:runway), which is # not published, and whose own parent is Spring Boot's. Installed as-is, they would make every author's build # warn "The POM for mx.quest:runway-spi … is invalid, transitive dependencies … will not be available" and drop # the testkit's dependency on runway-spi. The consumer pom states the coordinates outright, has no parent, and # keeps only the non-test dependencies with their versions resolved — read from the module pom, so a dependency # added there cannot be silently missing here (an unresolvable version is refused, not guessed). # # Wired into runway-dist's `dist` profile before make-release-aliases.sh, which lists these files in SHA256SUMS # and refuses when one is missing. Tools: bash, cp, python3 (standard library only; output is deterministic). # # Usage: make-spi-assets.sh set -euo pipefail usage="usage: make-spi-assets.sh " ROOT="${1:?$usage}" TARGET="${2:?$usage}" VERSION="${3:?$usage}" VERSION="${VERSION#v}" command -v python3 >/dev/null 2>&1 || { echo "[spi-assets] python3 is required to write the consumer poms" >&2; exit 1; } mkdir -p "$TARGET" for module in runway-spi runway-spi-testkit; do for f in "${module}-${VERSION}.jar" "${module}-${VERSION}-sources.jar"; do src="$ROOT/$module/target/$f" [ -f "$src" ] || { echo "[spi-assets] missing $src — build the reactor with 'mvn -P dist package'" >&2; exit 1; } cp -f "$src" "$TARGET/$f" done part="$TARGET/${module}-${VERSION}.pom.part" if ! python3 - "$ROOT/$module/pom.xml" "$module" "$VERSION" > "$part" <<'PY' import sys, re import xml.etree.ElementTree as ET from xml.sax.saxutils import escape pom_path, artifact, version = sys.argv[1], sys.argv[2], sys.argv[3] NS = {"m": "http://maven.apache.org/POM/4.0.0"} root = ET.parse(pom_path).getroot() def text(el, path, default=None): found = el.find(path, NS) return default if found is None or found.text is None else " ".join(found.text.split()) def die(msg): sys.stderr.write("[spi-assets] %s: %s\n" % (pom_path, msg)) sys.exit(1) if text(root, "m:artifactId") != artifact: die("artifactId is %r, expected %r" % (text(root, "m:artifactId"), artifact)) group = text(root, "m:groupId") or text(root, "m:parent/m:groupId") if group != "mx.quest": die("groupId is %r, expected 'mx.quest'" % group) def resolve(value, what): value = value.replace("${project.version}", version).replace("${project.groupId}", group) if "${" in value: die("cannot resolve %s %r for the consumer pom" % (what, value)) return value deps = [] for d in root.findall("m:dependencies/m:dependency", NS): scope = text(d, "m:scope", "compile") if scope == "test": continue g, a, v = text(d, "m:groupId"), text(d, "m:artifactId"), text(d, "m:version") if not v: die("dependency %s:%s has no explicit version (managed versions do not survive without the parent)" % (g, a)) deps.append((resolve(g, "groupId"), a, resolve(v, "version"), scope, text(d, "m:optional"))) out = [] w = out.append w('') w('' % (artifact, version, artifact, version)) w('') w(' 4.0.0') w(' %s' % escape(group)) w(' %s' % escape(artifact)) w(' %s' % escape(version)) w(' jar') for tag in ("name", "description"): v = text(root, "m:" + tag) if v: w(' <%s>%s' % (tag, escape(v), tag)) w(' ') w(' Quest ICT SAS de CV') w(' https://quest.mx') w(' ') w(' ') w(' ') w(' GNU Affero General Public License v3.0, with the Runway additional permission for plugins') w(' https://www.gnu.org/licenses/agpl-3.0.txt') w(' repo') w(' Additional permission for plugins: META-INF/LICENSE-EXCEPTION in this jar.') w(' ') w(' ') if deps: w(' ') for g, a, v, scope, optional in deps: w(' ') w(' %s' % escape(g)) w(' %s' % escape(a)) w(' %s' % escape(v)) if scope != "compile": w(' %s' % escape(scope)) if optional: w(' %s' % escape(optional)) w(' ') w(' ') w('') sys.stdout.write("\n".join(out) + "\n") PY then rm -f "$part" exit 1 fi mv -f "$part" "$TARGET/${module}-${VERSION}.pom" done echo "[spi-assets] plugin-author artifacts for ${VERSION} staged in $TARGET:" (cd "$TARGET" && ls -l runway-spi*-"${VERSION}"*.jar runway-spi*-"${VERSION}".pom | awk '{printf " %-46s %s\n", $9, $5}')