diff --git a/docs/changelog.md b/docs/changelog.md
index 8b964861..90ee5846 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -23,6 +23,9 @@
# Changelog
+## 1.0.3
+* Minor issues fixed
+
## 1.0.2
* Add postgres database support
* Upgrade gradle version to `8.9`
diff --git a/docs/getting-report.md b/docs/getting-report.md
index ee552f28..1bd7cbe4 100644
--- a/docs/getting-report.md
+++ b/docs/getting-report.md
@@ -26,7 +26,7 @@ Gradle Analytics Plugin uses daily basis data to generate reports. So you could
Execute Gradle Task
```Gradle
-./gradlew reportAnalytics --task="REQUESTED_TASK" --branch="BRANCH_NAME" --period="can be like today, s:yyyy/MM/dd,e:yyyy/MM/dd, 1y, 4m, 38d, 3m 06d"
+./gradlew reportAnalytics --task="REQUESTED_TASK" --branch="BRANCH_NAME" --database="ci/local" --period="can be like today, s:yyyy/MM/dd,e:yyyy/MM/dd, 1y, 4m, 38d, 3m 06d"
```
diff --git a/docs/setup.md b/docs/setup.md
index 3449da7d..2535c1dd 100644
--- a/docs/setup.md
+++ b/docs/setup.md
@@ -38,13 +38,13 @@ Apply the Gradle Plugin to the root of your project.
=== "Kotlin"
``` kotlin
plugins {
- id("io.github.janbarari.gradle-analytics-plugin") version "1.0.2"
+ id("io.github.janbarari.gradle-analytics-plugin") version "1.0.3"
}
```
=== "Groovy"
``` groovy
plugins {
- id 'io.github.janbarari.gradle-analytics-plugin' version '1.0.2'
+ id 'io.github.janbarari.gradle-analytics-plugin' version '1.0.3'
}
```
[For legacy plugin application, see the Gradle Plugin Portal.](https://plugins.gradle.org/plugin/io.github.janbarari.gradle-analytics-plugin)
diff --git a/gradle.properties b/gradle.properties
index 336b018a..ca72a857 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -31,4 +31,4 @@ pluginTags = kotlin,plugin,analytics,analysis,gradle,gradle-plugin,gradle-plugin
pluginImplementationClass = io.github.janbarari.gradle.analytics.GradleAnalyticsPlugin
pluginDeclarationName = gradleAnalyticsPlugin
pluginGroupPackageName = io.github.janbarari
-pluginVersion = 1.0.2
+pluginVersion = 1.0.3
diff --git a/src/main/kotlin/io/github/janbarari/gradle/analytics/GradleAnalyticsPlugin.kt b/src/main/kotlin/io/github/janbarari/gradle/analytics/GradleAnalyticsPlugin.kt
index eff84249..dde95e50 100644
--- a/src/main/kotlin/io/github/janbarari/gradle/analytics/GradleAnalyticsPlugin.kt
+++ b/src/main/kotlin/io/github/janbarari/gradle/analytics/GradleAnalyticsPlugin.kt
@@ -57,7 +57,7 @@ class GradleAnalyticsPlugin @Inject constructor(
companion object {
const val PLUGIN_NAME = "gradleAnalyticsPlugin"
- const val PLUGIN_VERSION = "1.0.2"
+ const val PLUGIN_VERSION = "1.0.3"
const val OUTPUT_DIRECTORY_NAME = "gradle-analytics-plugin"
}
diff --git a/src/main/kotlin/io/github/janbarari/gradle/analytics/database/Database.kt b/src/main/kotlin/io/github/janbarari/gradle/analytics/database/Database.kt
index 02a6f801..ad7797bd 100644
--- a/src/main/kotlin/io/github/janbarari/gradle/analytics/database/Database.kt
+++ b/src/main/kotlin/io/github/janbarari/gradle/analytics/database/Database.kt
@@ -27,7 +27,7 @@ import io.github.janbarari.gradle.analytics.database.table.TemporaryMetricTable
import io.github.janbarari.gradle.ExcludeJacocoGenerated
import io.github.janbarari.gradle.analytics.DatabaseConfig
import io.github.janbarari.gradle.analytics.database.table.SingleMetricTable
-import io.github.janbarari.gradle.extension.isNotNull
+import io.github.janbarari.gradle.extension.isNull
import io.github.janbarari.gradle.extension.toRealPath
import io.github.janbarari.gradle.extension.whenNotNull
import io.github.janbarari.gradle.logger.Tower
@@ -58,10 +58,13 @@ class Database(
private fun connect(config: DatabaseConfig) {
tower.i(clazz, "connect()")
- databaseConfig = config.local
- if (isCI && config.ci.isNotNull()) {
+ if (isCI) {
+ if (config.ci.isNull()) throw InvalidDatabaseConfigException("ci database config is not present!")
databaseConfig = config.ci
+ } else {
+ if (config.local.isNull()) throw InvalidDatabaseConfigException("local database config is not present!")
+ databaseConfig = config.local
}
databaseConfig.whenNotNull {
diff --git a/src/main/kotlin/io/github/janbarari/gradle/analytics/database/InvalidDatabaseConfigException.kt b/src/main/kotlin/io/github/janbarari/gradle/analytics/database/InvalidDatabaseConfigException.kt
new file mode 100644
index 00000000..4d357867
--- /dev/null
+++ b/src/main/kotlin/io/github/janbarari/gradle/analytics/database/InvalidDatabaseConfigException.kt
@@ -0,0 +1,27 @@
+/**
+ * MIT License
+ * Copyright (c) 2024 Mehdi Janbarari (@janbarari)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package io.github.janbarari.gradle.analytics.database
+
+import java.lang.Exception
+
+class InvalidDatabaseConfigException(val msg: String): Exception(msg)
diff --git a/src/main/kotlin/io/github/janbarari/gradle/analytics/reporttask/ReportAnalyticsLogic.kt b/src/main/kotlin/io/github/janbarari/gradle/analytics/reporttask/ReportAnalyticsLogic.kt
index cbe4b6a9..df5c5b32 100644
--- a/src/main/kotlin/io/github/janbarari/gradle/analytics/reporttask/ReportAnalyticsLogic.kt
+++ b/src/main/kotlin/io/github/janbarari/gradle/analytics/reporttask/ReportAnalyticsLogic.kt
@@ -42,6 +42,9 @@ interface ReportAnalyticsLogic {
@kotlin.jvm.Throws(MissingPropertyException::class, InvalidPropertyException::class)
fun ensureTaskArgumentValid(requestedTasksArgument: String)
+ @kotlin.jvm.Throws(MissingPropertyException::class, InvalidPropertyException::class)
+ fun ensureDatabaseArgumentValid(databaseArgument: String)
+
@kotlin.jvm.Throws(InvalidPropertyException::class)
fun convertQueryToPeriod(query: String): Pair
diff --git a/src/main/kotlin/io/github/janbarari/gradle/analytics/reporttask/ReportAnalyticsLogicImp.kt b/src/main/kotlin/io/github/janbarari/gradle/analytics/reporttask/ReportAnalyticsLogicImp.kt
index 4f8e78b5..0bf3266e 100644
--- a/src/main/kotlin/io/github/janbarari/gradle/analytics/reporttask/ReportAnalyticsLogicImp.kt
+++ b/src/main/kotlin/io/github/janbarari/gradle/analytics/reporttask/ReportAnalyticsLogicImp.kt
@@ -260,6 +260,11 @@ class ReportAnalyticsLogicImp(
if (requestedTasksArgument.isEmpty()) throw MissingPropertyException("`--task` is not present!")
}
+ override fun ensureDatabaseArgumentValid(databaseArgument: String) {
+ tower.i(clazz, "ensureDatabaseArgumentValid")
+ if (databaseArgument.isEmpty()) throw MissingPropertyException("`--database` is not present!")
+ }
+
@kotlin.jvm.Throws(InvalidPropertyException::class)
override fun convertQueryToPeriod(query: String): Pair {
tower.i(clazz, "convertQueryToPeriod() query=$query")
diff --git a/src/main/kotlin/io/github/janbarari/gradle/analytics/reporttask/ReportAnalyticsTask.kt b/src/main/kotlin/io/github/janbarari/gradle/analytics/reporttask/ReportAnalyticsTask.kt
index 0454aa2b..2d4ee607 100644
--- a/src/main/kotlin/io/github/janbarari/gradle/analytics/reporttask/ReportAnalyticsTask.kt
+++ b/src/main/kotlin/io/github/janbarari/gradle/analytics/reporttask/ReportAnalyticsTask.kt
@@ -22,12 +22,12 @@
*/
package io.github.janbarari.gradle.analytics.reporttask
+import com.mysql.cj.exceptions.WrongArgumentException
import io.github.janbarari.gradle.ExcludeJacocoGenerated
import io.github.janbarari.gradle.analytics.DatabaseConfig
import io.github.janbarari.gradle.analytics.GradleAnalyticsPlugin
import io.github.janbarari.gradle.analytics.GradleAnalyticsPluginConfig
import io.github.janbarari.gradle.analytics.reporttask.exception.EmptyMetricsException
-import io.github.janbarari.gradle.extension.envCI
import io.github.janbarari.gradle.utils.ConsolePrinter
import io.github.janbarari.gradle.analytics.domain.model.Module
import io.github.janbarari.gradle.analytics.domain.model.Module.Companion.toModule
@@ -52,6 +52,7 @@ import org.gradle.work.DisableCachingByDefault
* A quick instruction about how to invoke the task:
* `./gradlew reportAnalytics --branch="{your-branch}"
* --task="{your-task}"
+ * --database="{ci/local}"
* --period can be like "today", "s:yyyy/MM/dd,e:yyyy/MM/dd", "1y", "4m", "38d", "3m 06d"`
*/
@ExcludeJacocoGenerated
@@ -68,7 +69,6 @@ abstract class ReportAnalyticsTask : DefaultTask() {
config.project.gradle.projectsEvaluated {
with(task) {
projectNameProperty.set(config.project.rootProject.name)
- envCIProperty.set(envCI())
outputPathProperty.set(config.outputPath)
trackingTasksProperty.set(config.trackingTasks)
trackingBranchesProperty.set(config.trackingBranches)
@@ -100,11 +100,12 @@ abstract class ReportAnalyticsTask : DefaultTask() {
@get:Input
var periodArgument: String = ""
+ @set:Option(option = "database", description = "Database type")
@get:Input
- abstract val projectNameProperty: Property
+ var databaseArgument: String = ""
@get:Input
- abstract val envCIProperty: Property
+ abstract val projectNameProperty: Property
@get:Input
abstract val outputPathProperty: Property
@@ -131,9 +132,14 @@ abstract class ReportAnalyticsTask : DefaultTask() {
*/
@TaskAction
fun execute() = runBlocking {
+ val isCI = when (databaseArgument.lowercase()) {
+ "ci" -> true
+ "local" -> false
+ else -> throw WrongArgumentException("`--database` can be equals to `ci` or `local`")
+ }
val injector = ReportAnalyticsInjector(
requestedTasks = requestedTasksArgument,
- isCI = envCIProperty.get(),
+ isCI = isCI,
databaseConfig = databaseConfigProperty.get(),
branch = branchArgument,
outputPath = outputPathProperty.get(),
@@ -149,7 +155,7 @@ abstract class ReportAnalyticsTask : DefaultTask() {
tower.r("gradle version: ${GradleVersion.current().version}")
tower.r("requested tasks: $requestedTasksArgument")
tower.r("modules count: ${modules.get().size}")
- tower.r("ci: ${envCIProperty.get()}")
+ tower.r("ci: $isCI")
tower.r("tracking tasks count: ${trackingTasksProperty.get().size}")
tower.r("tracking branches count: ${trackingBranchesProperty.get().size}")
@@ -157,6 +163,7 @@ abstract class ReportAnalyticsTask : DefaultTask() {
ensureBranchArgumentValid(branchArgument)
ensurePeriodArgumentValid(periodArgument)
ensureTaskArgumentValid(requestedTasksArgument)
+ ensureDatabaseArgumentValid(databaseArgument)
try {
val reportPath = saveReport(generateReport(branchArgument, requestedTasksArgument, periodArgument))
printSuccessfulResult(reportPath)