Skip to content

Commit

Permalink
Release/v1.0.0-beta6 (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
janbarari authored Jan 30, 2023
1 parent d778522 commit 6aea08f
Show file tree
Hide file tree
Showing 214 changed files with 4,582 additions and 741 deletions.
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.ByteArrayOutputStream
import kotlin.Throwable

val pluginId: String by project
val pluginDisplayName: String by project
Expand Down Expand Up @@ -70,6 +69,7 @@ dependencies {
kapt(libs.moshi.codegen)
implementation(libs.commons.io)
implementation(libs.coroutines)
implementation(libs.oshi)
}

tasks.withType<KotlinCompile>().configureEach {
Expand Down Expand Up @@ -146,11 +146,12 @@ tasks.register("publishToLocal") {
exec {
commandLine(
"./gradlew",
"clean",
"validateSourceHeaderLicense",
"detekt",
"build",
"test",
"publishToMavenLocal"
"publishToMavenLocal",
"test"
).args("--info")
}
}
Expand Down
11 changes: 11 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@

# Changelog

## 1.0.0-beta6
* [Issue 89](https://github.com/janbarari/gradle-analytics-plugin/issues/89)
* [Feature 52](https://github.com/janbarari/gradle-analytics-plugin/issues/52)
* [Issue 90](https://github.com/janbarari/gradle-analytics-plugin/issues/90)
* Redundant Dependency Connection Metric [PR](https://github.com/janbarari/gradle-analytics-plugin/pull/93)
* Internal Logger [PR](https://github.com/janbarari/gradle-analytics-plugin/pull/86)
* Change report font style
* Upgrade Gradle version to 7.6 [PR](https://github.com/janbarari/gradle-analytics-plugin/pull/84)
* Modules Dependency Graph selection feature added
* Fix minor critical bugs

## HotFix - 1.0.0-beta5
* [Issue 77](https://github.com/janbarari/gradle-analytics-plugin/issues/77)

Expand Down
Binary file added docs/img/modules-dependency-graph.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/img/modules-dependency-graph.png
Binary file not shown.
Binary file added docs/img/redundant-dependency-connection.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,13 @@ It represents the project module's dependency graph and their connection types.

Modules have colors that warm colors have represents more dependent modules, and It is recommended to have fewer warm color modules because by applying any change in these modules, all other dependent modules need to rebuild and this cost more time and resources from your machines and put the builds in queue.

![](img/modules-dependency-graph.png)
![](img/modules-dependency-graph.gif)

<br/>
## Redundant Dependency Connection
it represents the project modules redundant dependency connection.

![](img/redundant-dependency-connection.png)

<br/>
## Modules Execution Timeline
Expand Down
2 changes: 2 additions & 0 deletions docs/report-bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@
I appreciate reporting the bugs and crashes in the plugin. In order to submit please use either below ways:

[Github Link](https://github.com/janbarari/gradle-analytics-plugin/issues/new?title=RB:) or [Send Me Email](mailto:mehdi.janbarari@outlook.com?subject=[GAP]%20Report%20Bug)

You can submit the `build-log.txt` and `report-log.txt` log files inside the output directory to help us to reproduce the issue.
6 changes: 5 additions & 1 deletion docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ Add plugin configuration in the root of your project.
"master",
"develop"
)


isTrackAllBranchesEnabled = false // Default is false

outputPath = "OUTPUT_REPORT_PATH"
}
```
Expand Down Expand Up @@ -120,6 +122,8 @@ Add plugin configuration in the root of your project.
'develop'
]

isTrackAllBranchesEnabled = false // Default is false

outputPath = 'OUTPUT_REPORT_PATH'
}
```
Expand Down
1 change: 1 addition & 0 deletions docs/third-party.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ All third-party dependencies that are being used in the plugin source:
- `mysql:mysql-connector-java:8.0.29`
- `org.xerial:sqlite-jdbc:3.36.0.3`
- `commons-io:commons-io:2.11.0`
- `com.github.oshi:oshi-core`
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.0-beta5
pluginVersion = 1.0.0-beta6
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ moshi = "1.13.0"
commons-io = "2.11.0"
mockk = "1.12.4"
coroutines = "1.6.3"
oshi = "6.4.0"

[libraries]
sqlite_driver = { module = "org.xerial:sqlite-jdbc", version.ref = "sqlite_driver" }
Expand All @@ -41,6 +42,7 @@ commons-io = { module = "commons-io:commons-io", version.ref = "commons-io" }
mockk = { module = "io.mockk:mockk", version.ref = "mockk" }
coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
oshi = { module = "com.github.oshi:oshi-core", version.ref = "oshi" }

[plugins]
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class GradleAnalyticsPlugin @Inject constructor(

companion object {
const val PLUGIN_NAME = "gradleAnalyticsPlugin"
const val PLUGIN_VERSION = "1.0.0-beta5"
const val PLUGIN_VERSION = "1.0.0-beta6"
const val OUTPUT_DIRECTORY_NAME = "gradle-analytics-plugin"
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ open class GradleAnalyticsPluginConfig(val project: Project) {

var isEnabled: Boolean = true

var trackingTasks: List<String> = listOf()
var trackingTasks: Set<String> = setOf()

var trackingBranches: List<String> = listOf()
var trackingBranches: Set<String> = setOf()

/**
* Tracing all branches has disabled by default during to the significant drawback
* it creates in the database, especially for temporary branches.
*/
var isTrackAllBranchesEnabled: Boolean = false

var outputPath: String = project.rootProject.buildDir.absolutePath

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
*/
package io.github.janbarari.gradle.analytics.data

import com.squareup.moshi.Moshi
import io.github.janbarari.gradle.analytics.database.Database
import io.github.janbarari.gradle.analytics.database.DatabaseResultMigrationPipeline
import io.github.janbarari.gradle.analytics.database.ResetAutoIncremental
import io.github.janbarari.gradle.analytics.database.table.MetricTable
import io.github.janbarari.gradle.analytics.database.table.SingleMetricTable
Expand All @@ -33,6 +33,8 @@ import io.github.janbarari.gradle.analytics.domain.model.metric.BuildMetric
import io.github.janbarari.gradle.analytics.domain.model.metric.BuildMetricJsonAdapter
import io.github.janbarari.gradle.analytics.domain.repository.DatabaseRepository
import io.github.janbarari.gradle.extension.separateElementsWithSpace
import io.github.janbarari.gradle.logger.Tower
import io.github.janbarari.gradle.memorycache.MemoryCache
import io.github.janbarari.gradle.utils.DateTimeUtils
import org.jetbrains.exposed.sql.ResultRow
import org.jetbrains.exposed.sql.SortOrder
Expand All @@ -44,19 +46,27 @@ import org.jetbrains.exposed.sql.select
import org.jetbrains.exposed.sql.update

class DatabaseRepositoryImp(
private val tower: Tower,
private val db: Database,
private val branch: String,
private val requestedTasks: String,
moshi: Moshi
private val buildMetricJsonAdapter: BuildMetricJsonAdapter,
private val temporaryMetricsMemoryCache: MemoryCache<List<BuildMetric>>,
private val databaseResultMigrationPipeline: DatabaseResultMigrationPipeline
) : DatabaseRepository {

private var jsonAdapter: BuildMetricJsonAdapter = BuildMetricJsonAdapter(moshi)
companion object {
private val clazz = DatabaseRepositoryImp::class.java
}

private var temporaryMetricsLastDropTimestamp: Long = 0L

override fun saveNewMetric(metric: BuildMetric): Long {
tower.i(clazz, "saveNewMetric() metric.hashCode=${metric.hashCode()}")
return db.transaction {
val queryResult = MetricTable.insert {
it[createdAt] = metric.createdAt
it[value] = jsonAdapter.toJson(metric)
it[value] = buildMetricJsonAdapter.toJson(metric)
it[branch] = metric.branch
it[requestedTasks] = metric.requestedTasks.separateElementsWithSpace()
}
Expand All @@ -66,10 +76,11 @@ class DatabaseRepositoryImp(
}

override fun saveTemporaryMetric(metric: BuildMetric): Long {
tower.i(clazz, "saveTemporaryMetric() metric.hashCode=${metric.hashCode()}")
return db.transaction {
val queryResult = TemporaryMetricTable.insert {
it[createdAt] = metric.createdAt
it[value] = jsonAdapter.toJson(metric)
it[value] = buildMetricJsonAdapter.toJson(metric)
it[branch] = metric.branch
it[requestedTasks] = metric.requestedTasks.separateElementsWithSpace()
}
Expand All @@ -78,32 +89,42 @@ class DatabaseRepositoryImp(
}

override fun getDayMetric(): Pair<BuildMetric, Long> {
tower.i(clazz, "getDayMetric()")
return db.transaction {
val queryResult = MetricTable.select {
(MetricTable.createdAt greaterEq DateTimeUtils.getDayStartMs()) and
(MetricTable.createdAt less DateTimeUtils.getDayEndMs()) and
(MetricTable.branch eq branch) and
(MetricTable.requestedTasks eq requestedTasks)
}.single()

val buildMetric = databaseResultMigrationPipeline.execute(
buildMetricJsonAdapter.fromJson(queryResult[MetricTable.value])!!
)

return@transaction Pair(
jsonAdapter.fromJson(queryResult[MetricTable.value])!!, queryResult[MetricTable.number]
buildMetric, queryResult[MetricTable.number]
)
}
}

override fun isDayMetricExists(): Boolean {
tower.i(clazz, "isDayMetricExists()")
return db.transaction {
val queryResult = MetricTable.select {
(MetricTable.createdAt greaterEq DateTimeUtils.getDayStartMs()) and
(MetricTable.createdAt less DateTimeUtils.getDayEndMs()) and
(MetricTable.branch eq branch) and
(MetricTable.requestedTasks eq requestedTasks)
}
return@transaction queryResult.count() > 0
val result = queryResult.count() > 0
tower.i(clazz, "isDayMetricExists() return $result")
return@transaction result
}
}

override fun getMetrics(period: Pair<Long, Long>): List<BuildMetric> {
tower.i(clazz, "getMetrics() period from ${period.first} to ${period.second}")
return db.transaction {
val result = arrayListOf<BuildMetric>()
MetricTable.select {
Expand All @@ -113,26 +134,33 @@ class DatabaseRepositoryImp(
(MetricTable.requestedTasks eq requestedTasks)
}.orderBy(MetricTable.number, SortOrder.ASC).forEach {
result.add(
jsonAdapter.fromJson(it[MetricTable.value])!!
databaseResultMigrationPipeline.execute(
buildMetricJsonAdapter.fromJson(it[MetricTable.value])!!
)
)
}
return@transaction result
}
}

override fun updateDayMetric(number: Long, metric: BuildMetric): Boolean {
tower.i(clazz, "updateDayMetric() metric.hashCode=${metric.hashCode()}")
return db.transaction {
val queryResult = MetricTable.update({
MetricTable.number eq number
}) {
it[value] = jsonAdapter.toJson(metric)
it[value] = buildMetricJsonAdapter.toJson(metric)
it[createdAt] = System.currentTimeMillis()
}
return@transaction queryResult == 1
}
}

override fun dropOutdatedTemporaryMetrics(): Boolean {
// Do not drop outdated temporary if it's done in last 1 minute.
if (System.currentTimeMillis() - temporaryMetricsLastDropTimestamp < 60_000) return false
tower.i(clazz, "dropOutdatedTemporaryMetrics()")
temporaryMetricsLastDropTimestamp = System.currentTimeMillis()
return db.transaction {
val dayMetrics = mutableListOf<ResultRow>()
TemporaryMetricTable.select {
Expand All @@ -159,6 +187,7 @@ class DatabaseRepositoryImp(
}

override fun dropOutdatedMetrics() {
tower.i(clazz, "dropOutdatedMetrics()")
return db.transaction {
MetricTable.deleteWhere {
// Delete all metrics that are created more than 1 year ago.
Expand All @@ -168,6 +197,7 @@ class DatabaseRepositoryImp(
}

override fun dropMetrics(): Boolean {
tower.i(clazz, "dropMetrics()")
return db.transaction {
MetricTable.deleteAll()
ResetAutoIncremental.getQuery("metric")?.let {
Expand All @@ -178,26 +208,31 @@ class DatabaseRepositoryImp(
}

override fun getTemporaryMetrics(): List<BuildMetric> {
if (temporaryMetricsMemoryCache.isValid()) {
tower.i(clazz, "getTemporaryMetrics()", "from cache")
return temporaryMetricsMemoryCache.read()!!
}
tower.i(clazz, "getTemporaryMetrics()", "from db")
return db.transaction {
if (dropOutdatedTemporaryMetrics()) {
val metrics = arrayListOf<BuildMetric>()
val queryResult = TemporaryMetricTable.select {
(TemporaryMetricTable.branch eq branch) and
(TemporaryMetricTable.requestedTasks eq requestedTasks)
}
queryResult.toList().forEach {
jsonAdapter.fromJson(it[value])?.let { metric ->
metrics.add(metric)
}
}
return@transaction metrics
} else {
return@transaction emptyList()
dropOutdatedTemporaryMetrics()
val metrics = arrayListOf<BuildMetric>()
val queryResult = TemporaryMetricTable.select {
(TemporaryMetricTable.branch eq branch) and
(TemporaryMetricTable.requestedTasks eq requestedTasks)
}
queryResult.toList().forEach {
val metric = databaseResultMigrationPipeline.execute(
buildMetricJsonAdapter.fromJson(it[value])!!
)
metrics.add(metric)
}
temporaryMetricsMemoryCache.write(metrics)
return@transaction metrics
}
}

override fun getSingleMetric(key: String, branch: String): String? {
tower.i(clazz, "getSingleMetric() key=$key")
return db.transaction {
val queryResult = SingleMetricTable.select {
(SingleMetricTable.key eq key) and (SingleMetricTable.branch eq branch)
Expand All @@ -210,6 +245,7 @@ class DatabaseRepositoryImp(
}

override fun updateSingleMetric(key: String, branch: String, value: String): Boolean {
tower.i(clazz, "updateSingleMetric() key=$key value.hashCode=${value.hashCode()}")
return db.transaction {
val queryResult = SingleMetricTable.update(
{
Expand All @@ -224,6 +260,7 @@ class DatabaseRepositoryImp(
}

override fun saveSingleMetric(key: String, branch: String, value: String): Boolean {
tower.i(clazz, "saveSingleMetric() key=$key value.hashCode=${value.hashCode()}")
return db.transaction {
SingleMetricTable.insert {
it[SingleMetricTable.key] = key
Expand All @@ -236,6 +273,7 @@ class DatabaseRepositoryImp(
}

override fun dropSingleMetric(key: String, branch: String): Boolean {
tower.i(clazz, "dropSingleMetric() key=$key")
return db.transaction {
SingleMetricTable.deleteWhere {
(SingleMetricTable.key eq key) and (SingleMetricTable.branch eq branch)
Expand All @@ -245,10 +283,10 @@ class DatabaseRepositoryImp(
}

override fun dropSingleMetrics(): Boolean {
tower.i(clazz, "dropSingleMetrics()")
return db.transaction {
SingleMetricTable.deleteAll()
return@transaction true
}
}

}
Loading

0 comments on commit 6aea08f

Please sign in to comment.