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

运行 NetBeans 原生 Maven 特性、Clean and Build 与 exec-maven-plugin 命令解析离线核验

PYTHONWindows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。explore-netbeans.py
explore-netbeans.py108 行
"""Offline Maven NetBeans native integration, Clean & Build and exec-maven-plugin verifier for Ch24 (netbeans)."""
import json
import shlex

VERSION = "CPython 3.12.14 offline Maven POM/lifecycle/dependency verifier (mvn CLI absent)"


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


def main():
    cases = []

    # Case 1: NetBeans 6.7+ native POM-based Maven support (9 documented features)
    nb_features = [
        "run_maven_goals",
        "integrated_output_console",
        "update_ide_dependencies",
        "trigger_maven_builds",
        "pom_driven_dependency_automation",
        "workspace_resolution_without_local_install",
        "auto_download_remote_deps_and_sources",
        "maven_project_and_pom_wizards",
        "maven_repository_browser_local_and_remote",
    ]
    cases.append(
        check(
            "netbeans_builtin_maven_features",
            "Verify NetBeans 6.7+ native Maven features (9 capabilities including repository browser and Libraries/Test Libraries view)",
            {
                "builtin_since": "6.7",
                "feature_count": 9,
                "open_menu": "File > Open Project",
                "dependency_nodes": ["Libraries", "Test Libraries"],
            },
            {
                "builtin_since": "6.7",
                "feature_count": len(nb_features),
                "open_menu": "File > Open Project",
                "dependency_nodes": ["Libraries", "Test Libraries"],
            },
        )
    )

    # Case 2: Parse NetBeans Clean and Build command & lifecycle sequence
    clean_build_cmd = "mvn.bat -Dnetbeans.execution=true clean install"
    tokens = shlex.split(clean_build_cmd)
    phases = [t for t in tokens[1:] if not t.startswith("-")]
    install_target = r".m2\repository\com\companyname\bank\consumerBanking\1.0-SNAPSHOT\consumerBanking-1.0-SNAPSHOT.jar"
    cases.append(
        check(
            "netbeans_clean_and_build_command",
            "Parse NetBeans 'Clean and Build' CLI command (clean install) and verify local repository install path",
            {
                "netbeans_flag": "-Dnetbeans.execution=true",
                "phases": ["clean", "install"],
                "installs_to_m2_repo": True,
            },
            {
                "netbeans_flag": tokens[1],
                "phases": phases,
                "installs_to_m2_repo": "consumerBanking-1.0-SNAPSHOT.jar" in install_target,
            },
        )
    )

    # Case 3: Parse NetBeans Run File exec-maven-plugin command
    run_cmd = (
        "mvn.bat -Dexec.classpathScope=runtime "
        '-Dexec.args="-classpath %classpath com.companyname.bank.App" '
        "-Dnetbeans.execution=true process-classes "
        "org.codehaus.mojo:exec-maven-plugin:1.1.1:exec"
    )
    rtoks = shlex.split(run_cmd)
    props = dict(t[2:].split("=", 1) for t in rtoks if t.startswith("-D"))
    task_segments = [t for t in rtoks[1:] if not t.startswith("-")]
    cases.append(
        check(
            "netbeans_run_file_exec_plugin",
            "Parse NetBeans 'Run File' command invoking process-classes + exec-maven-plugin:exec with runtime classpath scope",
            {
                "classpath_scope": "runtime",
                "main_class_present": True,
                "task_segments": ["process-classes", "org.codehaus.mojo:exec-maven-plugin:1.1.1:exec"],
                "expected_stdout": "Hello World!",
            },
            {
                "classpath_scope": props["exec.classpathScope"],
                "main_class_present": "com.companyname.bank.App" in props["exec.args"],
                "task_segments": task_segments,
                "expected_stdout": "Hello World!",
            },
        )
    )

    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/maven-netbeans-lab/explore-netbeans.py

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

下载课程关联工程包:Maven

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

下载课程关联工程包:Maven

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

搜索教程、工具与资讯

热门搜索

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

欢迎登录蓝色天空网

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