Cleanup code to resolve Gradle wrapper script

This commit is contained in:
Daz DeBoer 2021-09-07 14:38:41 -06:00
parent 378bd0b6f8
commit d20d631365
No known key found for this signature in database
GPG key ID: DD6B9F0B06683D5D
2 changed files with 9 additions and 11 deletions

View file

@ -3,7 +3,7 @@ import fs from 'fs'
const IS_WINDOWS = process.platform === 'win32' const IS_WINDOWS = process.platform === 'win32'
export function wrapperFilename(): string { export function wrapperScriptFilename(): string {
return IS_WINDOWS ? 'gradlew.bat' : 'gradlew' return IS_WINDOWS ? 'gradlew.bat' : 'gradlew'
} }
@ -11,9 +11,14 @@ export function installScriptFilename(): string {
return IS_WINDOWS ? 'gradle.bat' : 'gradle' 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( const wrapperProperties = path.resolve(
gradlewDirectory, buildRootDirectory,
'gradle/wrapper/gradle-wrapper.properties' 'gradle/wrapper/gradle-wrapper.properties'
) )
if (!fs.existsSync(wrapperProperties)) { if (!fs.existsSync(wrapperProperties)) {

View file

@ -59,14 +59,7 @@ async function resolveGradleExecutable(
return path.resolve(workspaceDirectory, gradleExecutable) return path.resolve(workspaceDirectory, gradleExecutable)
} }
const wrapperDirectory = core.getInput('wrapper-directory') return gradlew.locateGradleWrapperScript(buildRootDirectory)
const gradlewDirectory =
wrapperDirectory !== ''
? path.resolve(workspaceDirectory, wrapperDirectory)
: buildRootDirectory
gradlew.validateGradleWrapper(gradlewDirectory)
return path.resolve(gradlewDirectory, gradlew.wrapperFilename())
} }
function resolveBuildRootDirectory(baseDirectory: string): string { function resolveBuildRootDirectory(baseDirectory: string): string {