Repository navigation
Expand file tree
/
Copy pathaethercode-build-helper.ps1
More file actions
235 lines (217 loc) · 9.62 KB
/
Copy pathaethercode-build-helper.ps1
File metadata and controls
235 lines (217 loc) · 9.62 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# Copyright (c) 2026 maijun
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# aethercode-build-helper.ps1
# Intelligent build entry point for AetherCode + downstream Java projects.
# Replaces the 9-13 minute "stuck build" pattern that the RAG Day 2
# Q19/Q20/Q21 sessions hit when mockito 5.14.x + byte-buddy 1.14.x
# were selected against JDK 25 (class file version 65). R722 standardises
# the dependency pick by JDK version and adds exponential-backoff
# retry on a real BUILD FAILURE — the previous behaviour was to
# let the user (or the model) flail for 9-13 minutes before noticing
# the build had been silently stuck on a Mockito/ByteBuddy incompatibility.
#
# Usage:
# .\aethercode-build-helper.ps1 -Goals 'package -DskipTests'
# .\aethercode-build-helper.ps1 -Goals 'test' -MaxAttempts 2
# .\aethercode-build-helper.ps1 -Help
#
# Behaviour:
# 1. Detects JDK major version (`mvn -v` → java version).
# 2. Picks mockito + byte-buddy versions known to work on that
# JDK. (Table below — see the version table comment.)
# 3. Runs `mvn <goals>`. On BUILD FAILURE retries with
# exponential backoff (5s, 15s, 45s by default; tunable).
# 4. Logs to $env:USERPROFILE\aethercode-build-helper.log so the
# model can read the trail without a separate `tee`.
#
# Exit codes:
# 0 = BUILD SUCCESS
# 1 = BUILD FAILURE after all attempts
# 2 = prerequisites missing (mvn not on PATH, etc.)
#
# Tested on:
# - JDK 25.0.1 (Adoptium Temurin) + mockito 5.15.2 + byte-buddy 1.15.11
# — the (current) safe triplet for AetherCode's multi-module
# build (RAG Day 3 Q20 already uses these).
# - JDK 21.0.5 (Adoptium Temurin) + mockito 5.12.0 + byte-buddy 1.14.13
# — pre-R720 baseline.
[CmdletBinding()]
param(
[string]$Goals = 'package -DskipTests -q',
[int]$MaxAttempts = 3,
[int]$FirstBackoffSeconds = 5,
[string]$LogFile = "$env:USERPROFILE\aethercode-build-helper.log",
[switch]$Help,
[switch]$DryRun
)
# Version table — when a JDK major version is added, only this
# table needs to grow. The script applies the table via -D
# overrides on the mvn command line; it does NOT mutate
# pom.xml (the user might be running ad-hoc from a different
# shell, and silently changing a checked-in pom is rude).
#
# Mockito's official JDK support matrix:
# 5.0+ → JDK 17+ (class file version 61)
# 5.10+ → JDK 21+ (class file version 65) requires byte-buddy 1.14.13+
# 5.12+ → JDK 21+ works with byte-buddy 1.14.13+
# 5.14+ → JDK 21+ works with byte-buddy 1.14.13+ (the RAG Day 2 default)
# 5.15+ → JDK 21+ works with byte-buddy 1.15.0+ (JDK 25 verified)
#
# ByteBuddy 1.15.0+ is required for Mockito to handle JDK 25
# class files (version 65) without an IllegalArgumentException
# from the inline mock-maker. 1.14.x can read 65-class files
# but raises on the inline-mock path that Mockito's
# mockStatic / @Spy uses.
$versionTable = @(
@{ jdk = 25; mockito = '5.15.2'; byteBuddy = '1.15.11'; notes = 'RAG Day 3 verified (Q20 RAG)' },
@{ jdk = 24; mockito = '5.14.2'; byteBuddy = '1.14.18'; notes = 'RAG Day 2 baseline (Q19)' },
@{ jdk = 23; mockito = '5.12.0'; byteBuddy = '1.14.13'; notes = 'pre-R720 default' },
@{ jdk = 22; mockito = '5.12.0'; byteBuddy = '1.14.13'; notes = 'pre-R720 default' },
@{ jdk = 21; mockito = '5.12.0'; byteBuddy = '1.14.13'; notes = 'LTS line' },
@{ jdk = 17; mockito = '5.5.0'; byteBuddy = '1.14.0'; notes = 'lowest supported' }
)
function Write-Log {
param([string]$Message, [string]$Level = 'INFO')
$ts = Get-Date -Format 'yyyy-MM-ddTHH:mm:ss'
$line = "[$ts] [$Level] $Message"
Write-Host $line
Add-Content -Path $LogFile -Value $line -Encoding UTF8
}
function Show-Help {
@"
aethercode-build-helper.ps1 — R722 intelligent Java build entry
Usage:
.\aethercode-build-helper.ps1 [-Goals <string>] [-MaxAttempts <int>]
[-FirstBackoffSeconds <int>] [-DryRun] [-Help]
Examples:
# default: package -DskipTests -q, retry up to 3 times
.\aethercode-build-helper.ps1
# run tests, fail fast on second attempt
.\aethercode-build-helper.ps1 -Goals 'test' -MaxAttempts 2
# see what would run, don't actually invoke mvn
.\aethercode-build-helper.ps1 -DryRun
The script:
1. Reads the JDK major version from `mvn -v`.
2. Looks up a safe (mockito, byte-buddy) pair for that JDK.
3. Invokes mvn with the goal string + the pair as -D
overrides (mockito.version, byte-buddy.version).
4. On BUILD FAILURE, retries with exponential backoff
(5s, 15s, 45s by default).
5. Logs every step to $env:USERPROFILE\aethercode-build-helper.log.
Exit codes:
0 = BUILD SUCCESS
1 = BUILD FAILURE after all attempts
2 = prerequisites missing (e.g. mvn not on PATH)
"@
}
if ($Help) { Show-Help; exit 0 }
# ---- prerequisites ----
if (-not (Get-Command mvn -ErrorAction SilentlyContinue)) {
Write-Log "mvn not on PATH; install Apache Maven 3.9.x or set M2_HOME." "ERROR"
exit 2
}
if (-not (Test-Path 'D:\work\workspace\idea\engine\AetherCode\aethercode\pom.xml')) {
Write-Log "expected AetherCode repo at D:\work\workspace\idea\engine\AetherCode\aethercode; aborting." "ERROR"
exit 2
}
# R722: auto-cd into the multi-module subdir so the user can
# invoke the script from the repo root. Pre-R722 the script
# expected the user to `cd aethercode` first, which is a
# minor friction that's easy to forget when the model is
# driving the build via a tool call.
Set-Location 'D:\work\workspace\idea\engine\AetherCode\aethercode'
Write-Log "auto-cd into $(Get-Location)"
# ---- JDK detection ----
$mvnv = (& mvn -v) 2>&1 | Out-String
$jdkMajor = 0
if ($mvnv -match 'Java version:\s*(\d+)(?:\.\d+)*') {
$jdkMajor = [int]$Matches[1]
}
if ($jdkMajor -lt 17) {
Write-Log "JDK major $jdkMajor is below the supported minimum (17); aborting." "ERROR"
exit 2
}
# pick the highest entry in the table whose jdk is <= current
$picked = $null
foreach ($row in $versionTable) {
if ($row.jdk -le $jdkMajor) {
$picked = $row
break # sorted descending; first match wins
}
}
if ($null -eq $picked) {
# JDK 17 or below — take the lowest table entry
$picked = $versionTable[-1]
}
$mockitoVersion = $picked.mockito
$byteBuddyVersion = $picked.byteBuddy
Write-Log "JDK $jdkMajor detected; picked mockito=$mockitoVersion byteBuddy=$byteBuddyVersion ($($picked.notes))"
# ---- mvn command assembly ----
# R722: split goals + -D overrides into an array so PowerShell
# doesn't concatenate them into a single whitespace-stripped
# arg. The first cut of this script used a single $fullGoals
# string and `& mvn $fullGoals`, which mvn then parsed as
# one giant lifecycle-phase name (e.g. "compile -DskipTests
# -q -Dmockito.version=5.15.2" → "Unknown lifecycle phase")
# and failed before any compile work happened. Splatting
# the args via an array is the standard PowerShell idiom.
$goalArgs = @()
foreach ($tok in ($Goals -split '\s+')) {
if ($tok) { $goalArgs += $tok }
}
$goalArgs += "-Dmockito.version=$mockitoVersion"
$goalArgs += "-Dbyte-buddy.version=$byteBuddyVersion"
$cmd = "mvn $($goalArgs -join ' ')"
Write-Log "mvn command: $cmd"
if ($DryRun) {
Write-Log "DRY-RUN: not executing mvn. Exit 0."
exit 0
}
# ---- exponential-backoff retry loop ----
$backoff = $FirstBackoffSeconds
$attempt = 0
while ($attempt -lt $MaxAttempts) {
$attempt++
Write-Log "attempt $attempt of $MaxAttempts"
$sw = [System.Diagnostics.Stopwatch]::StartNew()
# Use a fresh $LASTEXITCODE capture inside a subshell via &
# so transient env doesn't leak.
$output = & mvn @goalArgs 2>&1
$exitCode = $LASTEXITCODE
$sw.Stop()
Add-Content -Path $LogFile -Value $output -Encoding UTF8
if ($exitCode -eq 0) {
Write-Log "BUILD SUCCESS in $([math]::Round($sw.Elapsed.TotalSeconds, 2))s on attempt $attempt"
exit 0
}
# look for the JDK 25 incompatibility signal
$errMatch = ($output | Select-String -Pattern 'class file version 65|UnsupportedClassVersionError|byte-buddy' -ErrorAction SilentlyContinue | Select-Object -First 1)
if ($errMatch) {
Write-Log "BUILD FAILURE (exit=$exitCode) — detected JDK-compat signal: $($errMatch.Line)" "WARN"
} else {
Write-Log "BUILD FAILURE (exit=$exitCode) after $([math]::Round($sw.Elapsed.TotalSeconds, 2))s — see $LogFile" "WARN"
}
if ($attempt -ge $MaxAttempts) { break }
Write-Log "sleeping $backoff seconds before retry (exponential backoff: ${backoff}s -> $(${backoff}*3)s -> $(${backoff}*9)s)"
Start-Sleep -Seconds $backoff
$backoff = $backoff * 3
}
Write-Log "BUILD FAILURE after $MaxAttempts attempts; giving up. See $LogFile for the full mvn output." "ERROR"
exit 1