Repository navigation
Expand file tree
/
Copy pathbuild-demo.ps1
More file actions
53 lines (43 loc) · 2.34 KB
/
Copy pathbuild-demo.ps1
File metadata and controls
53 lines (43 loc) · 2.34 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
$ErrorActionPreference = 'Stop'
$repoRoot = Split-Path -Parent $PSScriptRoot
$sourceFile = Join-Path $repoRoot 'demo-app/src/main/java/dev/deploylatch/demo/DemoServer.java'
$buildDirectory = Join-Path $repoRoot 'demo-app/build'
$classesDirectory = Join-Path $buildDirectory 'classes'
$distDirectory = Join-Path $repoRoot 'demo-app/dist'
$javacCommand = (Get-Command 'javac.exe' -ErrorAction Stop).Source
$jdkBin = Split-Path -Parent $javacCommand
$javacExe = Join-Path $jdkBin 'javac.exe'
$jarExe = Join-Path $jdkBin 'jar.exe'
if (-not (Test-Path $jarExe)) {
# Some Windows Java installations expose javac through a separate PATH directory.
$javaSettings = (& cmd.exe /d /c 'java -XshowSettings:properties -version 2>&1' | Out-String)
$javaHomeMatch = [regex]::Match($javaSettings, '(?m)^\s*java\.home\s*=\s*(.+)$')
if (-not $javaHomeMatch.Success) {
throw 'Could not locate the JDK tools. Check your Java installation.'
}
$jdkBin = Join-Path $javaHomeMatch.Groups[1].Value.Trim() 'bin'
$javacExe = Join-Path $jdkBin 'javac.exe'
$jarExe = Join-Path $jdkBin 'jar.exe'
}
if (-not (Test-Path $javacExe) -or -not (Test-Path $jarExe)) {
throw "JDK tools not found in $jdkBin"
}
New-Item -ItemType Directory -Force $classesDirectory, $distDirectory | Out-Null
& $javacExe -d $classesDirectory $sourceFile
if ($LASTEXITCODE -ne 0) { throw 'Java compilation failed.' }
$releases = @(
@{ Version = 'v1'; Healthy = 'true' },
@{ Version = 'v2'; Healthy = 'true' },
@{ Version = 'v3'; Healthy = 'false' }
)
foreach ($release in $releases) {
$resourceDirectory = Join-Path $buildDirectory ('resources-' + $release.Version)
New-Item -ItemType Directory -Force $resourceDirectory | Out-Null
$resourceFile = Join-Path $resourceDirectory 'release.properties'
$contents = @("version=$($release.Version)", "healthy=$($release.Healthy)", "") -join [Environment]::NewLine
[System.IO.File]::WriteAllText($resourceFile, $contents, (New-Object System.Text.UTF8Encoding($false)))
$outputFile = Join-Path $distDirectory ('demo-app-' + $release.Version + '.jar')
& $jarExe --create --file $outputFile --main-class dev.deploylatch.demo.DemoServer -C $classesDirectory . -C $resourceDirectory release.properties
if ($LASTEXITCODE -ne 0) { throw "Failed to package $($release.Version)." }
Write-Host "Built $outputFile"
}