Skip to content
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

feat(package): added showing gradle version based on the gradle.properties file #4432

Merged
merged 9 commits into from
Oct 30, 2022
27 changes: 23 additions & 4 deletions src/modules/package.rs
Original file line number Diff line number Diff line change
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();
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