136 lines
6.5 KiB
Bash
136 lines
6.5 KiB
Bash
#!/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-<VERSION>.jar runway-spi-<VERSION>-sources.jar runway-spi-<VERSION>.pom
|
||
|
|
# runway-spi-testkit-<VERSION>.jar runway-spi-testkit-<VERSION>-sources.jar runway-spi-testkit-<VERSION>.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 <reactor-root> <target-dir> <version>
|
||
|
|
set -euo pipefail
|
||
|
|
|
||
|
|
usage="usage: make-spi-assets.sh <reactor-root> <target-dir> <version>"
|
||
|
|
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('<?xml version="1.0" encoding="UTF-8"?>')
|
||
|
|
w('<!-- Consumer pom for the Runway release assets, generated by scripts/make-spi-assets.sh from %s/pom.xml:' % artifact)
|
||
|
|
w(' no parent, coordinates and dependency versions resolved. Install with')
|
||
|
|
w(' mvn install:install-file -Dfile=%s-%s.jar -DpomFile=%s-%s.pom -->' % (artifact, version, artifact, version))
|
||
|
|
w('<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
|
||
|
|
w(' xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">')
|
||
|
|
w(' <modelVersion>4.0.0</modelVersion>')
|
||
|
|
w(' <groupId>%s</groupId>' % escape(group))
|
||
|
|
w(' <artifactId>%s</artifactId>' % escape(artifact))
|
||
|
|
w(' <version>%s</version>' % escape(version))
|
||
|
|
w(' <packaging>jar</packaging>')
|
||
|
|
for tag in ("name", "description"):
|
||
|
|
v = text(root, "m:" + tag)
|
||
|
|
if v:
|
||
|
|
w(' <%s>%s</%s>' % (tag, escape(v), tag))
|
||
|
|
w(' <organization>')
|
||
|
|
w(' <name>Quest ICT SAS de CV</name>')
|
||
|
|
w(' <url>https://quest.mx</url>')
|
||
|
|
w(' </organization>')
|
||
|
|
w(' <licenses>')
|
||
|
|
w(' <license>')
|
||
|
|
w(' <name>GNU Affero General Public License v3.0, with the Runway additional permission for plugins</name>')
|
||
|
|
w(' <url>https://www.gnu.org/licenses/agpl-3.0.txt</url>')
|
||
|
|
w(' <distribution>repo</distribution>')
|
||
|
|
w(' <comments>Additional permission for plugins: META-INF/LICENSE-EXCEPTION in this jar.</comments>')
|
||
|
|
w(' </license>')
|
||
|
|
w(' </licenses>')
|
||
|
|
if deps:
|
||
|
|
w(' <dependencies>')
|
||
|
|
for g, a, v, scope, optional in deps:
|
||
|
|
w(' <dependency>')
|
||
|
|
w(' <groupId>%s</groupId>' % escape(g))
|
||
|
|
w(' <artifactId>%s</artifactId>' % escape(a))
|
||
|
|
w(' <version>%s</version>' % escape(v))
|
||
|
|
if scope != "compile":
|
||
|
|
w(' <scope>%s</scope>' % escape(scope))
|
||
|
|
if optional:
|
||
|
|
w(' <optional>%s</optional>' % escape(optional))
|
||
|
|
w(' </dependency>')
|
||
|
|
w(' </dependencies>')
|
||
|
|
w('</project>')
|
||
|
|
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}')
|