Skip to content

Commit

Permalink
feat(package): added showing gradle version based on the gradle.prope…
Browse files Browse the repository at this point in the history
…rties 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 <davidkna@users.noreply.github.com>

* 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 <BattleCh1cken@Larkov.de>
Co-authored-by: David Knaack <davidkna@users.noreply.github.com>
  • Loading branch information
3 people committed Oct 30, 2022
1 parent d1bc982 commit 14ee81b
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/modules/package.rs
Expand Up @@ -102,11 +102,19 @@ fn get_setup_cfg_version(context: &Context, config: &PackageConfig) -> Option<St
}

fn get_gradle_version(context: &Context, config: &PackageConfig) -> Option<String> {
let file_contents = context.read_file_from_pwd("build.gradle")?;
let re = Regex::new(r#"(?m)^version ['"](?P<version>[^'"]+)['"]$"#).unwrap();
let caps = re.captures(&file_contents)?;
context
.read_file_from_pwd("gradle.properties")
.and_then(|contents| {
let re = Regex::new(r"version=(?P<version>.*)").unwrap();

This comment has been minimized.

Copy link
@swpalmer

swpalmer Dec 26, 2022

Contributor

This regex is wrong. It will pick up commented out lines with 'version=' and it should allow for whitespace on either side of the '='

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<version>[^'"]+)['"]$"#).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<String> {
Expand Down Expand Up @@ -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<()> {
Expand Down

0 comments on commit 14ee81b

Please sign in to comment.