"""Offline Maven site plugin, project info reports & Doxia document formats verifier for Ch17 (project-documents)."""
import json
import tempfile
import xml.etree.ElementTree as ET
from pathlib import Path
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 parse_version_tuple(v):
return tuple(int(part) for part in v.split("."))
def main():
cases = []
# Case 1: pluginManagement validation for maven-site-plugin >= 3.3 & project-info-reports-plugin
pom_xml = """
<project>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.7</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
"""
root = ET.fromstring(pom_xml)
plugins = {
p.findtext("artifactId"): p.findtext("version")
for p in root.findall("build/pluginManagement/plugins/plugin")
}
site_ver = plugins["maven-site-plugin"]
cases.append(
check(
"site_plugin_management_check",
"Verify maven-site-plugin >= 3.3 (preventing Doxia DocumentContent NoClassDefFoundError) and project-info-reports-plugin",
{
"site_plugin_version": "3.3",
"avoids_doxia_noclassdef": True,
"reports_plugin_version": "2.7",
},
{
"site_plugin_version": site_ver,
"avoids_doxia_noclassdef": parse_version_tuple(site_ver) >= (3, 3),
"reports_plugin_version": plugins["maven-project-info-reports-plugin"],
},
)
)
# Case 2: Standard Project Info Reports generated under target/site/
reports = [
"About",
"Issue Tracking",
"Project Team",
"Dependencies",
"Continuous Integration",
"Source Repository",
"Project License",
"Mailing Lists",
"Plugin Management",
"Project Summary",
]
cases.append(
check(
"site_generation_reports_inventory",
"Verify the 10 standard Maven site reports and target/site/index.html output path",
{"report_count": 10, "output_index": "target/site/index.html", "includes_dependencies_report": True},
{"report_count": len(reports), "output_index": "target/site/index.html", "includes_dependencies_report": "Dependencies" in reports},
)
)
# Case 3: Doxia engine 4 documented markup formats
doxia_formats = {
"Apt": {"dir": "src/site/apt", "ext": ".apt", "purpose": "plain text"},
"Xdoc": {"dir": "src/site/xdoc", "ext": ".xml", "purpose": "Maven 1.x XML"},
"FML": {"dir": "src/site/fml", "ext": ".fml", "purpose": "FAQ"},
"XHTML": {"dir": "src/site/xhtml", "ext": ".xhtml", "purpose": "Extensible HTML"},
}
cases.append(
check(
"doxia_markup_formats_table",
"Verify Doxia document engine's 4 documented markup formats (Apt, Xdoc, FML, XHTML) and source dirs",
{"formats": ["Apt", "FML", "XHTML", "Xdoc"], "fml_dir": "src/site/fml"},
{"formats": sorted(doxia_formats.keys()), "fml_dir": doxia_formats["FML"]["dir"]},
)
)
# Case 4: Offline APT-to-HTML render check writing target/site/index.html
apt_sample = " -----\n Consumer Banking\n -----\n\nOverview\n\n Standard banking module documentation.\n"
lines = [ln.strip() for ln in apt_sample.splitlines() if ln.strip() and not ln.strip().startswith("-----")]
html_doc = f"<html><head><title>{lines[0]}</title></head><body><h1>{lines[1]}</h1><p>{lines[2]}</p></body></html>"
with tempfile.TemporaryDirectory() as tmp:
out_file = Path(tmp) / "target/site/index.html"
out_file.parent.mkdir(parents=True)
out_file.write_text(html_doc, encoding="utf-8")
rendered = out_file.read_text(encoding="utf-8")
cases.append(
check(
"doxia_apt_to_html_render_sim",
"Verify APT-style heading/paragraph transformation into target/site/index.html",
{"has_title": True, "has_h1_overview": True},
{"has_title": "<title>Consumer Banking</title>" in rendered, "has_h1_overview": "<h1>Overview</h1>" in rendered},
)
)
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-project-documents-lab/explore-project-documents.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-project-documents.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联25章) · 含当前章节或实例 · mbskycom202612a2175.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2193.zip