Skip to content

Commit 78f07e2

Browse files
romtsnclaude
andcommitted
feat(bundle-jvm): Add JVM extension filtering and default excludes
Filter collected sources by JVM file extensions (java, kt, scala, groovy, kts) and exclude common build output directories by default (build, .gradle, .cxx, node_modules). Also respect .gitignore rules as an additional layer of defense. Users can provide extra --exclude glob patterns on top of the defaults. This enables invoking bundle-jvm directly on a project root without needing to pre-copy sources into a separate directory. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1854c4e commit 78f07e2

2 files changed

Lines changed: 45 additions & 7 deletions

File tree

src/commands/debug_files/bundle_jvm.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::utils::file_upload::SourceFile;
77
use crate::utils::fs::path_as_url;
88
use crate::utils::source_bundle::{self, BundleContext};
99
use anyhow::{bail, Context as _, Result};
10-
use clap::{Arg, ArgMatches, Command};
10+
use clap::{Arg, ArgAction, ArgMatches, Command};
1111
use sentry::types::DebugId;
1212
use std::collections::BTreeMap;
1313
use std::fs;
@@ -16,6 +16,12 @@ use std::str::FromStr as _;
1616
use std::sync::Arc;
1717
use symbolic::debuginfo::sourcebundle::SourceFileType;
1818

19+
/// File extensions for JVM-based languages.
20+
const JVM_EXTENSIONS: &[&str] = &["java", "kt", "scala", "groovy", "kts"];
21+
22+
/// Default directory patterns to exclude from source collection.
23+
const DEFAULT_EXCLUDES: &[&str] = &["!build", "!.gradle", "!.cxx", "!node_modules"];
24+
1925
pub fn make_command(command: Command) -> Command {
2026
command
2127
.hide(true) // experimental for now
@@ -47,6 +53,16 @@ pub fn make_command(command: Command) -> Command {
4753
.value_parser(DebugId::from_str)
4854
.help("Debug ID (UUID) to use for the source bundle."),
4955
)
56+
.arg(
57+
Arg::new("exclude")
58+
.long("exclude")
59+
.value_name("PATTERN")
60+
.action(ArgAction::Append)
61+
.help(
62+
"Glob pattern to exclude files/directories. Can be repeated. \
63+
By default, 'build', '.gradle', and '.cxx' directories are excluded.",
64+
),
65+
)
5066
}
5167

5268
pub fn execute(matches: &ArgMatches) -> Result<()> {
@@ -75,7 +91,22 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
7591
))?;
7692
}
7793

78-
let sources = ReleaseFileSearch::new(path.clone()).collect_files()?;
94+
let user_excludes: Vec<String> = matches
95+
.get_many::<String>("exclude")
96+
.map(|vals| vals.map(|v| format!("!{v}")).collect())
97+
.unwrap_or_default();
98+
99+
let all_excludes: Vec<&str> = DEFAULT_EXCLUDES
100+
.iter()
101+
.copied()
102+
.chain(user_excludes.iter().map(|s| s.as_str()))
103+
.collect();
104+
105+
let sources = ReleaseFileSearch::new(path.clone())
106+
.extensions(JVM_EXTENSIONS.iter().copied())
107+
.ignores(all_excludes)
108+
.respect_ignores(true)
109+
.collect_files()?;
79110
let files = sources.iter().map(|source| {
80111
let local_path = source.path.strip_prefix(&source.base_path).unwrap();
81112
let local_path_jvm_ext = local_path.with_extension("jvm");

src/utils/file_search.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub struct ReleaseFileSearch {
2020
ignores: BTreeSet<String>,
2121
ignore_file: Option<String>,
2222
decompress: bool,
23+
respect_ignores: bool,
2324
}
2425

2526
#[derive(Eq, PartialEq, Hash)]
@@ -37,6 +38,7 @@ impl ReleaseFileSearch {
3738
ignore_file: None,
3839
ignores: BTreeSet::new(),
3940
decompress: false,
41+
respect_ignores: false,
4042
}
4143
}
4244

@@ -78,6 +80,11 @@ impl ReleaseFileSearch {
7880
self
7981
}
8082

83+
pub fn respect_ignores(&mut self, respect: bool) -> &mut Self {
84+
self.respect_ignores = respect;
85+
self
86+
}
87+
8188
pub fn collect_file(path: PathBuf) -> Result<ReleaseFileMatch> {
8289
// NOTE: `collect_file` currently do not handle gzip decompression,
8390
// as its mostly used for 3rd tools like xcode or gradle.
@@ -105,11 +112,11 @@ impl ReleaseFileSearch {
105112
let mut collected = Vec::new();
106113

107114
let mut builder = WalkBuilder::new(&self.path);
108-
builder
109-
.follow_links(true)
110-
.git_exclude(false)
111-
.git_ignore(false)
112-
.ignore(false);
115+
builder.follow_links(true);
116+
117+
if !self.respect_ignores {
118+
builder.git_exclude(false).git_ignore(false).ignore(false);
119+
}
113120

114121
if !&self.extensions.is_empty() {
115122
let mut types_builder = TypesBuilder::new();

0 commit comments

Comments
 (0)