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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
use std::collections::HashSet;
use flatpak_rs::build_system::FlatpakBuildSystem;
use flatpak_rs::module::FlatpakModule;
use flatpak_rs::source::{FlatpakSource, FlatpakSourceItem};
use serde::{Deserialize, Serialize};
#[derive(Clone)]
#[derive(Deserialize)]
#[derive(Serialize)]
#[derive(Default)]
pub struct SoftwareProject {
pub id: String,
pub vcs_url: String,
pub name: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
pub web_urls: HashSet<String>,
pub vcs_urls: HashSet<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub siblings: Option<HashSet<String>>,
pub flatpak_app_manifests: HashSet<String>,
pub flatpak_module_manifests: HashSet<String>,
pub flatpak_sources_manifests: HashSet<String>,
pub tags: HashSet<String>,
pub build_systems: HashSet<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub main_branch: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_known_commit: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_updated: Option<String>,
pub root_hashes: Vec<String>,
}
impl SoftwareProject {
pub fn merge(&mut self, other_project: &SoftwareProject) {
if self.id != other_project.id {
panic!(
"Cannot merge projects with different IDs! {} != {}",
self.id, other_project.id
);
}
if self.vcs_url != other_project.vcs_url {
panic!(
"Cannot merge projects with different VCS URLs! {} != {}",
self.vcs_url, other_project.vcs_url
);
}
for web_url in &other_project.web_urls {
self.web_urls.insert(web_url.to_string());
}
for vcs_url in &other_project.vcs_urls {
self.vcs_urls.insert(vcs_url.to_string());
}
for build_system in &other_project.build_systems {
self.build_systems.insert(build_system.to_string());
}
for app_manifest in &other_project.flatpak_app_manifests {
self.flatpak_app_manifests.insert(app_manifest.to_string());
}
for module_manifest in &other_project.flatpak_module_manifests {
self.flatpak_module_manifests.insert(module_manifest.to_string());
}
for source_manifest in &other_project.flatpak_sources_manifests {
self.flatpak_sources_manifests.insert(source_manifest.to_string());
}
for tag in &other_project.tags {
self.tags.insert(tag.to_string());
}
if self.root_hashes.len() == 0 {
for hash in &other_project.root_hashes {
self.root_hashes.push(hash.clone());
}
}
if let Some(siblings) = &other_project.siblings {
if self.siblings.is_none() {
self.siblings = other_project.siblings.clone();
}
}
if let Some(description) = &other_project.description {
self.description = Some(description.clone());
}
if let Some(last_known_commit) = &other_project.last_known_commit {
self.last_known_commit = Some(last_known_commit.clone());
}
if let Some(main_branch) = &other_project.main_branch {
self.main_branch = Some(main_branch.clone());
}
if let Some(last_updated) = &other_project.last_updated {
self.last_updated = Some(last_updated.clone());
}
}
pub fn supports_flatpak(&self) -> bool {
if !self.flatpak_app_manifests.is_empty() {
return true;
}
if !self.flatpak_module_manifests.is_empty() {
return true;
}
if !self.flatpak_sources_manifests.is_empty() {
return true;
}
return false;
}
pub fn get_main_vcs_url(&self) -> String {
return self.vcs_url.to_string();
}
pub fn get_root_signature(&self) -> String {
let mut root_signature: String = "".to_string();
for root_hash in &self.root_hashes {
root_signature += root_hash;
}
root_signature
}
pub fn get_default_modules(&self) -> Vec<FlatpakModule> {
let mut response = vec![];
let mut git_source = FlatpakSource::default();
git_source.url = Some(self.vcs_url.clone());
if let Some(branch) = &self.main_branch {
git_source.branch = Some(branch.clone());
}
for build_system in &self.build_systems {
let buildsystem = match FlatpakBuildSystem::from_string(build_system) {
Err(e) => {
continue;
}
Ok(b) => b,
};
let mut derived_module = FlatpakModule::default();
derived_module.name = self.id.clone();
derived_module.buildsystem = Some(buildsystem);
derived_module
.sources
.push(FlatpakSourceItem::Description(git_source.clone()));
response.push(derived_module);
}
response
}
}