Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 10 additions & 2 deletions .github/workflows/cloud-51did.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,18 @@ jobs:
with:
# pipeline.did builds against the owid-java submodule source.
submodules: recursive
# The tests run on Java 8, the oldest Java the packages support. Maven
# runs on JDK 17, the JDK every build compiles with, and compiles for
# Java 8 through the tree's release-8 profile.
- uses: actions/setup-java@v4
id: test-jdk
with:
# The reactor targets 1.8, so the tests are compiled and run on a
# toolchain that can still produce it.
distribution: temurin
java-version: '8'
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'
cache: maven
- name: Cloud 51Did tests
shell: pwsh
Expand Down Expand Up @@ -102,8 +108,10 @@ jobs:
'repository.')
}
# Only the Pipeline API tree is built, as in its own repository.
$testJava = Join-Path '${{ steps.test-jdk.outputs.path }}' 'bin' 'java'
mvn -B -f pipeline/pom.xml `
-pl pipeline.did,pipeline.cloudrequestengine -am test `
"-Djvm=$testJava" `
'-Dtest=DidClientLiveTests,CloudRequestEngineLiveTests#build_Process_LicenseKeyAlone*' `
-DfailIfNoTests=false
if ($LASTEXITCODE -ne 0) { exit 1 }
13 changes: 12 additions & 1 deletion .github/workflows/examples-fresh-clone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: Examples from a fresh clone

# Builds each product's console examples as AGENTS.md says, from a clone
# with its submodules, against the packages published on Maven Central, with
# the JDK and Maven the runner has. Then runs the getting started example
# the Maven the runner has on JDK 17, which compiles for Java 8 with no
# warning. Then runs the getting started example
# from the repository root with no settings. A fresh clone holds only a link
# for each free data file. On Ubuntu the example downloads its file, which
# tests the download, and the job keeps the file in the cache. The other
Expand Down Expand Up @@ -52,6 +53,11 @@ jobs:
submodules: recursive
persist-credentials: false

- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'

- name: The runner's Java and Maven
shell: pwsh
run: |
Expand Down Expand Up @@ -126,6 +132,11 @@ jobs:
enableCrossOsArchive: true
fail-on-cache-miss: true

- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '17'

- name: The runner's Java and Maven
shell: pwsh
run: |
Expand Down
9 changes: 5 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ the native engines from `cxx` and does need them, as the README says.
### Prerequisites

