provenant/models/
diagnostic.rs1use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
7pub enum DiagnosticSeverity {
8 Warning,
9 Error,
10}
11
12#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
13pub struct ScanDiagnostic {
14 pub severity: DiagnosticSeverity,
15 pub message: String,
16}
17
18impl ScanDiagnostic {
19 pub fn warning(message: impl Into<String>) -> Self {
20 Self {
21 severity: DiagnosticSeverity::Warning,
22 message: message.into(),
23 }
24 }
25
26 pub fn error(message: impl Into<String>) -> Self {
27 Self {
28 severity: DiagnosticSeverity::Error,
29 message: message.into(),
30 }
31 }
32}
33
34pub fn diagnostics_from_legacy_scan_errors(messages: &[String]) -> Vec<ScanDiagnostic> {
35 messages
36 .iter()
37 .cloned()
38 .map(|message| {
39 if is_legacy_warning_message(&message) {
40 ScanDiagnostic::warning(message)
41 } else {
42 ScanDiagnostic::error(message)
43 }
44 })
45 .collect()
46}
47
48pub fn is_legacy_warning_message(message: &str) -> bool {
49 let first_line = message.lines().next().unwrap_or(message).trim();
50 first_line.starts_with("Maven property ")
51 || first_line.starts_with("Skipping Maven template coordinates")
52 || first_line.starts_with("Circular include detected")
53}