Skip to content

Commit

Permalink
Merge into existing toolchains.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz committed Jan 4, 2024
1 parent 76f88a5 commit 13f7591
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/cache-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,27 @@ export class GradleStateCache {
fs.writeFileSync(initScriptPath, initScriptContent)
}

// Copy the toolchain definitions file to `~/.m2/toolchains.xml` (if the file doesn't already exist)
// Copy the default toolchain definitions to `~/.m2/toolchains.xml`
const toolchainContent = this.readResourceFileAsString('toolchains.xml')
const m2dir = path.resolve(this.userHome, '.m2')
const toolchainXmlTarget = path.resolve(m2dir, 'toolchains.xml')
if (!fs.existsSync(toolchainXmlTarget)) {
// Write a new toolchains.xml file if it doesn't exist
fs.mkdirSync(m2dir, {recursive: true})
const toolchainContent = this.readResourceFileAsString('toolchains.xml')
fs.writeFileSync(toolchainXmlTarget, toolchainContent)

core.info(`Wrote default JDK locations to ${toolchainXmlTarget}`)
} else {
// Merge into an existing toolchains.xml file
const existingToolchainContent = fs.readFileSync(toolchainXmlTarget, 'utf8')
const appendedContent = toolchainContent.split("<toolchains>").pop()!
const mergedContent = existingToolchainContent.replace('</toolchains>', appendedContent)

core.info(`Merged toolchains.xml`)
core.info(mergedContent)

fs.writeFileSync(mergedContent, toolchainXmlTarget)
core.info(`Merged default JDK locations into ${toolchainXmlTarget}`)
}
}

Expand Down

0 comments on commit 13f7591

Please sign in to comment.