Files
NeitzelFXDesigner/scripts/run-fixture-host.py
T

67 lines
4.3 KiB
Python

#!/usr/bin/env python3
"""Launch a disposable standalone or isolated IntelliJ fixture host (macOS development)."""
import argparse
import os
from pathlib import Path
import subprocess
import sys
import tempfile
import zipfile
from xml.sax.saxutils import escape
ROOT = Path(__file__).resolve().parent.parent
p = argparse.ArgumentParser(description=__doc__)
p.add_argument("host", choices=["standalone","intellij"])
p.add_argument("--java-home", type=Path, required=True)
p.add_argument("--target-java-home", type=Path, required=True)
p.add_argument("--idea-home", type=Path)
p.add_argument("--check", action="store_true", help="Install the disposable IDE qualification companion")
p.add_argument("--mode", choices=["classpath","modulepath"], default="classpath")
args = p.parse_args()
base = Path(tempfile.mkdtemp(prefix="neitzel-designer-host-")).resolve()
project = base / "project"
subprocess.run([sys.executable, ROOT / "scripts/prepare-fixture-host.py", "--destination", project,
"--target-java-home", args.target_java_home, "--mode", args.mode], check=True)
settings = project / ".neitzel-fx-designer/host.properties"
file = project / "app/src/main/resources/fixture/components/Person.fxml"
env = dict(os.environ)
if args.host == "standalone":
cp = os.pathsep.join([str(ROOT / "designer-standalone/target/classes"),
(ROOT / "designer-standalone/target/smoke-classpath.txt").read_text().strip()])
command = [str(args.java_home / "bin/java"), "--enable-native-access=ALL-UNNAMED", "-cp", cp,
"de.neitzel.fxdesigner.standalone.Launcher", str(settings), str(file)]
else:
if args.idea_home is None:
p.error("--idea-home is required for IntelliJ")
plugin = next((ROOT / "designer-intellij/build/distributions").glob("*.zip"))
with zipfile.ZipFile(plugin) as archive:
archive.extractall(base / "plugins")
if args.check:
classes = base / "check-classes"
classes.mkdir()
jars = [*(args.idea_home / "lib").glob("*.jar"), *(base / "plugins").rglob("*.jar")]
subprocess.run([str(args.java_home / "bin/javac"), "-cp", os.pathsep.join(map(str,jars)), "-d", str(classes),
str(ROOT / "integration-tests/idea/WorkflowProbe.java")], check=True)
meta = classes / "META-INF"
meta.mkdir()
(meta / "plugin.xml").write_text('<idea-plugin><id>de.neitzel.fxdesigner.qualification</id><name>Designer workflow qualification</name><version>1</version><vendor>Local tests</vendor><idea-version since-build="263" until-build="263.*"/><depends>com.intellij.modules.platform</depends><depends>de.neitzel.fxdesigner</depends><extensions defaultExtensionNs="com.intellij"><postStartupActivity implementation="qualification.WorkflowProbe"/></extensions></idea-plugin>')
jar = base / "plugins/qualification/lib/qualification.jar"
jar.parent.mkdir(parents=True)
subprocess.run([str(args.java_home / "bin/jar"), "cf", str(jar), "-C", str(classes), "."], check=True)
options = base / "config/options"
options.mkdir(parents=True)
(options / "ide.general.xml").write_text('<application><component name="Registry"><entry key="embed.scene.builder" value="false"/></component></application>')
(options / "trusted-paths.xml").write_text('<application><component name="Trusted.Paths"><option name="TRUSTED_PROJECT_PATHS"><map><entry key="'+escape(str(project))+'" value="true"/></map></option></component></application>')
props = base / "idea.properties"
props.write_text("\n".join("idea."+name+".path="+str(base/name) for name in ["config","system","plugins","log"])+"\nidea.initially.ask.config=false\n")
vm = base / "idea.vmoptions"
vm.write_text((args.idea_home / "bin/idea.vmoptions").read_text()+"\n--enable-native-access=ALL-UNNAMED\n-Dneitzel.designer.launch="+str(settings)+"\n-Ddesigner.check.output="+str(base)+"\n")
env.update(IDEA_PROPERTIES=str(props), IDEA_VM_OPTIONS=str(vm), IDEA_JDK=str(args.java_home))
command = [str(args.idea_home / "MacOS/idea"), str(project), str(file)]
with (base / "launcher.log").open("w") as log:
process = subprocess.Popen(command, env=env, stdout=log, stderr=subprocess.STDOUT, start_new_session=True)
(base / "host.pid").write_text(str(process.pid))
print("Host PID:", process.pid)
print("Disposable host:", base)
print("FXML:", file)