From b0c29bffb74bc43b49e424138eff02951e484e12 Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Sat, 27 Nov 2021 16:07:07 -0700 Subject: [PATCH] Use a properties file to disable daemon execution Instead of passing `--no-daemon` on the command line, the same functionality is now acheived by writing a gradle.properties file when initializing Gradle User Home. --- src/cache-base.ts | 5 ++++- src/cache-gradle-user-home.ts | 12 ++++++++++++ src/execution.ts | 3 --- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/cache-base.ts b/src/cache-base.ts index 1a1f183..be07516 100644 --- a/src/cache-base.ts +++ b/src/cache-base.ts @@ -146,7 +146,8 @@ export abstract class AbstractCache { const cacheResult = await this.restoreCache(this.getCachePath(), cacheKey.key, cacheKey.restoreKeys) if (!cacheResult) { - core.info(`${this.cacheDescription} cache not found. Will start with empty.`) + core.info(`${this.cacheDescription} cache not found. Will initialize empty.`) + await this.initializeState() return } @@ -181,6 +182,8 @@ export abstract class AbstractCache { } } + protected async initializeState(): Promise {} + protected async afterRestore(_listener: CacheListener): Promise {} async save(listener: CacheListener): Promise { diff --git a/src/cache-gradle-user-home.ts b/src/cache-gradle-user-home.ts index 3cd65ff..74a94c7 100644 --- a/src/cache-gradle-user-home.ts +++ b/src/cache-gradle-user-home.ts @@ -22,6 +22,18 @@ export class GradleUserHomeCache extends AbstractCache { this.gradleUserHome = this.determineGradleUserHome(rootDir) } + async initializeState(): Promise { + this.initializeGradleUserHome(this.gradleUserHome) + } + + private initializeGradleUserHome(gradleUserHome: string): void { + fs.mkdirSync(gradleUserHome, {recursive: true}) + + const propertiesFile = path.resolve(gradleUserHome, 'gradle.properties') + this.debug(`Initializing gradle.properties to disable daemon: ${propertiesFile}`) + fs.writeFileSync(propertiesFile, 'org.gradle.daemon=false') + } + async afterRestore(listener: CacheListener): Promise { await this.reportGradleUserHomeSize('as restored from cache') await this.restoreArtifactBundles(listener) diff --git a/src/execution.ts b/src/execution.ts index c28abc1..fd8097d 100644 --- a/src/execution.ts +++ b/src/execution.ts @@ -6,9 +6,6 @@ import {writeInitScript} from './build-scan-capture' export async function execute(executable: string, root: string, args: string[]): Promise { let buildScanUrl: string | undefined - // TODO: instead of running with no-daemon, run `--stop` in post action. - args.push('--no-daemon') - const initScript = writeInitScript() args.push('--init-script') args.push(initScript)