186 lines
12 KiB
Python
186 lines
12 KiB
Python
#!/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("--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")
|
|
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"), '<DirectBinding control="folders" property="value" path="folder" direction="both"/>'),
|
|
(file.with_name("FolderTab.fxml"), '<DirectBinding control="grid" property="items" path="rows" direction="view"/>'),
|
|
]:
|
|
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("</VBox>", '<ComboBox fx:id="untypedPick" visible="false" managed="false"/></VBox>')
|
|
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'<DirectBinding control="{control}" property="{prop}" path="{path}" direction="view"/>'
|
|
if source.count(declaration) != 1:
|
|
raise ValueError(f"Expected the shipped sample binding for {control}.{prop}")
|
|
source = source.replace(declaration, "")
|
|
file.write_text(source)
|
|
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.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()
|
|
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.0-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.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('<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><depends>com.intellij.problemsView</depends><extensions defaultExtensionNs="com.intellij"><postStartupActivity implementation="qualification.'+probe+'"/></extensions></idea-plugin>')
|
|
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('<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)
|