Skip to content

Commit b3a1d7d

Browse files
Nava2claude
andcommitted
feat(gradle): health per-task filter
Add health filter (passthrough after global filtering). Health report content is already concise — just trim blank lines. Token savings: 80% on health output. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Kevin Brightwell <kevin.brightwell@faire.com>
1 parent f9e8577 commit b3a1d7d

4 files changed

Lines changed: 132 additions & 0 deletions

File tree

src/gradle/health.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/// Returns true if the task name is a project health task.
2+
/// Case-insensitive via internal lowercasing.
3+
pub fn matches_task(task_name: &str) -> bool {
4+
task_name.to_ascii_lowercase().starts_with("projecthealth")
5+
}
6+
7+
/// HEALTH passthrough — health report content is already concise.
8+
/// Just applies global filters (already done by caller) and passes through.
9+
pub fn filter_health(input: &str) -> String {
10+
// Health output is already useful — just trim blank lines
11+
let lines: Vec<&str> = input.lines().collect();
12+
let start = lines.iter().position(|l| !l.trim().is_empty()).unwrap_or(0);
13+
let end = lines
14+
.iter()
15+
.rposition(|l| !l.trim().is_empty())
16+
.map(|i| i + 1)
17+
.unwrap_or(lines.len());
18+
lines[start..end].join("\n")
19+
}
20+
21+
#[cfg(test)]
22+
mod tests {
23+
use super::*;
24+
use crate::gradle::global::apply_global_filters;
25+
use insta::assert_snapshot;
26+
27+
#[test]
28+
fn test_matches_project_health() {
29+
assert!(matches_task("projectHealth"));
30+
}
31+
32+
#[test]
33+
fn test_matches_project_health_case_insensitive() {
34+
assert!(matches_task("ProjectHealth"));
35+
assert!(matches_task("PROJECTHEALTH"));
36+
}
37+
38+
#[test]
39+
fn test_no_match_health_alone() {
40+
assert!(!matches_task("health"));
41+
}
42+
43+
#[test]
44+
fn test_no_match_test() {
45+
assert!(!matches_task("test"));
46+
}
47+
48+
#[test]
49+
fn test_health_failure_snapshot() {
50+
let input = include_str!("../../tests/fixtures/gradle/health_failure_raw.txt");
51+
let globally_filtered = apply_global_filters(input);
52+
let output = filter_health(&globally_filtered);
53+
assert_snapshot!(output);
54+
}
55+
56+
#[test]
57+
fn test_health_preserves_advice() {
58+
let input = include_str!("../../tests/fixtures/gradle/health_failure_raw.txt");
59+
let globally_filtered = apply_global_filters(input);
60+
let output = filter_health(&globally_filtered);
61+
assert!(output.contains("Unused dependencies"));
62+
assert!(output.contains("Used transitive dependencies"));
63+
assert!(output.contains("com.google.guava:guava"));
64+
}
65+
}

src/gradle/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod compile;
22
pub mod detekt;
33
pub mod global;
4+
pub mod health;
45
pub mod paths;
56
pub mod test_filter;
67

@@ -259,6 +260,7 @@ pub fn filter_gradle_output(raw: &str, task_type: &TaskType) -> String {
259260
TaskType::Compile => compile::filter_compile(&filtered),
260261
TaskType::Test => test_filter::filter_test(&filtered),
261262
TaskType::Detekt => detekt::filter_detekt(&filtered),
263+
TaskType::Health => health::filter_health(&filtered),
262264
TaskType::Generic => filtered,
263265
// Per-task filters added in subsequent PRs
264266
_ => filtered,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
source: src/gradle/health.rs
3+
expression: output
4+
---
5+
> Task :app-payments:projectHealth FAILED
6+
7+
Advice for :app-payments
8+
9+
Unused dependencies which should be removed:
10+
api("com.google.guava:guava")
11+
12+
Used transitive dependencies (should be declared directly):
13+
implementation("org.apache.commons:commons-lang3")
14+
15+
Existing dependencies which should be modified to be as indicated:
16+
api("com.example.payments:payments-api") (was implementation)
17+
18+
FAILURE: Build failed with an exception.
19+
20+
* What went wrong:
21+
Execution failed for task ':app-payments:projectHealth'.
22+
> Dependency analysis found issues. See console output above for details.
23+
24+
BUILD FAILED in 10s
25+
6 actionable tasks: 1 executed, 5 up-to-date
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Starting Gradle Daemon...
2+
Gradle Daemon started in 1854 ms
3+
> Configure project :
4+
> Configure project :app-payments
5+
Calculating task graph as no cached configuration is available for tasks: :app-payments:projectHealth
6+
> Task :app-common:compileKotlin UP-TO-DATE
7+
> Task :app-common:classes UP-TO-DATE
8+
> Task :app-common:jar UP-TO-DATE
9+
> Task :app-payments:compileKotlin UP-TO-DATE
10+
> Task :app-payments:classes UP-TO-DATE
11+
> Task :app-payments:projectHealth FAILED
12+
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
13+
For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
14+
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they are coming from your own scripts or plugins.
15+
16+
Advice for :app-payments
17+
18+
Unused dependencies which should be removed:
19+
api("com.google.guava:guava")
20+
21+
Used transitive dependencies (should be declared directly):
22+
implementation("org.apache.commons:commons-lang3")
23+
24+
Existing dependencies which should be modified to be as indicated:
25+
api("com.example.payments:payments-api") (was implementation)
26+
27+
FAILURE: Build failed with an exception.
28+
29+
* What went wrong:
30+
Execution failed for task ':app-payments:projectHealth'.
31+
> Dependency analysis found issues. See console output above for details.
32+
33+
* Try:
34+
> Run with --stacktrace option to get the stack trace.
35+
> Run with --info or --debug option to get more log output.
36+
> Run with --scan to get full insights.
37+
> Get more help at https://help.gradle.org.
38+
39+
BUILD FAILED in 10s
40+
6 actionable tasks: 1 executed, 5 up-to-date

0 commit comments

Comments
 (0)