Repository: starship/starship
File: src/modules/gradle.rs (Rust)

Code before:
        .set_files(&config.detect_files)
        .set_extensions(&config.detect_extensions)
        .set_folders(&config.detect_folders)
        .is_match();

    if !is_gradle_project {
        return None;
    }

    let parsed = StringFormatter::new(config.format).and_then(|formatter| {
        formatter
            .map_meta(|var, _| match var {
                "symbol" => Some(config.symbol),
                _ => None,
            })
            .map_style(|variable| match variable {
                "style" => Some(Ok(config.style)),
                _ => None,
            })
            .map(|variable| match variable {
                "version" => {
                    let gradle_version = match config.strategy {
                        GradleVersionStrategy::Executable => parse_gradle_version_from_stdout(
                            &context
                                .exec_cmds_return_first(vec![
                                    vec!["./gradlew", "--version"],
                                    vec!["gradle", "--version"],
                                ])?
                                .stdout,
                        )?,
                        GradleVersionStrategy::WrapperProperties => {
                            let properties_file =
                                find_wrapper_properties_file(&context.current_dir)?;
                            let properties = fs::read_to_string(properties_file).ok()?;
                            parse_gradle_version_from_properties(&properties)?
                        }
                    };
                    VersionFormatter::format_module_version(
                        module.get_name(),
                        &gradle_version,
                        config.version_format,
                    )
                    .map(Ok)
                }
                _ => None,
            })
            .parse(None, Some(context))
    });

    module.set_segments(match parsed {
        Ok(segments) => segments,

Review comment (suggestion):
I would avoid executing files from the current working directory unless explicitly configured to do so.

Code after:

    if !is_gradle_project {
        return None;
    }

    let parsed = StringFormatter::new(config.format).and_then(|formatter| {
        formatter
            .map_meta(|var, _| match var {
                "symbol" => Some(config.symbol),
                _ => None,
            })
            .map_style(|variable| match variable {
                "style" => Some(Ok(config.style)),
                _ => None,
            })
            .map(|variable| match variable {
                "version" => {
                    let gradle_version = {
                        let properties = get_wrapper_properties_file(context, config.recursive)?;
                        parse_gradle_version_from_properties(&properties)?
                    };
                    VersionFormatter::format_module_version(
                        module.get_name(),
                        &gradle_version,
                        config.version_format,
                    )
                    .map(Ok)
                }
                _ => None,
            })
            .parse(None, Some(context))
    });

    module.set_segments(match parsed {
        Ok(segments) => segments,
        Err(error) => {
            log::warn!("Error in module `gradle`:\n{}", error);
            return None;
        }
    });

    Some(module)
}

fn parse_gradle_version_from_properties(wrapper_properties: &str) -> Option<String> {
    // example gradle.properties content
    /*
        distributionBase=GRADLE_USER_HOME
        distributionPath=wrapper/dists
        distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
        zipStoreBase=GRADLE_USER_HOME