|
| 1 | +# Enable error handling |
| 2 | +Set-StrictMode -Version Latest |
| 3 | +$ErrorActionPreference = 'Stop' |
| 4 | + |
| 5 | +function TestJvm { |
| 6 | + param ($JavaHomeName, $ExpectedJavaVersion) |
| 7 | + |
| 8 | + if (-not (Test-Path "env:$JavaHomeName")) { |
| 9 | + Write-Host "❌ $JavaHomeName is not set. Please set $JavaHomeName to refer to a JDK $ExpectedJavaVersion installation." -ForegroundColor Red |
| 10 | + exit 1 |
| 11 | + } |
| 12 | + else { |
| 13 | + $javaHome = Get-Item "env:$JavaHomeName" | Select-Object -ExpandProperty Value |
| 14 | + |
| 15 | + try { |
| 16 | + # try to handle differences between PowerShell 7 and Windows PowerShell 5 |
| 17 | + $ErrorActionPreference = 'Continue' |
| 18 | + $javaVersionOutput = & "$javaHome\bin\java.exe" -version 2>&1 |
| 19 | + } |
| 20 | + catch { |
| 21 | + Write-Host "❌ Error running `"$javaHome\bin\java.exe -version`". Please check that $JavaHomeName is set to a JDK $ExpectedJavaVersion installation." |
| 22 | + exit 1 |
| 23 | + } |
| 24 | + finally { |
| 25 | + $ErrorActionPreference = 'Stop' |
| 26 | + } |
| 27 | + |
| 28 | + if ($javaVersionOutput[0] -notmatch "version `"$ExpectedJavaVersion") { |
| 29 | + Write-Host "❌ $JavaHomeName is set to $javaHome, but it does not refer to a JDK $ExpectedJavaVersion installation." -ForegroundColor Red |
| 30 | + exit 1 |
| 31 | + } |
| 32 | + else { |
| 33 | + Write-Host "✅ $JavaHomeName is set to $javaHome." |
| 34 | + } |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +Write-Host 'ℹ️ Checking required JVM:' |
| 39 | +if (Test-Path 'env:JAVA_HOME') { |
| 40 | + TestJvm 'JAVA_HOME' '1.8' |
| 41 | +} |
| 42 | + |
| 43 | +TestJvm 'JAVA_8_HOME' '1.8' |
| 44 | +TestJvm 'JAVA_11_HOME' '11' |
| 45 | +TestJvm 'JAVA_17_HOME' '17' |
| 46 | +TestJvm 'JAVA_21_HOME' '21' |
| 47 | +TestJvm 'JAVA_GRAALVM17_HOME' '17' |
| 48 | + |
| 49 | +# Check for required commands (e.g., git, docker) |
| 50 | +function TestCommand { |
| 51 | + param ($command) |
| 52 | + |
| 53 | + if (Get-Command $command -ErrorAction SilentlyContinue) { |
| 54 | + Write-Host "✅ The $command command line is installed." |
| 55 | + } |
| 56 | + else { |
| 57 | + Write-Host "❌ The $command command line is missing. Please install $command." -ForegroundColor Red |
| 58 | + exit 1 |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +function Get-FileHashMD5 { |
| 63 | + param ($file) |
| 64 | + return (Get-FileHash -Path $file -Algorithm MD5).Hash |
| 65 | +} |
| 66 | + |
| 67 | +function TestHook { |
| 68 | + param ($hookName) |
| 69 | + |
| 70 | + $hookChecksum = Get-FileHashMD5 ".githooks/$hookName" |
| 71 | + $hooksPath = (git config core.hooksPath) -or '.git/hooks' |
| 72 | + |
| 73 | + if ((Test-Path ".git/hooks/$hookName") -and (Get-FileHashMD5 ".git/hooks/$hookName" -eq $hookChecksum)) { |
| 74 | + Write-Host "✅ $hookName hook is installed in repository." |
| 75 | + } |
| 76 | + elseif ((Test-Path "$hooksPath/$hookName") -and (Get-FileHashMD5 "$hooksPath/$hookName" -eq $hookChecksum)) { |
| 77 | + Write-Host "✅ $hookName hook is installed in git hooks path." |
| 78 | + } |
| 79 | + else { |
| 80 | + Write-Host "🟨 $hookName hook was not found (optional but recommended)." |
| 81 | + } |
| 82 | +} |
| 83 | + |
| 84 | +function TestGitConfig { |
| 85 | + param ($configName, $expectedValue) |
| 86 | + |
| 87 | + $actualValue = git config $configName |
| 88 | + |
| 89 | + if ($actualValue -eq $expectedValue) { |
| 90 | + Write-Host "✅ git config $configName is set to $expectedValue." |
| 91 | + } |
| 92 | + elseif (-not $actualValue) { |
| 93 | + Write-Host "❌ git config $configName is not set. Please set it to $expectedValue." -ForegroundColor Red |
| 94 | + } |
| 95 | + else { |
| 96 | + Write-Host "🟨 git config $configName is set to $actualValue (expected: $expectedValue)." |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +Write-Host 'ℹ️ Checking git configuration:' |
| 101 | +TestCommand 'git' |
| 102 | +TestHook 'pre-commit' |
| 103 | +TestGitConfig 'submodule.recurse' 'true' |
| 104 | + |
| 105 | +# Check Docker environment |
| 106 | +function TestDockerServer { |
| 107 | + try { |
| 108 | + # try to handle differences between PowerShell 7 and Windows PowerShell 5 |
| 109 | + $ErrorActionPreference = 'Continue' |
| 110 | + docker info *> $null |
| 111 | + |
| 112 | + if ($LASTEXITCODE -eq 0) { |
| 113 | + Write-Host "✅ The Docker server is running." |
| 114 | + } |
| 115 | + else { |
| 116 | + Write-Host "🟨 The Docker server is not running. Please start it to run all tests." |
| 117 | + } |
| 118 | + } |
| 119 | + catch { |
| 120 | + Write-Host "❌ Error running `"docker info *> $null`"." |
| 121 | + exit 1 |
| 122 | + } |
| 123 | + finally { |
| 124 | + $ErrorActionPreference = 'Stop' |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +Write-Host 'ℹ️ Checking Docker environment:' |
| 129 | +TestCommand 'docker' |
| 130 | +TestDockerServer |
0 commit comments