#!/usr/bin/env python3 """Launch a disposable standalone or isolated IntelliJ fixture host (macOS development).""" import argparse import os import shutil 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") p.add_argument("--spring-di", action="store_true", help="Use the Spring DI preview fixture") p.add_argument("--archiver", type=Path, help="Use a disposable copy of the Archiver project") forms = p.add_mutually_exclusive_group() forms.add_argument("--connection-form", action="store_true", help="Open and qualify the Archiver connection form") forms.add_argument("--grid-docking", type=Path, metavar="REFERENCE_FXML", help="Qualify the Archiver grid, dock layout and the supplied reference workspace") forms.add_argument("--dock-rules", action="store_true", help="Verify group minima, split directions and persistence in the Archiver") forms.add_argument("--media-layout-grid", action="store_true", help="Verify media permissions, form destinations and grid setups in the Archiver") forms.add_argument("--management-readers", action="store_true", help="Verify account and trash commands and the five reader toolbars") forms.add_argument("--reader-states", action="store_true", help="Verify the Archiver tag template, attachment export and HTML recovery") forms.add_argument("--viewer-import", action="store_true", help="Verify HtmlViewer references and retry in the Archiver import dialog") forms.add_argument("--row-menus", action="store_true", help="Edit Archiver row menu bindings and literal grid group labels") forms.add_argument("--folder-profiles", action="store_true", help="Check the Archiver profile commands and metadata columns") forms.add_argument("--folder-actions", action="store_true", help="Check visual event references, folder search, selection and display profiles") forms.add_argument("--import-form", action="store_true", help="Check generic binding types and the Archiver import collision") forms.add_argument("--document-tabs", action="store_true", help="Qualify the production Archiver HTML document tabs") forms.add_argument("--saved-document", action="store_true", help="Open the Archiver saved HTML and tag example") args = p.parse_args() if (args.connection_form or args.grid_docking or args.saved_document or args.document_tabs or args.import_form or args.folder_actions or args.reader_states or args.viewer_import or args.row_menus or args.folder_profiles or args.management_readers or args.media_layout_grid or args.dock_rules) and not args.archiver: p.error("Selecting an Archiver view requires --archiver") if args.spring_di and args.archiver: p.error("Choose only one fixture") base = Path(tempfile.mkdtemp(prefix="neitzel-designer-host-")).resolve() project = base / "project" if args.archiver: if args.host != "intellij" or args.mode != "classpath": p.error("Archiver requires the IntelliJ classpath configuration") shutil.copytree(args.archiver, project, ignore=shutil.ignore_patterns(".git", ".idea", "target", ".neitzel-fx-designer")) subprocess.run([sys.executable, ROOT / "scripts/configure-library-example.py", "--project", project, "--target-java-home", args.target_java_home], check=True) view = "ConnectionForm" if args.connection_form else "ArchiveWindow" if args.media_layout_grid or args.reader_states or args.viewer_import: view = "HtmlDocument" if args.management_readers: view = "MailControls" if args.reader_states: view = "DocumentTag" if args.folder_profiles or args.row_menus: view = "FolderTab" if args.folder_actions: view = "DocumentDetails" if args.check else "FolderTab" if args.document_tabs and args.check: view = "DocumentTag" if args.grid_docking: view = "FolderTab" shutil.copyfile(args.grid_docking, project / "src/main/resources/ReferenceWorkspace.fxml") file = project / f"src/main/resources/de/neitzel/archiver/ui/{view}.fxml" if args.import_form: file = file.with_name("ConnectionForm.fxml") if args.check: # Author two shipped bindings again in the disposable copy. One deliberately # untyped selector exercises the diagnostic without changing the product form. for form, declaration in [ (file.with_name("ImportForm.fxml"), ''), (file.with_name("FolderTab.fxml"), ''), ]: source = form.read_text() if source.count(declaration) != 1: raise ValueError(f"Expected the shipped binding in {form.name}") source = "".join(line for line in source.splitlines(keepends=True) if line.strip() != declaration) if form.name == "FolderTab.fxml": source = source.replace("", '') form.write_text(source) if args.saved_document: file = project / "src/designer/resources/de/neitzel/archiver/preview/SavedDocument.fxml" if args.check: # Start the authoring test with both destinations unbound in the disposable copy. source = file.read_text() for control, prop, path in (("article", "html", "html"), ("dynamic", "suggestionsSource", "tags")): declaration = f'' if source.count(declaration) != 1: raise ValueError(f"Expected the shipped sample binding for {control}.{prop}") source = source.replace(declaration, "") file.write_text(source) elif args.spring_di: shutil.copytree(ROOT / "integration-fixtures/spring-di", project, ignore=shutil.ignore_patterns("target", ".neitzel-fx-designer")) subprocess.run([sys.executable, ROOT / "scripts/configure-library-example.py", "--project", project, "--target-java-home", args.target_java_home], check=True) file = project / "app/src/main/resources/fixture/spring/ui/Book.fxml" else: subprocess.run([sys.executable, ROOT / "scripts/prepare-fixture-host.py", "--destination", project, "--target-java-home", args.target_java_home, "--mode", args.mode], check=True) file = project / "app/src/main/resources/fixture/components/Person.fxml" settings = project / ".neitzel-fx-designer/host.properties" env = dict(os.environ) if args.spring_di and args.check: agent_classes = base / "agent-classes" classpath = (ROOT / "designer-standalone/target/smoke-classpath.txt").read_text().strip() subprocess.run([args.java_home / "bin/javac", "-cp", classpath, "-d", agent_classes, ROOT / "integration-tests/idea/SpringTargetProbe.java"], check=True) agent = base / "spring-ui-check.jar" with zipfile.ZipFile(agent, "w") as archive: archive.writestr("META-INF/MANIFEST.MF", "Manifest-Version: 1.0\nPremain-Class: qualification.SpringTargetProbe\n\n") for item in agent_classes.rglob("*.class"): archive.write(item, item.relative_to(agent_classes)) env["JAVA_TOOL_OPTIONS"] = env.get("JAVA_TOOL_OPTIONS", "") + f' "-javaagent:{agent}={base}"' 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)] if args.spring_di and args.check: command[3] = str(ROOT / "designer-standalone/target/test-classes") + os.pathsep + cp command[4] = "de.neitzel.fxdesigner.standalone.SpringPreviewHostSmoke" command.append(str(base)) 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() checks = base / "plugins/qualification/lib/projection-checks.jar" checks.parent.mkdir(parents=True) shutil.copyfile(ROOT / "designer-kit-ui/target/designer-kit-ui-0.1.1-tests.jar", checks) jars = [*(args.idea_home / "lib").glob("*.jar"), *(base / "plugins").rglob("*.jar"), *(args.idea_home / "plugins/platform-problemView-plugin").rglob("*.jar")] sources = ROOT / "integration-tests/idea" suite = "Archive" if args.connection_form: suite = "Connection" elif args.grid_docking: suite = "GridDock" elif args.dock_rules: suite = "DockRules" elif args.media_layout_grid: suite = "MediaLayoutGrid" elif args.management_readers: suite = "ManagementReaders" elif args.reader_states: suite = "ReaderStates" elif args.viewer_import: suite = "ViewerImport" elif args.row_menus: suite = "RowMenus" elif args.folder_profiles: suite = "FolderProfiles" elif args.folder_actions: suite = "FolderActions" elif args.import_form: suite = "Import" elif args.document_tabs: suite = "DocumentTabs" elif args.saved_document: suite = "SavedDocument" probe = f"{suite}WorkflowProbe" if args.archiver else "WorkflowProbe" files = [sources / "WorkflowProbe.java"] if args.spring_di: probe = "SpringWorkflowProbe" files.append(sources / f"{probe}.java") if args.connection_form or args.saved_document or args.document_tabs or args.import_form or args.folder_actions or args.reader_states or args.viewer_import or args.row_menus or args.folder_profiles or args.management_readers or args.media_layout_grid or args.dock_rules: files.append(sources / "FormWorkflowProbe.java") if args.media_layout_grid or args.dock_rules or args.reader_states or args.viewer_import or args.row_menus or args.folder_profiles: files.append(sources / "DeclarationWorkflowProbe.java") if args.archiver: files.append(sources / f"{probe}.java") target_probe = f"{suite}TargetProbe" agent_classes = base / "agent-classes" agent_classes.mkdir() subprocess.run([args.java_home / "bin/javac", "-cp", os.pathsep.join(map(str,jars)), "-d", agent_classes, sources / f"{target_probe}.java", *([sources / "DocumentTabsTargetProbe.java"] if args.reader_states else []), *([sources / "FolderActionsTargetProbe.java"] if args.folder_profiles or args.reader_states or args.viewer_import or args.row_menus else [])], check=True) agent = base / "archiver-ui-check.jar" with zipfile.ZipFile(agent, "w") as archive: archive.writestr("META-INF/MANIFEST.MF", f"Manifest-Version: 1.0\nPremain-Class: qualification.{target_probe}\n\n") for item in agent_classes.rglob("*.class"): archive.write(item, item.relative_to(agent_classes)) env["JAVA_TOOL_OPTIONS"] = env.get("JAVA_TOOL_OPTIONS", "") + f' "-javaagent:{agent}={base}"' subprocess.run([str(args.java_home / "bin/javac"), "-cp", os.pathsep.join(map(str,jars)), "-d", str(classes), *files], check=True) meta = classes / "META-INF" meta.mkdir() (meta / "plugin.xml").write_text('de.neitzel.fxdesigner.qualificationDesigner workflow qualification1Local testscom.intellij.modules.platformde.neitzel.fxdesignercom.intellij.problemsView') jar = base / "plugins/qualification/lib/qualification.jar" jar.parent.mkdir(parents=True, exist_ok=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('') (options / "trusted-paths.xml").write_text('') 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)