2021-06-24 19:13:54 +00:00
|
|
|
import * as path from 'path'
|
|
|
|
import fs from 'fs'
|
|
|
|
|
2020-06-13 11:44:30 +00:00
|
|
|
const IS_WINDOWS = process.platform === 'win32'
|
2019-09-23 10:10:49 +00:00
|
|
|
|
2021-09-07 20:38:41 +00:00
|
|
|
export function wrapperScriptFilename(): string {
|
2023-07-16 05:04:38 +00:00
|
|
|
return IS_WINDOWS ? './gradlew.bat' : './gradlew'
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|
|
|
|
|
2019-09-23 10:10:49 +00:00
|
|
|
export function installScriptFilename(): string {
|
2020-06-13 11:44:30 +00:00
|
|
|
return IS_WINDOWS ? 'gradle.bat' : 'gradle'
|
2019-09-21 14:01:53 +00:00
|
|
|
}
|
2021-06-24 19:13:54 +00:00
|
|
|
|
2023-07-13 19:30:34 +00:00
|
|
|
export function gradleWrapperScript(buildRootDirectory: string): string {
|
2021-09-07 20:38:41 +00:00
|
|
|
validateGradleWrapper(buildRootDirectory)
|
2023-07-13 19:30:34 +00:00
|
|
|
return wrapperScriptFilename()
|
2021-09-07 20:38:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function validateGradleWrapper(buildRootDirectory: string): void {
|
2023-07-13 19:30:34 +00:00
|
|
|
const wrapperScript = path.resolve(buildRootDirectory, wrapperScriptFilename())
|
|
|
|
verifyExists(wrapperScript, 'Gradle Wrapper script')
|
|
|
|
verifyIsExecutableScript(wrapperScript)
|
|
|
|
|
2021-10-29 13:34:44 +00:00
|
|
|
const wrapperProperties = path.resolve(buildRootDirectory, 'gradle/wrapper/gradle-wrapper.properties')
|
2023-07-13 19:30:34 +00:00
|
|
|
verifyExists(wrapperProperties, 'Gradle wrapper properties file')
|
|
|
|
}
|
|
|
|
|
|
|
|
function verifyExists(file: string, description: string): void {
|
|
|
|
if (!fs.existsSync(file)) {
|
2021-06-24 19:13:54 +00:00
|
|
|
throw new Error(
|
2023-07-13 19:30:34 +00:00
|
|
|
`Cannot locate ${description} at '${file}'. Specify 'gradle-version' or 'gradle-executable' for projects without Gradle wrapper configured.`
|
2021-06-24 19:13:54 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2023-07-13 19:30:34 +00:00
|
|
|
|
|
|
|
function verifyIsExecutableScript(toExecute: string): void {
|
|
|
|
try {
|
|
|
|
fs.accessSync(toExecute, fs.constants.X_OK)
|
|
|
|
} catch (err) {
|
|
|
|
throw new Error(`Gradle script '${toExecute}' is not executable.`)
|
|
|
|
}
|
|
|
|
}
|