$ErrorActionPreference = "Stop"

$root = Split-Path -Parent $MyInvocation.MyCommand.Path
$outDir = Join-Path $root "build\lua54-jme-smoke-classes"

New-Item -ItemType Directory -Force $outDir | Out-Null

$sources = @(
    "core\src\main\java\org\luaj\vm2\LuaValue.java",
    "core\src\main\java\org\luaj\vm2\LoadState.java",
    "core\src\main\java\org\luaj\vm2\LocVars.java",
    "core\src\main\java\org\luaj\vm2\LuaClosure.java",
    "core\src\main\java\org\luaj\vm2\LuaThread.java",
    "core\src\main\java\org\luaj\vm2\Upvaldesc.java",
    "core\src\main\java\org\luaj\vm2\compiler\DumpState.java",
    "core\src\main\java\org\luaj\vm2\compiler\FuncState.java",
    "core\src\main\java\org\luaj\vm2\compiler\LexState.java",
    "core\src\main\java\org\luaj\vm2\libs\BaseLib.java",
    "core\src\main\java\org\luaj\vm2\libs\CoroutineLib.java",
    "core\src\main\java\org\luaj\vm2\libs\IoLib.java",
    "core\src\main\java\org\luaj\vm2\libs\MathLib.java",
    "core\src\main\java\org\luaj\vm2\libs\StringLib.java",
    "jme\src\main\java\javax\microedition\io\Connection.java",
    "jme\src\main\java\javax\microedition\io\InputConnection.java",
    "jme\src\main\java\javax\microedition\io\OutputConnection.java",
    "jme\src\main\java\javax\microedition\io\StreamConnection.java",
    "jme\src\main\java\javax\microedition\io\Connector.java",
    "jme\src\main\java\org\luaj\vm2\libs\jme\JmeIoLib.java",
    "jme\src\main\java\org\luaj\vm2\libs\jme\JmePlatform.java",
    "jme\src\test\java\org\luaj\vm2\Lua54JmeSmokeTestMain.java"
)

$classpath = "core\src\main\java;jme\src\main\java;jme\src\test\java"
$sourceArgs = $sources | ForEach-Object { Join-Path $root $_ }

& javac -encoding UTF-8 -cp $classpath -d $outDir $sourceArgs
if ($LASTEXITCODE -ne 0) {
    exit $LASTEXITCODE
}

& java -cp "$outDir;$classpath" org.luaj.vm2.Lua54JmeSmokeTestMain
exit $LASTEXITCODE
