fix(gradle-plugin): invalid build version name in AndroidIDEBuildInfo

This commit is contained in:
Akash Yadav
2023-04-13 18:25:22 +05:30
parent c4b60c662d
commit d10fd0fa11
3 changed files with 79 additions and 61 deletions
+78 -22
View File
@@ -15,38 +15,94 @@
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* @author Akash Yadav
*/
import org.gradle.api.Project
/** @author Akash Yadav */
object ProjectConfig {
/**
* The GitHub organization for this project.
*/
/** The GitHub organization for this project. */
const val GITHUB_ORGANIZATION = "AndroidIDEOfficial"
/**
* The GitHub repsitory for this project.
*/
/** The GitHub repsitory for this project. */
const val GITHUB_REPOSITORY = "AndroidIDE"
/**
* The GitHub repository URL for this project.
*/
/** The GitHub repository URL for this project. */
const val GITHUB_URL = "https://github.com/${GITHUB_ORGANIZATION}/${GITHUB_REPOSITORY}"
/**
* The Project website.
*/
/** The Project website. */
const val PROJECT_SITE = "https://androidide.com"
/**
* The GIT SCM URL.
*/
/** The GIT SCM URL. */
const val SCM_GIT = "scm:git:git://github.com/${GITHUB_ORGANIZATION}/${GITHUB_REPOSITORY}.git"
/**
* The SSH SCM URL.
*/
/** The SSH SCM URL. */
const val SCM_SSH = "scm:git:ssh://git@github.com/${GITHUB_ORGANIZATION}/${GITHUB_REPOSITORY}.git"
}
}
private var simpleVersion: String? = null
val Project.simpleVersionName: String
get() {
if (simpleVersion != null) {
return simpleVersion!!
}
val version = rootProject.version.toString()
val regex = Regex("^v\\d+\\.?\\d+\\.?\\d+-\\w+")
simpleVersion =
regex.find(version)?.value?.substring(1)?.also {
logger.warn("Simple version name is '$it' (from version $version)")
}
if (simpleVersion == null) {
if (CI.isTestEnv) {
return "1.0.0-beta"
}
throw IllegalStateException(
"Cannot extract simple version name. Invalid version string '$version'. Version names must be SEMVER with 'v' prefix"
)
}
return simpleVersion!!
}
private var versionCode: Int? = null
val Project.projectVersionCode: Int
get() {
if (versionCode != null) {
return versionCode!!
}
val version = simpleVersionName
val regex = Regex("^\\d+\\.?\\d+\\.?\\d+")
versionCode =
regex.find(version)?.value?.replace(".", "")?.toInt()?.also {
logger.warn("Version code is '$it' (from version ${version}).")
}
if (versionCode == null) {
throw IllegalStateException(
"Cannot extract version code. Invalid version string '$version'. Version names must be SEMVER with 'v' prefix"
)
}
return versionCode!!
}
private var publishing: String? = null
val Project.publishingVersion: String
get() {
if (publishing != null) {
return publishing!!
}
publishing = simpleVersionName
if (CI.isCiBuild && CI.branchName != "main") {
publishing += "-${CI.commitHash}-SNAPSHOT"
}
return publishing!!
}
-38
View File
@@ -44,44 +44,6 @@ buildscript {
}
}
val Project.simpleVersionName: String by lazy {
val version = rootProject.version.toString()
val regex = Regex("^v\\d+\\.?\\d+\\.?\\d+-\\w+")
return@lazy regex.find(version)?.value?.substring(1)?.also {
logger.warn("Simple version name is '$it' (from version $version)")
}
?: run {
if (CI.isTestEnv) {
return@run "1.0.0-beta"
}
throw IllegalStateException(
"Cannot extract simple version name. Invalid version string '$version'. Version names must be SEMVER with 'v' prefix"
)
}
}
val Project.projectVersionCode: Int by lazy {
val version = simpleVersionName
val regex = Regex("^\\d+\\.?\\d+\\.?\\d+")
return@lazy regex.find(version)?.value?.replace(".", "")?.toInt()?.also {
logger.warn("Version code is '$it' (from version ${version}).")
}
?: throw IllegalStateException(
"Cannot extract version code. Invalid version string '$version'. Version names must be SEMVER with 'v' prefix"
)
}
val Project.publishingVersion by lazy {
var version = simpleVersionName
if (CI.isCiBuild && CI.branchName != "main") {
version += "-${CI.commitHash}-SNAPSHOT"
}
return@lazy version
}
fun Project.configureBaseExtension() {
extensions.findByType(BaseExtension::class)?.run {
compileSdkVersion(BuildConfig.compileSdk)
+1 -1
View File
@@ -32,7 +32,7 @@ tasks.create("generateBuildInfo") {
.file(buildInfoFileIn)
.replaceContents(
dest = project.file(buildInfoFile),
candidates = arrayOf("@@BUILD_VERSION@@" to project.version.toString())
candidates = arrayOf("@@BUILD_VERSION@@" to project.publishingVersion)
)
}