Skip to content

Commit

Permalink
Support for RC version classifier. Close #52
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirosson committed Feb 24, 2023
1 parent 227a09e commit 74c72f5
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 52 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,14 @@ The `maximumPatchVersion` parameter represents the maximum value allowed for the
### Snapshot
The `snapshot` parameter represents whether the version should have the `-SNAPSHOT` classifier or not. By default, all the versions are considered as snapshots, so all the local builds don't interfere with the release builds.

### Alpha
The `alpha` parameter represents whether the version should have the `-ALPHA` classifier or not.

### Beta
The `beta` parameter represents whether the version should have the `-BETA` classifier or not.

### Alpha
The `alpha` parameter represents whether the version should have the `-ALPHA` classifier or not.
### RC
The `rc` parameter represents whether the version should have the `-RC` classifier or not.

### Version Classifier
The `versionClassifier` parameter represents the classifier appended to the version. You can use this property to define a custom version classifier.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ open class SemanticVersionAndroidGradlePlugin : SemanticVersionGradlePlugin() {
semanticVersionConfig.maximumPatchVersion,
semanticVersionConfig.versionClassifier,
semanticVersionConfig.snapshot,
semanticVersionConfig.beta,
semanticVersionConfig.alpha,
semanticVersionConfig.beta,
semanticVersionConfig.rc,
semanticVersionAndroidExtension.versionCodePrefix,
semanticVersionAndroidExtension.minSdkVersionAsVersionCodePrefix,
semanticVersionAndroidExtension.versionCodeExtraBit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ open class SemanticVersionGradlePlugin : Plugin<Project> {
val propertyResolver = project.propertyResolver
val snapshot: Boolean? = propertyResolver.getBooleanProp("snapshot")
val versionClassifier: String? = propertyResolver.getStringProp("versionClassifier")
val beta: Boolean? = propertyResolver.getBooleanProp("beta")
val alpha: Boolean? = propertyResolver.getBooleanProp("alpha")
val beta: Boolean? = propertyResolver.getBooleanProp("beta")
val rc: Boolean? = propertyResolver.getBooleanProp("rc")
// The maximum number the MAJOR, MINOR or PATCH version can achieve. If it is not specified,
// 99 is used for Android projects and 999 for non Android projects
val maximumMajorVersion: Int? = propertyResolver.getIntegerProp("maximumMajorVersion")
val maximumMinorVersion: Int? = propertyResolver.getIntegerProp("maximumMinorVersion")
val maximumPatchVersion: Int? = propertyResolver.getIntegerProp("maximumPatchVersion")

semanticVersionConfig = SemanticVersionConfig(maximumMajorVersion, maximumMinorVersion, maximumPatchVersion, versionClassifier, snapshot, beta, alpha)
semanticVersionConfig = SemanticVersionConfig(maximumMajorVersion, maximumMinorVersion, maximumPatchVersion, versionClassifier, snapshot, alpha, beta, rc)

baseVersion = Version(project.version.toString(), maximumMajorVersion, maximumMinorVersion, maximumPatchVersion).baseVersion
val version = Version(baseVersion, semanticVersionConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class IncrementVersionHelperTest {
null,
null,
null,
null,
null,
FakeGitHelper()
)

Expand All @@ -86,6 +88,8 @@ class IncrementVersionHelperTest {
null,
null,
null,
null,
null,
FakeGitHelper()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ open class SemanticVersionConfig(
var maximumPatchVersion: Int? = null,
var versionClassifier: String? = null,
var snapshot: Boolean? = null,
var alpha: Boolean? = null,
var beta: Boolean? = null,
var alpha: Boolean? = null
var rc: Boolean? = null
)

// var featureBranchPrefix: String? = propertyResolver.getStringProp(::featureBranchPrefix.name)
Expand Down
73 changes: 49 additions & 24 deletions semantic-version/src/main/java/com/semanticversion/Version.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ open class Version {
companion object {
const val VERSION_CLASSIFIER_SEPARATOR = "-"
const val SNAPSHOT_CLASSIFIER = "SNAPSHOT"
const val BETA_CLASSIFIER = "BETA"
const val ALPHA_CLASSIFIER = "ALPHA"
const val BETA_CLASSIFIER = "BETA"
const val RC_CLASSIFIER = "RC"
const val BASE_VERSION_SEPARATOR = "."
// const val LOCAL_CLASSIFIER = "LOCAL"
// const val VERSION_TIMESTAMP_FORMAT = "YYYYMMddHHmmss"
Expand All @@ -17,8 +18,9 @@ open class Version {
var versionPatch: Int? = null
var versionClassifier: String? = null
var isSnapshot: Boolean = true
var isBeta: Boolean = false
var isAlpha: Boolean = false
var isBeta: Boolean = false
var isRc: Boolean = false

// TODO Add support to this
// var isVersionTimestampEnabled: Boolean = false
Expand Down Expand Up @@ -109,32 +111,45 @@ open class Version {
// versionClassifier += format(now(), VERSION_TIMESTAMP_FORMAT)
// }

if (config.snapshot == true || config.snapshot == null) {
versionClassifier = SNAPSHOT_CLASSIFIER

isSnapshot = true
isAlpha = false
isBeta = false
isRc = false
} else {
isSnapshot = false
isAlpha = false
isBeta = false
isRc = false
}

if (config.alpha == true) {
versionClassifier = ALPHA_CLASSIFIER

isSnapshot = false
isAlpha = true
isBeta = false
isRc = false
}

if (config.beta == true) {
versionClassifier = BETA_CLASSIFIER

isSnapshot = false
} else {
if (config.beta == true) {
versionClassifier = BETA_CLASSIFIER

isAlpha = false
isBeta = true
isSnapshot = false
} else {
if (config.snapshot == true || config.snapshot == null) {
versionClassifier = SNAPSHOT_CLASSIFIER

isAlpha = false
isBeta = false
isSnapshot = true
} else {
isAlpha = false
isBeta = false
isSnapshot = false
}
}
isAlpha = false
isBeta = true
isRc = false
}

if (config.rc == true) {
versionClassifier = RC_CLASSIFIER

isSnapshot = false
isAlpha = false
isBeta = false
isRc = true
}
} else {
parseVersionClassifier(versionClassifier!!)
Expand All @@ -145,25 +160,35 @@ open class Version {

private fun parseVersionClassifier(versionClassifier: String) {
when (versionClassifier) {
SNAPSHOT_CLASSIFIER -> {
isSnapshot = true
isBeta = false
isAlpha = false
isRc = false
}
ALPHA_CLASSIFIER -> {
isSnapshot = false
isBeta = false
isAlpha = true
isRc = false
}
BETA_CLASSIFIER -> {
isSnapshot = false
isBeta = true
isAlpha = false
isRc = false
}
SNAPSHOT_CLASSIFIER -> {
isSnapshot = true
RC_CLASSIFIER -> {
isSnapshot = false
isBeta = false
isAlpha = false
isRc = true
}
else -> {
isSnapshot = false
isBeta = false
isAlpha = false
isRc = false
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class AndroidSemanticVersionConfig(
snapshot: Boolean? = null,
beta: Boolean? = null,
alpha: Boolean? = null,
rc: Boolean? = null,
var versionCodePrefix: Int?,
var minSdkVersionAsVersionCodePrefix: Boolean,
var versionCodeExtraBit: Int,
var minSdkVersion: Int
) : SemanticVersionConfig(maximumMajorVersion, maximumMinorVersion, maximumPatchVersion, versionClassifier, snapshot, beta, alpha)
) : SemanticVersionConfig(maximumMajorVersion, maximumMinorVersion, maximumPatchVersion, versionClassifier, snapshot, alpha, beta, rc)
Loading

0 comments on commit 74c72f5

Please # to comment.