# Compiles rsx-protocol plus its tests and runs them. # # ASCII only, for the same reason as build.ps1. $ErrorActionPreference = 'Stop' $Repo = Split-Path -Parent $PSScriptRoot if (-not $Repo) { $Repo = $PSCommandPath | Split-Path -Parent | Split-Path -Parent } $Out = Join-Path $Repo 'build' function Say($text) { Write-Host " $text" -ForegroundColor Cyan } New-Item -ItemType Directory -Force -Path $Out | Out-Null $mainOut = Join-Path $Out 'classes' Remove-Item $mainOut -Recurse -Force -ErrorAction SilentlyContinue New-Item -ItemType Directory -Force -Path $mainOut | Out-Null $mainFiles = @(Get-ChildItem (Join-Path $Repo 'src\main\java') -Recurse -Filter '*.java' | ForEach-Object { $_.FullName }) & javac -encoding UTF-8 --release 17 -Xlint:-options -nowarn -d $mainOut $mainFiles if ($LASTEXITCODE -ne 0) { Write-Host ' Main failed.' -ForegroundColor Red; exit 1 } # The tests read the item table, so it has to be on the class path as well. $resources = Join-Path $Repo 'src\main\resources' if (Test-Path -LiteralPath $resources) { Copy-Item -Path (Join-Path $resources '*') -Destination $mainOut -Recurse -Force } $testOut = Join-Path $Out 'test-classes' Remove-Item $testOut -Recurse -Force -ErrorAction SilentlyContinue New-Item -ItemType Directory -Force -Path $testOut | Out-Null $testFiles = @(Get-ChildItem (Join-Path $Repo 'src\test\java') -Recurse -Filter '*.java' | ForEach-Object { $_.FullName }) & javac -encoding UTF-8 --release 17 -Xlint:-options -nowarn -cp $mainOut -d $testOut $testFiles if ($LASTEXITCODE -ne 0) { Write-Host ' Test failed to compile.' -ForegroundColor Red; exit 1 } Say "compiled $($mainFiles.Count) main + $($testFiles.Count) test files" & java -cp "$mainOut;$testOut" net.rustnotmc.protocol.ProtocolTest if ($LASTEXITCODE -ne 0) { Write-Host '' Write-Host ' PROTOCOL TESTS FAILED' -ForegroundColor Red exit 1 } & java -cp "$mainOut;$testOut" net.rustnotmc.protocol.ItemTest if ($LASTEXITCODE -ne 0) { Write-Host '' Write-Host ' ITEM TESTS FAILED' -ForegroundColor Red exit 1 } Write-Host '' Write-Host ' Protocol tests passed.' -ForegroundColor Green