forked from DataDog/dd-trace-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
190 lines (165 loc) · 5.18 KB
/
setup.ps1
File metadata and controls
190 lines (165 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<#
.DESCRIPTION
This script checks the development environment for required tools and configurations.
#>
# Enable error handling
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
# Check for required JDKs
function Get-JavaMajorVersion {
param ($javaCommand)
try {
$ErrorActionPreference = 'Continue'
$javaVersionOutput = & $javaCommand -version 2>&1
}
catch {
return $null
}
finally {
$ErrorActionPreference = 'Stop'
}
# Extract version from output like 'version "21.0.1"' or 'version "1.8.0_392"'
if ($javaVersionOutput[0] -match 'version "1\.(\d+)') {
# Old versioning scheme (Java 8 and earlier): 1.X.Y_Z -> major version is X
return [int]$matches[1]
}
elseif ($javaVersionOutput[0] -match 'version "(\d+)') {
# New versioning scheme (Java 9+): X.Y.Z -> major version is X
return [int]$matches[1]
}
return $null
}
function Test-Jdk {
param ($javaCommand, $minJavaVersion)
$javaVersion = Get-JavaMajorVersion $javaCommand
if ($null -eq $javaVersion) {
Write-Host "❌ Could not determine Java version from $javaCommand." -ForegroundColor Red
exit 1
}
elseif ($javaVersion -lt $minJavaVersion) {
Write-Host "🟨 $javaCommand refers to JDK $javaVersion but JDK $minJavaVersion or above is recommended."
}
else {
Write-Host "✅ $javaCommand is set to JDK $javaVersion."
}
}
function Show-AvailableJdks {
try {
$ErrorActionPreference = 'Continue'
$javaToolchainsOutput = & .\gradlew.bat -q javaToolchains 2>&1
$jdkName = ''
foreach ($line in $javaToolchainsOutput) {
if ($line -match '^ \+ (.+)$') {
$jdkName = $matches[1]
}
elseif ($line -match '^\s+\| Location:\s+(.+)$') {
if ($jdkName) {
Write-Host "✅ $jdkName from $($matches[1])."
$jdkName = ''
}
}
}
}
catch {
Write-Host "⚠️ Could not retrieve available JDKs from Gradle."
}
finally {
$ErrorActionPreference = 'Stop'
}
}
Write-Host 'ℹ️ Checking JDK:'
if (Test-Path 'env:JAVA_HOME') {
$javaHome = Get-Item 'env:JAVA_HOME' | Select-Object -ExpandProperty Value
Test-Jdk "$javaHome\bin\java.exe" 21
}
elseif (Get-Command java -ErrorAction SilentlyContinue) {
Test-Jdk 'java' 21
}
else {
Write-Host "❌ No Java installation found. Please install JDK 21 or above." -ForegroundColor Red
exit 1
}
Write-Host 'ℹ️ Checking other JDKs available for testing:'
Show-AvailableJdks
# Check for required commands (e.g., git, docker)
function TestCommand {
param ($command)
if (Get-Command $command -ErrorAction SilentlyContinue) {
Write-Host "✅ The $command command line is installed."
}
else {
Write-Host "❌ The $command command line is missing. Please install $command." -ForegroundColor Red
exit 1
}
}
function Get-FileHashMD5 {
param ($file)
return (Get-FileHash -Path $file -Algorithm MD5).Hash
}
function TestHook {
param ($hookName)
$hookChecksum = Get-FileHashMD5 ".githooks/$hookName"
$hooksPath = (git config core.hooksPath) -or '.git/hooks'
if ((Test-Path ".git/hooks/$hookName") -and (Get-FileHashMD5 ".git/hooks/$hookName" -eq $hookChecksum)) {
Write-Host "✅ $hookName hook is installed in repository."
}
elseif ((Test-Path "$hooksPath/$hookName") -and (Get-FileHashMD5 "$hooksPath/$hookName" -eq $hookChecksum)) {
Write-Host "✅ $hookName hook is installed in git hooks path."
}
else {
Write-Host "🟨 $hookName hook was not found (optional but recommended)."
}
}
function TestGitConfig {
param ($configName, $expectedValue)
$actualValue = git config $configName
if ($actualValue -eq $expectedValue) {
Write-Host "✅ git config $configName is set to $expectedValue."
}
elseif (-not $actualValue) {
Write-Host "❌ git config $configName is not set. Please run 'git config set $configName $expectedValue'." -ForegroundColor Red
}
else {
Write-Host "🟨 git config $configName is set to $actualValue (expected: $expectedValue). Please run 'git config set $configName $expectedValue'."
}
}
function TestSubmoduleInitialization {
if (Test-Path '.gitmodules') {
$uninitializedSubmodules = git submodule status | Select-String '^-'
if ($uninitializedSubmodules) {
Write-Host "❌ A git submodule are not initialized. Please run 'git submodule update --init --recursive'." -ForegroundColor Red
}
else {
Write-Host "✅ All git submodules are initialized."
}
}
}
Write-Host 'ℹ️ Checking git configuration:'
TestCommand 'git'
TestHook 'pre-commit'
TestGitConfig 'submodule.recurse' 'true'
TestSubmoduleInitialization
# Check Docker environment
function TestDockerServer {
try {
# try to handle differences between PowerShell 7 and Windows PowerShell 5
$ErrorActionPreference = 'Continue'
docker info *> $null
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ The Docker server is running."
}
else {
Write-Host "🟨 The Docker server is not running. Please start it to run all tests."
}
}
catch {
Write-Host "❌ Error running `"docker info *> $null`"."
exit 1
}
finally {
$ErrorActionPreference = 'Stop'
}
}
Write-Host 'ℹ️ Checking Docker environment:'
TestCommand 'docker'
TestDockerServer