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
use crate::error::*;
use std::path::{Path, PathBuf};
use std::process::Command;
pub struct GetSizeTotal {
apks: PathBuf,
device_spec: Option<PathBuf>,
dimensions: Option<String>,
instant: bool,
modules: Option<String>,
}
impl GetSizeTotal {
pub fn new(apks: &Path) -> Self {
Self {
apks: apks.to_owned(),
device_spec: None,
dimensions: None,
instant: false,
modules: None,
}
}
pub fn device_spec(&mut self, device_spec: &Path) -> &mut Self {
self.device_spec = Some(device_spec.to_owned());
self
}
pub fn dimensions(&mut self, dimensions: String) -> &mut Self {
self.dimensions = Some(dimensions);
self
}
pub fn instant(&mut self, instant: bool) -> &mut Self {
self.instant = instant;
self
}
pub fn modules(&mut self, modules: String) -> &mut Self {
self.modules = Some(modules);
self
}
pub fn run(&self) -> Result<()> {
let mut get_size_total = Command::new("java");
get_size_total.arg("-jar");
if let Ok(bundletool_path) = std::env::var("BUNDLETOOL_PATH") {
get_size_total.arg(bundletool_path);
} else {
return Err(Error::BundletoolNotFound.into());
}
get_size_total.arg("get-size");
get_size_total.arg("total");
get_size_total.arg("--apks");
get_size_total.arg(&self.apks);
if let Some(device_spec) = &self.device_spec {
get_size_total.arg("--device-spec").arg(device_spec);
}
if let Some(dimensions) = &self.dimensions {
get_size_total.arg("--dimensions").arg(dimensions);
}
if self.instant {
get_size_total.arg("--instant");
}
if let Some(modules) = &self.modules {
get_size_total.arg("--modules").arg(modules);
}
get_size_total.output_err(true)?;
Ok(())
}
}