1pub(crate) mod parse;
2pub(crate) mod serde_utils;
3pub mod time;
4
5pub fn group_id_to_path(group_id: &str) -> String {
6 group_id.replace(".", "/")
7}
8
9pub fn group_id_and_artifact_id_to_path(group_id: &str, artifact_id: &str) -> String {
10 format!("{}/{}", group_id_to_path(group_id), artifact_id)
11}
12pub fn group_id_and_artifact_id_and_version_to_path(
14 group_id: &str,
15 artifact_id: &str,
16 version: &str,
17) -> String {
18 format!("{}/{}/{}", group_id_to_path(group_id), artifact_id, version)
19}
20
21#[cfg(any(test, feature = "bug-files"))]
29pub mod bug_testing {
30 use std::fmt::Display;
31
32 use serde::{Deserialize, Serialize};
33
34 use crate::pom::Dependency;
35
36 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
37 pub struct BugFile {
38 pub source: Source,
39 pub error: String,
41 #[serde(default)]
42 pub depends: Vec<DependBug>,
43 }
44 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
46 pub struct DependBug {
47 pub xml: String,
48 pub expected: FoundBugDependency,
49 }
50 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
52 pub struct Source {
53 pub group_id: String,
54 pub artifact_id: String,
55 pub version: String,
56 pub file_name: String,
57 }
58 impl Display for Source {
59 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
60 write!(
61 f,
62 "Group ID {}\n Artifact ID {}\n Version {}",
63 self.group_id, self.artifact_id, self.version
64 )
65 }
66 }
67 #[derive(Debug, Serialize, Deserialize, Clone, Default)]
68 pub struct FoundBugDependency {
69 pub group_id: String,
70 pub artifact_id: String,
71 pub version: String,
72 pub depend_type: Option<String>,
73 pub scope: Option<String>,
74 pub classifier: Option<String>,
75 }
76 impl From<FoundBugDependency> for Dependency {
77 fn from(val: FoundBugDependency) -> Self {
78 Dependency {
79 group_id: val.group_id,
80 artifact_id: val.artifact_id,
81 version: Some(val.version.parse().expect("Failed to parse version")),
82 depend_type: val.depend_type,
83 scope: val.scope,
84 classifier: val.classifier,
85 }
86 }
87 }
88
89 #[cfg(test)]
90 pub fn get_bugs_path() -> std::path::PathBuf {
91 let cargo_home = env!("CARGO_MANIFEST_DIR");
92 std::path::PathBuf::from(cargo_home)
93 .join("tests")
94 .join("data")
95 .join("bugs")
96 }
97}