Copy the raw JDK path into toolchains.xml

Previously we were relying on Gradle to substitute JDK environment variables
in toolchains.xml. With this change, the actual path to the JDK is encoded instead.
This should avoid issues where Gradle is not able to successfully resolve the
envioronment variable.
This commit is contained in:
daz 2025-01-18 10:30:15 -07:00
parent 392620bad1
commit faf1d7ca7a
No known key found for this signature in database
2 changed files with 11 additions and 9 deletions

View file

@ -16,9 +16,9 @@ export function getPredefinedToolchains(): string | null {
// Get the version and path for each JAVA_HOME env var
const javaHomeEnvs = Object.entries(process.env)
.filter(([key]) => key.startsWith('JAVA_HOME_') && process.env[key])
.map(([key, _value]) => ({
.map(([key, value]) => ({
jdkVersion: key.match(/JAVA_HOME_(\d+)_/)?.[1] ?? null,
jdkPath: `\${env.${key}}`
jdkPath: value as string
}))
.filter(env => env.jdkVersion !== null)
@ -40,7 +40,9 @@ ${javaHomeEnvs
<configuration>
<jdkHome>${jdkPath}</jdkHome>
</configuration>
</toolchain>`).join('\n')}
</toolchain>`
)
.join('\n')}
</toolchains>\n`
}

View file

@ -39,7 +39,7 @@ describe('predefined-toolchains', () => {
<version>8</version>
</provides>
<configuration>
<jdkHome>\${env.JAVA_HOME_8_X64}</jdkHome>
<jdkHome>/jdks/foo_8</jdkHome>
</configuration>
</toolchain>
<toolchain>
@ -48,7 +48,7 @@ describe('predefined-toolchains', () => {
<version>11</version>
</provides>
<configuration>
<jdkHome>\${env.JAVA_HOME_11_X64}</jdkHome>
<jdkHome>/jdks/foo_11</jdkHome>
</configuration>
</toolchain>
<toolchain>
@ -57,7 +57,7 @@ describe('predefined-toolchains', () => {
<version>21</version>
</provides>
<configuration>
<jdkHome>\${env.JAVA_HOME_21_ARM64}</jdkHome>
<jdkHome>/jdks/foo_21</jdkHome>
</configuration>
</toolchain>
</toolchains>
@ -81,7 +81,7 @@ describe('predefined-toolchains', () => {
<version>8</version>
</provides>
<configuration>
<jdkHome>\${env.JAVA_HOME_8_X64}</jdkHome>
<jdkHome>/jdks/foo_8</jdkHome>
</configuration>
</toolchain>
</toolchains>
@ -98,7 +98,7 @@ describe('predefined-toolchains', () => {
<version>8</version>
</provides>
<configuration>
<jdkHome>\${env.JAVA_HOME_8_X64}</jdkHome>
<jdkHome>/jdks/foo_8</jdkHome>
</configuration>
</toolchain>
@ -109,7 +109,7 @@ describe('predefined-toolchains', () => {
<version>11</version>
</provides>
<configuration>
<jdkHome>\${env.JAVA_HOME_11_X64}</jdkHome>
<jdkHome>/jdks/foo_11</jdkHome>
</configuration>
</toolchain>
</toolchains>