-
-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add command sentry-cli debug-files bundle-jvm
for bundling Java (and other JVM based languages) sources
#1551
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
ccb8b39
Add command for bundling Java sources
adinauer 77c49a1
remove commented out code
adinauer 05f0c7e
Allow passing in debug_id; add tests; cleanup
adinauer 1c8034c
Fix existing tests
adinauer 6af257e
Test help
adinauer 2adb20d
Merge branch 'master' into feat/java-source-bundling
adinauer 7fff72d
Fix tests after merge
adinauer 9fc5b01
Apply fmt
adinauer f1a1a0e
fix clippy
adinauer 80462d8
Add tests for windows
adinauer 696c658
fmt
adinauer a883b56
add comma
adinauer 7fea001
fix windows test
adinauer 280c47f
revert windows test
adinauer 4241cc4
try to fix windows test
adinauer 3644f88
another try
adinauer 6084679
yet another try
adinauer 907dea9
Apply suggestions from code review
adinauer 958c8f4
Merge windows and non windows help test
adinauer c749169
clippy
adinauer 76d8a16
Update expected test output after merging suggestions (caused by added)
adinauer 73f0436
If out dir does not exist, create it
adinauer 629ebdb
fix tests
adinauer 06e615b
Expect success
adinauer f5a2ef3
Unify windows and non windows test
adinauer ba0227a
Remove commented out short options
adinauer 624a52c
PR feedback; use clap value_parser; move code; etc
adinauer db04bee
Merge is-file tests for windows and non windows
adinauer c348d99
Rename command to bundle-jvm
adinauer e05eacb
Rename JvmBased to Jvm
adinauer b83271d
fmt
adinauer 04418d6
Forgot to add renamed dir after move
adinauer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really want this here? The file we create is just a
SourceBundle
, and no debug file on its own exists for JVM.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an internal discussion we didn't decide whether we actually need the new type but it was suggested to err on the side of defining a new one. Do you want me to reopen that conversation internally? Handling of
jvm
bundles is different from others in that files are renamed while bundling and lookup constructs the file path frommodule
andabs_path
if available.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it doesn’t hurt either :-)