Beispiel #1
0
 def __violation(self, violation: Element, namespaces: Namespaces,
                 models: ModelFilePaths,
                 severities: list[str]) -> Optional[Entity]:
     """Return the violation as entity."""
     location = violation.find("./ns:location", namespaces)
     if not location:
         raise SourceCollectorException(
             f"OJAudit violation {violation} has no location element")
     severity = violation.findtext("./ns:values/ns:value",
                                   default="",
                                   namespaces=namespaces)
     if severities and severity not in severities:
         return None
     message = violation.findtext("ns:message",
                                  default="",
                                  namespaces=namespaces)
     line_number = violation.findtext(".//ns:line-number",
                                      namespaces=namespaces)
     column_offset = violation.findtext(".//ns:column-offset",
                                        namespaces=namespaces)
     model = models[location.get("model", "")]
     component = f"{model}:{line_number}:{column_offset}"
     key = sha1_hash(f"{message}:{component}")
     entity = Entity(key=key,
                     severity=severity,
                     message=message,
                     component=component)
     if entity["key"] in self.violation_counts:
         self.violation_counts[entity["key"]] += 1
         return None  # Ignore duplicate violation
     self.violation_counts[entity["key"]] = 1
     return entity
Beispiel #2
0
 def _parse_entity(  # pylint: disable=no-self-use
         self, dependency: Element, dependency_index: int, namespaces: Namespaces, landing_url: str) -> Entity:
     """Parse the entity from the dependency."""
     file_path = dependency.findtext("ns:filePath", default="", namespaces=namespaces)
     sha1 = dependency.findtext("ns:sha1", namespaces=namespaces)
     # We can only generate an entity landing url if a sha1 is present in the XML, but unfortunately not all
     # dependencies have one, so check for it:
     entity_landing_url = f"{landing_url}#l{dependency_index + 1}_{sha1}" if sha1 else ""
     key = sha1 if sha1 else sha1_hash(file_path)
     return Entity(key=key, file_path=file_path, url=entity_landing_url)