import type { Stats } from 'fs' ; import os from 'os' ; import upath from 'upath' ; import { GlobalConfig } from '../../config/global' ; import { logger } from '../../logger' ; import { chmod } from '../../util/fs' ; import { regEx } from '../../util/regex' ; import gradleVersioning from '../../versioning/gradle' ; import { id as npmVersioning } from '../../versioning/npm' ; import { GradleVersionExtract } from './types' ; export const extraEnv = { GRADLE_OPTS : '-Dorg.gradle.parallel=true -Dorg.gradle.configureondemand=true -Dorg.gradle.daemon=false -Dorg.gradle.caching=false' , } ; export function gradleWrapperFileName ( ) { if ( os . platform ( ) === 'win32' && GlobalConfig . get ( 'binarySource' ) !== 'docker' ) { return 'gradlew.bat' ; } return './gradlew' ; } export async function prepareGradleCommand ( gradlewName , cwd , gradlew , args ) { if ( gradlew ?. isFile ( ) === true ) { if ( ( gradlew . mode & 0o1 ) === 0 ) { await chmod ( upath . join ( cwd , gradlewName ) , gradlew . mode | 0o111 ) ; } if ( args === null ) { return gradlewName ; } return `${ gradlewName } ${ args }` ; } return null ; } param gradleVersion returns export function getJavaContraint ( gradleVersion ) { if ( GlobalConfig . get ( 'binarySource' ) !== 'docker' ) { return null ; } const major = gradleVersioning . getMajor ( gradleVersion ) ; if ( major >= 7 ) { return '^16.0.0' ; } if ( major > 0 && major < 5 ) { return '^8.0.0' ; } return '^11.0.0' ; } export function getJavaVersioning ( ) { return npmVersioning ; } const DISTRIBUTION_URL_REGEX = regEx ( '^(?:distributionUrl\\s*=\\s*)(?<url>\\S*-(?<version>\\d+\\.\\d+(?:\\.\\d+)?(?:-\\w+)*)-(?<type>bin|all)\\.zip)\\s*$' ) ; export function extractGradleVersion ( fileContent ) { const lines = fileContent ?. split ( '\n' ) ?? [ ] ; for ( const line of lines ) { const distributionUrlMatch = DISTRIBUTION_URL_REGEX . exec ( line ) ; if ( distributionUrlMatch ) { return { url : distributionUrlMatch . groups . url , version : distributionUrlMatch . groups . version , } ; } } logger . debug ( 'Gradle wrapper version and url could not be extracted from properties - skipping update' ) ; return null ; }