From 5128e6918ff235e9daf22198e1febe122bdac531 Mon Sep 17 00:00:00 2001 From: Fred Eisele Date: Thu, 23 Sep 2021 19:18:39 -0500 Subject: [PATCH 01/12] port to Powershell no syntax errors it must be good ;-) --- bin/gng.ps1 | 158 ++++++++++++++++++++++++++++++++++++++++++++++++ gradle/gng.json | 0 2 files changed, 158 insertions(+) create mode 100644 bin/gng.ps1 create mode 100644 gradle/gng.json diff --git a/bin/gng.ps1 b/bin/gng.ps1 new file mode 100644 index 0000000..eafe843 --- /dev/null +++ b/bin/gng.ps1 @@ -0,0 +1,158 @@ +#!/usr/bin/env pwsh + +param ( + [Parameter(Mandatory=$true)][string]$task = ':tasks', + [Parameter(Mandatory=$false)][string]$action, + [Parameter(Mandatory=$false)][string]$version, + [Parameter(Mandatory=$false)][string]$distributionType, + [Parameter(Mandatory=$false)][string]$mirror, + [Parameter(Mandatory=$false)][string]$destinationDir, + [Parameter(Mandatory=$false)][string]$help +) + +# resolve $$sourceFile until the file is no longer a symlink +$sourceFile=$PSCommandPath +$sourceDir=$PSScriptRoot +New-Variable -Option Constant -Name selfDir -Value (Get-Item -Path $sourceDir).Target + +# Powershell 7 has an operator for this. +# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.1#null-coalescing-operator- +function NullCoalesce($source, $default) { + if ($source == $null) { + return $default + } + return $source +} + +New-Variable -Option Constant -Name debugLevel -Value (NullCoalesce $env:DEBUG 0).Target + +New-Variable -Option Constant -Name debugLevel -Value (NullCoalesce $env:GRADLEW "gradlew.bat").Target + +function die($message) { + Write-Error "failure : $message" + Exit-PSHostProcess +} + + +# Search recursively upwards for the file. +# https://stackoverflow.com/questions/45642517/search-directory-for-a-file-iterating-up-parent-directories-if-not-found +function lookUpwards($file, $currPath){ + $currPath = if (-not(Test-Path -Path $currPath)) { $currPath = Get-Location } + + while($path -and !(Test-Path (Join-Path $path $file))) { + if ($path -eq ((Split-Path $path -Qualifier)+"/")) { + break + } + $path = Split-Path $path -Parent + } + return $path +} + +function cfgGet($key) { +# for kv in "${__GNG_CONFIG[@]}"; do +# if [[ ${kv} =~ ^${key}= ]]; then +# trim "${kv#${key}=}" +# fi +# done +} + +function installGng($version, $type, $mirrorUrl = 'https://services.gradle.org/distributions', $dir) { + $dir = if (-not (Test-Path -Path $dir -PathType Container)) + { + New-Item -ItemType Directory -Force -Path (Join-Path $dir 'gradle' 'wrapper') + } + + Write-Information "Installing Gradle Wrapper in ${dir}. (version=${version}, distributionType=${type}, mirrorUrl=${mirrorUrl:-})" + + #Copy the embedded Gradle Wrapper + $srcDir = Split-Path -Path $selfDir -Parent + Copy-Item -LiteralPath (Join-Path $srcDir 'gradle' 'gng.cfg') -Destination (Join-Path $dir 'gradle') + Copy-Item -LiteralPath (Join-Path $srcDir 'gradle' 'gradlew') -Destination $dir + Copy-Item -LiteralPath (Join-Path $srcDir 'gradle' 'gradlew.bat') -Destination $dir + Copy-Item -LiteralPath (Join-Path $srcDir 'gradle' 'wrapper' 'gradle-warpper-jar') -Destination (Join-Path $dir 'gradle' 'wrapper') + + $distributionUrl = $mirrorUrl -replace '[#\!=:]','\$0' + $distributionUrl = Join-Path $distributionUrl "gradle-${version}-${type}.zip" + @" +#Generated by GNG +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=${distributionUrl} +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +"@ | Out-File -FilePath (Join-Path $dir 'gradle' 'wrapper' 'gradle-wrapper.properties') +} + +# Pick the project's lowest level gradle command. +function selectGradle($dir) { + $gradlew = lookUpwards $gradlew $dir + if (-not (Test-Path -Path $gradlew)) + { + die "No ${gradlew} set up for this project; Please use 'gng wrapper' installing a Gradle Wrapper'." + } + Write-Information "${gradlew}" + return 0 +} + +function gradle($task, $action) { + $gradle = selectGradle (Get-Location).Path + Write-Debug "Using gradle at '${gradle}' to run" + $jsonConf = Get-Content (Join-Path $gradleDir 'gradle' 'gng.json') | Out-String | ConvertFrom-Json + $gradleDir = (Split-Path -Path $gradle -Parent) + loadConfig $gradleDir + $procOptions = @{ + FilePath = $gradle + WorkingDirectory = $gradleDir + ArgumentList = $task,$action + } + Start-Process @procOptions +} + +function bootstrap_help { + Write-Host @" +Generates a Gradle Wrapper +Usage: gng wrapper [-v|--version ] [-t|--distribution-type ] [-m|--mirror ] [-h|--help] [ -d|--destination-dir +-v, --version: Gradle Version (default: 'latest', version information is from https://services.gradle.org/versions/current, visit https://services.gradle.org/versions/all for all available versions) +-t, --distribution-type: Gradle Distribution Type (default: 'all') +-m, --mirror: Gradle Distribution Mirror URL Prefix(Optional with no default value, The url prefix replaces https://services.gradle.org/distributions/) + It replaces the whole distributionUrl except the file part in a URL. For example, if specify '-m "https://example.com/gradle/"', then + "https://services.gradle.org/distributions/gradle-6.8-all.zip" will become "https://example.com/gradle/gradle-6.8-all.zip" +-d, --destination-dir : The folder location where generated Gradle Wrapper(default: 'Your current working directory') +-h, --help: Prints help +"@ +} + +function bootstrap($argVersion = "latest", $argDistType = "all") { + $argDestinationDir = Get-Location + + if ($version -eq 'latest') { + Write-Information "Fetching the latest Gradle version from services.gradle.org" + $gradleInfo = Invoke-WebRequest -Uri "https://services.gradle.org/versions/current" | ConvertFrom-Json + Write-Information "The latest Gradle version is ${gradleInfo}" + } + + installGw $gradleInfo $argDistType $mirror $argDestinationDir +} + + +# manage certificates +# use https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html +function trust($host,$port = 443) { +# local KEYSTORE_FILE +# KEYSTORE_FILE="$(readlink -e "$(dirname "$(readlink -e "$(which keytool)")")")"/../lib/security/cacerts +# local KEYSTORE_PASS="${KEYSTORE_PASS:-changeit}" +# keytool -printcert -sslserver "${HOST}:${PORT}" -rfc | keytool -import -noprompt -alias "${HOST}" -keystore "${KEYSTORE_FILE}" -storepass "${KEYSTORE_PASS}" +} + + +Switch -Exact ($task) { + 'trust' { + trust $action + } + 'wrapper' { + bootstrap $action + } + Default { + gradle $task $action + } +} diff --git a/gradle/gng.json b/gradle/gng.json new file mode 100644 index 0000000..e69de29 From b95a5dfd862b039f21c38c5cfa39b0f69c7d4ea7 Mon Sep 17 00:00:00 2001 From: Fred Eisele Date: Fri, 24 Sep 2021 16:29:10 -0500 Subject: [PATCH 02/12] rewrote the gng as a powershell module with three functions and two alias --- bin/gng.ps1 | 158 ----------------------------- bin/gng.psm1 | 178 +++++++++++++++++++++++++++++++++ bin/install.ps1 | 27 +++++ docs/index-powershell.asciidoc | 131 ++++++++++++++++++++++++ 4 files changed, 336 insertions(+), 158 deletions(-) delete mode 100644 bin/gng.ps1 create mode 100644 bin/gng.psm1 create mode 100644 bin/install.ps1 create mode 100644 docs/index-powershell.asciidoc diff --git a/bin/gng.ps1 b/bin/gng.ps1 deleted file mode 100644 index eafe843..0000000 --- a/bin/gng.ps1 +++ /dev/null @@ -1,158 +0,0 @@ -#!/usr/bin/env pwsh - -param ( - [Parameter(Mandatory=$true)][string]$task = ':tasks', - [Parameter(Mandatory=$false)][string]$action, - [Parameter(Mandatory=$false)][string]$version, - [Parameter(Mandatory=$false)][string]$distributionType, - [Parameter(Mandatory=$false)][string]$mirror, - [Parameter(Mandatory=$false)][string]$destinationDir, - [Parameter(Mandatory=$false)][string]$help -) - -# resolve $$sourceFile until the file is no longer a symlink -$sourceFile=$PSCommandPath -$sourceDir=$PSScriptRoot -New-Variable -Option Constant -Name selfDir -Value (Get-Item -Path $sourceDir).Target - -# Powershell 7 has an operator for this. -# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-7.1#null-coalescing-operator- -function NullCoalesce($source, $default) { - if ($source == $null) { - return $default - } - return $source -} - -New-Variable -Option Constant -Name debugLevel -Value (NullCoalesce $env:DEBUG 0).Target - -New-Variable -Option Constant -Name debugLevel -Value (NullCoalesce $env:GRADLEW "gradlew.bat").Target - -function die($message) { - Write-Error "failure : $message" - Exit-PSHostProcess -} - - -# Search recursively upwards for the file. -# https://stackoverflow.com/questions/45642517/search-directory-for-a-file-iterating-up-parent-directories-if-not-found -function lookUpwards($file, $currPath){ - $currPath = if (-not(Test-Path -Path $currPath)) { $currPath = Get-Location } - - while($path -and !(Test-Path (Join-Path $path $file))) { - if ($path -eq ((Split-Path $path -Qualifier)+"/")) { - break - } - $path = Split-Path $path -Parent - } - return $path -} - -function cfgGet($key) { -# for kv in "${__GNG_CONFIG[@]}"; do -# if [[ ${kv} =~ ^${key}= ]]; then -# trim "${kv#${key}=}" -# fi -# done -} - -function installGng($version, $type, $mirrorUrl = 'https://services.gradle.org/distributions', $dir) { - $dir = if (-not (Test-Path -Path $dir -PathType Container)) - { - New-Item -ItemType Directory -Force -Path (Join-Path $dir 'gradle' 'wrapper') - } - - Write-Information "Installing Gradle Wrapper in ${dir}. (version=${version}, distributionType=${type}, mirrorUrl=${mirrorUrl:-})" - - #Copy the embedded Gradle Wrapper - $srcDir = Split-Path -Path $selfDir -Parent - Copy-Item -LiteralPath (Join-Path $srcDir 'gradle' 'gng.cfg') -Destination (Join-Path $dir 'gradle') - Copy-Item -LiteralPath (Join-Path $srcDir 'gradle' 'gradlew') -Destination $dir - Copy-Item -LiteralPath (Join-Path $srcDir 'gradle' 'gradlew.bat') -Destination $dir - Copy-Item -LiteralPath (Join-Path $srcDir 'gradle' 'wrapper' 'gradle-warpper-jar') -Destination (Join-Path $dir 'gradle' 'wrapper') - - $distributionUrl = $mirrorUrl -replace '[#\!=:]','\$0' - $distributionUrl = Join-Path $distributionUrl "gradle-${version}-${type}.zip" - @" -#Generated by GNG -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=${distributionUrl} -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -"@ | Out-File -FilePath (Join-Path $dir 'gradle' 'wrapper' 'gradle-wrapper.properties') -} - -# Pick the project's lowest level gradle command. -function selectGradle($dir) { - $gradlew = lookUpwards $gradlew $dir - if (-not (Test-Path -Path $gradlew)) - { - die "No ${gradlew} set up for this project; Please use 'gng wrapper' installing a Gradle Wrapper'." - } - Write-Information "${gradlew}" - return 0 -} - -function gradle($task, $action) { - $gradle = selectGradle (Get-Location).Path - Write-Debug "Using gradle at '${gradle}' to run" - $jsonConf = Get-Content (Join-Path $gradleDir 'gradle' 'gng.json') | Out-String | ConvertFrom-Json - $gradleDir = (Split-Path -Path $gradle -Parent) - loadConfig $gradleDir - $procOptions = @{ - FilePath = $gradle - WorkingDirectory = $gradleDir - ArgumentList = $task,$action - } - Start-Process @procOptions -} - -function bootstrap_help { - Write-Host @" -Generates a Gradle Wrapper -Usage: gng wrapper [-v|--version ] [-t|--distribution-type ] [-m|--mirror ] [-h|--help] [ -d|--destination-dir --v, --version: Gradle Version (default: 'latest', version information is from https://services.gradle.org/versions/current, visit https://services.gradle.org/versions/all for all available versions) --t, --distribution-type: Gradle Distribution Type (default: 'all') --m, --mirror: Gradle Distribution Mirror URL Prefix(Optional with no default value, The url prefix replaces https://services.gradle.org/distributions/) - It replaces the whole distributionUrl except the file part in a URL. For example, if specify '-m "https://example.com/gradle/"', then - "https://services.gradle.org/distributions/gradle-6.8-all.zip" will become "https://example.com/gradle/gradle-6.8-all.zip" --d, --destination-dir : The folder location where generated Gradle Wrapper(default: 'Your current working directory') --h, --help: Prints help -"@ -} - -function bootstrap($argVersion = "latest", $argDistType = "all") { - $argDestinationDir = Get-Location - - if ($version -eq 'latest') { - Write-Information "Fetching the latest Gradle version from services.gradle.org" - $gradleInfo = Invoke-WebRequest -Uri "https://services.gradle.org/versions/current" | ConvertFrom-Json - Write-Information "The latest Gradle version is ${gradleInfo}" - } - - installGw $gradleInfo $argDistType $mirror $argDestinationDir -} - - -# manage certificates -# use https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html -function trust($host,$port = 443) { -# local KEYSTORE_FILE -# KEYSTORE_FILE="$(readlink -e "$(dirname "$(readlink -e "$(which keytool)")")")"/../lib/security/cacerts -# local KEYSTORE_PASS="${KEYSTORE_PASS:-changeit}" -# keytool -printcert -sslserver "${HOST}:${PORT}" -rfc | keytool -import -noprompt -alias "${HOST}" -keystore "${KEYSTORE_FILE}" -storepass "${KEYSTORE_PASS}" -} - - -Switch -Exact ($task) { - 'trust' { - trust $action - } - 'wrapper' { - bootstrap $action - } - Default { - gradle $task $action - } -} diff --git a/bin/gng.psm1 b/bin/gng.psm1 new file mode 100644 index 0000000..48baeeb --- /dev/null +++ b/bin/gng.psm1 @@ -0,0 +1,178 @@ +<# + Gradle Wrapper Module + This module contains a set of wrapper scripts that + enable a user to perform Gradle tasks. + #> + +$script:psprovidername = "Microsoft-Windows-PowerShell" +$script:gradlewFileName = "gradlew.bat" + +# Search recursively upwards for the file. +function Invoke-Gradle { + param( + [Parameter( + Mandatory=$false, + HelpMessage=@" +The gradle task to run preceed it with a ':'. +By default runs the ':tasks' task. +"@)] + [string] + $task = ':tasks', + + [Parameter( + Mandatory=$false, + HelpMessage=@" +The working directory, defaults to current directory. +"@)] + [string] + $workingDir = (Get-Location) + ) + + Write-Debug "select $gradlewFileName starting in $workingDir" + $path = if (-Not (Test-Path -Path $workingDir)) { Get-Location } else { $workingDir } + $fileName = $script:gradlewFileName + # https://stackoverflow.com/questions/45642517/search-directory-for-a-file-iterating-up-parent-directories-if-not-found + while($path -and (-Not (Test-Path (Join-Path $path $fileName)))) { + Write-Debug "candidate path $path $fileName" + if ($path -eq ((Split-Path $path -Qualifier)+"/")) { + break + } + $path = Split-Path $path -Parent + } + $gradlewPath = (Join-Path $path $fileName) + if (-Not (Test-Path -Path $gradlewPath)) + { + Write-Error "No ${gradlew} set up for this project; Please use 'Install-Gradle'." + Exit-PSHostProcess + } + Write-Debug "Using gradle at '${gradlewPath}' to run" + $gradlewDir = (Split-Path -Path $gradlewPath -Parent) + $jsonConfFile = Join-Path $gradlewDir 'gradle/gng.json' + $jsonConf = if (Test-Path -Path $jsonConfFile) { + Get-Content (Join-Path (Join-Path $gradlewDir 'gradle') 'gng.json') | Out-String | ConvertFrom-Json + } else { + ConvertFrom-Json '' + } + Write-Debug "gradlew configuration '${jsonConf}'" + $procOptions = @{ + FilePath = $gradlewPath + WorkingDirectory = $gradlewDir + ArgumentList = $task + Wait = $True + PassThru = $True + NoNewWindow = $True + } + [string[]] $procOptionString = $procOptions.GetEnumerator().ForEach({ "$($_.Name)=$($_.Value)" }) + Write-Debug "gradlew command '$procOptionString'" + Start-Process @procOptions +} + +function Install-GradleWrapper { + Param( + [Parameter( + Mandatory=$false, + HelpMessage=@" +Gradle Version (default: 'latest') +Version information is from https://services.gradle.org/versions/current, +visit https://services.gradle.org/versions/all for all available versions) +"@)] + [string] + $version = 'latest', + + [Parameter( + Mandatory=$false, + HelpMessage="Gradle Distribution Type (default: 'all')")] + [string] + $distributionType = 'all', + + [Parameter( + Mandatory=$false, + HelpMessage=@" +Gradle Distribution Mirror URL Prefix +(Optional with no default value. The url prefix replaces https://services.gradle.org/distributions/) +It replaces the whole distributionUrl except the file part in a URL. +For example, if specify '-m "https://example.com/gradle/"', +then "https://services.gradle.org/distributions/gradle-6.8-all.zip" +will become "https://example.com/gradle/gradle-6.8-all.zip" +"@)] + [string] + $mirrorUrl, + + [Parameter( + Mandatory=$false, + HelpMessage=@" +The folder location where generated Gradle Wrapper(default: 'Your current working directory') +"@)] + [string] + $destinationDir = (Get-Location) + ) + if ($version -eq 'latest') { + Write-Information "Fetching the latest Gradle version from services.gradle.org" + $gradleInfo = Invoke-WebRequest -Uri "https://services.gradle.org/versions/current" | ConvertFrom-Json + Write-Information "The latest Gradle version is ${gradleInfo}" + } + $dir = if (-not (Test-Path -Path $destinationDir -PathType Container)) { + New-Item -ItemType Directory -Force -Path (Join-Path $dir 'gradle/wrapper') + } else { $destinationDir } + Write-Information "Installing Gradle Wrapper in ${dir}. (version=${version}, distributionType=${distributionType}, mirrorUrl=${mirrorUrl})" + + #Copy the embedded Gradle Wrapper + $srcDir = $PSScriptRoot + Copy-Item -LiteralPath (Join-Path $srcDir 'gng.cfg') -Destination (Join-Path $dir 'gradle') + Copy-Item -LiteralPath (Join-Path $srcDir 'gradlew') -Destination $dir + Copy-Item -LiteralPath (Join-Path $srcDir 'gradlew.bat') -Destination $dir + Copy-Item -LiteralPath (Join-Path $srcDir 'wrapper/gradle-wrapper.jar') -Destination (Join-Path $dir 'gradle/wrapper') + + $distributionUrl = $mirrorUrl -replace '[#\!=:]','\$0' + $distributionUrl = Join-Path $distributionUrl "gradle-${version}-${type}.zip" + @" +#Generated by GNG +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=${distributionUrl} +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +"@ | Out-File -FilePath (Join-Path $dir 'gradle/wrapper/gradle-wrapper.properties') + +} + + +# manage certificates +# use https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html + +function Get-GradleCert { + Param( + [Parameter( + Mandatory=$false, + HelpMessage=@" +host +"@)] + [string] + $host = 'localhost', + + [Parameter( + Mandatory=$false, + HelpMessage=@" +port +"@)] + [string] + $port = '443', + + [Parameter( + Mandatory=$true, + HelpMessage=@" +provide the keystore password +"@)] + [string] + $password + ) + $keytoolPath = (Get-Command keytool).Source + $keytoolDir = (Split-Path -Path $keytoolPath -Parent) + $keystoreFile = (Join-Path -Path $keytoolDir -ChildPath '/../lib/security/cacerts') + & keytoolPath -printcert -sslserver "${host}:${port}" -rfc | keytoolPath -import -noprompt -alias "${host}" -keystore "${keystoreFile}" -storepass "${password}" +} + +Set-Alias gw Invoke-Gradle +Set-Alias gng Install-GradleWrapper + +Export-ModuleMember -Function Invoke-Gradle, Install-GradleWrapper, Get-Gradle-Cert -Alias gw, gng \ No newline at end of file diff --git a/bin/install.ps1 b/bin/install.ps1 new file mode 100644 index 0000000..10a5646 --- /dev/null +++ b/bin/install.ps1 @@ -0,0 +1,27 @@ + +Param( + [Parameter( + Mandatory=$false, + HelpMessage=@" +Which level of the Powershell modules folders is the target for this module? +"@)] + [Int32] + $level = 0 + ) + +$script:mm = ($ENV:PSModulePath -split ';')[$level] +$script:mmPath = Join-Path -Path $script:mm -ChildPath 'gng' +if (-Not (Test-Path -Path $script:mmPath)) { + New-Item -Path $script:mmPath -ItemType Directory +} + +Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath 'gng.psm1') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') +$gradleDir = Join-Path -Path $PSScriptRoot -ChildPath '../gradle' +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'wrapper') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gng.json') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew.bat') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') + +Get-Module -ListAvailable gng | Format-List name, path +Import-Module -Verbose gng + diff --git a/docs/index-powershell.asciidoc b/docs/index-powershell.asciidoc new file mode 100644 index 0000000..8e8617b --- /dev/null +++ b/docs/index-powershell.asciidoc @@ -0,0 +1,131 @@ +![](https://github.com/dantesun/gng/workflows/Validate%20Gradle%20Wrapper/badge.svg) [![Gitter](https://badges.gitter.im/gdubw/community.svg)](https://gitter.im/gdubw/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) + +GNG is the successor of [gdub](https://www.gdub.rocks). It keeps the original `gw` command and with more features. + +It is written in both a bash script and a powershell module. + +## Quick Start + +The PowerShell version of GNG is implemented as a PowerShell Module. + +### Installing + +#### From Source : Windows (Powershell) + +[source,powershell] +---- +git clone https://github.com/babeloff/gng.git +cd gng +./bin/install.ps1 +---- + +After the Gradle Module has been installed into it can be used to initialize a gradle project. + +Create a new Gradle project with a GNG wrapper. +[source,powershell] +---- +Install-GradleWrapper -DestinationDir example-project +cd example-project +---- + +For that configured project, use `gw` whenever you need to type `gradlew` or `gradle`. +[source,powershell] +---- +gw :tasks +gw -Task :tasks +---- + +## Usage + +Type `gw` whenever you need to type `gradle` or `gradlew`. +It will search upwards from your current directory until it finds `gradlew.bat`. +It will run the gradlew command found from that directory. + +Note:: don't worry +[source,powershell] +---- +gng -Action wrapper +---- +This will create a Gradle wrapper in your current working directory. + +### 'gng' and 'gw' + +There are two commands `gw` and `gng`. `gw` is for your daily use and `gng` provides extra functions. + +* `gw` is originally from [gdub](http://gdub.rocks) and shorter than `gng`. It's easy to type and good for daily use. +* `gng` is the new name, and provides more features than `gw`. For example, `gng wrapper` can generate a copy of Gradle + Wrapper for you, type `gng wrapper -h` for details. + +[source,powershell] +---- +gw -Action wrapper -Help +---- + +Please note that `gw wrapper` OVERRIDES the original command `gradle wrapper` that executes Gradle Wrapper task. If you +want to execute the Gradle wrapper task instead, please type `gw wrapper`. + +Example: The following command will create a directory 'test' and install a copy of Gradle Wrapper with the latest +version Gradle. + +[source,powershell] +---- +gw -Action wrapper -d test +---- + +It will output like this(version number may vary as time goes by): + +[source,powershell] +---- +Fetching the latest Gradle version from services.gradle.org + +The latest Gradle version is 6.8.1 + +Installing Gradle Wrapper in test. (version=6.8.1, distributionType=all, mirrorUrl=) +---- + +### More examples + +1. `gw wrapper` will silently upgrade your existing Gradle Wrapper to the latest version +2. `gw wrapper -v 4.8.1` will silently set your existing Gradle Wrapper to the version 4.8.1 +3. `gw wrapper -t all` will silently set your existing Gradle Wrapper to the latest version with Gradle source code + archive(gradle-xxx-all.zip). +4. `gw wrapper -v 4.2.1 -m 'http://example.com/gradle/` will set your Gradle's version to 4.2.1 and distributionUrl + to `http://example.com/gradle/gradle-4.2.1-bin.zip` +5. `gw wrapper -v 4.2.1 -t all -m 'http://example.com/gradle/` will set your Gradle's version to 4.2.1 and + distributionUrl to `http://example.com/gradle/gradle-4.2.1-all.zip` + + +## How does GNG install Gradle Wrapper? + +It copies the embedded Gradle Wrapper to your project directly. +You can trust the embedded gradle-wrapper.jar. +It is verified +by [Gradle Wrapper Validation](https://github.com/marketplace/actions/gradle-wrapper-validation) +![](https://github.com/dantesun/gng/workflows/Validate%20Gradle%20Wrapper/badge.svg) +. + + +### Development + +#### From Source : Windows (Powershell) + +- https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_modules?view=powershell-5.1 + +[source,powershell] +---- +git clone https://github.com/babeloff/gng.git +cd gng +---- + +[source,powershell] +---- +Import-Module -Name ~/IdeaProjects/gng/bin/gng.psm1 -Force -Verbose +---- + +The `gw` command can now be run from a properly configured project. +[source,powershell] +---- +gw :tasks -Debug +---- + + From c638e10e3c2fa1b4bf5e957b311cbe85d0cb94c2 Mon Sep 17 00:00:00 2001 From: Fred Eisele Date: Fri, 24 Sep 2021 16:55:40 -0500 Subject: [PATCH 03/12] updated documentation from Markdown to Asciidoc --- .github/README.asciidoc | 6 ++ .github/README.md | 1 - ...install.ps1 => install-gng-powershell.ps1} | 0 docs/{index.md => index-bash.asciidoc} | 91 +++++++++++-------- 4 files changed, 58 insertions(+), 40 deletions(-) create mode 100644 .github/README.asciidoc delete mode 120000 .github/README.md rename bin/{install.ps1 => install-gng-powershell.ps1} (100%) rename docs/{index.md => index-bash.asciidoc} (85%) diff --git a/.github/README.asciidoc b/.github/README.asciidoc new file mode 100644 index 0000000..2e5a0d2 --- /dev/null +++ b/.github/README.asciidoc @@ -0,0 +1,6 @@ + +## GNG + +- link:../docs/index-bash.asciidoc[GNG for Bash] + +- link:../docs/index-powershell.asciidoc[GNG for PowerShell] diff --git a/.github/README.md b/.github/README.md deleted file mode 120000 index 1f6fde9..0000000 --- a/.github/README.md +++ /dev/null @@ -1 +0,0 @@ -../docs/index.md \ No newline at end of file diff --git a/bin/install.ps1 b/bin/install-gng-powershell.ps1 similarity index 100% rename from bin/install.ps1 rename to bin/install-gng-powershell.ps1 diff --git a/docs/index.md b/docs/index-bash.asciidoc similarity index 85% rename from docs/index.md rename to docs/index-bash.asciidoc index b8e0193..1a9091a 100644 --- a/docs/index.md +++ b/docs/index-bash.asciidoc @@ -1,41 +1,47 @@ -![](https://github.com/dantesun/gng/workflows/Validate%20Gradle%20Wrapper/badge.svg) [![Gitter](https://badges.gitter.im/gdubw/community.svg)](https://gitter.im/gdubw/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +image:https://github.com/dantesun/gng/workflows/Validate%20Gradle%20Wrapper/badge.svg[] +image:https://badges.gitter.im/gdubw/community.svg[Gitter] +link:https://gitter.im/gdubw/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge[] -GNG is the successor of [gdub](https://www.gdub.rocks). It keeps the original `gw` command and with more features. +GNG is the successor of link:https://www.gdub.rocks[gdub]. +It keeps the original `gw` command and with more features. It is written totally in bash script. -# Quick Start +## Quick Start -## Homebrew +### Homebrew -```shell -#Install gng +[source,shell] +---- +##Install gng brew tap gdubw/gng brew install gng -``` +---- -## Self-Extracting Installer +### Self-Extracting Installer The self-extracting installer is created with [makeself](https://github.com/megastep/makeself). If you are interested in the packaging details , Please see [release.yml](https://github.com/gdubw/gng/blob/master/.github/workflows/release.yml). -```shell +[source,shell] +---- # Downloading the latest release curl -fsSL https://github.com/gdubw/gng/releases/latest/download/gng-installer.sh -o gng-installer.sh sudo bash ./gng-installer.sh -``` +---- After Installation is complete: -```shell -# Creates a new Gradle project with Gradle wrapper +[source,shell] +---- +## Creates a new Gradle project with Gradle wrapper gng wrapper -d example-project cd example-project -# From now on, always type `gw` whenever you need to type `gradlew` +## From now on, always type `gw` whenever you need to type `gradlew` gw -``` +---- -# GNG is Not Gradle +## GNG is Not Gradle GNG is a script that automatically search your `gradlew` when you are inside your Gradle project and execute it. It also contains an official Gradle wrapper. You can create gradle projects from scratch without installing Gradle. @@ -43,7 +49,7 @@ contains an official Gradle wrapper. You can create gradle projects from scratch This is originally inspired by [gdub](https://www.gdub.rocks/) and [gradlew-bootstrap](https://github.com/viphe/gradlew-bootstrap). -## What's the problem? +### What's the problem? I worked with a lot of gradle projects, every project has its own Gradle Wrapper. So the global installed one, normally installed with `brew install gradle`, is seldom used. In fact, the global installed gradle’s version may conflict with @@ -64,14 +70,14 @@ You might interest in these discussions. > - [Phil Swenson's Gradle Forum Post](http://gsfn.us/t/39h67) > -# Usage +## Usage Just type `gw` whenever you need to type `gradle` or `gradlew`, then your life will be easier. If you don't have any Gradle or Gradle Wrapper installed, please don't worry. just type `gng wrapper`. It will create a Gradle wrapper in your current working directory. -## 'gng' and 'gw' +### 'gng' and 'gw' There are two commands `gw` and `gng`. `gw` is for your daily use and `gng` provides extra functions. @@ -79,7 +85,8 @@ There are two commands `gw` and `gng`. `gw` is for your daily use and `gng` prov * `gng` is the new name, and provides more features than `gw`. For example, `gng wrapper` can generate a copy of Gradle Wrapper for you, type `gng wrapper -h` for details. -```bash +[source,bash] +---- gng wrapper -h Generates a Gradle Wrapper Usage: gng wrapper [-v|--version ] [-t|--distribution-type ] [-m|--mirror ] [-h|--help] [ -d|--destination-dir @@ -90,7 +97,7 @@ Usage: gng wrapper [-v|--version ] [-t|--distribution-type ] [-m|--mir "https://services.gradle.org/distributions/gradle-6.8-all.zip" will become "https://example.com/gradle/gradle-6.8-all.zip" -d, --destination-dir : Your Gradle project root directory. (default: 'Your current working directory retrieved using ${PWD}') -h, --help: Prints help -``` +---- Please note that `gng wrapper` OVERRIDES the original command `gradle wrapper` that executes Gradle Wrapper task. If you want to execute the Gradle wrapper task instead, please type `gw wrapper`. @@ -98,21 +105,23 @@ want to execute the Gradle wrapper task instead, please type `gw wrapper`. Example: The following command will create a directory 'test' and install a copy of Gradle Wrapper with the latest version Gradle. -```bash +[source,bash] +---- gng wrapper -d test -``` +---- It will output like this(version number may vary as time goes by): -```bash +[source,bash] +---- Fetching the latest Gradle version from services.gradle.org The latest Gradle version is 6.8.1 Installing Gradle Wrapper in test. (version=6.8.1, distributionType=all, mirrorUrl=) -``` +---- -## More examples +### More examples 1. `gng wrapper` will silently upgrade your existing Gradle Wrapper to the latest version 2. `gng wrapper -v 4.8.1` will silently set your existing Gradle Wrapper to the version 4.8.1 @@ -123,38 +132,42 @@ Installing Gradle Wrapper in test. (version=6.8.1, distributionType=all, mirrorU 5. `gng wrapper -v 4.2.1 -t all -m 'http://example.com/gradle/` will set your Gradle's version to 4.2.1 and distributionUrl to `http://example.com/gradle/gradle-4.2.1-all.zip` -# Installation +## Installation -## Homebrew +### Homebrew -```bash +[source,bash] +---- brew tap gdubw/gng brew install gng -``` +---- -## Installing from source +### Installing from source -```bash +[source,bash] +---- git clone https://github.com/gdubw/gng.git cd gng sudo ./install.sh -``` +---- -## Aliasing the `gradle` command +### Aliasing the `gradle` command To avoid using any system wide Gradle distribution add a `gradle` alias to `gw` to your shell's configuration file. Example *bash*: -```text +[source,text] +---- echo "alias gradle=gw" >> ~/.bashrc echo "export PATH=/usr/local/bin:${PATH}" >> ~/.bashrc source ~/.bashrc -``` +---- -## install.sh usage +### install.sh usage -```bash +[source,bash] +---- sudo ./install.sh [-fhsu] Install gng from git source tree. See http://github.com/gdubw/gng for details. @@ -163,7 +176,7 @@ Install gng from git source tree. See http://github.com/gdubw/gng for details. -f re-install -h usage -s check for update -``` +---- examples: @@ -171,7 +184,7 @@ examples: 2. `./install.sh -s` will check for latest updates from remote master 3. `git reset --hard && git pull` will keep your copy to the latest -# How does GNG install Gradle Wrapper? +## How does GNG install Gradle Wrapper? It copies the embedded Gradle Wrapper to your project directly. You can trust the embedded gradle-wrapper.jar. It is verified From 40aaa278bd81109c109de321194bd432be627e4a Mon Sep 17 00:00:00 2001 From: Fred Eisele Date: Fri, 24 Sep 2021 17:00:58 -0500 Subject: [PATCH 04/12] not sure what to do with the badges --- docs/index-powershell.asciidoc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/index-powershell.asciidoc b/docs/index-powershell.asciidoc index 8e8617b..71dff86 100644 --- a/docs/index-powershell.asciidoc +++ b/docs/index-powershell.asciidoc @@ -1,4 +1,6 @@ -![](https://github.com/dantesun/gng/workflows/Validate%20Gradle%20Wrapper/badge.svg) [![Gitter](https://badges.gitter.im/gdubw/community.svg)](https://gitter.im/gdubw/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) +image:https://github.com/dantesun/gng/workflows/Validate%20Gradle%20Wrapper/badge.svg[] +image:https://badges.gitter.im/gdubw/community.svg[Gitter] +link:https://gitter.im/gdubw/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge[] GNG is the successor of [gdub](https://www.gdub.rocks). It keeps the original `gw` command and with more features. From f3b3c82886fd3d1de9fc8fa299693f55b4e2415f Mon Sep 17 00:00:00 2001 From: Fred Eisele Date: Fri, 24 Sep 2021 17:02:36 -0500 Subject: [PATCH 05/12] not sure what to do with the badges --- docs/index-bash.asciidoc | 2 +- docs/index-powershell.asciidoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/index-bash.asciidoc b/docs/index-bash.asciidoc index 1a9091a..9d9e68a 100644 --- a/docs/index-bash.asciidoc +++ b/docs/index-bash.asciidoc @@ -1,6 +1,6 @@ image:https://github.com/dantesun/gng/workflows/Validate%20Gradle%20Wrapper/badge.svg[] image:https://badges.gitter.im/gdubw/community.svg[Gitter] -link:https://gitter.im/gdubw/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge[] +//link:https://gitter.im/gdubw/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge[] GNG is the successor of link:https://www.gdub.rocks[gdub]. It keeps the original `gw` command and with more features. diff --git a/docs/index-powershell.asciidoc b/docs/index-powershell.asciidoc index 71dff86..3ce4dc3 100644 --- a/docs/index-powershell.asciidoc +++ b/docs/index-powershell.asciidoc @@ -1,6 +1,6 @@ image:https://github.com/dantesun/gng/workflows/Validate%20Gradle%20Wrapper/badge.svg[] image:https://badges.gitter.im/gdubw/community.svg[Gitter] -link:https://gitter.im/gdubw/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge[] +//link:https://gitter.im/gdubw/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge[] GNG is the successor of [gdub](https://www.gdub.rocks). It keeps the original `gw` command and with more features. From 256c53a2cea82c50b2b0fe8a1ca4b89e907fb216 Mon Sep 17 00:00:00 2001 From: Fred Eisele Date: Mon, 27 Sep 2021 19:29:24 -0500 Subject: [PATCH 06/12] add parameters for all options excepting the incubating and deprecated --- bin/gng.psm1 | 310 +++++++++++++++++++++++++++++++-- bin/install-gng-powershell.ps1 | 12 +- docs/index-powershell.asciidoc | 2 +- 3 files changed, 304 insertions(+), 20 deletions(-) diff --git a/bin/gng.psm1 b/bin/gng.psm1 index 48baeeb..8a1dc54 100644 --- a/bin/gng.psm1 +++ b/bin/gng.psm1 @@ -16,16 +16,297 @@ function Invoke-Gradle { The gradle task to run preceed it with a ':'. By default runs the ':tasks' task. "@)] - [string] + [string[]] $task = ':tasks', - [Parameter( - Mandatory=$false, - HelpMessage=@" + [Parameter( + Mandatory=$false, + HelpMessage=@" The working directory, defaults to current directory. "@)] - [string] - $workingDir = (Get-Location) + [string] + $workingDir = (Get-Location), + + [Parameter( + Mandatory=$false, + HelpMessage="Do not rebuild project dependencies.")] + [switch] + $noRebuild = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Enables the Gradle build cache. Gradle will try to reuse outputs from previous builds.")] + [switch] + $buildCache = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Do not rebuild project dependencies.")] + [switch] + $noRebuild = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Specifies which type of console output to generate. Values are 'plain', 'auto' (default), 'rich' or 'verbose'.")] + [string] + $console = "auto", + + [Parameter( + Mandatory=$false, + HelpMessage="Continue task execution after a task failure.")] + [switch] + $continue = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Set system property of the JVM (e.g. -Dmyprop=myvalue).")] + [string[]] + $systemProp = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Log in debug mode (includes normal stacktrace).")] + [switch] + $debug = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Uses the Gradle Daemon to run the build. Starts the Daemon if not running.")] + [switch] + $daemon = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Configures the dependency verification mode (strict, lenient or off)")] + [string] + $dependencyVerification = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Starts the Gradle Daemon in the foreground.")] + [switch] + $foreground = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Specifies the gradle user home directory.")] + [string] + $gradleUserHome = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Specify an initialization script.")] + [switch] + $initScript = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Set log level to info.")] + [switch] + $info = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Include the specified build in the composite.")] + [switch] + $includeBuild = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Generates checksums for dependencies used in the project (comma-separated list).")] + [switch] + $writeVerificationMetadata = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Run the builds with all task actions disabled.")] + [switch] + $dryRun = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Configure the number of concurrent workers Gradle is allowed to use.")] + [Int32] + $maxWorkers = 3, + + [Parameter( + Mandatory=$false, + HelpMessage="Disables the Gradle build cache.")] + [switch] + $noBuildCache = $false, + + [Parameter( + Mandatory=$false, + HelpMessage=@" +Do not use the Gradle daemon to run the build. +Useful occasionally if you have configured Gradle to always run with the daemon by default. +"@)] + [switch] + $noDaemon = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Disables parallel execution to build projects.")] + [switch] + $noParallel = $false, + + [Parameter( + Mandatory=$false, + HelpMessage=@" +Disables the creation of a build scan. +For more information about build scans, please visit https://gradle.com/build-scans. +"@)] + [switch] + $noScan = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Disables watching the file system.")] + [switch] + $noWatchFs = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Execute the build without accessing network resources.")] + [switch] + $offline = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Set project property for the build script (e.g. -Pmyprop=myvalue).")] + [string[]] + $projectProp = "", + + [Parameter( + Mandatory=$false, + HelpMessage="Specifies the start directory for Gradle. Defaults to current directory.")] + [string] + $projectDir = (Get-Location), + + [Parameter( + Mandatory=$false, + HelpMessage="Build projects in parallel. Gradle will attempt to determine the optimal number of executor threads to use.")] + [switch] + $parallel = $false, + + [Parameter( + Mandatory=$false, + HelpMessage=@" +Specifies the scheduling priority for the Gradle daemon and all processes launched by it. +Values are 'normal' (default) or 'low' +"@)] + [switch] + $priority = "normal", + + [Parameter( + Mandatory=$false, + HelpMessage="Profile build execution time and generates a report in the /reports/profile directory.")] + [switch] + $profile = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Specify the project-specific cache directory. Defaults to .gradle in the root project directory.")] + [string] + $projectCacheDir = ".gradle", + + [Parameter( + Mandatory=$false, + HelpMessage="Log errors only.")] + [switch] + $quiet = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Refresh the state of dependencies.")] + [switch] + $refreshDependencies = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Refresh the public keys used for dependency verification.")] + [switch] + $refreshKeys = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Ignore previously cached task results.")] + [switch] + $rerunTasks = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Print out the full (very verbose) stacktrace for all exceptions.")] + [switch] + $fullStacktrace = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Print out the stacktrace for all exceptions.")] + [switch] + $stacktrace = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Creates a build scan. Gradle will emit a warning if the build scan plugin has not been applied. (https://gradle.com/build-scans)")] + [switch] + $scan = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Shows status of running and recently stopped Gradle Daemon(s).")] + [switch] + $status = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Stops the Gradle Daemon if it is running.")] + [switch] + $stop = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Enables continuous build. Gradle does not exit and will re-execute tasks when task file inputs change.")] + [switch] + $continuous = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Print version info.")] + [switch] + $version = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Set log level to warn.")] + [switch] + $warn = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Specifies which mode of warnings to generate. Values are 'all', 'fail', 'summary'(default) or 'none'")] + [string] + $warningMode = "summary", + + [Parameter( + Mandatory=$false, + HelpMessage=@" +Enables watching the file system for changes, allowing data about the file system to be re-used for the next build. +"@)] + [switch] + $watchFilesystem = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Persists dependency resolution for locked configurations, ignoring existing locking information if it exists")] + [switch] + $writeLocks = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Specify a task to be excluded from execution.")] + [string[]] + $excludeTask = "" ) Write-Debug "select $gradlewFileName starting in $workingDir" @@ -114,14 +395,17 @@ The folder location where generated Gradle Wrapper(default: 'Your current workin $dir = if (-not (Test-Path -Path $destinationDir -PathType Container)) { New-Item -ItemType Directory -Force -Path (Join-Path $dir 'gradle/wrapper') } else { $destinationDir } - Write-Information "Installing Gradle Wrapper in ${dir}. (version=${version}, distributionType=${distributionType}, mirrorUrl=${mirrorUrl})" + Write-Information @" +Installing Gradle Wrapper in ${dir}. (version=${version}, distributionType=${distributionType}, mirrorUrl=${mirrorUrl}) +"@ #Copy the embedded Gradle Wrapper $srcDir = $PSScriptRoot - Copy-Item -LiteralPath (Join-Path $srcDir 'gng.cfg') -Destination (Join-Path $dir 'gradle') - Copy-Item -LiteralPath (Join-Path $srcDir 'gradlew') -Destination $dir - Copy-Item -LiteralPath (Join-Path $srcDir 'gradlew.bat') -Destination $dir - Copy-Item -LiteralPath (Join-Path $srcDir 'wrapper/gradle-wrapper.jar') -Destination (Join-Path $dir 'gradle/wrapper') + Copy-Item -LiteralPath (Join-Path $srcDir 'gng.cfg') -Destination (Join-Path $dir 'gradle') -Force + Copy-Item -LiteralPath (Join-Path $srcDir 'gradlew') -Destination $dir -Force + Copy-Item -LiteralPath (Join-Path $srcDir 'gradlew.bat') -Destination $dir -Force + Copy-Item -LiteralPath (Join-Path $srcDir 'wrapper/gradle-wrapper.jar') ` + -Destination (Join-Path $dir 'gradle/wrapper') -Force $distributionUrl = $mirrorUrl -replace '[#\!=:]','\$0' $distributionUrl = Join-Path $distributionUrl "gradle-${version}-${type}.zip" @@ -132,7 +416,7 @@ distributionPath=wrapper/dists distributionUrl=${distributionUrl} zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -"@ | Out-File -FilePath (Join-Path $dir 'gradle/wrapper/gradle-wrapper.properties') +"@ | Out-File -FilePath (Join-Path $dir 'gradle/wrapper/gradle-wrapper.properties') -Force } @@ -163,7 +447,7 @@ port HelpMessage=@" provide the keystore password "@)] - [string] + [SecureString] $password ) $keytoolPath = (Get-Command keytool).Source diff --git a/bin/install-gng-powershell.ps1 b/bin/install-gng-powershell.ps1 index 10a5646..11c1e01 100644 --- a/bin/install-gng-powershell.ps1 +++ b/bin/install-gng-powershell.ps1 @@ -15,13 +15,13 @@ if (-Not (Test-Path -Path $script:mmPath)) { New-Item -Path $script:mmPath -ItemType Directory } -Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath 'gng.psm1') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') +Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath 'gng.psm1') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Force $gradleDir = Join-Path -Path $PSScriptRoot -ChildPath '../gradle' -Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'wrapper') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gng.json') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew.bat') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'wrapper') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Force +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gng.json') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Force +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Force +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew.bat') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Force Get-Module -ListAvailable gng | Format-List name, path -Import-Module -Verbose gng +Import-Module -Verbose gng -Force diff --git a/docs/index-powershell.asciidoc b/docs/index-powershell.asciidoc index 3ce4dc3..f39f319 100644 --- a/docs/index-powershell.asciidoc +++ b/docs/index-powershell.asciidoc @@ -18,7 +18,7 @@ The PowerShell version of GNG is implemented as a PowerShell Module. ---- git clone https://github.com/babeloff/gng.git cd gng -./bin/install.ps1 +./bin/install-gng-powershell.ps1 ---- After the Gradle Module has been installed into it can be used to initialize a gradle project. From e06a14b58a5b269c5a27e723091634ecfd968dec Mon Sep 17 00:00:00 2001 From: Fred Eisele Date: Tue, 28 Sep 2021 10:07:09 -0500 Subject: [PATCH 07/12] add some comments --- bin/gng.psm1 | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/bin/gng.psm1 b/bin/gng.psm1 index 8a1dc54..50d7353 100644 --- a/bin/gng.psm1 +++ b/bin/gng.psm1 @@ -7,7 +7,13 @@ $script:psprovidername = "Microsoft-Windows-PowerShell" $script:gradlewFileName = "gradlew.bat" -# Search recursively upwards for the file. +<# +This is the primary GNG function. +It performs an upward search for the gradlew.bat file and runs that. +It is mostly just a wrapper for gradlew but it adds a few parameters. +It does not include the incubating or deprecated paramters. +It allows for either the current directory or the gradlew.bat directory. + #> function Invoke-Gradle { param( [Parameter( @@ -39,12 +45,6 @@ The working directory, defaults to current directory. [switch] $buildCache = $false, - [Parameter( - Mandatory=$false, - HelpMessage="Do not rebuild project dependencies.")] - [switch] - $noRebuild = $false, - [Parameter( Mandatory=$false, HelpMessage="Specifies which type of console output to generate. Values are 'plain', 'auto' (default), 'rich' or 'verbose'.")] @@ -348,6 +348,11 @@ Enables watching the file system for changes, allowing data about the file syste Start-Process @procOptions } +<# +The wrapper does not make use of the gradle wrapper task. +Instead it replicates the behavior of that script. +This is because GNG has some configuration properties to install in the project as well. + #> function Install-GradleWrapper { Param( [Parameter( From b1a53b375e903a90906282b236cdeedec3905e58 Mon Sep 17 00:00:00 2001 From: Fred Eisele Date: Tue, 28 Sep 2021 10:49:46 -0500 Subject: [PATCH 08/12] added the gradle parameters --- bin/gng.psm1 | 147 +++++++++++++++++---------------- bin/install-gng-powershell.ps1 | 18 ++-- 2 files changed, 87 insertions(+), 78 deletions(-) diff --git a/bin/gng.psm1 b/bin/gng.psm1 index 50d7353..89cc1d4 100644 --- a/bin/gng.psm1 +++ b/bin/gng.psm1 @@ -23,7 +23,7 @@ The gradle task to run preceed it with a ':'. By default runs the ':tasks' task. "@)] [string[]] - $task = ':tasks', + $Task = ':tasks', [Parameter( Mandatory=$false, @@ -31,61 +31,85 @@ By default runs the ':tasks' task. The working directory, defaults to current directory. "@)] [string] - $workingDir = (Get-Location), + $WorkingDir = (Get-Location), [Parameter( Mandatory=$false, HelpMessage="Do not rebuild project dependencies.")] [switch] - $noRebuild = $false, + $NoRebuild = $false, [Parameter( Mandatory=$false, HelpMessage="Enables the Gradle build cache. Gradle will try to reuse outputs from previous builds.")] [switch] - $buildCache = $false, + $BuildCache = $false, [Parameter( Mandatory=$false, - HelpMessage="Specifies which type of console output to generate. Values are 'plain', 'auto' (default), 'rich' or 'verbose'.")] + HelpMessage=@" +Specifies which type of console output to generate. default: 'auto'. +"@)] + [ValidateNotNullOrEmpty()] + [ValidateSet('plain','auto','rich','verbose')] [string] - $console = "auto", + $Console = "auto", [Parameter( Mandatory=$false, HelpMessage="Continue task execution after a task failure.")] [switch] - $continue = $false, + $Continue = $false, [Parameter( Mandatory=$false, HelpMessage="Set system property of the JVM (e.g. -Dmyprop=myvalue).")] [string[]] - $systemProp = $false, + $SystemProp = $false, [Parameter( Mandatory=$false, HelpMessage="Log in debug mode (includes normal stacktrace).")] [switch] - $debug = $false, + $GradleDebug = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Set log level to warn.")] + [switch] + $GradleWarn = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Set log level to info.")] + [switch] + $GradleInfo = $false, + + [Parameter( + Mandatory=$false, + HelpMessage="Log errors only.")] + [switch] + $GradleError = $true, [Parameter( Mandatory=$false, HelpMessage="Uses the Gradle Daemon to run the build. Starts the Daemon if not running.")] [switch] - $daemon = $false, + $Daemon = $false, [Parameter( Mandatory=$false, - HelpMessage="Configures the dependency verification mode (strict, lenient or off)")] + HelpMessage="Configures the dependency verification mode, default: 'off'")] + [ValidateNotNullOrEmpty()] + [ValidateSet('strict','lenient','off')] [string] - $dependencyVerification = $false, + $DependencyVerification = 'off', [Parameter( Mandatory=$false, HelpMessage="Starts the Gradle Daemon in the foreground.")] [switch] - $foreground = $false, + $Foreground = $false, [Parameter( Mandatory=$false, @@ -97,43 +121,37 @@ The working directory, defaults to current directory. Mandatory=$false, HelpMessage="Specify an initialization script.")] [switch] - $initScript = $false, - - [Parameter( - Mandatory=$false, - HelpMessage="Set log level to info.")] - [switch] - $info = $false, + $InitScript = $false, [Parameter( Mandatory=$false, HelpMessage="Include the specified build in the composite.")] [switch] - $includeBuild = $false, + $IncludeBuild = $false, [Parameter( Mandatory=$false, HelpMessage="Generates checksums for dependencies used in the project (comma-separated list).")] [switch] - $writeVerificationMetadata = $false, + $WriteVerificationMetadata = $false, [Parameter( Mandatory=$false, HelpMessage="Run the builds with all task actions disabled.")] [switch] - $dryRun = $false, + $DryRun = $false, [Parameter( Mandatory=$false, HelpMessage="Configure the number of concurrent workers Gradle is allowed to use.")] [Int32] - $maxWorkers = 3, + $MaxWorkers = 3, [Parameter( Mandatory=$false, HelpMessage="Disables the Gradle build cache.")] [switch] - $noBuildCache = $false, + $NoBuildCache = $false, [Parameter( Mandatory=$false, @@ -142,13 +160,13 @@ Do not use the Gradle daemon to run the build. Useful occasionally if you have configured Gradle to always run with the daemon by default. "@)] [switch] - $noDaemon = $false, + $NoDaemon = $false, [Parameter( Mandatory=$false, HelpMessage="Disables parallel execution to build projects.")] [switch] - $noParallel = $false, + $NoParallel = $false, [Parameter( Mandatory=$false, @@ -157,136 +175,127 @@ Disables the creation of a build scan. For more information about build scans, please visit https://gradle.com/build-scans. "@)] [switch] - $noScan = $false, + $NoScan = $false, [Parameter( Mandatory=$false, HelpMessage="Disables watching the file system.")] [switch] - $noWatchFs = $false, + $NoWatchFs = $false, [Parameter( Mandatory=$false, HelpMessage="Execute the build without accessing network resources.")] [switch] - $offline = $false, + $Offline = $false, [Parameter( Mandatory=$false, HelpMessage="Set project property for the build script (e.g. -Pmyprop=myvalue).")] [string[]] - $projectProp = "", + $ProjectProp = "", [Parameter( Mandatory=$false, HelpMessage="Specifies the start directory for Gradle. Defaults to current directory.")] [string] - $projectDir = (Get-Location), + $ProjectDir = (Get-Location), [Parameter( Mandatory=$false, HelpMessage="Build projects in parallel. Gradle will attempt to determine the optimal number of executor threads to use.")] [switch] - $parallel = $false, + $Parallel = $false, [Parameter( Mandatory=$false, HelpMessage=@" -Specifies the scheduling priority for the Gradle daemon and all processes launched by it. -Values are 'normal' (default) or 'low' +Specifies the scheduling priority for the Gradle daemon and all processes launched by it. default: 'normal' "@)] - [switch] - $priority = "normal", + [ValidateNotNullOrEmpty()] + [ValidateSet('normal','low')] + [string] + $Priority = "normal", [Parameter( Mandatory=$false, HelpMessage="Profile build execution time and generates a report in the /reports/profile directory.")] [switch] - $profile = $false, + $Profile = $false, [Parameter( Mandatory=$false, HelpMessage="Specify the project-specific cache directory. Defaults to .gradle in the root project directory.")] [string] - $projectCacheDir = ".gradle", - - [Parameter( - Mandatory=$false, - HelpMessage="Log errors only.")] - [switch] - $quiet = $false, + $ProjectCacheDir = ".gradle", [Parameter( Mandatory=$false, HelpMessage="Refresh the state of dependencies.")] [switch] - $refreshDependencies = $false, + $RefreshDependencies = $false, [Parameter( Mandatory=$false, HelpMessage="Refresh the public keys used for dependency verification.")] [switch] - $refreshKeys = $false, + $RefreshKeys = $false, [Parameter( Mandatory=$false, HelpMessage="Ignore previously cached task results.")] [switch] - $rerunTasks = $false, + $RerunTasks = $false, [Parameter( Mandatory=$false, HelpMessage="Print out the full (very verbose) stacktrace for all exceptions.")] [switch] - $fullStacktrace = $false, + $FullStacktrace = $false, [Parameter( Mandatory=$false, HelpMessage="Print out the stacktrace for all exceptions.")] [switch] - $stacktrace = $false, + $Stacktrace = $false, [Parameter( Mandatory=$false, HelpMessage="Creates a build scan. Gradle will emit a warning if the build scan plugin has not been applied. (https://gradle.com/build-scans)")] [switch] - $scan = $false, + $Scan = $false, [Parameter( Mandatory=$false, HelpMessage="Shows status of running and recently stopped Gradle Daemon(s).")] [switch] - $status = $false, + $Status = $false, [Parameter( Mandatory=$false, HelpMessage="Stops the Gradle Daemon if it is running.")] [switch] - $stop = $false, + $Stop = $false, [Parameter( Mandatory=$false, HelpMessage="Enables continuous build. Gradle does not exit and will re-execute tasks when task file inputs change.")] [switch] - $continuous = $false, + $Continuous = $false, [Parameter( Mandatory=$false, HelpMessage="Print version info.")] [switch] - $version = $false, - - [Parameter( - Mandatory=$false, - HelpMessage="Set log level to warn.")] - [switch] - $warn = $false, + $Version = $false, [Parameter( Mandatory=$false, - HelpMessage="Specifies which mode of warnings to generate. Values are 'all', 'fail', 'summary'(default) or 'none'")] + HelpMessage="Specifies which mode of warnings to generate. default 'summary'")] + [ValidateNotNullOrEmpty()] + [ValidateSet('all','fail','summary','none')] [string] - $warningMode = "summary", + $WarningMode = "summary", [Parameter( Mandatory=$false, @@ -294,23 +303,23 @@ Values are 'normal' (default) or 'low' Enables watching the file system for changes, allowing data about the file system to be re-used for the next build. "@)] [switch] - $watchFilesystem = $false, + $Watch = $false, [Parameter( Mandatory=$false, HelpMessage="Persists dependency resolution for locked configurations, ignoring existing locking information if it exists")] [switch] - $writeLocks = $false, + $WriteLocks = $false, [Parameter( Mandatory=$false, HelpMessage="Specify a task to be excluded from execution.")] [string[]] - $excludeTask = "" + $ExcludeTask = "" ) - Write-Debug "select $gradlewFileName starting in $workingDir" - $path = if (-Not (Test-Path -Path $workingDir)) { Get-Location } else { $workingDir } + Write-Debug "select $gradlewFileName starting in $WorkingDir" + $path = if (-Not (Test-Path -Path $WorkingDir)) { Get-Location } else { $WorkingDir } $fileName = $script:gradlewFileName # https://stackoverflow.com/questions/45642517/search-directory-for-a-file-iterating-up-parent-directories-if-not-found while($path -and (-Not (Test-Path (Join-Path $path $fileName)))) { @@ -338,7 +347,7 @@ Enables watching the file system for changes, allowing data about the file syste $procOptions = @{ FilePath = $gradlewPath WorkingDirectory = $gradlewDir - ArgumentList = $task + ArgumentList = $Task Wait = $True PassThru = $True NoNewWindow = $True diff --git a/bin/install-gng-powershell.ps1 b/bin/install-gng-powershell.ps1 index 11c1e01..ab65ae0 100644 --- a/bin/install-gng-powershell.ps1 +++ b/bin/install-gng-powershell.ps1 @@ -10,17 +10,17 @@ Which level of the Powershell modules folders is the target for this module? ) $script:mm = ($ENV:PSModulePath -split ';')[$level] -$script:mmPath = Join-Path -Path $script:mm -ChildPath 'gng' -if (-Not (Test-Path -Path $script:mmPath)) { - New-Item -Path $script:mmPath -ItemType Directory +$script:moduleTarget = Join-Path -Path $script:mm -ChildPath 'gng' +if (-Not (Test-Path -Path $script:moduleTarget)) { + New-Item -Path $script:moduleTarget -ItemType Directory } - -Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath 'gng.psm1') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Force +Write-Debug "Module paths: source = $PSScriptRoot, target = $script:moduleTarget" +Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath 'gng.psm1') -Destination $script:moduleTarget -Force $gradleDir = Join-Path -Path $PSScriptRoot -ChildPath '../gradle' -Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'wrapper') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Force -Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gng.json') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Force -Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Force -Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew.bat') -Destination (Join-Path -Path $script:mm -ChildPath 'gng') -Force +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'wrapper') -Destination $script:moduleTarget -Force +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gng.json') -Destination $script:moduleTarget -Force +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew') -Destination $script:moduleTarget -Force +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew.bat') -Destination $script:moduleTarget -Force Get-Module -ListAvailable gng | Format-List name, path Import-Module -Verbose gng -Force From 7b0d94dddce7f5bd57cf52db4b7039b2bb428309 Mon Sep 17 00:00:00 2001 From: Fred Eisele Date: Tue, 28 Sep 2021 11:07:17 -0500 Subject: [PATCH 09/12] act on the gradle switch parameters --- bin/gng.psm1 | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/bin/gng.psm1 b/bin/gng.psm1 index 89cc1d4..9d78f71 100644 --- a/bin/gng.psm1 +++ b/bin/gng.psm1 @@ -89,7 +89,7 @@ Specifies which type of console output to generate. default: 'auto'. Mandatory=$false, HelpMessage="Log errors only.")] [switch] - $GradleError = $true, + $GradleQuiet = $false, [Parameter( Mandatory=$false, @@ -120,14 +120,14 @@ Specifies which type of console output to generate. default: 'auto'. [Parameter( Mandatory=$false, HelpMessage="Specify an initialization script.")] - [switch] - $InitScript = $false, + [string] + $InitScript, [Parameter( Mandatory=$false, HelpMessage="Include the specified build in the composite.")] - [switch] - $IncludeBuild = $false, + [string] + $IncludeBuild, [Parameter( Mandatory=$false, @@ -343,11 +343,44 @@ Enables watching the file system for changes, allowing data about the file syste } else { ConvertFrom-Json '' } + $argList = $Task + if ($NoRebuild) { $argList += '--no-rebuild' } + if ($BuildCache) { $argList += '--build-cache' } + if ($Continue) { $argList += '--continue' } + if ($GradleDebug) { $argList += '--debug' } + if ($GradleWarn) { $argList += '--warn' } + if ($GradleInfo) { $argList += '--info' } + if ($GradleQuiet) { $argList += '--quiet' } + if ($Daemon) { $argList += '--daemon' } + if ($Foreground) { $argList += '--foreground' } + if ($WriteVerificationMetadata) { $argList += '--write-verification-metadata' } + if ($DryRun) { $argList += '--dry-run' } + if ($NoBuildCache) { $argList += '--no-build-cache' } + if ($NoDaemon) { $argList += '--no-daemon' } + if ($NoParallel) { $argList += '--no-parallel' } + if ($NoScan) { $argList += '--no-scan' } + if ($NoWatchFs) { $argList += '--no-watch-fs' } + if ($Offline) { $argList += '--offline' } + if ($Parallel) { $argList += '--parallel' } + if ($Profile) { $argList += '--profile' } + if ($RefreshDependencies) { $argList += '--refresh-dependencies' } + if ($RefreshKeys) { $argList += '--refresh-keys' } + if ($RerunTasks) { $argList += '--rerun-tasks' } + if ($FullStacktrace) { $argList += '--full-stacktrace' } + if ($Stacktrace) { $argList += '--stacktrace' } + if ($Scan) { $argList += '--scan' } + if ($Status) { $argList += '--status' } + if ($Stop) { $argList += '--stop' } + if ($Continuous) { $argList += '--continuous' } + if ($Version) { $argList += '--version' } + if ($Watch) { $argList += '--watch-fs' } + if ($WriteLocks) { $argList += '--write-locks' } + Write-Debug "gradlew configuration '${jsonConf}'" $procOptions = @{ FilePath = $gradlewPath WorkingDirectory = $gradlewDir - ArgumentList = $Task + ArgumentList = $argList Wait = $True PassThru = $True NoNewWindow = $True From 5a67220fd2e4541688f86a6f6455ab5dfc4480a6 Mon Sep 17 00:00:00 2001 From: Fred Eisele Date: Tue, 28 Sep 2021 12:01:18 -0500 Subject: [PATCH 10/12] act on remaining gradle parameters --- bin/gng.psm1 | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/bin/gng.psm1 b/bin/gng.psm1 index 9d78f71..5f8700c 100644 --- a/bin/gng.psm1 +++ b/bin/gng.psm1 @@ -23,7 +23,7 @@ The gradle task to run preceed it with a ':'. By default runs the ':tasks' task. "@)] [string[]] - $Task = ':tasks', + $Tasks = ':tasks', [Parameter( Mandatory=$false, @@ -64,8 +64,8 @@ Specifies which type of console output to generate. default: 'auto'. [Parameter( Mandatory=$false, HelpMessage="Set system property of the JVM (e.g. -Dmyprop=myvalue).")] - [string[]] - $SystemProp = $false, + [string] + $SystemProp, [Parameter( Mandatory=$false, @@ -115,7 +115,7 @@ Specifies which type of console output to generate. default: 'auto'. Mandatory=$false, HelpMessage="Specifies the gradle user home directory.")] [string] - $gradleUserHome = $false, + $GradleUserHome, [Parameter( Mandatory=$false, @@ -192,7 +192,7 @@ For more information about build scans, please visit https://gradle.com/build-sc [Parameter( Mandatory=$false, HelpMessage="Set project property for the build script (e.g. -Pmyprop=myvalue).")] - [string[]] + [string] $ProjectProp = "", [Parameter( @@ -311,11 +311,12 @@ Enables watching the file system for changes, allowing data about the file syste [switch] $WriteLocks = $false, + [Alias('x')] [Parameter( Mandatory=$false, HelpMessage="Specify a task to be excluded from execution.")] [string[]] - $ExcludeTask = "" + $ExcludeTask ) Write-Debug "select $gradlewFileName starting in $WorkingDir" @@ -343,7 +344,8 @@ Enables watching the file system for changes, allowing data about the file syste } else { ConvertFrom-Json '' } - $argList = $Task + $argList = @() + if ($NoRebuild) { $argList += '--no-rebuild' } if ($BuildCache) { $argList += '--build-cache' } if ($Continue) { $argList += '--continue' } @@ -376,6 +378,25 @@ Enables watching the file system for changes, allowing data about the file syste if ($Watch) { $argList += '--watch-fs' } if ($WriteLocks) { $argList += '--write-locks' } + if ($SystemProp.Length -gt 0) { $argList += @('--system-prop', $SystemProp) } + if ($ProjectProp.Length -gt 0) { $argList += @('--project-prop', $ProjectProp) } + if ($GradleUserHome.Length -gt 0) { $argList += @('--gradle-user-home', $GradleUserHome) } + if ($ProjectDir.Length -gt 0) { $argList += @('--project-dir', $ProjectDir) } + if ($ProjectCacheDir.Length -gt 0) { $argList += @('--project-cache-dir', $ProjectCacheDir) } + + if ($Console -ne 'auto') { $argList += @('--console', $Console) } + if ($DependencyVerification -ne 'off') { $argList += @('--dependency-verification', $DependencyVerification) } + if ($Priority -ne 'normal') { $argList += @('--priority', $Priority) } + if ($WarningMode -ne 'summary') { $argList += @('--warning-mode', $WarningMode) } + + $argList += @('--max-workers', $MaxWorkers) + + Foreach ($xtask in $ExcludeTask) { + $argList += @('--exclude-task') + $xtask + } + + $argList += $Tasks + Write-Debug "gradlew argument list '${argList}'" Write-Debug "gradlew configuration '${jsonConf}'" $procOptions = @{ FilePath = $gradlewPath @@ -386,7 +407,7 @@ Enables watching the file system for changes, allowing data about the file syste NoNewWindow = $True } [string[]] $procOptionString = $procOptions.GetEnumerator().ForEach({ "$($_.Name)=$($_.Value)" }) - Write-Debug "gradlew command '$procOptionString'" + Write-Debug "start-process '$procOptionString'" Start-Process @procOptions } From 4f72331230dda97f1d678ef8e3f8773aad1fe44f Mon Sep 17 00:00:00 2001 From: Fred Eisele Date: Thu, 7 Oct 2021 13:30:20 -0500 Subject: [PATCH 11/12] publication content --- bin/GradleWrapperModule.psd1 | 132 ++++++++ bin/{gng.psm1 => GradleWrapperModule.psm1} | 302 +++++++++++------- ...-powershell.ps1 => install-powershell.ps1} | 11 +- docs/index-powershell.asciidoc | 20 +- 4 files changed, 343 insertions(+), 122 deletions(-) create mode 100644 bin/GradleWrapperModule.psd1 rename bin/{gng.psm1 => GradleWrapperModule.psm1} (70%) rename bin/{install-gng-powershell.ps1 => install-powershell.ps1} (64%) diff --git a/bin/GradleWrapperModule.psd1 b/bin/GradleWrapperModule.psd1 new file mode 100644 index 0000000..9a01271 --- /dev/null +++ b/bin/GradleWrapperModule.psd1 @@ -0,0 +1,132 @@ +# +# Module manifest for module 'GradleWrapperModule' +# +# Generated by: eiselef +# +# Generated on: 10/7/2021 +# + +@{ + +# Script module or binary module file associated with this manifest. +# RootModule = '' + +# Version number of this module. +ModuleVersion = '0.0.1' + +# Supported PSEditions +# CompatiblePSEditions = @() + +# ID used to uniquely identify this module +GUID = 'dd7d4915-d62a-47df-aa28-16325dbefe28' + +# Author of this module +Author = 'eiselef' + +# Company or vendor of this module +CompanyName = 'Unknown' + +# Copyright statement for this module +Copyright = '(c) fredrick.eisele@gmail.com. All rights reserved.' + +# Description of the functionality provided by this module +Description = 'This is provides a streamlined version of the gradle wrapper.' + +# Minimum version of the PowerShell engine required by this module +# PowerShellVersion = '' + +# Name of the PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# DotNetFrameworkVersion = '' + +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# ClrVersion = '' + +# Processor architecture (None, X86, Amd64) required by this module +# ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +# RequiredModules = @() + +# Assemblies that must be loaded prior to importing this module +# RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module. +# ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +# TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +# FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = @("Invoke-Gradle","Install-GradleWrapper") + +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +CmdletsToExport = @() + +# Variables to export from this module +VariablesToExport = '*' + +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +AliasesToExport = @("gw","gng") + +# DSC resources to export from this module +# DscResourcesToExport = @() + +# List of all modules packaged with this module +# ModuleList = @() + +# List of all files packaged with this module +# FileList = @() + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + # Tags = @() + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + # ProjectUri = '' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + # Prerelease string of this module + # Prerelease = '' + + # Flag to indicate whether the module requires explicit user acceptance for install/update/save + # RequireLicenseAcceptance = $false + + # External dependent modules of this module + # ExternalModuleDependencies = @() + + } # End of PSData hashtable + +} # End of PrivateData hashtable + +# HelpInfo URI of this module +# HelpInfoURI = '' + +# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. +# DefaultCommandPrefix = '' + +} + diff --git a/bin/gng.psm1 b/bin/GradleWrapperModule.psm1 similarity index 70% rename from bin/gng.psm1 rename to bin/GradleWrapperModule.psm1 index 5f8700c..904d3c1 100644 --- a/bin/gng.psm1 +++ b/bin/GradleWrapperModule.psm1 @@ -5,15 +5,20 @@ #> $script:psprovidername = "Microsoft-Windows-PowerShell" -$script:gradlewFileName = "gradlew.bat" +$script:baseGradlewFileName = "gradlew" <# -This is the primary GNG function. -It performs an upward search for the gradlew.bat file and runs that. +.SYNOPSIS + It is mostly just a wrapper for gradlew but it adds a few parameters. + +.DESCRIPTION + +This is the primary GNG function. +It performs an upward search for the $script:baseGradlewFileName and runs that. It does not include the incubating or deprecated paramters. -It allows for either the current directory or the gradlew.bat directory. - #> +It allows for either the current directory or the $script:baseGradlewFileName directory. +#> function Invoke-Gradle { param( [Parameter( @@ -24,7 +29,7 @@ By default runs the ':tasks' task. "@)] [string[]] $Tasks = ':tasks', - + # [Parameter( Mandatory=$false, HelpMessage=@" @@ -32,19 +37,28 @@ The working directory, defaults to current directory. "@)] [string] $WorkingDir = (Get-Location), - + # + [Alias('w')] + [Parameter( + Mandatory=$false, + HelpMessage=@" +Use the working directory, defaults to false, i.e. use the gradlew-directory. +"@)] + [switch] + $UseWorkingDirectory = $false, + # [Parameter( Mandatory=$false, HelpMessage="Do not rebuild project dependencies.")] [switch] $NoRebuild = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Enables the Gradle build cache. Gradle will try to reuse outputs from previous builds.")] [switch] $BuildCache = $false, - + # [Parameter( Mandatory=$false, HelpMessage=@" @@ -54,49 +68,49 @@ Specifies which type of console output to generate. default: 'auto'. [ValidateSet('plain','auto','rich','verbose')] [string] $Console = "auto", - + # [Parameter( Mandatory=$false, HelpMessage="Continue task execution after a task failure.")] [switch] $Continue = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Set system property of the JVM (e.g. -Dmyprop=myvalue).")] [string] $SystemProp, - + # [Parameter( Mandatory=$false, HelpMessage="Log in debug mode (includes normal stacktrace).")] [switch] $GradleDebug = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Set log level to warn.")] [switch] $GradleWarn = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Set log level to info.")] [switch] $GradleInfo = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Log errors only.")] [switch] $GradleQuiet = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Uses the Gradle Daemon to run the build. Starts the Daemon if not running.")] [switch] $Daemon = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Configures the dependency verification mode, default: 'off'")] @@ -104,55 +118,55 @@ Specifies which type of console output to generate. default: 'auto'. [ValidateSet('strict','lenient','off')] [string] $DependencyVerification = 'off', - + # [Parameter( Mandatory=$false, HelpMessage="Starts the Gradle Daemon in the foreground.")] [switch] $Foreground = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Specifies the gradle user home directory.")] [string] $GradleUserHome, - + # [Parameter( Mandatory=$false, HelpMessage="Specify an initialization script.")] [string] $InitScript, - + # [Parameter( Mandatory=$false, HelpMessage="Include the specified build in the composite.")] [string] $IncludeBuild, - + # [Parameter( Mandatory=$false, HelpMessage="Generates checksums for dependencies used in the project (comma-separated list).")] [switch] $WriteVerificationMetadata = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Run the builds with all task actions disabled.")] [switch] $DryRun = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Configure the number of concurrent workers Gradle is allowed to use.")] [Int32] $MaxWorkers = 3, - + # [Parameter( Mandatory=$false, HelpMessage="Disables the Gradle build cache.")] [switch] $NoBuildCache = $false, - + # [Parameter( Mandatory=$false, HelpMessage=@" @@ -161,13 +175,13 @@ Useful occasionally if you have configured Gradle to always run with the daemon "@)] [switch] $NoDaemon = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Disables parallel execution to build projects.")] [switch] $NoParallel = $false, - + # [Parameter( Mandatory=$false, HelpMessage=@" @@ -176,37 +190,37 @@ For more information about build scans, please visit https://gradle.com/build-sc "@)] [switch] $NoScan = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Disables watching the file system.")] [switch] $NoWatchFs = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Execute the build without accessing network resources.")] [switch] $Offline = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Set project property for the build script (e.g. -Pmyprop=myvalue).")] [string] $ProjectProp = "", - + # [Parameter( Mandatory=$false, HelpMessage="Specifies the start directory for Gradle. Defaults to current directory.")] [string] $ProjectDir = (Get-Location), - + # [Parameter( Mandatory=$false, HelpMessage="Build projects in parallel. Gradle will attempt to determine the optimal number of executor threads to use.")] [switch] $Parallel = $false, - + # [Parameter( Mandatory=$false, HelpMessage=@" @@ -216,79 +230,79 @@ Specifies the scheduling priority for the Gradle daemon and all processes launch [ValidateSet('normal','low')] [string] $Priority = "normal", - + # [Parameter( Mandatory=$false, HelpMessage="Profile build execution time and generates a report in the /reports/profile directory.")] [switch] $Profile = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Specify the project-specific cache directory. Defaults to .gradle in the root project directory.")] [string] $ProjectCacheDir = ".gradle", - + # [Parameter( Mandatory=$false, HelpMessage="Refresh the state of dependencies.")] [switch] $RefreshDependencies = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Refresh the public keys used for dependency verification.")] [switch] $RefreshKeys = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Ignore previously cached task results.")] [switch] $RerunTasks = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Print out the full (very verbose) stacktrace for all exceptions.")] [switch] $FullStacktrace = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Print out the stacktrace for all exceptions.")] [switch] $Stacktrace = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Creates a build scan. Gradle will emit a warning if the build scan plugin has not been applied. (https://gradle.com/build-scans)")] [switch] $Scan = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Shows status of running and recently stopped Gradle Daemon(s).")] [switch] $Status = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Stops the Gradle Daemon if it is running.")] [switch] $Stop = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Enables continuous build. Gradle does not exit and will re-execute tasks when task file inputs change.")] [switch] $Continuous = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Print version info.")] [switch] $Version = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Specifies which mode of warnings to generate. default 'summary'")] @@ -296,7 +310,7 @@ Specifies the scheduling priority for the Gradle daemon and all processes launch [ValidateSet('all','fail','summary','none')] [string] $WarningMode = "summary", - + # [Parameter( Mandatory=$false, HelpMessage=@" @@ -304,33 +318,33 @@ Enables watching the file system for changes, allowing data about the file syste "@)] [switch] $Watch = $false, - + # [Parameter( Mandatory=$false, HelpMessage="Persists dependency resolution for locked configurations, ignoring existing locking information if it exists")] [switch] $WriteLocks = $false, - + # [Alias('x')] [Parameter( Mandatory=$false, - HelpMessage="Specify a task to be excluded from execution.")] + HelpMessage="Specify tasks to be excluded from execution.")] [string[]] $ExcludeTask ) - Write-Debug "select $gradlewFileName starting in $WorkingDir" + Write-Debug "select $baseGradlewFileName starting in $WorkingDir" $path = if (-Not (Test-Path -Path $WorkingDir)) { Get-Location } else { $WorkingDir } - $fileName = $script:gradlewFileName + $gradlewFileName = $script:baseGradlewFileName # https://stackoverflow.com/questions/45642517/search-directory-for-a-file-iterating-up-parent-directories-if-not-found - while($path -and (-Not (Test-Path (Join-Path $path $fileName)))) { - Write-Debug "candidate path $path $fileName" + while($path -and (-Not (Test-Path (Join-Path $path $gradlewFileName)))) { + Write-Debug "candidate path $path $gradlewFileName" if ($path -eq ((Split-Path $path -Qualifier)+"/")) { break } $path = Split-Path $path -Parent } - $gradlewPath = (Join-Path $path $fileName) + $gradlewPath = (Join-Path $path $gradlewFileName) if (-Not (Test-Path -Path $gradlewPath)) { Write-Error "No ${gradlew} set up for this project; Please use 'Install-Gradle'." @@ -344,78 +358,128 @@ Enables watching the file system for changes, allowing data about the file syste } else { ConvertFrom-Json '' } - $argList = @() - - if ($NoRebuild) { $argList += '--no-rebuild' } - if ($BuildCache) { $argList += '--build-cache' } - if ($Continue) { $argList += '--continue' } - if ($GradleDebug) { $argList += '--debug' } - if ($GradleWarn) { $argList += '--warn' } - if ($GradleInfo) { $argList += '--info' } - if ($GradleQuiet) { $argList += '--quiet' } - if ($Daemon) { $argList += '--daemon' } - if ($Foreground) { $argList += '--foreground' } - if ($WriteVerificationMetadata) { $argList += '--write-verification-metadata' } - if ($DryRun) { $argList += '--dry-run' } - if ($NoBuildCache) { $argList += '--no-build-cache' } - if ($NoDaemon) { $argList += '--no-daemon' } - if ($NoParallel) { $argList += '--no-parallel' } - if ($NoScan) { $argList += '--no-scan' } - if ($NoWatchFs) { $argList += '--no-watch-fs' } - if ($Offline) { $argList += '--offline' } - if ($Parallel) { $argList += '--parallel' } - if ($Profile) { $argList += '--profile' } - if ($RefreshDependencies) { $argList += '--refresh-dependencies' } - if ($RefreshKeys) { $argList += '--refresh-keys' } - if ($RerunTasks) { $argList += '--rerun-tasks' } - if ($FullStacktrace) { $argList += '--full-stacktrace' } - if ($Stacktrace) { $argList += '--stacktrace' } - if ($Scan) { $argList += '--scan' } - if ($Status) { $argList += '--status' } - if ($Stop) { $argList += '--stop' } - if ($Continuous) { $argList += '--continuous' } - if ($Version) { $argList += '--version' } - if ($Watch) { $argList += '--watch-fs' } - if ($WriteLocks) { $argList += '--write-locks' } - - if ($SystemProp.Length -gt 0) { $argList += @('--system-prop', $SystemProp) } - if ($ProjectProp.Length -gt 0) { $argList += @('--project-prop', $ProjectProp) } - if ($GradleUserHome.Length -gt 0) { $argList += @('--gradle-user-home', $GradleUserHome) } - if ($ProjectDir.Length -gt 0) { $argList += @('--project-dir', $ProjectDir) } - if ($ProjectCacheDir.Length -gt 0) { $argList += @('--project-cache-dir', $ProjectCacheDir) } - - if ($Console -ne 'auto') { $argList += @('--console', $Console) } - if ($DependencyVerification -ne 'off') { $argList += @('--dependency-verification', $DependencyVerification) } - if ($Priority -ne 'normal') { $argList += @('--priority', $Priority) } - if ($WarningMode -ne 'summary') { $argList += @('--warning-mode', $WarningMode) } - - $argList += @('--max-workers', $MaxWorkers) + $gradleArgList = @() + + if ($NoRebuild) { $gradleArgList += '--no-rebuild' } + if ($BuildCache) { $gradleArgList += '--build-cache' } + if ($Continue) { $gradleArgList += '--continue' } + if ($GradleDebug) { $gradleArgList += '--debug' } + if ($GradleWarn) { $gradleArgList += '--warn' } + if ($GradleInfo) { $gradleArgList += '--info' } + if ($GradleQuiet) { $gradleArgList += '--quiet' } + if ($Daemon) { $gradleArgList += '--daemon' } + if ($Foreground) { $gradleArgList += '--foreground' } + if ($WriteVerificationMetadata) { $gradleArgList += '--write-verification-metadata' } + if ($DryRun) { $gradleArgList += '--dry-run' } + if ($NoBuildCache) { $gradleArgList += '--no-build-cache' } + if ($NoDaemon) { $gradleArgList += '--no-daemon' } + if ($NoParallel) { $gradleArgList += '--no-parallel' } + if ($NoScan) { $gradleArgList += '--no-scan' } + if ($NoWatchFs) { $gradleArgList += '--no-watch-fs' } + if ($Offline) { $gradleArgList += '--offline' } + if ($Parallel) { $gradleArgList += '--parallel' } + if ($Profile) { $gradleArgList += '--profile' } + if ($RefreshDependencies) { $gradleArgList += '--refresh-dependencies' } + if ($RefreshKeys) { $gradleArgList += '--refresh-keys' } + if ($RerunTasks) { $gradleArgList += '--rerun-tasks' } + if ($FullStacktrace) { $gradleArgList += '--full-stacktrace' } + if ($Stacktrace) { $gradleArgList += '--stacktrace' } + if ($Scan) { $gradleArgList += '--scan' } + if ($Status) { $gradleArgList += '--status' } + if ($Stop) { $gradleArgList += '--stop' } + if ($Continuous) { $gradleArgList += '--continuous' } + if ($Version) { $gradleArgList += '--version' } + if ($Watch) { $gradleArgList += '--watch-fs' } + if ($WriteLocks) { $gradleArgList += '--write-locks' } + + if ($SystemProp.Length -gt 0) { $gradleArgList += @('--system-prop', $SystemProp) } + if ($ProjectProp.Length -gt 0) { $gradleArgList += @('--project-prop', $ProjectProp) } + if ($GradleUserHome.Length -gt 0) { $gradleArgList += @('--gradle-user-home', $GradleUserHome) } + if ($InitScript.Length -gt 0) { $gradleArgList += @('--init-script', $InitScript) } + if ($IncludeBuild.Length -gt 0) { $gradleArgList += @('--include-build', $IncludeBuild) } + if ($ProjectDir.Length -gt 0) { $gradleArgList += @('--project-dir', $ProjectDir) } + if ($ProjectCacheDir.Length -gt 0) { $gradleArgList += @('--project-cache-dir', $ProjectCacheDir) } + + if ($Console -ne 'auto') { $gradleArgList += @('--console', $Console) } + if ($DependencyVerification -ne 'off') { $gradleArgList += @('--dependency-verification', $DependencyVerification) } + if ($Priority -ne 'normal') { $gradleArgList += @('--priority', $Priority) } + if ($WarningMode -ne 'summary') { $gradleArgList += @('--warning-mode', $WarningMode) } + + $gradleArgList += @('--max-workers', $MaxWorkers) Foreach ($xtask in $ExcludeTask) { - $argList += @('--exclude-task') + $xtask + $gradleArgList += @('--exclude-task') + $xtask } - - $argList += $Tasks - Write-Debug "gradlew argument list '${argList}'" + $gradleArgList += $Tasks + Write-Debug "gradlew argument list '${gradleArgList}'" Write-Debug "gradlew configuration '${jsonConf}'" + + # We bypass the gradlew.bat and run the java program directly. + # The gradlew.bat script only does a few things. + $appBaseName = $gradlewFileName + $appHome = $gradlewDir + + # Add default JVM options here. + # You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. + $defaultJvmOpts = @("-Xmx64m","-Xms64m") + + if (Test-Path env:JAVA_HOME) { + $javaHome = env:JAVA_HOME.Replace('"','') + $javaExe = Join-Path -Path env:JAVA_HOME -ChildPath "bin/java.exe" + + if (-Not (Test-Path $javaExe)) { + Write-Error @" +JAVA_HOME is set to an invalid directory: $javaHome +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation. +"@ + } + } else { + $javaExe = Get-Command "java.exe" + if (-Not (Test-Path $javaExe)) { + Write-Error @" +JAVA_HOME is not set and no 'java' command could be found in your PATH. +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation. +"@ + } + $javaHome = Split-Path -Path (Split-Path -Path $javaExe -Parent) -Parent + } + $classPath = Join-Path -Path $appHome -ChildPath 'gradle/wrapper/gradle-wrapper.jar' + $javaArgList = @( + $defaultJvmOpts, $env:JAVA_OPTS, $env:GRADLE_OPTS, + "-Dorg.gradle.appname=$appBaseName", + '-classpath', $classPath, + 'org.gradle.wrapper.GradleWrapperMain' + ) + $workingDirectory = if ($UseWorkingDirectory) { $WorkingDir } else { $gradlewDir } + $procOptions = @{ - FilePath = $gradlewPath - WorkingDirectory = $gradlewDir - ArgumentList = $argList - Wait = $True - PassThru = $True - NoNewWindow = $True + FilePath = $javaExe + WorkingDirectory = $workingDirectory + ArgumentList = $javaArgList + $gradleArgList + Wait = $True + PassThru = $True + NoNewWindow = $True } [string[]] $procOptionString = $procOptions.GetEnumerator().ForEach({ "$($_.Name)=$($_.Value)" }) Write-Debug "start-process '$procOptionString'" - Start-Process @procOptions + + $rc = Start-Process @procOptions + if ($rc.ExitCode -eq 0) { + Write-Debug "gradlew task complete" + } else { + Write-Error "gradle task complete with error ${rc.ExitCode}" + } } <# +.SYNOPSIS + The wrapper does not make use of the gradle wrapper task. Instead it replicates the behavior of that script. This is because GNG has some configuration properties to install in the project as well. - #> +#> function Install-GradleWrapper { Param( [Parameter( @@ -489,9 +553,15 @@ zipStorePath=wrapper/dists } -# manage certificates -# use https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html +<# +.SYNOPSIS + +Manage certificates + +.LINK +https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html +#> function Get-GradleCert { Param( [Parameter( diff --git a/bin/install-gng-powershell.ps1 b/bin/install-powershell.ps1 similarity index 64% rename from bin/install-gng-powershell.ps1 rename to bin/install-powershell.ps1 index ab65ae0..92d8ecd 100644 --- a/bin/install-gng-powershell.ps1 +++ b/bin/install-powershell.ps1 @@ -8,20 +8,23 @@ Which level of the Powershell modules folders is the target for this module? [Int32] $level = 0 ) +$script:moduleTitle = 'GradleWrapperModule' $script:mm = ($ENV:PSModulePath -split ';')[$level] -$script:moduleTarget = Join-Path -Path $script:mm -ChildPath 'gng' +$script:moduleTarget = Join-Path -Path $script:mm -ChildPath $script:moduleTitle if (-Not (Test-Path -Path $script:moduleTarget)) { New-Item -Path $script:moduleTarget -ItemType Directory } Write-Debug "Module paths: source = $PSScriptRoot, target = $script:moduleTarget" -Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath 'gng.psm1') -Destination $script:moduleTarget -Force +Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath "${script:moduleTitle}.psm1") -Destination $script:moduleTarget -Force +Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath "${script:moduleTitle}.psd1") -Destination $script:moduleTarget -Force $gradleDir = Join-Path -Path $PSScriptRoot -ChildPath '../gradle' Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'wrapper') -Destination $script:moduleTarget -Force Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gng.json') -Destination $script:moduleTarget -Force Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew') -Destination $script:moduleTarget -Force Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew.bat') -Destination $script:moduleTarget -Force -Get-Module -ListAvailable gng | Format-List name, path -Import-Module -Verbose gng -Force +Get-Module -ListAvailable $script:moduleTitle | Format-List name, path +Import-Module -Verbose -Name $script:moduleTitle -Force + diff --git a/docs/index-powershell.asciidoc b/docs/index-powershell.asciidoc index f39f319..aff5f39 100644 --- a/docs/index-powershell.asciidoc +++ b/docs/index-powershell.asciidoc @@ -12,6 +12,13 @@ The PowerShell version of GNG is implemented as a PowerShell Module. ### Installing +The Gng Powershell module is available from the Powershell Gallery. +If you have PowerShellGet installed then simply: +[source,powershell] +---- +Install-Module -Name GradleWrapperModule -Scope CurrentUser +---- + #### From Source : Windows (Powershell) [source,powershell] @@ -21,7 +28,7 @@ cd gng ./bin/install-gng-powershell.ps1 ---- -After the Gradle Module has been installed into it can be used to initialize a gradle project. +After the Gradle Module has been installed, it can be used to initialize a gradle project. Create a new Gradle project with a GNG wrapper. [source,powershell] @@ -121,7 +128,16 @@ cd gng [source,powershell] ---- -Import-Module -Name ~/IdeaProjects/gng/bin/gng.psm1 -Force -Verbose +./bin/install-powershell.ps1 +---- + +https://docs.microsoft.com/en-us/powershell/module/powershellget/publish-module + +Presuming the $nugetkey has been set. + +[source,powershell] +---- +Publish-Module -Name GradleWrapperModule -NuGetApiKey $nugetkey ---- The `gw` command can now be run from a properly configured project. From 717ce00fb86448876a43282861ebc6d1c1967bdf Mon Sep 17 00:00:00 2001 From: Fred Eisele Date: Thu, 7 Oct 2021 18:51:51 -0500 Subject: [PATCH 12/12] provide a default gng.yaml configuration file --- bin/GradleWrapperModule.psd1 | 8 ++--- bin/GradleWrapperModule.psm1 | 58 +++++++++++++++++++++++++----------- bin/install-powershell.ps1 | 12 ++++---- gradle/gng.json | 0 gradle/gng.yaml | 10 +++++++ 5 files changed, 62 insertions(+), 26 deletions(-) delete mode 100644 gradle/gng.json create mode 100644 gradle/gng.yaml diff --git a/bin/GradleWrapperModule.psd1 b/bin/GradleWrapperModule.psd1 index 9a01271..64f013e 100644 --- a/bin/GradleWrapperModule.psd1 +++ b/bin/GradleWrapperModule.psd1 @@ -12,7 +12,7 @@ # RootModule = '' # Version number of this module. -ModuleVersion = '0.0.1' +ModuleVersion = '0.0.3' # Supported PSEditions # CompatiblePSEditions = @() @@ -51,7 +51,7 @@ Description = 'This is provides a streamlined version of the gradle wrapper.' # ProcessorArchitecture = '' # Modules that must be imported into the global environment prior to importing this module -# RequiredModules = @() +RequiredModules = @("powershell-yaml") # Assemblies that must be loaded prior to importing this module # RequiredAssemblies = @() @@ -87,7 +87,7 @@ AliasesToExport = @("gw","gng") # ModuleList = @() # List of all files packaged with this module -# FileList = @() +FileList = @("gng.yaml", "gradlew", "wrapper/gradle-wrapper.jar", "GradleWrapperModule.psm1") # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. PrivateData = @{ @@ -123,7 +123,7 @@ PrivateData = @{ } # End of PrivateData hashtable # HelpInfo URI of this module -# HelpInfoURI = '' +HelpInfoURI = 'https://github.com/babeloff/gng' # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. # DefaultCommandPrefix = '' diff --git a/bin/GradleWrapperModule.psm1 b/bin/GradleWrapperModule.psm1 index 904d3c1..b005fc9 100644 --- a/bin/GradleWrapperModule.psm1 +++ b/bin/GradleWrapperModule.psm1 @@ -10,7 +10,7 @@ $script:baseGradlewFileName = "gradlew" <# .SYNOPSIS -It is mostly just a wrapper for gradlew but it adds a few parameters. +It is mostly just a wrapper for gradlew with some additional parameters. .DESCRIPTION @@ -18,6 +18,8 @@ This is the primary GNG function. It performs an upward search for the $script:baseGradlewFileName and runs that. It does not include the incubating or deprecated paramters. It allows for either the current directory or the $script:baseGradlewFileName directory. + +Defaults for some values are read from the gng.yaml configuration file. #> function Invoke-Gradle { param( @@ -352,12 +354,22 @@ Enables watching the file system for changes, allowing data about the file syste } Write-Debug "Using gradle at '${gradlewPath}' to run" $gradlewDir = (Split-Path -Path $gradlewPath -Parent) - $jsonConfFile = Join-Path $gradlewDir 'gradle/gng.json' - $jsonConf = if (Test-Path -Path $jsonConfFile) { - Get-Content (Join-Path (Join-Path $gradlewDir 'gradle') 'gng.json') | Out-String | ConvertFrom-Json + $yamlConfFile = Join-Path $gradlewDir 'gradle/gng.yaml' + $defaultYamlConfFile = Join-Path $PSScriptRoot "gng.yaml" + + $yamlConf = if (Test-Path -Path $yamlConfFile) { + Get-Content $yamlConfFile | Out-String | ConvertFrom-Yaml + } elseif (Test-Path -Path $defaultYamlConfFile) { + Get-Content $defaultYamlConfFile | Out-String | ConvertFrom-Yaml } else { - ConvertFrom-Json '' + ConvertFrom-Yaml @' +options: +'@ } + # Add default JVM options here. + $defaultJvmOpts = $yamlConf["options"]["jvm"] + $defaultGradleOpts = $yamlConf["options"]["gradle"] + $gradleArgList = @() if ($NoRebuild) { $gradleArgList += '--no-rebuild' } @@ -412,20 +424,16 @@ Enables watching the file system for changes, allowing data about the file syste } $gradleArgList += $Tasks Write-Debug "gradlew argument list '${gradleArgList}'" - Write-Debug "gradlew configuration '${jsonConf}'" + Write-Debug "gradlew configuration '${yamlConf}'" # We bypass the gradlew.bat and run the java program directly. # The gradlew.bat script only does a few things. $appBaseName = $gradlewFileName $appHome = $gradlewDir - # Add default JVM options here. - # You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. - $defaultJvmOpts = @("-Xmx64m","-Xms64m") - - if (Test-Path env:JAVA_HOME) { - $javaHome = env:JAVA_HOME.Replace('"','') - $javaExe = Join-Path -Path env:JAVA_HOME -ChildPath "bin/java.exe" + if (Test-Path $env:JAVA_HOME) { + $javaHome = $env:JAVA_HOME.Replace('"','') + $javaExe = Join-Path -Path $env:JAVA_HOME -ChildPath "bin/java.exe" if (-Not (Test-Path $javaExe)) { Write-Error @" @@ -446,18 +454,34 @@ location of your Java installation. $javaHome = Split-Path -Path (Split-Path -Path $javaExe -Parent) -Parent } $classPath = Join-Path -Path $appHome -ChildPath 'gradle/wrapper/gradle-wrapper.jar' - $javaArgList = @( - $defaultJvmOpts, $env:JAVA_OPTS, $env:GRADLE_OPTS, + $javaArgList = @() + if ($Watch) { $gradleArgList += '--watch-fs' } + + $javaArgList = @() + + # You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. + if (Test-Path -Path $env:JAVA_OPTS -ErrorAction SilentlyContinue) { + $javaArgList += $env:JAVA_OPTS + } elseif (-Not ($defaultJvmOpts -eq $null)) { + $javaArgList += $defaultJvmOpts + } + if (Test-Path -Path $env:GRADLE_OPTS -ErrorAction SilentlyContinue) { + $javaArgList += $env:GRADLE_OPTS + } elseif (-Not ($defaultGradleOpts -eq $null)) { + $javaArgList += $defaultGradleOpts + } + $javaArgList += @( "-Dorg.gradle.appname=$appBaseName", '-classpath', $classPath, 'org.gradle.wrapper.GradleWrapperMain' ) $workingDirectory = if ($UseWorkingDirectory) { $WorkingDir } else { $gradlewDir } - + $argList = $javaArgList + $gradleArgList + Write-Debug "start-process argList '$argList'" $procOptions = @{ FilePath = $javaExe WorkingDirectory = $workingDirectory - ArgumentList = $javaArgList + $gradleArgList + ArgumentList = $argList Wait = $True PassThru = $True NoNewWindow = $True diff --git a/bin/install-powershell.ps1 b/bin/install-powershell.ps1 index 92d8ecd..26ae9d3 100644 --- a/bin/install-powershell.ps1 +++ b/bin/install-powershell.ps1 @@ -17,14 +17,16 @@ if (-Not (Test-Path -Path $script:moduleTarget)) { } Write-Debug "Module paths: source = $PSScriptRoot, target = $script:moduleTarget" Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath "${script:moduleTitle}.psm1") -Destination $script:moduleTarget -Force -Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath "${script:moduleTitle}.psd1") -Destination $script:moduleTarget -Force +#Copy-Item -Path (Join-Path -Path $PSScriptRoot -ChildPath "${script:moduleTitle}.psd1") -Destination $script:moduleTarget -Force + $gradleDir = Join-Path -Path $PSScriptRoot -ChildPath '../gradle' -Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'wrapper') -Destination $script:moduleTarget -Force -Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gng.json') -Destination $script:moduleTarget -Force +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'wrapper') -Recurse -Destination $script:moduleTarget -Force +Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gng.yaml') -Destination $script:moduleTarget -Force Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew') -Destination $script:moduleTarget -Force Copy-Item -Path (Join-Path -Path $gradleDir -ChildPath 'gradlew.bat') -Destination $script:moduleTarget -Force -Get-Module -ListAvailable $script:moduleTitle | Format-List name, path -Import-Module -Verbose -Name $script:moduleTitle -Force +#Get-Module -ListAvailable $script:moduleTitle | Remove-Module -Verbose -Force +Get-Module -ListAvailable $script:moduleTitle | Format-List +Import-Module -Verbose $script:moduleTitle -Force diff --git a/gradle/gng.json b/gradle/gng.json deleted file mode 100644 index e69de29..0000000 diff --git a/gradle/gng.yaml b/gradle/gng.yaml new file mode 100644 index 0000000..3f83c8d --- /dev/null +++ b/gradle/gng.yaml @@ -0,0 +1,10 @@ +# Configuration file of gng + +# https://github.com/ddimtirov/gwo-agent + +tasks: + - name: ":tasks" +options: + jvm: ["-Xmx64m","-Xms64m"] +# gradle: "-javaagent:~/.gradle/gwo-agent.jar=distributionUrl~=@https://services.gradle.org/distributions@https://mymirror/gradle/@ +