-
Notifications
You must be signed in to change notification settings - Fork 123
/
maven.py
31 lines (24 loc) 路 1.06 KB
/
maven.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Parser utilities for Java-based dependency files."""
import re
from typing import List
from readmeai.core.parsers import BaseFileParser
class MavenParser(BaseFileParser):
"""Parser for Maven dependency files in pom.xml format."""
def __init__(self) -> None:
"""Initializes the handler with given configuration."""
super().__init__()
def parse(self, content: str) -> List[str]:
"""Extract packages names from Maven pom.xml files."""
try:
regex = re.compile(
r"<dependency>\s*<groupId>([^<]+)</groupId>\s*<artifactId>([^<]+)</artifactId>\s*<version>([^<]+)</version>"
)
matches = regex.findall(content)
dependencies = [
artifact_id for group_id, artifact_id, version in matches
]
if any("spring" in dependency for dependency in dependencies):
dependencies.append("spring")
return set(dependencies)
except re.error as exc:
return self.handle_parsing_error(f"pom.xml: {str(exc)}")