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
40 changes: 40 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
description = "Rust flake template";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
utils.url = "github:numtide/flake-utils";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, utils, fenix }:
utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
fenix.overlay
];
};
in
{


devShell = with pkgs; mkShell {
shellHook = ''
'';
buildInputs = with pkgs; [
(pkgs.fenix.complete.withComponents [
"cargo"
"clippy"
"rust-src"
"rustc"
"rustfmt"
"rust-analyzer"
])
];
};
});
}
BattleCh1cken marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 24 additions & 5 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)?;

format_version(&caps["version"], config.version_format)
context
.read_file_from_pwd("build.gradle")
.and_then(|contents| {
let re = Regex::new(r#"(?m)^version ['"](?P<version>[^'"]+)['"]$"#).unwrap(); /*dark magic*/
let caps = re.captures(&contents)?;
format_version(&caps["version"], config.version_format)
})
.or_else(|| {
let properties_file_contents = context.read_file_from_pwd("gradle.properties")?;
let re = Regex::new(r"version=(?P<version>.*)").unwrap();
let caps = re.captures(&properties_file_contents)?;
format_version(&caps["version"], config.version_format)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the comments from moritzreiter, please read the properties file first.

})
}

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