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
use regex::Regex;
use std::sync::OnceLock;
static MAVEN_DOWNLOAD_RE: OnceLock<Regex> = OnceLock::new();
static MAVEN_PROGRESS_RE: OnceLock<Regex> = OnceLock::new();
static GRADLE_DOWNLOAD_RE: OnceLock<Regex> = OnceLock::new();
static GRADLE_PROGRESS_RE: OnceLock<Regex> = OnceLock::new();
static TESTS_RUN_RE: OnceLock<Regex> = OnceLock::new();
fn maven_download_re() -> &'static Regex {
MAVEN_DOWNLOAD_RE
.get_or_init(|| Regex::new(r"(?i)\[INFO\]\s+(Downloading|Downloaded)\s+").unwrap())
}
fn maven_progress_re() -> &'static Regex {
MAVEN_PROGRESS_RE.get_or_init(|| Regex::new(r"\[INFO\].*kB\s+\|").unwrap())
}
fn gradle_download_re() -> &'static Regex {
GRADLE_DOWNLOAD_RE
.get_or_init(|| Regex::new(r"(?i)^(Downloading|Download)\s+https?://").unwrap())
}
fn gradle_progress_re() -> &'static Regex {
GRADLE_PROGRESS_RE.get_or_init(|| Regex::new(r"^[<>=\s]+$|^[0-9]+%\s+EXECUTING").unwrap())
}
fn tests_run_re() -> &'static Regex {
TESTS_RUN_RE.get_or_init(|| Regex::new(r"Tests run:\s*\d+").unwrap())
}
fn is_maven_noise(line: &str) -> bool {
let t = line.trim_start();
if maven_download_re().is_match(t) {
return true;
}
if maven_progress_re().is_match(t) {
return true;
}
if t.contains("Progress (") && t.contains("):") && t.contains('%') {
return true;
}
false
}
fn is_gradle_noise(line: &str) -> bool {
let t = line.trim();
if gradle_download_re().is_match(t) {
return true;
}
if gradle_progress_re().is_match(t) {
return true;
}
let tl = t.to_ascii_lowercase();
if tl.starts_with("consider enabling configuration cache")
|| tl.contains("deprecated gradle features were used")
|| tl.starts_with("you can use '--warning-mode")
{
return true;
}
false
}
fn is_maven_or_gradle_command(command: &str) -> bool {
let c = command.trim();
let cl = c.to_ascii_lowercase();
cl.starts_with("mvn ")
|| cl.starts_with("./mvnw ")
|| cl.starts_with("mvnw ")
|| cl.starts_with("gradle ")
|| cl.starts_with("./gradlew ")
|| cl.starts_with("gradlew ")
}
fn is_gradle_command(command: &str) -> bool {
let cl = command.trim().to_ascii_lowercase();
cl.starts_with("gradle ") || cl.starts_with("./gradlew ") || cl.starts_with("gradlew ")
}
pub fn compress(command: &str, output: &str) -> Option<String> {
if !is_maven_or_gradle_command(command) {
return None;
}
if is_gradle_command(command) {
Some(compress_gradle(output))
} else {
Some(compress_maven(output))
}
}
fn compress_maven(output: &str) -> String {
let mut kept = Vec::new();
for line in output.lines() {
let t = line.trim_end();
if t.trim().is_empty() {
continue;
}
if is_maven_noise(t) {
continue;
}
let tl = t.to_ascii_lowercase();
if tl.contains("[error]")
|| tl.contains("[fatal]")
|| tl.contains("build failure")
|| tl.contains("build success")
|| tl.contains("failure!")
|| tl.contains("tests run:")
|| tl.contains("failures:")
|| tl.contains("errors:")
|| tl.contains("skipped:")
|| tests_run_re().is_match(t)
{
kept.push(t.trim().to_string());
continue;
}
if tl.contains("[warning]") {
kept.push(t.trim().to_string());
}
}
if kept.is_empty() {
"mvn (no build/test lines kept)".to_string()
} else {
kept.join("\n")
}
}
fn compress_gradle(output: &str) -> String {
let mut kept = Vec::new();
let mut task_lines = Vec::new();
for line in output.lines() {
let t = line.trim_end();
if t.trim().is_empty() {
continue;
}
if is_gradle_noise(t) {
continue;
}
let tl = t.to_ascii_lowercase();
if tl.starts_with("> task ") {
if tl.contains("failed")
|| tl.contains("failure")
|| tl.contains("skipped")
|| tl.contains("no-source")
{
task_lines.push(t.trim().to_string());
}
continue;
}
if tl.contains("actionable tasks:") {
kept.push(t.trim().to_string());
continue;
}
if tl.contains("build successful")
|| tl.contains("build failed")
|| tl.starts_with("failure:")
|| tl.contains("what went wrong:")
|| tl.contains("execution failed for task")
|| tl.contains("error:")
|| tl.contains("exception")
|| tl.contains("tests completed:")
|| (tl.contains("test ") && (tl.contains("failed") || tl.contains("passed")))
|| tl.contains("there were failing tests")
{
kept.push(t.trim().to_string());
}
}
if !task_lines.is_empty() {
kept.push("tasks:\n".to_string() + &task_lines.join("\n"));
}
if kept.is_empty() {
"gradle (no summary kept)".to_string()
} else {
kept.join("\n")
}
}