Skip to content

Commit

Permalink
Release/1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarari authored Jul 21, 2024
1 parent 8a05859 commit 4aced2e
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 14 deletions.
3 changes: 3 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

# Changelog

## 1.0.3
* Minor issues fixed

## 1.0.2
* Add postgres database support
* Upgrade gradle version to `8.9`
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Gradle Analytics Plugin uses daily basis data to generate reports. So you could

<strong>Execute Gradle Task</strong><br/>
```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"
```

<br/>
Expand Down
4 changes: 2 additions & 2 deletions docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long, Long>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long, Long> {
tower.i(clazz, "convertQueryToPeriod() query=$query")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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<String>
var databaseArgument: String = ""

@get:Input
abstract val envCIProperty: Property<Boolean>
abstract val projectNameProperty: Property<String>

@get:Input
abstract val outputPathProperty: Property<String>
Expand All @@ -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(),
Expand All @@ -149,14 +155,15 @@ 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}")

with(injector.provideReportAnalyticsLogic()) {
ensureBranchArgumentValid(branchArgument)
ensurePeriodArgumentValid(periodArgument)
ensureTaskArgumentValid(requestedTasksArgument)
ensureDatabaseArgumentValid(databaseArgument)
try {
val reportPath = saveReport(generateReport(branchArgument, requestedTasksArgument, periodArgument))
printSuccessfulResult(reportPath)
Expand Down

0 comments on commit 4aced2e

Please sign in to comment.