From 14ee81b9c31047993217f060b57fb327a58c0d38 Mon Sep 17 00:00:00 2001 From: Felix H <75806385+BattleCh1cken@users.noreply.github.com> Date: Sun, 30 Oct 2022 11:43:32 -0400 Subject: [PATCH] feat(package): added showing gradle version based on the gradle.properties file (#4432) * feat: added showing gradle version based on the gradle.properties file * fix: wouldn't return version * fix: forgot to remove "version=" from returned version" * fix: ran rustfmt * fix: test now actually tests for something Co-authored-by: David Knaack * fix: the regex actually makes sense now * fix: complete refactor of control flow * Delete flake.nix * changed order in which files are processed Co-authored-by: BattleCh1cken Co-authored-by: David Knaack --- src/modules/package.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/modules/package.rs b/src/modules/package.rs index f278b64b..03e787bf 100644 --- a/src/modules/package.rs +++ b/src/modules/package.rs @@ -102,11 +102,19 @@ fn get_setup_cfg_version(context: &Context, config: &PackageConfig) -> Option Option { - let file_contents = context.read_file_from_pwd("build.gradle")?; - let re = Regex::new(r#"(?m)^version ['"](?P[^'"]+)['"]$"#).unwrap(); - let caps = re.captures(&file_contents)?; + context + .read_file_from_pwd("gradle.properties") + .and_then(|contents| { + let re = Regex::new(r"version=(?P.*)").unwrap(); + let caps = re.captures(&contents)?; + format_version(&caps["version"], config.version_format) + }).or_else(|| { + let build_file_contents = context.read_file_from_pwd("build.gradle")?; + let re = Regex::new(r#"(?m)^version ['"](?P[^'"]+)['"]$"#).unwrap(); /*dark magic*/ + let caps = re.captures(&build_file_contents)?; + format_version(&caps["version"], config.version_format) - format_version(&caps["version"], config.version_format) + }) } fn get_composer_version(context: &Context, config: &PackageConfig) -> Option { @@ -960,6 +968,17 @@ java { expect_output(&project_dir, None, None); project_dir.close() } + #[test] + fn test_extract_grade_version_from_properties() -> io::Result<()> { + let config_name = "gradle.properties"; + let config_content = " + version=1.2.3 + "; + let project_dir = create_project_dir()?; + fill_config(&project_dir, config_name, Some(config_content))?; + expect_output(&project_dir, Some("v1.2.3"), None); + project_dir.close() + } #[test] fn test_extract_mix_version() -> io::Result<()> {