- Git.
- A JDK, 8 or later. CI tests 8, 11, 17 and 21 (`ci/options.json`), and
builds and runs the examples on the JDK each runner has (see
[What CI tests](#pitfalls)).
- JDK 17. The examples compile for Java 8 and treat every compiler warning
as an error, and javac 21 and later warn that Java 8 is obsolete. CI
compiles with JDK 17 and runs the tests on JDK 8, 11, 17 and 21
(`ci/options.json`, see [What CI tests](#pitfalls)).
- Maven 3.8 or later, or the `mvnw` wrapper at the root.
- Network access to GitHub, to Maven Central for the packages the examples
use, and to `distributor.51degrees.com` for the data files.
Expand Down Expand Up @@ -251,7 +252,7 @@ and for a list of properties that fails once or every time.
when CI has them. Publish tests them against the packages it has just
built (`ci/run-integration-tests.ps1`).
[examples-fresh-clone.yml](.github/workflows/examples-fresh-clone.yml)
does what [Run the examples](#run-the-examples) says, with the JDK and
does what [Run the examples](#run-the-examples) says, with JDK 17 and the
Maven each runner has. It
builds the console examples against the published packages and runs each
product's `GettingStartedOnPrem` jar from the repository root with no
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,12 @@ longer includes them, because Git leaves a removed submodule's folder on disk.

## Building

You need a JDK (8 or later) and either Maven 3.8 or later or the `mvnw`
wrapper in this folder. The two on-premise engines compile their native
library during the build, which needs CMake 3.10 or later and a C++ toolchain:
You need JDK 17 and either Maven 3.8 or later or the `mvnw` wrapper in this
folder. The build compiles for Java 8 and treats every compiler warning as an
error, and javac 21 and later warn that Java 8 is obsolete, so JDK 17 is the
one to build with. The packages it makes run on Java 8 or later. The two
on-premise engines compile their native library during the build, which needs
CMake 3.10 or later and a C++ toolchain:
Visual Studio with the C++ workload on Windows, GCC or Clang elsewhere.

From this folder:
Expand Down
9 changes: 7 additions & 2 deletions ci/build-package-requirements.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
param(
[Parameter(Mandatory)][string]$RepoName,
[string]$Name
[string]$Name,
# The runner variable naming the entry's JDK. The native modules and those
# they depend on compile with JDK 17 of the same architecture.
[Parameter(Mandatory)][string]$JavaSDKEnvVar
)
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true
Expand All @@ -13,7 +16,9 @@ Write-Host "Entering '$RepoName'"
Push-Location $RepoName
try {
Write-Host "Building '$Name'"
mvn package @MavenOptions -DskipTests -pl ($NativePackages.Path -join ',') -am
Invoke-WithJavaHome (Get-CompileJavaHome $JavaSDKEnvVar) {
mvn package @MavenOptions -DskipTests -pl ($NativePackages.Path -join ',') -am
}
} finally {
Write-Host "Leaving '$RepoName'"
Pop-Location
Expand Down
18 changes: 18 additions & 0 deletions ci/build-package.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ BeforeAll {
Copy-Item -Recurse $PSScriptRoot (Join-Path $Root 'repo' 'ci')
$Script = Join-Path $Root 'repo' 'ci' 'build-package.ps1'
$Given = Join-Path $Root 'given.json'
$JavaHomeSeen = Join-Path $Root 'java-home.txt'

# The JDK the runner has to compile with, under the name the runner gives
# it for its architecture.
$Arch = if ([Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq
[Runtime.InteropServices.Architecture]::Arm64) { 'arm64' } else { 'X64' }
$CompileJdkName = "JAVA_HOME_17_$Arch"
$CompileJdk = Join-Path $Root 'jdk-17'
[Environment]::SetEnvironmentVariable($CompileJdkName, $CompileJdk)
Set-Content (Join-Path $Root 'steps' 'release-plan.ps1') `
'function Get-ReleasePlan([string]$RepoPath) { }'

Expand All @@ -29,6 +38,7 @@ param(
[string[]]$VersionPaths = @('.')
)
$PSBoundParameters | ConvertTo-Json | Set-Content (Join-Path $PWD 'given.json')
Set-Content (Join-Path $PWD 'java-home.txt') $env:JAVA_HOME
$global:LASTEXITCODE = 0
'@

Expand Down Expand Up @@ -56,6 +66,7 @@ $global:LASTEXITCODE = 0
}

AfterAll {
[Environment]::SetEnvironmentVariable($CompileJdkName, $null)
Remove-Item -Recurse -Force $Root
}

Expand Down Expand Up @@ -88,4 +99,11 @@ Describe 'build-package.ps1' {
'-DskipNativeBuild=true', '-pl', 'pipeline/pipeline.core')
$given.VersionPaths | Should -BeNullOrEmpty
}

It 'builds on JDK 17 and puts JAVA_HOME back' {
$javaHome = $env:JAVA_HOME
Invoke-Build
(Get-Content $JavaHomeSeen) | Should -Be $CompileJdk
$env:JAVA_HOME | Should -Be $javaHome
}
}
17 changes: 10 additions & 7 deletions ci/build-package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ $modules = @($plan | ForEach-Object { Get-ModulePath $_ })
# common-ci deploys from the root to a local staging folder with signing, and
# copies the result and the publishing bundle into the package folder. It reads
# the signing keys from the environment of the job that signs. The versions are
# already set, so it is given no folder to set them in.
./java/build-package.ps1 `
-RepoName $RepoName `
-Name $Name `
-Version $Version `
-VersionPaths @() `
-ExtraArgs "-DskipNativeBuild=true", "-pl", ($modules -join ',')
# already set, so it is given no folder to set them in. It compiles with the
# same JDK as every other build.
Invoke-WithJavaHome (Get-CompileJavaHome) {
./java/build-package.ps1 `
-RepoName $RepoName `
-Name $Name `
-Version $Version `
-VersionPaths @() `
-ExtraArgs "-DskipNativeBuild=true", "-pl", ($modules -join ',')
}
$exitCode = $LASTEXITCODE

# Maven Central limits each organisation's release size and file count in a
Expand Down
12 changes: 9 additions & 3 deletions ci/build-project.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
param(
[Parameter(Mandatory)][string]$RepoName,
[string]$Name
[string]$Name,
# The runner variable naming the entry's JDK. The build compiles with JDK
# 17 of the same architecture, whichever JDK the entry tests on.
[Parameter(Mandatory)][string]$JavaSDKEnvVar
)
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true

. "$PSScriptRoot/packages.ps1"

Write-Host "JAVA_HOME: $ENV:JAVA_HOME"
$compileJavaHome = Get-CompileJavaHome $JavaSDKEnvVar
Write-Host "Compiling with $compileJavaHome, testing with $ENV:JAVA_HOME"

# A publish releases a package's dependents only when packages.json names
# them, so a module or dependency it leaves out fails here, before the change
Expand All @@ -24,7 +28,9 @@ if ($gaps.Count -gt 0) {
Push-Location $RepoName
try {
Write-Host "Building $Name..."
mvn install @MavenOptions -DskipTests -Pdev
Invoke-WithJavaHome $compileJavaHome {
mvn install @MavenOptions -DskipTests -Pdev
}
} finally {
Pop-Location
}
127 changes: 127 additions & 0 deletions ci/java-home.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# Pester 5 tests of the helpers in packages.ps1 that make every Maven call
# that compiles run on JDK 17 while the tests run on the entry's own JDK, and
# a check that each script that compiles uses them.

BeforeAll {
. (Join-Path $PSScriptRoot 'packages.ps1')

# The runner variables are set by name here, as the runner sets them.
function Set-RunnerJdk([string]$Name, [string]$Value) {
[Environment]::SetEnvironmentVariable($Name, $Value)
}
$Arch = if ([Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq
[Runtime.InteropServices.Architecture]::Arm64) { 'arm64' } else { 'X64' }
}

Describe 'Get-CompileJavaHome' {
BeforeEach {
Set-RunnerJdk 'JAVA_HOME_17_X64' '/jdk/17-x64'
Set-RunnerJdk 'JAVA_HOME_17_arm64' '/jdk/17-arm64'
}
AfterEach {
Set-RunnerJdk 'JAVA_HOME_17_X64' $null
Set-RunnerJdk 'JAVA_HOME_17_arm64' $null
}

It 'gives JDK 17 for an entry on <Entry>' -ForEach @(
@{ Entry = 'JAVA_HOME_8_X64'; Expected = '/jdk/17-x64' }
@{ Entry = 'JAVA_HOME_11_X64'; Expected = '/jdk/17-x64' }
@{ Entry = 'JAVA_HOME_17_X64'; Expected = '/jdk/17-x64' }
@{ Entry = 'JAVA_HOME_21_X64'; Expected = '/jdk/17-x64' }
@{ Entry = 'JAVA_HOME_11_arm64'; Expected = '/jdk/17-arm64' }
@{ Entry = 'JAVA_HOME_21_arm64'; Expected = '/jdk/17-arm64' }
) {
Get-CompileJavaHome $Entry | Should -Be $Expected
}

It 'gives JDK 17 of the runner architecture with no entry' {
Get-CompileJavaHome | Should -Be "/jdk/17-$($Arch.ToLower())"
}

It 'fails when the runner has no JDK 17' {
Set-RunnerJdk 'JAVA_HOME_17_X64' $null
{ Get-CompileJavaHome 'JAVA_HOME_8_X64' } |
Should -Throw '*JAVA_HOME_17_X64 is not set*'
}

It 'fails on a name that is not a runner JDK variable' {
{ Get-CompileJavaHome 'JAVA_HOME' } |
Should -Throw "*'JAVA_HOME' is not a runner JDK variable*"
}
}

Describe 'Invoke-WithJavaHome' {
It 'runs the block on the JDK given and puts JAVA_HOME and PATH back' {
$javaHome, $path = $env:JAVA_HOME, $env:PATH
$seen = Invoke-WithJavaHome '/jdk/17' {
$env:JAVA_HOME
($env:PATH -split [IO.Path]::PathSeparator)[0]
}
$seen | Should -Be @('/jdk/17', (Join-Path '/jdk/17' 'bin'))
$env:JAVA_HOME | Should -Be $javaHome
$env:PATH | Should -Be $path
}

It 'puts JAVA_HOME and PATH back when the block fails' {
$javaHome, $path = $env:JAVA_HOME, $env:PATH
{ Invoke-WithJavaHome '/jdk/17' { throw 'failed' } } | Should -Throw 'failed'
$env:JAVA_HOME | Should -Be $javaHome
$env:PATH | Should -Be $path
}
}

Describe 'Get-TestJvmArgument' {
It "gives Surefire the java of the entry's JDK" {
$javaHome = $env:JAVA_HOME
try {
$env:JAVA_HOME = '/jdk/8'
$java = Join-Path '/jdk/8' 'bin' "java$(if ($IsWindows) { '.exe' })"
Get-TestJvmArgument | Should -Be "-Djvm=$java"
} finally {
$env:JAVA_HOME = $javaHome
}
}
}

# Every Maven call in a script that compiles is inside a block that runs it on
# the compile JDK, so a new call that compiles on the entry's JDK fails here.
Describe 'Scripts that compile' {
It '<Name> runs every Maven call on the compile JDK' -ForEach @(
@{ Name = 'build-project.ps1' }
@{ Name = 'build-package-requirements.ps1' }
@{ Name = 'build-package.ps1' }
@{ Name = 'run-integration-tests.ps1' }
@{ Name = 'run-performance-tests.ps1' }
) {
$path = Join-Path $PSScriptRoot $Name
$ast = [Management.Automation.Language.Parser]::ParseFile(
$path, [ref]$null, [ref]$null)
$calls = $ast.FindAll({
param($node)
$node -is [Management.Automation.Language.CommandAst] -and
$node.GetCommandName() -in 'mvn', './java/build-package.ps1'
}, $true)
$calls.Count | Should -BeGreaterThan 0
foreach ($call in $calls) {
$inside = $false
for ($node = $call.Parent; $node; $node = $node.Parent) {
if ($node -is [Management.Automation.Language.CommandAst] -and
$node.GetCommandName() -eq 'Invoke-WithJavaHome') {
$inside = $true
break
}
}
$inside | Should -BeTrue -Because "line $($call.Extent.StartLineNumber) of $Name runs Maven"
}
}

It '<Name> takes the entry JDK variable' -ForEach @(
@{ Name = 'build-project.ps1' }
@{ Name = 'build-package-requirements.ps1' }
@{ Name = 'run-integration-tests.ps1' }
@{ Name = 'run-performance-tests.ps1' }
) {
(Get-Command (Join-Path $PSScriptRoot $Name)).Parameters.ContainsKey(
'JavaSDKEnvVar') | Should -BeTrue
}
}
Loading
Loading