Skip to content

Commit

Permalink
Only write toolchains.xml if it doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
bigdaz committed Jan 4, 2024
1 parent e878422 commit 915b7c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
24 changes: 7 additions & 17 deletions src/cache-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,26 +204,16 @@ export class GradleStateCache {
fs.writeFileSync(initScriptPath, initScriptContent)
}

// Copy the toolchains.xml file to `~/.m2`
// Copy the toolchain definitions file to `~/.m2/toolchains.xml` (if the file doesn't already exist)
const m2dir = path.resolve(this.userHome, '.m2')
fs.mkdirSync(m2dir, {recursive: true})
core.info(`Created m2 directory ${m2dir}`)

const settingsXml = path.resolve(m2dir, 'settings.xml')
if (fs.existsSync(settingsXml)) {
const existingSettings = fs.readFileSync(settingsXml, 'utf8')
core.info("Found existing settings.xml with content:")
core.info(existingSettings)
}

const toolchainXmlTarget = path.resolve(m2dir, 'toolchains.xml')
if (fs.existsSync(toolchainXmlTarget)) {
const existingToolchains = fs.readFileSync(toolchainXmlTarget, 'utf8')
core.info("Found existing toolchains.xml with content:")
core.info(existingToolchains)
if (!fs.existsSync(toolchainXmlTarget)) {
fs.mkdirSync(m2dir, {recursive: true})
const toolchainContent = this.readInitScriptAsString('toolchains.xml')
fs.writeFileSync(toolchainXmlTarget, toolchainContent)

core.info(`Wrote default JDK locations to ${toolchainXmlTarget}`)
}
const toolchainContent = this.readInitScriptAsString('toolchains.xml')
fs.writeFileSync(toolchainXmlTarget, toolchainContent)
}

private readInitScriptAsString(resource: string): string {
Expand Down
2 changes: 1 addition & 1 deletion src/resources/init-scripts/toolchains.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- JDK Toolchains installed by default on GitHub-hosted runners -->
<toolchains>
<!-- JDK Toolchains installed by default on GitHub-hosted runners -->
<toolchain>
<type>jdk</type>
<provides>
Expand Down

0 comments on commit 915b7c5

Please sign in to comment.