name.remal.gradle_plugins.toolkit.build_logic.properties.gradle Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of build-logic Show documentation
Show all versions of build-logic Show documentation
Remal Gradle plugins: toolkit: build-logic
import org.gradle.util.GradleVersion
allprojects {
File rootProjectDir = project.rootDir
if (project.isBuildSrcProject) rootProjectDir = rootProjectDir.parentFile
project.ext['rootProjectDir'] = rootProjectDir
if (project.isBuildSrcProject) {
Properties props = new Properties()
File gradlePropertiesFile = new File(rootProjectDir, 'gradle.properties')
if (gradlePropertiesFile.isFile()) {
gradlePropertiesFile.newInputStream().withCloseable { props.load(it) }
}
props.forEach { key, value ->
if (!rootProject.hasProperty(key)) {
rootProject.ext[key] = value
}
}
}
File ciPropertiesFile = new File(rootProjectDir, 'build/gradle-ci.properties')
synchronized (rootProject) {
if (!rootProject.hasProperty('ciProperties')) {
Properties props = new Properties()
rootProject.ext['ciProperties'] = props
if (ciPropertiesFile.isFile()) {
ciPropertiesFile.newInputStream().withCloseable { props.load(it) }
}
}
}
def getCiProperty = { String name, String defaultValue, boolean storeValue = false ->
Properties ciProperties = rootProject.ext['ciProperties']
String value = ciProperties.getProperty(name)
if (value == null) {
value = project.findProperty(name)?.toString()
}
if (value == null) {
value = rootProject.findProperty(name)?.toString()
}
if (value == null) {
value = System.getProperty(name)
}
if (value == null) {
String envName = name.replaceAll(/\W/, '_').toUpperCase(Locale.ROOT)
value = System.getenv(envName)
}
if (value != null) {
if (storeValue) {
ciProperties.setProperty(name, value)
synchronized (rootProject) {
ciPropertiesFile.parentFile.mkdirs()
ciPropertiesFile.newOutputStream().withCloseable { ciProperties.store(it, null) }
}
}
return value
}
return defaultValue
}
if (rootProject.findProperty('isJavaRuntimeVersionSet') == null) {
rootProject.ext.isJavaRuntimeVersionSet = getCiProperty('java-runtime.version', null) != null
}
if (rootProject.findProperty('isGradleApiVersionSet') == null) {
rootProject.ext.isGradleApiVersionSet = getCiProperty('gradle-api.version', null) != null
}
project.ext['java-runtime.version'] = getCiProperty('java-runtime.version', JavaVersion.current().majorVersion)
project.ext['java-runtime.min-version'] = getCiProperty('java-runtime.min-version', JavaVersion.current().majorVersion)
project.ext['gradle-api.version'] = getCiProperty('gradle-api.version', GradleVersion.current().version)
project.ext['gradle-api.min-version'] = getCiProperty('gradle-api.min-version', GradleVersion.current().version)
project.ext.javaRuntimeVersion = JavaVersion.toVersion(project.ext['java-runtime.version'])
project.ext.javaRuntimeMinVersion = JavaVersion.toVersion(project.ext['java-runtime.min-version'])
project.ext.gradleApiVersion = GradleVersion.version(project.ext['gradle-api.version'])
project.ext.gradleApiMinVersion = GradleVersion.version(project.ext['gradle-api.min-version'])
project.ext['git-ref'] = getCiProperty('git-ref', '')
project.ext['git-sha'] = getCiProperty('git-sha', '')
project.ext['github-actions-token'] = getCiProperty('github-actions-token', '')
project.ext['github-actions-run-id'] = getCiProperty('github-actions-run-id', '')
project.ext['github-actions-run-attempt'] = getCiProperty('github-actions-run-attempt', '')
project.ext['github-actions-job'] = getCiProperty('github-actions-job', '')
project.ext['github-actions-job-index'] = getCiProperty('github-actions-job-index', '')
project.ext['disable-compilation'] = getCiProperty('disable-compilation', 'false')
project.ext['disable-tests'] = getCiProperty('disable-tests', 'false')
project.ext['disable-verification'] = getCiProperty('disable-verification', 'false')
project.ext['disable-verification-except-tests'] = getCiProperty('disable-verification-except-tests', 'false')
project.ext['repository-name'] = getCiProperty('repository-name', '', true)
project.ext['repository-full-name'] = getCiProperty('repository-full-name', '', true)
project.ext['repository-api-url'] = getCiProperty('repository-api-url', '', true)
project.ext['repository-html-url'] = getCiProperty('repository-html-url', '', true)
project.ext['repository-description'] = getCiProperty('repository-description', '', true)
project.ext['repository-topics'] = getCiProperty('repository-topics', '', true)
project.ext['repository-is-template'] = getCiProperty('repository-is-template', '', true)
project.ext['repository-owner-name'] = getCiProperty('repository-owner-name', '', true)
project.ext['repository-license-name'] = getCiProperty('repository-license-name', '', true)
project.ext['repository-license-html-url'] = getCiProperty('repository-license-html-url', '', true)
String currentVersion = project.version.toString()
if (currentVersion == 'unspecified') {
project.version = '0-SNAPSHOT'
project.ext['majorVersion'] = '0'
} else if (currentVersion.matches(/^(0|[1-9]\d*)(\D.*)?$/)) {
project.ext['majorVersion'] = currentVersion.replaceFirst(/^(\d+).*/, '$1')
} else {
throw new GradleException("Can't extract major version for version '$currentVersion'")
}
}