diff --git a/.github/workflows/ci-check-no-dist-update.yml b/.github/workflows/ci-check-no-dist-update.yml
index f48a095..302c103 100644
--- a/.github/workflows/ci-check-no-dist-update.yml
+++ b/.github/workflows/ci-check-no-dist-update.yml
@@ -35,6 +35,6 @@ jobs:
done
- run: |
- echo "The 'dist' directory is auotmatically updated by the release process."
+ echo "The 'dist' directory is automatically updated by the release process."
echo "It should not be updated manually in a non-release branch or a pull request."
exit 1
diff --git a/sources/src/caching/gradle-user-home-cache.ts b/sources/src/caching/gradle-user-home-cache.ts
index 48d8fdf..2984090 100644
--- a/sources/src/caching/gradle-user-home-cache.ts
+++ b/sources/src/caching/gradle-user-home-cache.ts
@@ -9,7 +9,7 @@ import {CacheListener} from './cache-reporting'
import {saveCache, restoreCache, cacheDebug, isCacheDebuggingEnabled, tryDelete} from './cache-utils'
import {CacheConfig} from '../configuration'
import {GradleHomeEntryExtractor, ConfigurationCacheEntryExtractor} from './gradle-home-extry-extractor'
-import {getPredefinedToolchains, readResourceFileAsString} from './gradle-user-home-utils'
+import {getPredefinedToolchains, mergeToolchainContent, readResourceFileAsString} from './gradle-user-home-utils'
const RESTORED_CACHE_KEY_KEY = 'restored-cache-key'
@@ -233,8 +233,7 @@ export class GradleUserHomeCache {
} else {
// Merge into an existing toolchains.xml file
const existingToolchainContent = fs.readFileSync(toolchainXmlTarget, 'utf8')
- const appendedContent = preInstalledToolchains.split('').pop()!
- const mergedContent = existingToolchainContent.replace('', appendedContent)
+ const mergedContent = mergeToolchainContent(existingToolchainContent, preInstalledToolchains)
fs.writeFileSync(toolchainXmlTarget, mergedContent)
core.info(`Merged default JDK locations into ${toolchainXmlTarget}`)
diff --git a/sources/src/caching/gradle-user-home-utils.ts b/sources/src/caching/gradle-user-home-utils.ts
index d0ec406..4d38033 100644
--- a/sources/src/caching/gradle-user-home-utils.ts
+++ b/sources/src/caching/gradle-user-home-utils.ts
@@ -42,3 +42,8 @@ export function getPredefinedToolchains(): string | null {
toolchainsXml += `\n`
return toolchainsXml
}
+
+export function mergeToolchainContent(existingToolchainContent: string, preInstalledToolchains: string): string {
+ const appendedContent = preInstalledToolchains.split('').pop()!
+ return existingToolchainContent.replace('', appendedContent)
+}
diff --git a/sources/test/jest/predefined-toolchains.test.ts b/sources/test/jest/predefined-toolchains.test.ts
index 0d8221d..6f88a03 100644
--- a/sources/test/jest/predefined-toolchains.test.ts
+++ b/sources/test/jest/predefined-toolchains.test.ts
@@ -1,4 +1,4 @@
-import {getPredefinedToolchains} from "../../src/caching/gradle-user-home-utils";
+import {getPredefinedToolchains, mergeToolchainContent} from "../../src/caching/gradle-user-home-utils";
describe('predefined-toolchains', () => {
const OLD_ENV = process.env
@@ -62,4 +62,56 @@ describe('predefined-toolchains', () => {
`)
})
})
+
+ it("merges with existing toolchains", async () => {
+ jest.resetModules()
+ process.env = {
+ "JAVA_HOME_11_X64": "/jdks/foo_11",
+ }
+
+ // language=XML
+ const existingToolchains =
+ `
+
+
+ jdk
+
+ 8
+
+
+ \${env.JAVA_HOME_8_X64}
+
+
+
+`
+
+ const mergedContent = mergeToolchainContent(existingToolchains, getPredefinedToolchains()!)
+ expect(mergedContent).toBe(
+ // language=XML
+ `
+
+
+ jdk
+
+ 8
+
+
+ \${env.JAVA_HOME_8_X64}
+
+
+
+
+
+ jdk
+
+ 11
+
+
+ \${env.JAVA_HOME_11_X64}
+
+
+
+
+`)
+ })
})