From d20d631365e279829af55017377945cf57ffc36d Mon Sep 17 00:00:00 2001 From: Daz DeBoer Date: Tue, 7 Sep 2021 14:38:41 -0600 Subject: [PATCH] Cleanup code to resolve Gradle wrapper script --- src/gradlew.ts | 11 ++++++++--- src/main.ts | 9 +-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/gradlew.ts b/src/gradlew.ts index d9c0c58..69815c7 100644 --- a/src/gradlew.ts +++ b/src/gradlew.ts @@ -3,7 +3,7 @@ import fs from 'fs' const IS_WINDOWS = process.platform === 'win32' -export function wrapperFilename(): string { +export function wrapperScriptFilename(): string { return IS_WINDOWS ? 'gradlew.bat' : 'gradlew' } @@ -11,9 +11,14 @@ export function installScriptFilename(): string { return IS_WINDOWS ? 'gradle.bat' : 'gradle' } -export function validateGradleWrapper(gradlewDirectory: string): void { +export function locateGradleWrapperScript(buildRootDirectory: string): string { + validateGradleWrapper(buildRootDirectory) + return path.resolve(buildRootDirectory, wrapperScriptFilename()) +} + +function validateGradleWrapper(buildRootDirectory: string): void { const wrapperProperties = path.resolve( - gradlewDirectory, + buildRootDirectory, 'gradle/wrapper/gradle-wrapper.properties' ) if (!fs.existsSync(wrapperProperties)) { diff --git a/src/main.ts b/src/main.ts index bfa159f..a910b5e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -59,14 +59,7 @@ async function resolveGradleExecutable( return path.resolve(workspaceDirectory, gradleExecutable) } - const wrapperDirectory = core.getInput('wrapper-directory') - const gradlewDirectory = - wrapperDirectory !== '' - ? path.resolve(workspaceDirectory, wrapperDirectory) - : buildRootDirectory - - gradlew.validateGradleWrapper(gradlewDirectory) - return path.resolve(gradlewDirectory, gradlew.wrapperFilename()) + return gradlew.locateGradleWrapperScript(buildRootDirectory) } function resolveBuildRootDirectory(baseDirectory: string): string {