Skip to content

Commit

Permalink
feat(gradle): add gradle module (starship#4423)
Browse files Browse the repository at this point in the history
* docs: document gradle module

* implement gradle module

* gradle-module: add test for wrapper properties case

* docs: improve gradle module documentation

* fix: fix gradle module wrapper properties test

* drop gradle executable strategy

* apply suggested stuff

* Fix config schema
  • Loading branch information
NyCodeGHG authored and Indyandie committed Jul 26, 2023
1 parent e00c827 commit 2d90147
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 0 deletions.
79 changes: 79 additions & 0 deletions .github/config-schema.json
Expand Up @@ -621,6 +621,29 @@
}
]
},
"gradle": {
"default": {
"detect_extensions": [
"gradle",
"gradle.kts"
],
"detect_files": [],
"detect_folders": [
"gradle"
],
"disabled": false,
"format": "via [$symbol($version )]($style)",
"recursive": false,
"style": "bold bright-cyan",
"symbol": "🅶 ",
"version_format": "v${raw}"
},
"allOf": [
{
"$ref": "#/definitions/GradleConfig"
}
]
},
"guix_shell": {
"default": {
"disabled": false,
Expand Down Expand Up @@ -3189,6 +3212,62 @@
},
"additionalProperties": false
},
"GradleConfig": {
"type": "object",
"properties": {
"format": {
"default": "via [$symbol($version )]($style)",
"type": "string"
},
"version_format": {
"default": "v${raw}",
"type": "string"
},
"symbol": {
"default": "🅶 ",
"type": "string"
},
"style": {
"default": "bold bright-cyan",
"type": "string"
},
"disabled": {
"default": false,
"type": "boolean"
},
"recursive": {
"default": false,
"type": "boolean"
},
"detect_extensions": {
"default": [
"gradle",
"gradle.kts"
],
"type": "array",
"items": {
"type": "string"
}
},
"detect_files": {
"default": [],
"type": "array",
"items": {
"type": "string"
}
},
"detect_folders": {
"default": [
"gradle"
],
"type": "array",
"items": {
"type": "string"
}
}
},
"additionalProperties": false
},
"GuixShellConfig": {
"type": "object",
"properties": {
Expand Down
3 changes: 3 additions & 0 deletions docs/.vuepress/public/presets/toml/bracketed-segments.toml
Expand Up @@ -58,6 +58,9 @@ format = '([\[$all_status$ahead_behind\]]($style))'
[golang]
format = '\[[$symbol($version)]($style)\]'

[gradle]
format = '\[[$symbol($version)]($style)\]'

[guix_shell]
format = '\[[$symbol]($style)\]'

Expand Down
3 changes: 3 additions & 0 deletions docs/.vuepress/public/presets/toml/no-runtime-versions.toml
Expand Up @@ -37,6 +37,9 @@ format = 'via [$symbol]($style)'
[golang]
format = 'via [$symbol]($style)'

[gradle]
format = 'via [$symbol]($style)'

[haxe]
format = 'via [$symbol]($style)'

Expand Down
5 changes: 5 additions & 0 deletions docs/.vuepress/public/presets/toml/pastel-powerline.toml
Expand Up @@ -12,6 +12,7 @@ $c\
$elixir\
$elm\
$golang\
$gradle\
$haskell\
$java\
$julia\
Expand Down Expand Up @@ -97,6 +98,10 @@ symbol = " "
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[gradle]
style = "bg:#86BBD8"
format = '[ $symbol ($version) ]($style)'

[haskell]
symbol = ""
style = "bg:#86BBD8"
Expand Down
3 changes: 3 additions & 0 deletions docs/.vuepress/public/presets/toml/plain-text-symbols.toml
Expand Up @@ -64,6 +64,9 @@ symbol = "git "
[golang]
symbol = "go "

[gradle]
symbol = "gradle "

[guix_shell]
symbol = "guix "

Expand Down
37 changes: 37 additions & 0 deletions docs/config/README.md
Expand Up @@ -291,6 +291,7 @@ $helm\
$java\
$julia\
$kotlin\
$gradle\
$lua\
$nim\
$nodejs\
Expand Down Expand Up @@ -1927,6 +1928,42 @@ disabled = true
format = 'via [🐂](yellow bold) '
```

## Gradle

The `gradle` module shows the version of the [Gradle Wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html)
currently used in the project directory.

By default the module will be shown if any of the following conditions are met:

- The current directory contains a `gradle/wrapper/gradle-wrapper.properties` directory.
- The current directory contains a file ending with `.gradle` or `.gradle.kts`.

The `gradle` module is only able to read your Gradle Wrapper version from your config file, we don't execute your wrapper, because of the security concerns.

### Options

| Option | Default | Description |
| ------------------- | ------------------------------------ | ------------------------------------------------------------------------- |
| `format` | `"via [$symbol($version )]($style)"` | The format for the module. |
| `version_format` | `"v${raw}"` | The version format. Available vars are `raw`, `major`, `minor`, & `patch` |
| `symbol` | `"🅶 "` | A format string representing the symbol of Gradle. |
| `detect_extensions` | `["gradle", "gradle.kts"]` | Which extensions should trigger this module. |
| `detect_files` | `[]` | Which filenames should trigger this module. |
| `detect_folders` | `["gradle"]` | Which folders should trigger this module. |
| `style` | `"bold bright-cyan"` | The style for the module. |
| `disabled` | `false` | Disables the `gradle` module. |
| `recursive` | `false` | Enables recursive finding for the `gradle` directory. |

### Variables

| Variable | Example | Description |
| -------- | -------- | ------------------------------------ |
| version | `v7.5.1` | The version of `gradle` |
| symbol | | Mirrors the value of option `symbol` |
| style* | | Mirrors the value of option `style` |

*: This variable can only be used as a part of a style string

## Haskell

The `haskell` module finds the current selected GHC version and/or the selected Stack snapshot.
Expand Down
36 changes: 36 additions & 0 deletions src/configs/gradle.rs
@@ -0,0 +1,36 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Deserialize, Serialize)]
#[cfg_attr(
feature = "config-schema",
derive(schemars::JsonSchema),
schemars(deny_unknown_fields)
)]
#[serde(default)]
pub struct GradleConfig<'a> {
pub format: &'a str,
pub version_format: &'a str,
pub symbol: &'a str,
pub style: &'a str,
pub disabled: bool,
pub recursive: bool,
pub detect_extensions: Vec<&'a str>,
pub detect_files: Vec<&'a str>,
pub detect_folders: Vec<&'a str>,
}

impl<'a> Default for GradleConfig<'a> {
fn default() -> Self {
GradleConfig {
format: "via [$symbol($version )]($style)",
version_format: "v${raw}",
symbol: "🅶 ",
style: "bold bright-cyan",
disabled: false,
recursive: false,
detect_extensions: vec!["gradle", "gradle.kts"],
detect_files: vec![],
detect_folders: vec!["gradle"],
}
}
}
3 changes: 3 additions & 0 deletions src/configs/mod.rs
Expand Up @@ -33,6 +33,7 @@ pub mod git_metrics;
pub mod git_state;
pub mod git_status;
pub mod go;
pub mod gradle;
pub mod guix_shell;
pub mod haskell;
pub mod haxe;
Expand Down Expand Up @@ -164,6 +165,8 @@ pub struct FullConfig<'a> {
#[serde(borrow)]
golang: go::GoConfig<'a>,
#[serde(borrow)]
gradle: gradle::GradleConfig<'a>,
#[serde(borrow)]
guix_shell: guix_shell::GuixShellConfig<'a>,
#[serde(borrow)]
haskell: haskell::HaskellConfig<'a>,
Expand Down
1 change: 1 addition & 0 deletions src/configs/starship_root.rs
Expand Up @@ -58,6 +58,7 @@ pub const PROMPT_ORDER: &[&str] = &[
"elm",
"erlang",
"golang",
"gradle",
"haskell",
"haxe",
"helm",
Expand Down
1 change: 1 addition & 0 deletions src/module.rs
Expand Up @@ -41,6 +41,7 @@ pub const ALL_MODULES: &[&str] = &[
"git_state",
"git_status",
"golang",
"gradle",
"guix_shell",
"haskell",
"haxe",
Expand Down

0 comments on commit 2d90147

Please sign in to comment.