add info extension
This commit is contained in:
@@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
The GitExtension enhances versioning by dynamically appending the Git hash before "snapshot" in the version string. For example, 0.0.0-SNAPSHOT becomes 0.0.0.0a2b3c4d-SNAPSHOT, ensuring each build reflects its commit origin, prevents overwriting existing versions. This feature aids developers during development by providing clear version identification.
|
The GitExtension enhances versioning by dynamically appending the Git hash before "snapshot" in the version string. For example, 0.0.0-SNAPSHOT becomes 0.0.0.0a2b3c4d-SNAPSHOT, ensuring each build reflects its commit origin, prevents overwriting existing versions. This feature aids developers during development by providing clear version identification.
|
||||||
|
|
||||||
|
### Extension Info.
|
||||||
|
|
||||||
|
The InfoExtension provides information for name and version, vendor name, and UTC timestamp.
|
||||||
|
|
||||||
## Releasing gradle plugin locally.
|
## Releasing gradle plugin locally.
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package ltd.lulz.plugin
|
package ltd.lulz.plugin
|
||||||
|
|
||||||
import ltd.lulz.plugin.extension.GitExtension
|
import ltd.lulz.plugin.extension.GitExtension
|
||||||
|
import ltd.lulz.plugin.extension.InfoExtension
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import ltd.lulz.plugin.extension.GitExtension.Companion.PLUGIN_NAME as GIT_PLUGIN_NAME
|
import ltd.lulz.plugin.extension.GitExtension.Companion.PLUGIN_NAME as GIT_PLUGIN_NAME
|
||||||
|
import ltd.lulz.plugin.extension.InfoExtension.Companion.PLUGIN_NAME as INFO_PLUGIN_NAME
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
class CorePlugin : Plugin<Project> {
|
class CorePlugin : Plugin<Project> {
|
||||||
@@ -15,8 +17,14 @@ class CorePlugin : Plugin<Project> {
|
|||||||
project: Project,
|
project: Project,
|
||||||
) {
|
) {
|
||||||
gitExtension(project)
|
gitExtension(project)
|
||||||
|
infoExtension(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun infoExtension(
|
||||||
|
project: Project,
|
||||||
|
): InfoExtension = project.extensions
|
||||||
|
.create(INFO_PLUGIN_NAME, InfoExtension::class.java, project)
|
||||||
|
|
||||||
private fun gitExtension(
|
private fun gitExtension(
|
||||||
project: Project,
|
project: Project,
|
||||||
): GitExtension = project.extensions
|
): GitExtension = project.extensions
|
||||||
|
|||||||
16
src/main/kotlin/ltd/lulz/plugin/extension/InfoExtension.kt
Normal file
16
src/main/kotlin/ltd/lulz/plugin/extension/InfoExtension.kt
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package ltd.lulz.plugin.extension
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime.now
|
||||||
|
import java.time.ZoneId.of
|
||||||
|
import java.time.format.DateTimeFormatter.ofPattern
|
||||||
|
import org.gradle.api.Project
|
||||||
|
|
||||||
|
abstract class InfoExtension(private val project: Project) {
|
||||||
|
companion object {
|
||||||
|
const val PLUGIN_NAME = "info"
|
||||||
|
}
|
||||||
|
|
||||||
|
val nameVersion get() = "Project Name: ${project.name} Version: ${project.version}"
|
||||||
|
val utcTimestamp = now().atZoneSameInstant(of("UTC")).format(ofPattern("yyyy-MM-dd HH:mm:ss z")).toString()
|
||||||
|
val vendorName = "Lulz Ltd"
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package ltd.lulz.plugin.extension
|
||||||
|
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.mockkStatic
|
||||||
|
import io.mockk.unmockkStatic
|
||||||
|
import java.time.OffsetDateTime
|
||||||
|
import org.gradle.api.Project
|
||||||
|
import org.gradle.testfixtures.ProjectBuilder
|
||||||
|
import org.junit.jupiter.api.AfterAll
|
||||||
|
import org.junit.jupiter.api.Assertions.assertEquals
|
||||||
|
import org.junit.jupiter.api.BeforeAll
|
||||||
|
import org.junit.jupiter.api.BeforeEach
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
|
class InfoExtensionTest {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val BASIC_TIMESTAMP = "2002-02-20T02:10:11+01:00"
|
||||||
|
const val EXTENSION = "info"
|
||||||
|
const val PLUGIN_ID = "ltd.lulz.plugin.core-plugin"
|
||||||
|
const val PROJECT_NAME = "test-project"
|
||||||
|
const val SNAPSHOT_VERSION = "0.0.0-SNAPSHOT"
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@BeforeAll
|
||||||
|
fun buildUp() {
|
||||||
|
mockkStatic(OffsetDateTime::class)
|
||||||
|
every { OffsetDateTime.now() } returns OffsetDateTime.parse(BASIC_TIMESTAMP)
|
||||||
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@AfterAll
|
||||||
|
fun tearDown() {
|
||||||
|
unmockkStatic(OffsetDateTime::class)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lateinit var project: Project
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
fun beforeEach() {
|
||||||
|
project = ProjectBuilder.builder().withName(PROJECT_NAME).build()
|
||||||
|
project.version = SNAPSHOT_VERSION
|
||||||
|
project.pluginManager.apply(PLUGIN_ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `get vendor`() {
|
||||||
|
// when
|
||||||
|
val extension = project.extensions.getByName(EXTENSION) as InfoExtension
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertEquals("Lulz Ltd", extension.vendorName)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `get timestamp`() {
|
||||||
|
// when
|
||||||
|
val extension = project.extensions.getByName(EXTENSION) as InfoExtension
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertEquals("2002-02-20 01:10:11 UTC", extension.utcTimestamp)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `get build`() {
|
||||||
|
// when
|
||||||
|
val extension = project.extensions.getByName(EXTENSION) as InfoExtension
|
||||||
|
|
||||||
|
// then
|
||||||
|
assertEquals("Project Name: test-project Version: 0.0.0-SNAPSHOT", extension.nameVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user