Unverified Commit d20d6313 authored by Daz DeBoer's avatar Daz DeBoer
Browse files

Cleanup code to resolve Gradle wrapper script

parent 378bd0b6
Loading
Loading
Loading
Loading
+8 −3
Changes for src/gradlew.ts: 8 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -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)) {
+1 −8
Changes for src/main.ts: 1 added line, 8 removed lines.
Original line number Diff line number Diff line
@@ -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 {