Add SSM deployment and reliable Maven setup

This commit is contained in:
王鹏
2026-10-08 17:58:09 +08:00
parent 2d7b6216ba
commit d1695eba74
13 changed files with 626 additions and 46 deletions

View File

@@ -50,7 +50,7 @@ def scan_project(root: str | Path) -> ScanResult:
def _find_backend(root: Path) -> ProjectComponent | None:
candidates: list[tuple[int, Path, str]] = []
candidates: list[tuple[int, Path, str, str, dict[str, str]]] = []
for build_file in _walk_project_files(root, names={"pom.xml", "build.gradle", "build.gradle.kts"}):
project_dir = build_file.parent
score = 1
@@ -58,9 +58,29 @@ def _find_backend(root: Path) -> ProjectComponent | None:
text = _read_text(build_file)
metadata = _extract_backend_metadata(text)
metadata.update(_extract_backend_runtime_metadata(project_dir))
if "spring-boot" in text or "org.springframework.boot" in text:
is_spring_boot = "spring-boot" in text or "org.springframework.boot" in text
web_xml = project_dir / "src" / "main" / "webapp" / "WEB-INF" / "web.xml"
packaging = metadata.get("packaging", "")
is_ssm = not is_spring_boot and (
packaging == "war"
or web_xml.exists()
or ("spring" in text and "mybatis" in text)
)
if not is_spring_boot and not is_ssm:
continue
if is_spring_boot:
score += 3
detail_parts.append("Spring Boot dependency")
kind = "Spring Boot"
metadata["backend_type"] = "spring_boot"
else:
score += 3
kind = "SSM"
metadata["backend_type"] = "ssm"
metadata["packaging"] = "war"
context_name = metadata.get("final_name") or metadata.get("artifact_id") or project_dir.name
metadata.setdefault("context_path", f"/{context_name}")
detail_parts.append("SSM WAR application")
if java_version := metadata.get("java_version"):
detail_parts.append(f"Java {java_version}")
if boot_version := metadata.get("spring_boot_version"):
@@ -68,14 +88,14 @@ def _find_backend(root: Path) -> ProjectComponent | None:
if (project_dir / "src" / "main" / "java").exists():
score += 2
detail_parts.append("src/main/java")
candidates.append((score, project_dir, ", ".join(detail_parts), metadata))
candidates.append((score, project_dir, kind, ", ".join(detail_parts), metadata))
if not candidates:
return None
score, path, detail, metadata = sorted(candidates, key=lambda item: (-item[0], len(item[1].parts)))[0]
score, path, kind, detail, metadata = sorted(candidates, key=lambda item: (-item[0], len(item[1].parts)))[0]
if score < 2:
return None
return ProjectComponent("Spring Boot", path, detail, metadata)
return ProjectComponent(kind, path, detail, metadata)
def _find_frontends(root: Path) -> list[ProjectComponent]:
@@ -188,6 +208,11 @@ def _load_json(path: Path) -> dict:
def _extract_backend_metadata(text: str) -> dict[str, str]:
metadata: dict[str, str] = {}
project_text = re.sub(r"<parent\b[^>]*>.*?</parent>", "", text, flags=re.IGNORECASE | re.DOTALL)
for key, tag in (("packaging", "packaging"), ("artifact_id", "artifactId"), ("final_name", "finalName")):
match = re.search(rf"<{tag}>\s*([^<\s]+)\s*</{tag}>", project_text, re.IGNORECASE)
if match:
metadata[key] = match.group(1).strip()
java_patterns = [
r"<maven\.compiler\.source>\s*([^<\s]+)\s*</maven\.compiler\.source>",
r"<maven\.compiler\.target>\s*([^<\s]+)\s*</maven\.compiler\.target>",