Skip to content

Commit

Permalink
Make version computation lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
Virtlink committed Jul 19, 2024
1 parent 255b081 commit b9eb229
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project are documented in this file, based on [Keep
## [Unreleased]


## [1.7.2] - 2024-07-19
- Version computation is now lazy. Only assign the version to the project after configuring Gitonium.


## [1.7.1] - 2024-07-17
- No changes.


## [1.7.0] - 2024-07-16
- *Breaking*: The version must be explicitly set (if configuring Gitonium, set the version after configuring Gitonium):
```kotlin
Expand Down Expand Up @@ -103,7 +111,9 @@ All notable changes to this project are documented in this file, based on [Keep
- `Project.DEFAULT_VERSION` (`"unspecified"`) is assigned as version if no Git repository is found, instead of failing.
[Unreleased]: https://github.com/metaborg/gitonium/compare/release-1.7.0...HEAD
[Unreleased]: https://github.com/metaborg/gitonium/compare/release-1.7.2...HEAD
[1.7.2]: https://github.com/metaborg/gitonium/compare/release-1.7.1...release-1.7.2
[1.7.1]: https://github.com/metaborg/gitonium/compare/release-1.7.0...release-1.7.1
[1.7.0]: https://github.com/metaborg/gitonium/compare/release-1.6.2...release-1.7.0
[1.6.2]: https://github.com/metaborg/gitonium/compare/release-1.6.1...release-1.6.2
[1.6.1]: https://github.com/metaborg/gitonium/compare/release-1.6.0...release-1.6.1
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/mb/gitonium/CheckSnapshotDependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ open class CheckSnapshotDependencies @Inject constructor(
append("Project '")
append(project.path)
append("' will be published as a release under version '")
append(extension.version)
append(project.version)
append("', but has the following SNAPSHOT dependencies: ")
snapshotDependencies.forEach {
append("\n- ")
Expand Down
36 changes: 20 additions & 16 deletions src/main/kotlin/mb/gitonium/GitoniumExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,21 @@ open class GitoniumExtension @Inject constructor(
.convention(true)

/** The version info, determined lazily. */
val versionInfo: GitoniumVersion get() = GitoniumVersion.determineVersion(
project.rootDir,
tagPrefix.get(),
dirtySuffix.get(),
snapshotMajorIncrease.get(),
snapshotMinorIncrease.get(),
snapshotPatchIncrease.get(),
snapshotSuffix.get(),
snapshotIncludeBranch.get(),
firstParentOnly.get(),
alwaysSnapshotVersion.get() || (project.providers.gradleProperty("gitonium.isSnapshot").getOrNull()?.toBoolean() ?: false),
mainBranch.getOrNull(),
)
val versionInfo: GitoniumVersion by lazy {
GitoniumVersion.determineVersion(
project.rootDir,
tagPrefix.get(),
dirtySuffix.get(),
snapshotMajorIncrease.get(),
snapshotMinorIncrease.get(),
snapshotPatchIncrease.get(),
snapshotSuffix.get(),
snapshotIncludeBranch.get(),
firstParentOnly.get(),
alwaysSnapshotVersion.get() || (project.providers.gradleProperty("gitonium.isSnapshot").getOrNull()?.toBoolean() ?: false),
mainBranch.getOrNull(),
)
}

/**
* The computed version string.
Expand All @@ -93,9 +95,11 @@ open class GitoniumExtension @Inject constructor(
* and `-SNAPSHOT` as the suffix (e.g., `"1.0.1-develop-SNAPSHOT"`).
* If the repository is dirty, the version is suffixed with `+dirty` (e.g., `"1.0.1-SNAPSHOT+dirty"`).
*/
val version: String get() = versionInfo.versionString ?: run {
LOG.warn("Gitonium could not determine version from Git repository, using default version.")
Project.DEFAULT_VERSION
val version: String by lazy {
versionInfo.versionString ?: run {
LOG.warn("Gitonium could not determine version from Git repository, using default version.")
Project.DEFAULT_VERSION
}
}

/** Whether the current commit has a release version tag. */
Expand Down

0 comments on commit b9eb229

Please sign in to comment.