mirror of
https://github.com/gradle/actions
synced 2024-11-27 20:02:19 +00:00
Add a test for merging existing toolchains.xml (#151)
This commit is contained in:
parent
30a2ee13f2
commit
0f427bc07b
4 changed files with 61 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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('<toolchains>').pop()!
|
||||
const mergedContent = existingToolchainContent.replace('</toolchains>', appendedContent)
|
||||
const mergedContent = mergeToolchainContent(existingToolchainContent, preInstalledToolchains)
|
||||
|
||||
fs.writeFileSync(toolchainXmlTarget, mergedContent)
|
||||
core.info(`Merged default JDK locations into ${toolchainXmlTarget}`)
|
||||
|
|
|
@ -42,3 +42,8 @@ export function getPredefinedToolchains(): string | null {
|
|||
toolchainsXml += `</toolchains>\n`
|
||||
return toolchainsXml
|
||||
}
|
||||
|
||||
export function mergeToolchainContent(existingToolchainContent: string, preInstalledToolchains: string): string {
|
||||
const appendedContent = preInstalledToolchains.split('<toolchains>').pop()!
|
||||
return existingToolchainContent.replace('</toolchains>', appendedContent)
|
||||
}
|
||||
|
|
|
@ -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 =
|
||||
`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<toolchains>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>8</version>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>\${env.JAVA_HOME_8_X64}</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>
|
||||
`
|
||||
|
||||
const mergedContent = mergeToolchainContent(existingToolchains, getPredefinedToolchains()!)
|
||||
expect(mergedContent).toBe(
|
||||
// language=XML
|
||||
`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<toolchains>
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>8</version>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>\${env.JAVA_HOME_8_X64}</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
|
||||
<!-- JDK Toolchains installed by default on GitHub-hosted runners -->
|
||||
<toolchain>
|
||||
<type>jdk</type>
|
||||
<provides>
|
||||
<version>11</version>
|
||||
</provides>
|
||||
<configuration>
|
||||
<jdkHome>\${env.JAVA_HOME_11_X64}</jdkHome>
|
||||
</configuration>
|
||||
</toolchain>
|
||||
</toolchains>
|
||||
|
||||
`)
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue