Skip to content

Commit

Permalink
Remove Version Code by Date (#57)
Browse files Browse the repository at this point in the history
The algorithm was wrong and did not work from 2021 and later
  • Loading branch information
moallemi authored May 30, 2021
1 parent e6fb291 commit 424e763
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ package me.moallemi.gradle.advancedbuildversion.gradleextensions
import java.io.File
import java.io.FileInputStream
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date
import java.util.Locale
import java.util.Properties
import me.moallemi.gradle.advancedbuildversion.gradleextensions.VersionCodeType.AUTO_INCREMENT_DATE
import me.moallemi.gradle.advancedbuildversion.gradleextensions.VersionCodeType.AUTO_INCREMENT_ONE_STEP
import me.moallemi.gradle.advancedbuildversion.gradleextensions.VersionCodeType.AUTO_INCREMENT_STEP
import me.moallemi.gradle.advancedbuildversion.gradleextensions.VersionCodeType.DATE
import me.moallemi.gradle.advancedbuildversion.gradleextensions.VersionCodeType.GIT_COMMIT_COUNT
import me.moallemi.gradle.advancedbuildversion.utils.GitWrapper
import org.gradle.api.GradleException
Expand Down Expand Up @@ -65,7 +63,6 @@ class VersionCodeConfig(

val versionCode: Int
get() = lastLegacyCode + when (versionCodeType) {
DATE -> byDate()
AUTO_INCREMENT_ONE_STEP -> byAutoIncrement(1)
AUTO_INCREMENT_STEP -> byAutoIncrement(versionCodeStep)
AUTO_INCREMENT_DATE -> byDateAutoIncrement()
Expand All @@ -87,16 +84,6 @@ class VersionCodeConfig(
}
}

private fun byDate(): Int {
val calendar: Calendar = Calendar.getInstance(Locale.ENGLISH)
val year: Int = (calendar.get(Calendar.YEAR) - 2000) * 100000000
val month: Int = (calendar.get(Calendar.MONTH) + 1) * 1000000
val day: Int = calendar.get(Calendar.DAY_OF_MONTH) * 10000
val hour: Int = calendar.get(Calendar.HOUR_OF_DAY) * 100
val minutes: Int = calendar.get(Calendar.MINUTE)
return year + month + day + hour + minutes
}

private fun byAutoIncrement(step: Int) = if (versionPropsFile.canRead()) {
val versionProps = Properties()
versionProps.load(FileInputStream(versionPropsFile))
Expand All @@ -121,7 +108,6 @@ class VersionCodeConfig(
}

enum class VersionCodeType {
DATE,
@Deprecated(
"AUTO_INCREMENT_ONE_STEP is Deprecated and will be removed in next versions.",
ReplaceWith("AUTO_INCREMENT_STEP", "me.moallemi.gradle.advancedbuildversion.gradleextensions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import me.moallemi.gradle.advancedbuildversion.AdvancedBuildVersionPlugin
import me.moallemi.gradle.advancedbuildversion.AdvancedBuildVersionPlugin.Companion.EXTENSION_NAME
import me.moallemi.gradle.advancedbuildversion.gradleextensions.AdvancedBuildVersionConfig
import me.moallemi.gradle.advancedbuildversion.gradleextensions.VersionCodeType.AUTO_INCREMENT_DATE
import me.moallemi.gradle.advancedbuildversion.gradleextensions.VersionCodeType.DATE
import me.moallemi.gradle.advancedbuildversion.gradleextensions.VersionCodeType.GIT_COMMIT_COUNT
import org.eclipse.jgit.api.Git
import org.gradle.api.Project
Expand All @@ -39,15 +38,6 @@ class VersionCodeConfigTest {
@get:Rule
var testProjectRoot = TemporaryFolder()

@Test
fun `Check versionCodeType = DATE`() {
val advancedVersioning = givenProject()

advancedVersioning.versionCodeConfig.versionCodeType(DATE)

assertThat(advancedVersioning.versionCode, lessThan(MAX_VERSION_CODE))
}

@Test
fun `Check versionCodeType = AUTO_INCREMENT_DATE`() {
val advancedVersioning = givenProject()
Expand Down

0 comments on commit 424e763

Please sign in to comment.