85 lines
4.5 KiB
Python
Executable File
85 lines
4.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Run the Spring app and preview in fresh JavaFX processes on classpath and module path."""
|
|
import argparse
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
FIXTURE = ROOT / "integration-fixtures/spring-di"
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--target-java-home", type=Path, required=True)
|
|
args = parser.parse_args()
|
|
java = args.target_java_home.resolve() / "bin"
|
|
env = dict(os.environ, JAVA_HOME=str(java.parent))
|
|
logs = ROOT / "target/spring-preview"
|
|
logs.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
def run(label, command, timeout=120):
|
|
result = subprocess.run(list(map(str, command)), env=env, cwd=ROOT,
|
|
capture_output=True, text=True, timeout=timeout)
|
|
log = result.stdout + result.stderr
|
|
(logs / (label + ".log")).write_text(log)
|
|
if result.returncode:
|
|
raise RuntimeError(label + "\n" + log[-10000:])
|
|
return log
|
|
|
|
|
|
with tempfile.TemporaryDirectory(prefix="designer-spring-preview-") as temporary:
|
|
project = Path(temporary) / "spring-di"
|
|
shutil.copytree(FIXTURE, project, ignore=shutil.ignore_patterns("target", ".neitzel-fx-designer"))
|
|
run("build", [ROOT / "mvnw", "-B", "-ntp", "-f", project / "pom.xml", "package",
|
|
"org.apache.maven.plugins:maven-dependency-plugin:3.6.1:build-classpath",
|
|
"org.apache.maven.plugins:maven-dependency-plugin:3.6.1:tree",
|
|
"-Dmdep.outputFile=target/runtime.txt", "-DoutputFile=target/dependencies.txt"])
|
|
for module in ("app", "preview"):
|
|
tree = (project / module / "target/dependencies.txt").read_text()
|
|
(logs / f"{module}-dependencies.txt").write_text(tree)
|
|
if re.search(r"de\.neitzel\.lib:(?:fx-)?injection:|org\.reflections:reflections:", tree):
|
|
raise AssertionError(f"Unexpected DI dependency in {module}\n{tree}")
|
|
target = project / "preview/target"
|
|
tools = [ROOT / f"designer-{module}/target/designer-{module}-0.1.2-SNAPSHOT.jar"
|
|
for module in ("target-tools", "contracts", "preview-api")]
|
|
resolved = [Path(path) for path in (target / "runtime.txt").read_text().strip().split(os.pathsep)]
|
|
entries = list(dict.fromkeys([target / "spring-di-preview-1.jar", *resolved, *tools[:2]]))
|
|
(logs / "runtime-entries.txt").write_text("\n".join(map(str, entries)) + "\n")
|
|
cp = os.pathsep.join(map(str, entries))
|
|
classes = Path(temporary) / "checks"
|
|
run("compile-checks", [java / "javac", "-cp", cp, "-d", classes,
|
|
*sorted((project / "checks").glob("*.java"))])
|
|
results = []
|
|
|
|
def launch(label, mode, options, main="SpringChecks"):
|
|
access = "ALL-UNNAMED,javafx.graphics" if "--module-path" in options else "ALL-UNNAMED"
|
|
log = run(label, [java / "java", "--enable-native-access=" + access,
|
|
*options, main, mode], timeout=40)
|
|
match = re.search(r"^PASS " + re.escape(mode) + r" (\d+)$", log, re.MULTILINE)
|
|
assert match, log
|
|
if mode in ("application", "book", "card"):
|
|
arrangement = "module-path" if "--module-path" in options else "classpath"
|
|
assert f"SPRING FX ISOLATION {arrangement} " in log, log
|
|
results.append(int(match[1]))
|
|
print(label + ": " + match[0], flush=True)
|
|
|
|
for arrangement in ("classpath", "modulepath"):
|
|
options = (["-cp", str(classes) + os.pathsep + cp] if arrangement == "classpath"
|
|
else ["--module-path", cp, "--add-modules", "ALL-MODULE-PATH", "-cp", classes])
|
|
for mode in ("application", "book", "book-fresh", "card", "invalid", "readiness", "cancel",
|
|
"wrong-context", "missing-resource", "release-failure"):
|
|
launch(arrangement + "-" + mode, "book" if mode == "book-fresh" else mode, options)
|
|
if arrangement == "modulepath":
|
|
launch("modulepath-closed-resource", "closed-resource", options)
|
|
|
|
legacy_path = Path(temporary) / "legacy-runtime.txt"
|
|
run("resolve-legacy-runtime", [
|
|
ROOT / "mvnw", "-B", "-ntp", "-f", project / "checks/legacy/pom.xml",
|
|
"org.apache.maven.plugins:maven-dependency-plugin:3.6.1:build-classpath",
|
|
f"-Dmdep.outputFile={legacy_path}"])
|
|
legacy_runtime = os.pathsep.join([str(classes), *map(str, tools), legacy_path.read_text().strip()])
|
|
launch("classpath-missing-capability", "missing-capability", ["-cp", legacy_runtime], main="CapabilityCheck")
|
|
print(f"PASS {len(results)} Spring target processes, {sum(results)} checks", flush=True)
|