-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command
sentry-cli debug-files bundle-jvm
for bundling Java (an…
…d other JVM based languages) sources (#1551)
- Loading branch information
Showing
22 changed files
with
370 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
use std::fs; | ||
use std::path::{PathBuf}; | ||
use std::str::FromStr; | ||
use anyhow::{bail, Context, Result}; | ||
use clap::{Arg, ArgMatches, Command}; | ||
use sentry::types::DebugId; | ||
use symbolic::debuginfo::sourcebundle::{SourceFileType}; | ||
use crate::api::Api; | ||
use crate::config::Config; | ||
use crate::utils::args::ArgExt; | ||
use crate::utils::file_search::ReleaseFileSearch; | ||
use crate::utils::file_upload::{FileUpload, SourceFile, UploadContext}; | ||
use crate::utils::fs::{path_as_url}; | ||
|
||
pub fn make_command(command: Command) -> Command { | ||
command | ||
.hide(true) // experimental for now | ||
.about("Create a source bundle for the given JVM based source files (e.g. Java, Kotlin, ...)") | ||
.org_arg() | ||
.project_arg(false) | ||
.arg( | ||
Arg::new("path") | ||
.value_name("PATH") | ||
.required(true) | ||
.value_parser(clap::builder::PathBufValueParser::new()) | ||
.help("The directory containing source files to bundle."), | ||
) | ||
.arg( | ||
Arg::new("output") | ||
.long("output") | ||
.value_name("PATH") | ||
.required(true) | ||
.value_parser(clap::builder::PathBufValueParser::new()) | ||
.help("The path to the output folder."), | ||
) | ||
.arg( | ||
Arg::new("debug_id") | ||
.long("debug-id") | ||
.value_name("UUID") | ||
.required(true) | ||
.value_parser(DebugId::from_str) | ||
.help("Debug ID (UUID) to use for the source bundle."), | ||
) | ||
} | ||
|
||
pub fn execute(matches: &ArgMatches) -> Result<()> { | ||
let config = Config::current(); | ||
let org = config.get_org(matches)?; | ||
let project = config.get_project(matches).ok(); | ||
let api = Api::current(); | ||
let chunk_upload_options = api.get_chunk_upload_options(&org)?; | ||
let context = &UploadContext { | ||
org: &org, | ||
project: project.as_deref(), | ||
release: None, | ||
dist: None, | ||
note: None, | ||
wait: true, | ||
dedupe: false, | ||
chunk_upload_options: chunk_upload_options.as_ref(), | ||
}; | ||
let path = matches.get_one::<PathBuf>("path").unwrap(); | ||
let output_path = matches.get_one::<PathBuf>("output").unwrap(); | ||
let debug_id = matches.get_one::<DebugId>("debug_id").unwrap(); | ||
let out = output_path.join(format!("{debug_id}.zip")); | ||
|
||
if !path.exists() { | ||
bail!("Given path does not exist: {}", path.display()) | ||
} | ||
|
||
if !path.is_dir() { | ||
bail!("Given path is not a directory: {}", path.display()) | ||
} | ||
|
||
if !output_path.exists() { | ||
fs::create_dir_all(output_path).context(format!("Failed to create output directory {}", output_path.display()))?; | ||
} | ||
|
||
let sources = ReleaseFileSearch::new(path.to_path_buf()).collect_files()?; | ||
let files = sources | ||
.iter() | ||
.map(|source| { | ||
let local_path = source.path.strip_prefix(&source.base_path).unwrap(); | ||
let local_path_jvm_ext = local_path.with_extension("jvm"); | ||
let url = format!("~/{}", path_as_url(&local_path_jvm_ext)); | ||
( | ||
url.to_string(), | ||
SourceFile { | ||
url, | ||
path: source.path.clone(), | ||
contents: source.contents.clone(), | ||
ty: SourceFileType::Source, | ||
headers: vec![], | ||
messages: vec![], | ||
already_uploaded: false, | ||
}, | ||
) | ||
}) | ||
.collect(); | ||
|
||
let tempfile = FileUpload::new(context) | ||
.files(&files) | ||
.build_jvm_bundle(Some(*debug_id)) | ||
.context("Unable to create source bundle")?; | ||
|
||
fs::copy(tempfile.path(), &out).context("Unable to write source bundle")?; | ||
println!("Created {}", out.display()); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/integration/_cases/debug_files/debug_files-bundle-jvm-help.trycmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
``` | ||
$ sentry-cli debug-files bundle-jvm --help | ||
? success | ||
Create a source bundle for the given JVM based source files (e.g. Java, Kotlin, ...) | ||
|
||
Usage: sentry-cli[EXE] debug-files bundle-jvm [OPTIONS] --output <PATH> --debug-id <UUID> <PATH> | ||
|
||
Arguments: | ||
<PATH> The directory containing source files to bundle. | ||
|
||
Options: | ||
-o, --org <ORG> The organization slug | ||
--header <KEY:VALUE> Custom headers that should be attached to all requests | ||
in key:value format. | ||
-p, --project <PROJECT> The project slug. | ||
--auth-token <AUTH_TOKEN> Use the given Sentry auth token. | ||
--output <PATH> The path to the output folder. | ||
--debug-id <UUID> Debug ID (UUID) to use for the source bundle. | ||
--log-level <LOG_LEVEL> Set the log output verbosity. [possible values: trace, debug, info, | ||
warn, error] | ||
--quiet Do not print any output while preserving correct exit code. This | ||
flag is currently implemented only for selected subcommands. | ||
[aliases: silent] | ||
-h, --help Print help | ||
|
||
``` |
8 changes: 8 additions & 0 deletions
8
tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-dir-empty.trycmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
``` | ||
$ sentry-cli debug-files bundle-jvm --output . --debug-id 48dee70b-4f3f-4a49-9223-de441738f7cd empty-dir | ||
? success | ||
> Found 0 files | ||
> Bundled 0 files for upload | ||
Created ./48dee70b-4f3f-4a49-9223-de441738f7cd.zip | ||
|
||
``` |
9 changes: 9 additions & 0 deletions
9
tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-is-file.trycmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
``` | ||
$ sentry-cli debug-files bundle-jvm --output `cwd` --debug-id 59144E0E-52C4-41F8-9111-0D6F8F14905B tests/integration/_fixtures/jvm/io/sentry/sample/MainActivity.java | ||
? failed | ||
error: Given path is not a directory: tests/integration/_fixtures/jvm/io/sentry/sample/MainActivity.java | ||
|
||
Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output. | ||
Please attach the full debug log to all bug reports. | ||
|
||
``` |
9 changes: 9 additions & 0 deletions
9
tests/integration/_cases/debug_files/debug_files-bundle-jvm-input-not-found.trycmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
``` | ||
$ sentry-cli debug-files bundle-jvm --output `cwd` --debug-id 7A575F05-0585-4DB0-95DE-D0C032D7C707 tests/integration/_fixtures/i-do-not-exist | ||
? failed | ||
error: Given path does not exist: tests/integration/_fixtures/i-do-not-exist | ||
|
||
Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output. | ||
Please attach the full debug log to all bug reports. | ||
|
||
``` |
8 changes: 8 additions & 0 deletions
8
tests/integration/_cases/debug_files/debug_files-bundle-jvm-invalid-uuid.trycmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
``` | ||
$ sentry-cli debug-files bundle-jvm --output . --debug-id not-a-valid-uuid io | ||
? failed | ||
error: invalid value 'not-a-valid-uuid' for '--debug-id <UUID>': invalid debug identifier | ||
|
||
For more information, try '--help'. | ||
|
||
``` |
12 changes: 12 additions & 0 deletions
12
tests/integration/_cases/debug_files/debug_files-bundle-jvm-output-is-file.trycmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
``` | ||
$ sentry-cli debug-files bundle-jvm --output ./file.txt --debug-id D384DC3B-AB2F-4DC7-903D-2C851E27E094 ./io | ||
? failed | ||
> Found 2 files | ||
> Bundled 2 files for upload | ||
error: Unable to write source bundle | ||
caused by: [..] | ||
|
||
Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output. | ||
Please attach the full debug log to all bug reports. | ||
|
||
``` |
8 changes: 8 additions & 0 deletions
8
tests/integration/_cases/debug_files/debug_files-bundle-jvm-output-not-found.trycmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
``` | ||
$ sentry-cli debug-files bundle-jvm --output i-do-not-exist --debug-id 0B693ABA-531C-4EB6-99E4-B7320C3C85DA tests/integration/_fixtures/jvm | ||
? success | ||
> Found 2 files | ||
> Bundled 2 files for upload | ||
Created i-do-not-exist/0b693aba-531c-4eb6-99e4-b7320c3c85da.zip | ||
|
||
``` |
8 changes: 8 additions & 0 deletions
8
tests/integration/_cases/debug_files/debug_files-bundle-jvm.trycmd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
``` | ||
$ sentry-cli debug-files bundle-jvm --output . --debug-id a4368a48-0880-40d7-9a26-c9ef5a84d156 ./io | ||
? success | ||
> Found 2 files | ||
> Bundled 2 files for upload | ||
Created ./a4368a48-0880-40d7-9a26-c9ef5a84d156.zip | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
tests/integration/_fixtures/jvm/io/sentry/sample/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package integration._fixtures.jvm.io.sentry.sample; | ||
|
||
public class MainActivity { | ||
} |
4 changes: 4 additions & 0 deletions
4
tests/integration/_fixtures/jvm/io/sentry/sample/SampleActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package integration._fixtures.jvm.io.sentry.sample | ||
|
||
class SampleActivity { | ||
} |
Oops, something went wrong.