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

运行 IntelliJ IDEA 内建 Maven 特性、.iml 模块结构与 Rebuild/Run 启动参数离线核验

PYTHONWindows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。explore-intellij.py
explore-intellij.py122 行
"""Offline Maven IntelliJ IDEA integration, .iml module model & run command verifier for Ch25 (intellij)."""
import json
import xml.etree.ElementTree as ET

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: IntelliJ IDEA built-in Maven integration (8 features)
    idea_features = [
        "run_maven_goals",
        "integrated_terminal_output",
        "sync_and_update_dependencies",
        "launch_maven_builds",
        "pom_driven_dependency_automation",
        "workspace_module_resolution_without_local_install",
        "auto_download_remote_deps_and_sources",
        "new_maven_project_and_pom_wizards",
    ]
    cases.append(
        check(
            "intellij_builtin_maven_features",
            "Verify IntelliJ IDEA 8 built-in Maven integration features including workspace module resolution",
            {"builtin_maven_support": True, "feature_count": 8},
            {"builtin_maven_support": True, "feature_count": len(idea_features)},
        )
    )

    # Case 2: 7-step import wizard & generated .iml module descriptor XML
    wizard_steps = [
        "Open IntelliJ IDEA",
        "File > New Project",
        "Import project from existing model",
        "Select Maven",
        "Select consumerBanking path",
        "Select Maven project to import",
        "Enter project name and click Finish",
    ]
    iml_xml = """
    <module type="JAVA_MODULE" version="4">
      <component name="NewModuleRootManager" inherit-compiler-output="false">
        <output url="file://$MODULE_DIR$/target/classes"/>
        <output-test url="file://$MODULE_DIR$/target/test-classes"/>
        <content url="file://$MODULE_DIR$">
          <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false"/>
          <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true"/>
        </content>
        <orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project"/>
      </component>
    </module>
    """
    root = ET.fromstring(iml_xml)
    comp = root.find("component")
    src_folders = {sf.attrib["url"].split("$MODULE_DIR$/")[1]: sf.attrib["isTestSource"] for sf in comp.findall("content/sourceFolder")}
    lib = comp.find("orderEntry[@type='library']")
    cases.append(
        check(
            "intellij_import_wizard_and_iml_model",
            "Verify 7-step Maven import wizard and .iml source/test folders, target/classes output, and TEST-scoped junit library",
            {
                "wizard_step_count": 7,
                "source_folders": {"src/main/java": "false", "src/test/java": "true"},
                "output_dir": "target/classes",
                "junit_entry": {"name": "Maven: junit:junit:3.8.1", "scope": "TEST"},
            },
            {
                "wizard_step_count": len(wizard_steps),
                "source_folders": src_folders,
                "output_dir": comp.find("output").attrib["url"].split("$MODULE_DIR$/")[1],
                "junit_entry": {"name": lib.attrib["name"], "scope": lib.attrib["scope"]},
            },
        )
    )

    # Case 3: Rebuild Project log & Run App.main() JVM launch parameters
    rebuild_log = "4:01:56 PM Compilation completed successfully"
    run_config = {
        "encoding": "UTF-8",
        "classpath_entries": [r"C:\MVN\consumerBanking\target\classes"],
        "main_class": "com.companyname.bank.App",
        "stdout": "Hello World!",
        "exit_code": 0,
    }
    cases.append(
        check(
            "intellij_rebuild_and_run_main_command",
            "Verify IntelliJ Build > Rebuild Project completion status and Run App.main() classpath/UTF-8/stdout execution contract",
            {
                "compile_ok": True,
                "encoding": "UTF-8",
                "main_class": "com.companyname.bank.App",
                "stdout": "Hello World!",
                "exit_code": 0,
            },
            {
                "compile_ok": "Compilation completed successfully" in rebuild_log,
                "encoding": run_config["encoding"],
                "main_class": run_config["main_class"],
                "stdout": run_config["stdout"],
                "exit_code": run_config["exit_code"],
            },
        )
    )

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

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

下载课程关联工程包:Maven

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

下载课程关联工程包:Maven

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

搜索教程、工具与资讯

热门搜索

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

欢迎登录蓝色天空网

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