|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Regression guard: an artifact type a build extension defines must apply as it does in Maven's own |
| 3 | +# resolution. Type fat, from the types-ext extension, includes its dependencies and is a jar on disk, |
| 4 | +# so demo.ext:inner below demo.ext:fat must not be emitted, and --with-files must fetch fat-1.0.jar. |
| 5 | +# |
| 6 | +# Usage: smoke-test-extension-type.sh <path-to-mvn> <path-to-extension-jar> |
| 7 | +set -euo pipefail |
| 8 | +HERE="$(cd "$(dirname "$0")" && pwd)" |
| 9 | +MVN="${1:?usage: smoke-test-extension-type.sh <mvn> <extension-jar>}" |
| 10 | +JAR="${2:?usage: smoke-test-extension-type.sh <mvn> <extension-jar>}" |
| 11 | +PROJECT="$HERE/extension-type" |
| 12 | +RECORDS="$PROJECT/records.tsv" |
| 13 | +STUBS="$PROJECT/localrepo" |
| 14 | +# shellcheck source=SCRIPTDIR/../compat-cache.sh |
| 15 | +. "$HERE/../compat-cache.sh" |
| 16 | +M2="$SOCKET_COMPAT_CACHE/m2" |
| 17 | + |
| 18 | +bash "$HERE/../make-stub-repo.sh" "$STUBS" \ |
| 19 | + 'demo.ext:types-ext:1.0' \ |
| 20 | + 'demo.ext:fat:1.0+demo.ext:inner:1.0' \ |
| 21 | + 'demo.ext:inner:1.0' |
| 22 | +# The extension is a components.xml registering Maven's own handler class for type fat. |
| 23 | +EXT_DIR="$(mktemp -d)" |
| 24 | +trap 'rm -rf "$EXT_DIR"' EXIT |
| 25 | +mkdir -p "$EXT_DIR/META-INF/plexus" |
| 26 | +cat > "$EXT_DIR/META-INF/plexus/components.xml" <<'XML' |
| 27 | +<component-set> |
| 28 | + <components> |
| 29 | + <component> |
| 30 | + <role>org.apache.maven.artifact.handler.ArtifactHandler</role> |
| 31 | + <role-hint>fat</role-hint> |
| 32 | + <implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation> |
| 33 | + <configuration> |
| 34 | + <type>fat</type> |
| 35 | + <extension>jar</extension> |
| 36 | + <includesDependencies>true</includesDependencies> |
| 37 | + </configuration> |
| 38 | + </component> |
| 39 | + </components> |
| 40 | +</component-set> |
| 41 | +XML |
| 42 | +( cd "$EXT_DIR" && jar cf "$STUBS/demo/ext/types-ext/1.0/types-ext-1.0.jar" META-INF ) |
| 43 | +rm -rf "$M2/demo/ext/types-ext" "$M2/demo/ext/fat" "$M2/demo/ext/inner" "$RECORDS" |
| 44 | + |
| 45 | +echo "+ $("$MVN" -v 2>/dev/null | head -1) (extension type)" |
| 46 | +( cd "$PROJECT" && "$MVN" --batch-mode -q \ |
| 47 | + "-Dmaven.ext.class.path=$JAR" \ |
| 48 | + -Dcoana.task=socket-facts \ |
| 49 | + -Dsocket.withFiles=true \ |
| 50 | + "-Dmaven.repo.local=$M2" \ |
| 51 | + "-Dstub.repo.url=file://$STUBS" \ |
| 52 | + "-Dsocket.recordsFile=$RECORDS" \ |
| 53 | + validate ) |
| 54 | + |
| 55 | +python3 - "$RECORDS" <<'PY' |
| 56 | +import sys |
| 57 | +rows = [l.rstrip('\n').split('\t') for l in open(sys.argv[1]) if l.strip()] |
| 58 | +nodes = {r[2] for r in rows if r[0] == 'node'} |
| 59 | +files = {r[3] for r in rows if r[0] == 'file' and r[2].startswith('demo.ext:fat:')} |
| 60 | +failures = [r[1:] for r in rows if r[0] in ('failure', 'unscannable')] |
| 61 | +errors = [] |
| 62 | +if not any(n.startswith('demo.ext:fat:') for n in nodes): |
| 63 | + errors.append(f"demo.ext:fat missing; nodes={sorted(nodes)}") |
| 64 | +if any(n.startswith('demo.ext:inner:') for n in nodes): |
| 65 | + errors.append("demo.ext:inner emitted, though type fat includes its dependencies") |
| 66 | +if not any(p.endswith('fat-1.0.jar') for p in files): |
| 67 | + errors.append(f"fat-1.0.jar not materialized; files={sorted(files)}") |
| 68 | +if failures: |
| 69 | + errors.append(f"no failures expected; got {failures}") |
| 70 | +if errors: |
| 71 | + print("FAIL:") |
| 72 | + for e in errors: |
| 73 | + print(" -", e) |
| 74 | + sys.exit(1) |
| 75 | +print("PASS (extension type): fat emitted as a jar, inner not resolved below it") |
| 76 | +PY |
0 commit comments