"""Offline Eclipse Debug Configurations XML & arguments verifier for Ch20 (debug-configuration)."""
import json
import shlex
import xml.etree.ElementTree as ET
VERSION = "CPython 3.12.14 offline Eclipse Debug Configuration 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: Parse Eclipse Java Application .launch debug configuration
launch_xml = """
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="OrderDemo"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.example.order.AppMain"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--mode=debug input.csv"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx256m -Dapp.env=dev"/>
</launchConfiguration>
"""
root = ET.fromstring(launch_xml)
attrs = {
el.attrib["key"].split(".")[-1]: el.attrib["value"]
for el in root.findall("stringAttribute")
}
config_name = "AppMain_Debug"
cases.append(
check(
"debug_launch_config_xml",
"Verify Java Application Debug Configuration stores name, project name, and main class",
{
"config_name": "AppMain_Debug",
"launch_type": "org.eclipse.jdt.launching.localJavaApplication",
"project": "OrderDemo",
"main_type": "com.example.order.AppMain",
},
{
"config_name": config_name,
"launch_type": root.attrib["type"],
"project": attrs["PROJECT_ATTR"],
"main_type": attrs["MAIN_TYPE"],
},
)
)
# Case 2: Arguments tab supports zero or multiple program and VM arguments
empty_prog = shlex.split("")
multi_prog = shlex.split(attrs["PROGRAM_ARGUMENTS"])
multi_vm = shlex.split(attrs["VM_ARGUMENTS"])
cases.append(
check(
"program_and_vm_arguments_parse",
"Verify Arguments tab handles zero or multiple Program arguments and VM arguments",
{
"empty_program_args_count": 0,
"program_args": ["--mode=debug", "input.csv"],
"vm_args": ["-Xmx256m", "-Dapp.env=dev"],
},
{
"empty_program_args_count": len(empty_prog),
"program_args": multi_prog,
"vm_args": multi_vm,
},
)
)
# Case 3: Apply persists configuration and Debug builds JDWP launch command
saved_store = {}
saved_store[config_name] = dict(attrs, mode="debug")
jdwp_flag = "-agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:5005"
cmd = ["java", jdwp_flag, *multi_vm, "-cp", "OrderDemo/bin", attrs["MAIN_TYPE"], *multi_prog]
cases.append(
check(
"apply_and_debug_command_assembly",
"Verify Apply persists configuration and Debug launches JVM with JDWP before main class",
{
"persisted_mode": "debug",
"vm_args_before_main": True,
"program_args_after_main": True,
"has_jdwp_agent": True,
},
{
"persisted_mode": saved_store[config_name]["mode"],
"vm_args_before_main": cmd.index("-Xmx256m") < cmd.index("com.example.order.AppMain"),
"program_args_after_main": cmd.index("--mode=debug") > cmd.index("com.example.order.AppMain"),
"has_jdwp_agent": any(arg.startswith("-agentlib:jdwp=") for arg in cmd),
},
)
)
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-debug-configuration-lab/explore-debug-configuration.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-debug-configuration.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联35章) · 含当前章节或实例 · mbskycom202612a2259.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2271.zip