63 lines
2.4 KiB
PowerShell
63 lines
2.4 KiB
PowerShell
$JAVAC = 'C:\Program Files\Eclipse Adoptium\jdk-17.0.7.7-hotspot\bin\javac.exe'
|
|
$JAVA = 'C:\Program Files\Eclipse Adoptium\jdk-17.0.7.7-hotspot\bin\java.exe'
|
|
$BASE = 'C:\Users\Ankur\Claude\Projects\@ankurm Blog\design-patterns'
|
|
$OUTDIR = "$BASE\screenshots"
|
|
|
|
New-Item -Force -ItemType Directory $OUTDIR | Out-Null
|
|
|
|
$patterns = @(
|
|
@{dir="chain-of-responsibility"; pkg="chain"; main="chain.Main"},
|
|
@{dir="command"; pkg="command"; main="command.Main"},
|
|
@{dir="iterator"; pkg="iterator"; main="iterator.Main"},
|
|
@{dir="mediator"; pkg="mediator"; main="mediator.Main"},
|
|
@{dir="memento"; pkg="memento"; main="memento.Main"},
|
|
@{dir="observer"; pkg="observer"; main="observer.Main"},
|
|
@{dir="state"; pkg="state"; main="state.Main"},
|
|
@{dir="strategy"; pkg="strategy"; main="strategy.Main"},
|
|
@{dir="template-method"; pkg="template"; main="template.Main"},
|
|
@{dir="visitor"; pkg="visitor"; main="visitor.Main"}
|
|
)
|
|
|
|
$allOk = $true
|
|
|
|
foreach ($p in $patterns) {
|
|
$label = $p.dir.ToUpper()
|
|
Write-Host "`n=== $label ===" -ForegroundColor Cyan
|
|
|
|
$srcDir = "$BASE\03-behavioral\$($p.dir)"
|
|
$outDir = "$BASE\out\$($p.pkg)"
|
|
New-Item -Force -ItemType Directory $outDir | Out-Null
|
|
|
|
$files = @(Get-ChildItem "$srcDir\*.java" | Select-Object -ExpandProperty FullName)
|
|
|
|
if ($files.Count -eq 0) {
|
|
Write-Host "[SKIP] No .java files in $srcDir" -ForegroundColor Yellow
|
|
continue
|
|
}
|
|
|
|
$compileOut = & $JAVAC -d $outDir @files 2>&1
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "[FAIL] $label compile error:" -ForegroundColor Red
|
|
$compileOut | ForEach-Object { Write-Host " $_" -ForegroundColor Red }
|
|
$allOk = $false
|
|
continue
|
|
}
|
|
|
|
Write-Host "[OK] Compiled $($p.dir)" -ForegroundColor Green
|
|
|
|
$logFile = "$OUTDIR\$($p.pkg)-output.txt"
|
|
$runOut = & $JAVA -cp $outDir $($p.main) 2>&1
|
|
$runOut | Out-File -FilePath $logFile -Encoding utf8
|
|
$runOut | ForEach-Object { Write-Host $_ }
|
|
Write-Host "[SAVED] $logFile" -ForegroundColor DarkGray
|
|
}
|
|
|
|
Write-Host "`n============================================" -ForegroundColor Yellow
|
|
if ($allOk) {
|
|
Write-Host "All 10 behavioral patterns compiled and ran OK" -ForegroundColor Green
|
|
} else {
|
|
Write-Host "Some patterns had errors - check output above" -ForegroundColor Red
|
|
}
|
|
Write-Host "Output files: $OUTDIR" -ForegroundColor Yellow
|
|
Read-Host "`nPress Enter to close"
|