蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

运行 Eclipse File > Restart 状态保存、延迟插件激活与启动参数保留离线核验

PYTHONWindows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。explore-restart-option.py
explore-restart-option.py118 行
"""Offline Eclipse File > Restart lifecycle & eclipse.ini launcher verifier for Ch34 (restart-option)."""
import json

VERSION = "CPython 3.12.14 offline Eclipse Restart lifecycle & launcher args verifier (desktop SWT IDE absent)"


def check(name, summary, expected, actual):
    return {
        "name": name,
        "summary": summary,
        "expected": expected,
        "actual": actual,
        "passed": actual == expected,
    }


def main():
    cases = []

    # Case 1: File > Restart flushes dirty editors and reloads same workspace
    ide_state = {
        "workspace": "/workspace/java-ee",
        "dirty_editors": ["Main.java", "pom.xml"],
        "saved_files": [],
        "restarts": 0,
    }
    # Simulate File > Restart
    ide_state["saved_files"].extend(ide_state["dirty_editors"])
    ide_state["dirty_editors"].clear()
    ide_state["restarts"] += 1

    cases.append(
        check(
            "restart_menu_action_contract",
            "Verify File > Restart saves pending dirty buffers and relaunches on the active workspace",
            {
                "menu_path": "File > Restart",
                "dirty_after": 0,
                "saved_files": ["Main.java", "pom.xml"],
                "workspace_preserved": "/workspace/java-ee",
                "restart_count": 1,
            },
            {
                "menu_path": "File > Restart",
                "dirty_after": len(ide_state["dirty_editors"]),
                "saved_files": ide_state["saved_files"],
                "workspace_preserved": ide_state["workspace"],
                "restart_count": ide_state["restarts"],
            },
        )
    )

    # Case 2: Deferred restart after plugin installation activates staged P2 plugins
    active_plugins = ["org.eclipse.jdt", "org.eclipse.m2e"]
    staged_plugins = ["org.python.pydev"]
    pending_restart = True
    # User initially chose "Not Now", then triggered File > Restart later
    active_plugins.extend(staged_plugins)
    staged_plugins.clear()
    pending_restart = False

    cases.append(
        check(
            "plugin_install_deferred_restart",
            "Verify File > Restart activates plugins staged when post-install restart was deferred",
            {
                "active_plugins": ["org.eclipse.jdt", "org.eclipse.m2e", "org.python.pydev"],
                "staged_remaining": 0,
                "pending_restart": False,
            },
            {
                "active_plugins": active_plugins,
                "staged_remaining": len(staged_plugins),
                "pending_restart": pending_restart,
            },
        )
    )

    # Case 3: Parse eclipse.ini launcher and VM arguments preserved across restart
    ini_lines = [
        "-startup",
        "plugins/org.eclipse.equinox.launcher.jar",
        "-data",
        "/workspace/java-ee",
        "-vmargs",
        "-Xms256m",
        "-Xmx2048m",
        "-Dfile.encoding=UTF-8",
    ]
    vmargs_idx = ini_lines.index("-vmargs")
    launcher_args = ini_lines[:vmargs_idx]
    vm_args = ini_lines[vmargs_idx + 1 :]
    data_idx = launcher_args.index("-data")
    ws_arg = launcher_args[data_idx + 1]

    cases.append(
        check(
            "eclipse_ini_and_restart_args",
            "Verify eclipse.ini separates launcher arguments (-data) from -vmargs heap/encoding flags on restart",
            {
                "workspace_arg": "/workspace/java-ee",
                "vm_arg_count": 3,
                "has_utf8_encoding": True,
            },
            {
                "workspace_arg": ws_arg,
                "vm_arg_count": len(vm_args),
                "has_utf8_encoding": "-Dfile.encoding=UTF-8" in vm_args,
            },
        )
    )

    print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))


if __name__ == "__main__":
    main()
本例需在 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程

运行环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。

入口文件:projects/eclipse-restart-option-lab/explore-restart-option.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-restart-option.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Eclipse

课程关联工程包(登记关联35章) · 含当前章节或实例 · mbskycom202612a2259.zip

下载课程关联工程包:Eclipse

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2285.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习