From ce5c316c39171fb6d76b71a16aeef320034d684a Mon Sep 17 00:00:00 2001 From: Sebastian Simon Date: Tue, 19 Nov 2024 14:27:26 +0100 Subject: [PATCH] Remove comments when parsing pom.xml files --- src/cfgnet/plugins/concept/maven_plugin.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cfgnet/plugins/concept/maven_plugin.py b/src/cfgnet/plugins/concept/maven_plugin.py index 15f0abb..372d547 100644 --- a/src/cfgnet/plugins/concept/maven_plugin.py +++ b/src/cfgnet/plugins/concept/maven_plugin.py @@ -18,7 +18,7 @@ from typing import Optional, Tuple, List from lxml import etree as ET -from lxml.etree import _Element +from lxml.etree import _Element, _Comment from cfgnet.config_types.config_types import ConfigType from cfgnet.network.nodes import ( @@ -63,10 +63,14 @@ def _parse_config_file( maven_tree = ET.parse(abs_file_path) tree_root = maven_tree.getroot() - # Remove namespace prefixes + # Remove namespace prefixes and comments for elem in tree_root.getiterator(): if elem.tag is not ET.Comment: elem.tag = ET.QName(elem).localname + for child in list(elem): + if isinstance(child, _Comment): + elem.remove(child) + # Remove unused namespace declarations ET.cleanup_namespaces(tree_root) @@ -322,7 +326,7 @@ def get_config_type(self, option_name: str, value: str = "") -> ConfigType: if option_name in ("includes", "excludes", "filter", "file"): return ConfigType.PATH - if any(x in option_name for x in ["directory", "Directory", "Path"]): + if option_name in ("directory", "Directory", "Path"): return ConfigType.PATH if option_name in ("url", "organizationUrl", "picUrl", "downloadUrl"):