From 4d4a27599ebab35f14eb0f80e25c64301fb980b6 Mon Sep 17 00:00:00 2001 From: Mozart Petter Date: Sat, 16 May 2020 14:17:14 +0900 Subject: [PATCH 1/9] Make publisher fields internal only There's no need to expose the publisher configuration into the DSL. --- .../configuration/PublishersConfiguration.kt | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt b/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt index bb65f93d..bdec4c27 100644 --- a/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt +++ b/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt @@ -1,6 +1,5 @@ package com.cdsap.talaiot.configuration - import com.cdsap.talaiot.publisher.Publisher import com.cdsap.talaiot.publisher.rethinkdb.RethinkDbPublisher import groovy.lang.Closure @@ -30,19 +29,19 @@ class PublishersConfiguration( /** * Access to the configuration of [com.cdsap.talaiot.publisher.InfluxDbPublisher] */ - var influxDbPublisher: InfluxDbPublisherConfiguration? = null + internal var influxDbPublisher: InfluxDbPublisherConfiguration? = null /** * Access to the configuration of [com.cdsap.talaiot.publisher.OutputPublisher] */ - var outputPublisher: OutputPublisherConfiguration? = null + internal var outputPublisher: OutputPublisherConfiguration? = null /** * Access to the configuration of [com.cdsap.talaiot.publisher.PushGatewayPublisher] */ - var pushGatewayPublisher: PushGatewayPublisherConfiguration? = null + internal var pushGatewayPublisher: PushGatewayPublisherConfiguration? = null /** * Access to the configuration of [com.cdsap.talaiot.publisher.TaskDependencyGraphPublisher] */ - var taskDependencyGraphPublisher: TaskDependencyGraphConfiguration? = null + internal var taskDependencyGraphPublisher: TaskDependencyGraphConfiguration? = null /** * Flag to enable [com.cdsap.talaiot.publisher.timeline.TimelinePublisher] * @@ -58,24 +57,21 @@ class PublishersConfiguration( /** * Access to the configuration of [com.cdsap.talaiot.publisher.ElasticSearchPublisher] */ - - var elasticSearchPublisher: ElasticSearchPublisherConfiguration? = null + internal var elasticSearchPublisher: ElasticSearchPublisherConfiguration? = null /** * Access to the configuration of [com.cdsap.talaiot.publisher.HybridPublisher] */ - - var hybridPublisher: HybridPublisherConfiguration? = null + internal var hybridPublisher: HybridPublisherConfiguration? = null /** * Access to the configuration of [com.cdsap.talaiot.publisher.RethinkDbPublisher] */ - var rethinkDbPublisher: RethinkDbPublisherConfiguration? = null - + internal var rethinkDbPublisher: RethinkDbPublisherConfiguration? = null /** * Definition of a custom Publisher in the PublisherConfiguration. Requires implementation of Publisher. * * Some users of plugin might need to use a custom publisher to push to internal analytics for example. */ - var customPublisher: Publisher? = null + internal var customPublisher: Publisher? = null /** * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.TaskDependencyGraphPublisher] @@ -227,5 +223,4 @@ class PublishersConfiguration( closure.delegate = rethinkDbPublisher closure.call() } - -} \ No newline at end of file +} From bfdeb6c1c245d20e739a22f3561af3cd6b0b272b Mon Sep 17 00:00:00 2001 From: Mozart Petter Date: Sat, 16 May 2020 14:27:16 +0900 Subject: [PATCH 2/9] Remove documentation from internal members --- .../configuration/PublishersConfiguration.kt | 36 ++++--------------- 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt b/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt index bdec4c27..368a64ef 100644 --- a/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt +++ b/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt @@ -26,22 +26,16 @@ import org.gradle.api.Project class PublishersConfiguration( val project: Project ) { - /** - * Access to the configuration of [com.cdsap.talaiot.publisher.InfluxDbPublisher] - */ + internal var elasticSearchPublisher: ElasticSearchPublisherConfiguration? = null + internal var hybridPublisher: HybridPublisherConfiguration? = null internal var influxDbPublisher: InfluxDbPublisherConfiguration? = null - /** - * Access to the configuration of [com.cdsap.talaiot.publisher.OutputPublisher] - */ internal var outputPublisher: OutputPublisherConfiguration? = null - /** - * Access to the configuration of [com.cdsap.talaiot.publisher.PushGatewayPublisher] - */ internal var pushGatewayPublisher: PushGatewayPublisherConfiguration? = null - /** - * Access to the configuration of [com.cdsap.talaiot.publisher.TaskDependencyGraphPublisher] - */ + internal var rethinkDbPublisher: RethinkDbPublisherConfiguration? = null internal var taskDependencyGraphPublisher: TaskDependencyGraphConfiguration? = null + + internal var customPublisher: Publisher? = null + /** * Flag to enable [com.cdsap.talaiot.publisher.timeline.TimelinePublisher] * @@ -54,24 +48,6 @@ class PublishersConfiguration( * Generates a json representation of [com.cdsap.talaiot.entities.ExecutionReport] */ var jsonPublisher: Boolean = false - /** - * Access to the configuration of [com.cdsap.talaiot.publisher.ElasticSearchPublisher] - */ - internal var elasticSearchPublisher: ElasticSearchPublisherConfiguration? = null - /** - * Access to the configuration of [com.cdsap.talaiot.publisher.HybridPublisher] - */ - internal var hybridPublisher: HybridPublisherConfiguration? = null - /** - * Access to the configuration of [com.cdsap.talaiot.publisher.RethinkDbPublisher] - */ - internal var rethinkDbPublisher: RethinkDbPublisherConfiguration? = null - /** - * Definition of a custom Publisher in the PublisherConfiguration. Requires implementation of Publisher. - * - * Some users of plugin might need to use a custom publisher to push to internal analytics for example. - */ - internal var customPublisher: Publisher? = null /** * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.TaskDependencyGraphPublisher] From f9e1195cc12cb671b2b5cd8d39f674b61f4c9d8c Mon Sep 17 00:00:00 2001 From: Mozart Petter Date: Sat, 16 May 2020 14:53:32 +0900 Subject: [PATCH 3/9] Refactor customPublisher() to take N Publisher objects --- .../configuration/PublishersConfiguration.kt | 12 +++++------- .../cdsap/talaiot/provider/PublishersProvider.kt | 10 +++------- .../talaiot/publisher/PublishersProviderTest.kt | 16 ++++++---------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt b/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt index 368a64ef..48b27774 100644 --- a/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt +++ b/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt @@ -34,7 +34,7 @@ class PublishersConfiguration( internal var rethinkDbPublisher: RethinkDbPublisherConfiguration? = null internal var taskDependencyGraphPublisher: TaskDependencyGraphConfiguration? = null - internal var customPublisher: Publisher? = null + internal var customPublishers: MutableSet = mutableSetOf() /** * Flag to enable [com.cdsap.talaiot.publisher.timeline.TimelinePublisher] @@ -104,14 +104,12 @@ class PublishersConfiguration( } /** - * Configuration accessor within the [PublishersConfiguration] for the custom implementation for [Publisher] + * Adds the given custom publishers into the publisher list. * - * Will override another custom publisher instance if present - * - * @param configuration instance of your publisher + * @param publishers takes N [Publisher]s to be added to the publishers list. */ - fun customPublisher(configuration: Publisher) { - customPublisher = configuration + fun customPublishers(vararg publishers: Publisher) { + customPublishers.addAll(publishers) } /** diff --git a/talaiot/src/main/kotlin/com/cdsap/talaiot/provider/PublishersProvider.kt b/talaiot/src/main/kotlin/com/cdsap/talaiot/provider/PublishersProvider.kt index cb3ad2fe..d83336b3 100644 --- a/talaiot/src/main/kotlin/com/cdsap/talaiot/provider/PublishersProvider.kt +++ b/talaiot/src/main/kotlin/com/cdsap/talaiot/provider/PublishersProvider.kt @@ -2,6 +2,7 @@ package com.cdsap.talaiot.provider import com.cdsap.talaiot.TalaiotExtension import com.cdsap.talaiot.logger.LogTracker +import com.cdsap.talaiot.configuration.PublishersConfiguration import com.cdsap.talaiot.publisher.* import com.cdsap.talaiot.publisher.graphpublisher.GraphPublisherFactoryImpl import com.cdsap.talaiot.publisher.pushgateway.PushGatewayFormatter @@ -11,10 +12,9 @@ import com.cdsap.talaiot.publisher.timeline.TimelinePublisher import com.cdsap.talaiot.request.SimpleRequest import org.gradle.api.Project import java.util.concurrent.Executor -import java.util.concurrent.Executors /** - * Provides the [Publisher]s defined in the [com.cdsap.talaiot.configuration.PublishersConfiguration] of the [TalaiotExtension] + * Provides the [Publisher]s defined in the [PublishersConfiguration] of the [TalaiotExtension] */ class PublishersProvider( /** @@ -37,8 +37,6 @@ class PublishersProvider( val talaiotExtension = project.extensions.getByName("talaiot") as TalaiotExtension talaiotExtension.publishers?.apply { - - outputPublisher?.apply { publishers.add(OutputPublisher(this, logger)) } @@ -111,9 +109,7 @@ class PublishersProvider( ) } - customPublisher?.apply { - publishers.add(this) - } + publishers.addAll(customPublishers) } return publishers } diff --git a/talaiot/src/test/kotlin/com/cdsap/talaiot/publisher/PublishersProviderTest.kt b/talaiot/src/test/kotlin/com/cdsap/talaiot/publisher/PublishersProviderTest.kt index 40f839b3..05a1add7 100644 --- a/talaiot/src/test/kotlin/com/cdsap/talaiot/publisher/PublishersProviderTest.kt +++ b/talaiot/src/test/kotlin/com/cdsap/talaiot/publisher/PublishersProviderTest.kt @@ -11,7 +11,6 @@ import io.kotlintest.inspectors.forAtLeastOne import io.kotlintest.specs.BehaviorSpec import org.gradle.testfixtures.ProjectBuilder - class PublishersProviderTest : BehaviorSpec({ given("Publisher Provider") { val logger = LogTrackerImpl(LogTracker.Mode.SILENT) @@ -69,11 +68,11 @@ class PublishersProviderTest : BehaviorSpec({ } } } - `when`("CustomPublisher is included") { + `when`("One custom publisher is included") { val project = ProjectBuilder.builder().build() val talaiotExtension = project.extensions.create("talaiot", TalaiotExtension::class.java, project) talaiotExtension.publishers { - customPublisher(TestPublisher()) + customPublishers(TestPublisher()) } val publishers = PublishersProvider(project, logger, TestExecutor(), TestExecutor()).get() then("instance of CustomPublisher is created") { @@ -87,7 +86,7 @@ class PublishersProviderTest : BehaviorSpec({ val talaiotExtension = project.extensions.create("talaiot", TalaiotExtension::class.java, project) talaiotExtension.publishers { rethinkDbPublisher { - buildTableName = "builds" + buildTableName = "builds" } } val publishers = PublishersProvider(project, logger, TestExecutor(), TestExecutor()).get() @@ -102,7 +101,7 @@ class PublishersProviderTest : BehaviorSpec({ val project = ProjectBuilder.builder().build() val talaiotExtension = project.extensions.create("talaiot", TalaiotExtension::class.java, project) talaiotExtension.publishers { - customPublisher(TestPublisher()) + customPublishers(TestPublisher()) taskDependencyGraphPublisher { gexf = true } @@ -128,8 +127,5 @@ class PublishersProviderTest : BehaviorSpec({ }) class TestPublisher : Publisher { - override fun publish(report: ExecutionReport) { - - } - -} \ No newline at end of file + override fun publish(report: ExecutionReport) {} +} From 39173776033a3a84867e96c02b064f866ee46939 Mon Sep 17 00:00:00 2001 From: Mozart Petter Date: Sat, 16 May 2020 14:56:18 +0900 Subject: [PATCH 4/9] Move TestPublisher into a mock file --- .../kotlin/com/cdsap/talaiot/mock/CustomPublishersMock.kt | 8 ++++++++ .../com/cdsap/talaiot/publisher/PublishersProviderTest.kt | 7 ++----- 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 talaiot/src/test/kotlin/com/cdsap/talaiot/mock/CustomPublishersMock.kt diff --git a/talaiot/src/test/kotlin/com/cdsap/talaiot/mock/CustomPublishersMock.kt b/talaiot/src/test/kotlin/com/cdsap/talaiot/mock/CustomPublishersMock.kt new file mode 100644 index 00000000..728c0c97 --- /dev/null +++ b/talaiot/src/test/kotlin/com/cdsap/talaiot/mock/CustomPublishersMock.kt @@ -0,0 +1,8 @@ +package com.cdsap.talaiot.mock + +import com.cdsap.talaiot.entities.ExecutionReport +import com.cdsap.talaiot.publisher.Publisher + +class TestPublisher : Publisher { + override fun publish(report: ExecutionReport) {} +} diff --git a/talaiot/src/test/kotlin/com/cdsap/talaiot/publisher/PublishersProviderTest.kt b/talaiot/src/test/kotlin/com/cdsap/talaiot/publisher/PublishersProviderTest.kt index 05a1add7..83292457 100644 --- a/talaiot/src/test/kotlin/com/cdsap/talaiot/publisher/PublishersProviderTest.kt +++ b/talaiot/src/test/kotlin/com/cdsap/talaiot/publisher/PublishersProviderTest.kt @@ -4,6 +4,7 @@ import com.cdsap.talaiot.TalaiotExtension import com.cdsap.talaiot.entities.ExecutionReport import com.cdsap.talaiot.logger.LogTracker import com.cdsap.talaiot.logger.LogTrackerImpl +import com.cdsap.talaiot.mock.TestPublisher import com.cdsap.talaiot.provider.PublishersProvider import com.cdsap.talaiot.publisher.rethinkdb.RethinkDbPublisher import io.kotlintest.inspectors.forAll @@ -75,7 +76,7 @@ class PublishersProviderTest : BehaviorSpec({ customPublishers(TestPublisher()) } val publishers = PublishersProvider(project, logger, TestExecutor(), TestExecutor()).get() - then("instance of CustomPublisher is created") { + then("instance of TestPublisher exists") { publishers.forAtLeastOne { it is TestPublisher } @@ -125,7 +126,3 @@ class PublishersProviderTest : BehaviorSpec({ } } }) - -class TestPublisher : Publisher { - override fun publish(report: ExecutionReport) {} -} From dea47781779e16323d3e0d79e830ea0b35bf8efd Mon Sep 17 00:00:00 2001 From: Mozart Petter Date: Sat, 16 May 2020 15:03:36 +0900 Subject: [PATCH 5/9] Add test for two custom publishers --- .../talaiot/mock/CustomPublishersMock.kt | 4 ++++ .../publisher/PublishersProviderTest.kt | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/talaiot/src/test/kotlin/com/cdsap/talaiot/mock/CustomPublishersMock.kt b/talaiot/src/test/kotlin/com/cdsap/talaiot/mock/CustomPublishersMock.kt index 728c0c97..5607d84b 100644 --- a/talaiot/src/test/kotlin/com/cdsap/talaiot/mock/CustomPublishersMock.kt +++ b/talaiot/src/test/kotlin/com/cdsap/talaiot/mock/CustomPublishersMock.kt @@ -6,3 +6,7 @@ import com.cdsap.talaiot.publisher.Publisher class TestPublisher : Publisher { override fun publish(report: ExecutionReport) {} } + +class ConsolePublisher : Publisher { + override fun publish(report: ExecutionReport) {} +} diff --git a/talaiot/src/test/kotlin/com/cdsap/talaiot/publisher/PublishersProviderTest.kt b/talaiot/src/test/kotlin/com/cdsap/talaiot/publisher/PublishersProviderTest.kt index 83292457..1a3a0782 100644 --- a/talaiot/src/test/kotlin/com/cdsap/talaiot/publisher/PublishersProviderTest.kt +++ b/talaiot/src/test/kotlin/com/cdsap/talaiot/publisher/PublishersProviderTest.kt @@ -1,9 +1,9 @@ package com.cdsap.talaiot.publisher import com.cdsap.talaiot.TalaiotExtension -import com.cdsap.talaiot.entities.ExecutionReport import com.cdsap.talaiot.logger.LogTracker import com.cdsap.talaiot.logger.LogTrackerImpl +import com.cdsap.talaiot.mock.ConsolePublisher import com.cdsap.talaiot.mock.TestPublisher import com.cdsap.talaiot.provider.PublishersProvider import com.cdsap.talaiot.publisher.rethinkdb.RethinkDbPublisher @@ -82,6 +82,23 @@ class PublishersProviderTest : BehaviorSpec({ } } } + `when`("Two custom publishers are included") { + val project = ProjectBuilder.builder().build() + val talaiotExtension = project.extensions.create("talaiot", TalaiotExtension::class.java, project) + talaiotExtension.publishers { + customPublishers( + TestPublisher(), + ConsolePublisher() + ) + } + val publishers = PublishersProvider(project, logger, TestExecutor(), TestExecutor()).get() + then("instance of TestPublisher and ConsolePublisher exists") { + publishers.forAll { + it is TestPublisher + it is ConsolePublisher + } + } + } `when`("RethinkDb is included") { val project = ProjectBuilder.builder().build() val talaiotExtension = project.extensions.create("talaiot", TalaiotExtension::class.java, project) From e21863958e8387c05c8e38a522343347bf48eead Mon Sep 17 00:00:00 2001 From: Mozart Petter Date: Sat, 16 May 2020 15:22:33 +0900 Subject: [PATCH 6/9] Update PublishersConfiguration documentation Some of the methods are also re-arranged. --- .../configuration/PublishersConfiguration.kt | 159 +++++++++--------- 1 file changed, 80 insertions(+), 79 deletions(-) diff --git a/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt b/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt index 48b27774..aa5479fd 100644 --- a/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt +++ b/talaiot/src/main/kotlin/com/cdsap/talaiot/configuration/PublishersConfiguration.kt @@ -1,15 +1,19 @@ package com.cdsap.talaiot.configuration -import com.cdsap.talaiot.publisher.Publisher +import com.cdsap.talaiot.publisher.* +import com.cdsap.talaiot.publisher.pushgateway.PushGatewayPublisher import com.cdsap.talaiot.publisher.rethinkdb.RethinkDbPublisher +import com.cdsap.talaiot.publisher.timeline.TimelinePublisher import groovy.lang.Closure import org.gradle.api.Project + /** * Main configuration for the publishers. * * It offers the accessors for Groovy and KTS * + * ``` * publishers { * influxDbPublisher { * } @@ -22,6 +26,7 @@ import org.gradle.api.Project * customDependencies { * } * } + * ``` */ class PublishersConfiguration( val project: Project @@ -37,164 +42,160 @@ class PublishersConfiguration( internal var customPublishers: MutableSet = mutableSetOf() /** - * Flag to enable [com.cdsap.talaiot.publisher.timeline.TimelinePublisher] - * - * Generates an html report with the timeline of task execution + * Enables a [TimelinePublisher] if set to `true`. Disabled by default. */ var timelinePublisher: Boolean = false + /** - * Flag to enable [com.cdsap.talaiot.publisher.JsonPublisher] - * - * Generates a json representation of [com.cdsap.talaiot.entities.ExecutionReport] + * Enables a [JsonPublisher] if set to `true`. Disabled by default. */ var jsonPublisher: Boolean = false /** - * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.TaskDependencyGraphPublisher] + * Configuration accessor within the [PublishersConfiguration] for the [ElasticSearchPublisher] * - * @param configuration Configuration block for the [TaskDependencyGraphConfiguration] + * @param configuration Configuration block for the [ElasticSearchPublisherConfiguration] */ - fun taskDependencyGraphPublisher(configuration: TaskDependencyGraphConfiguration.() -> Unit) { - taskDependencyGraphPublisher = TaskDependencyGraphConfiguration(project).also(configuration) + fun elasticSearchPublisher(configuration: ElasticSearchPublisherConfiguration.() -> Unit) { + elasticSearchPublisher = ElasticSearchPublisherConfiguration().also(configuration) } /** - * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.InfluxDbPublisher] + * Configuration accessor within the [PublishersConfiguration] for the [ElasticSearchPublisher] * - * @param configuration Configuration block for the [InfluxDbPublisherConfiguration] + * @param closure closure for the [ElasticSearchPublisherConfiguration] */ - fun influxDbPublisher(configuration: InfluxDbPublisherConfiguration.() -> Unit) { - influxDbPublisher = InfluxDbPublisherConfiguration().also(configuration) + fun elasticSearchPublisher(closure: Closure<*>) { + elasticSearchPublisher = ElasticSearchPublisherConfiguration() + closure.delegate = elasticSearchPublisher + closure.call() } /** - * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.PushGatewayPublisher] + * Configuration accessor within the [PublishersConfiguration] for the [HybridPublisher] * - * @param configuration Configuration block for the [PushGatewayPublisherConfiguration] + * @param configuration Configuration block for the [HybridPublisherConfiguration] */ - fun pushGatewayPublisher(configuration: PushGatewayPublisherConfiguration.() -> Unit) { - pushGatewayPublisher = PushGatewayPublisherConfiguration().also(configuration) + fun hybridPublisher(configuration: HybridPublisherConfiguration.() -> Unit) { + hybridPublisher = HybridPublisherConfiguration().also(configuration) } /** - * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.ElasticSearchPublisher] + * Configuration accessor within the [HybridPublisherConfiguration] for the [HybridPublisher] * - * @param configuration Configuration block for the [ElasticSearchPublisherConfiguration] + * @param closure closure for the [HybridPublisherConfiguration] */ - fun elasticSearchPublisher(configuration: ElasticSearchPublisherConfiguration.() -> Unit) { - elasticSearchPublisher = ElasticSearchPublisherConfiguration().also(configuration) + fun hybridPublisher(closure: Closure<*>) { + hybridPublisher = HybridPublisherConfiguration() + closure.delegate = hybridPublisher + closure.call() } /** - * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.HybridPublisher] + * Configuration accessor within the [PublishersConfiguration] for the [InfluxDbPublisher] * - * @param configuration Configuration block for the [HybridPublisherConfiguration] + * @param configuration Configuration block for the [InfluxDbPublisherConfiguration] */ - fun hybridPublisher(configuration: HybridPublisherConfiguration.() -> Unit) { - hybridPublisher = HybridPublisherConfiguration().also(configuration) + fun influxDbPublisher(configuration: InfluxDbPublisherConfiguration.() -> Unit) { + influxDbPublisher = InfluxDbPublisherConfiguration().also(configuration) } /** - * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.OutputPublisher] + * Configuration accessor within the [PublishersConfiguration] for the [InfluxDbPublisher] * - * @param configuration Configuration block for the [OutputPublisherConfiguration] + * @param closure closure for the [InfluxDbPublisherConfiguration] */ - fun outputPublisher(configuration: OutputPublisherConfiguration.() -> Unit) { - outputPublisher = OutputPublisherConfiguration().also(configuration) + fun influxDbPublisher(closure: Closure<*>) { + influxDbPublisher = InfluxDbPublisherConfiguration() + closure.delegate = influxDbPublisher + closure.call() } /** - * Adds the given custom publishers into the publisher list. + * Configuration accessor within the [PublishersConfiguration] for the [OutputPublisher] * - * @param publishers takes N [Publisher]s to be added to the publishers list. + * @param configuration Configuration block for the [OutputPublisherConfiguration] */ - fun customPublishers(vararg publishers: Publisher) { - customPublishers.addAll(publishers) + fun outputPublisher(configuration: OutputPublisherConfiguration.() -> Unit) { + outputPublisher = OutputPublisherConfiguration().also(configuration) } /** - * Configuration accessor within the [RethinkDbPublisherConfiguration] for the custom implementation for [RethinkDbPublisher] + * Configuration accessor within the [PublishersConfiguration] for the [OutputPublisher] * - * @param configuration instance of your publisher + * @param closure closure for the [OutputPublisherConfiguration] */ - fun rethinkDbPublisher(configuration: RethinkDbPublisherConfiguration.() -> Unit) { - rethinkDbPublisher = RethinkDbPublisherConfiguration().also(configuration) + fun outputPublisher(closure: Closure<*>) { + outputPublisher = OutputPublisherConfiguration() + closure.delegate = outputPublisher + closure.call() } /** - * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.InfluxDbPublisher] + * Configuration accessor within the [PublishersConfiguration] for the [PushGatewayPublisher] * - * @param closure closure for the [InfluxDbPublisherConfiguration] + * @param configuration Configuration block for the [PushGatewayPublisherConfiguration] */ - fun influxDbPublisher(closure: Closure<*>) { - influxDbPublisher = InfluxDbPublisherConfiguration() - closure.delegate = influxDbPublisher - closure.call() + fun pushGatewayPublisher(configuration: PushGatewayPublisherConfiguration.() -> Unit) { + pushGatewayPublisher = PushGatewayPublisherConfiguration().also(configuration) } /** - * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.TaskDependencyGraphPublisher] + * Configuration accessor within the [PublishersConfiguration] for the [PushGatewayPublisher] * - * @param closure closure for the [TaskDependencyGraphConfiguration] + * @param closure closure for the [PushGatewayPublisherConfiguration] */ - fun taskDependencyGraphPublisher(closure: Closure<*>) { - taskDependencyGraphPublisher = TaskDependencyGraphConfiguration(project) - closure.delegate = taskDependencyGraphPublisher + fun pushGatewayPublisher(closure: Closure<*>) { + pushGatewayPublisher = PushGatewayPublisherConfiguration() + closure.delegate = pushGatewayPublisher closure.call() } /** - * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.ElasticSearchPublisher] + * Configuration accessor within the [RethinkDbPublisherConfiguration] for the custom implementation for [RethinkDbPublisher] * - * @param closure closure for the [ElasticSearchPublisherConfiguration] + * @param configuration instance of your publisher */ - fun elasticSearchPublisher(closure: Closure<*>) { - elasticSearchPublisher = ElasticSearchPublisherConfiguration() - closure.delegate = elasticSearchPublisher - closure.call() + fun rethinkDbPublisher(configuration: RethinkDbPublisherConfiguration.() -> Unit) { + rethinkDbPublisher = RethinkDbPublisherConfiguration().also(configuration) } /** - * Configuration accessor within the [HybridPublisherConfiguration] for the [com.cdsap.talaiot.publisher.HybridPublisher] + * Configuration accessor within the [RethinkDbPublisherConfiguration] for the [RethinkDbPublisher] * - * @param closure closure for the [HybridPublisherConfiguration] + * @param closure closure for the [RethinkDbPublisherConfiguration] */ - fun hybridPublisher(closure: Closure<*>) { - hybridPublisher = HybridPublisherConfiguration() - closure.delegate = hybridPublisher + fun rethinkDbPublisher(closure: Closure<*>) { + rethinkDbPublisher = RethinkDbPublisherConfiguration() + closure.delegate = rethinkDbPublisher closure.call() } - /** - * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.OutputPublisher] + * Configuration accessor within the [PublishersConfiguration] for the [TaskDependencyGraphPublisher] * - * @param closure closure for the [OutputPublisherConfiguration] + * @param configuration Configuration block for the [TaskDependencyGraphConfiguration] */ - fun outputPublisher(closure: Closure<*>) { - outputPublisher = OutputPublisherConfiguration() - closure.delegate = outputPublisher - closure.call() + fun taskDependencyGraphPublisher(configuration: TaskDependencyGraphConfiguration.() -> Unit) { + taskDependencyGraphPublisher = TaskDependencyGraphConfiguration(project).also(configuration) } /** - * Configuration accessor within the [PublishersConfiguration] for the [com.cdsap.talaiot.publisher.PushGatewayPublisher] + * Configuration accessor within the [PublishersConfiguration] for the [TaskDependencyGraphPublisher] * - * @param closure closure for the [PushGatewayPublisherConfiguration] + * @param closure closure for the [TaskDependencyGraphConfiguration] */ - fun pushGatewayPublisher(closure: Closure<*>) { - pushGatewayPublisher = PushGatewayPublisherConfiguration() - closure.delegate = pushGatewayPublisher + fun taskDependencyGraphPublisher(closure: Closure<*>) { + taskDependencyGraphPublisher = TaskDependencyGraphConfiguration(project) + closure.delegate = taskDependencyGraphPublisher closure.call() } /** - * Configuration accessor within the [RethinkDbPublisherConfiguration] for the [com.cdsap.talaiot.publisher.RethinkDbPublisher] + * Adds the given custom publishers into the publisher list. * - * @param closure closure for the [RethinkDbPublisherConfiguration] + * @param publishers takes N [Publisher]s to be added to the publishers list. */ - fun rethinkDbPublisher(closure: Closure<*>) { - rethinkDbPublisher = RethinkDbPublisherConfiguration() - closure.delegate = rethinkDbPublisher - closure.call() + fun customPublishers(vararg publishers: Publisher) { + customPublishers.addAll(publishers) } } From 32dd6f25cb23d9ed99328fc843360fd43711f887 Mon Sep 17 00:00:00 2001 From: Mozart Petter Date: Sat, 16 May 2020 15:41:56 +0900 Subject: [PATCH 7/9] Update sample build file --- sample/build.gradle.kts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/sample/build.gradle.kts b/sample/build.gradle.kts index 35fd8d11..eaef374a 100644 --- a/sample/build.gradle.kts +++ b/sample/build.gradle.kts @@ -23,23 +23,35 @@ dependencies { talaiot { logger = LogTracker.Mode.INFO publishers { + // Publishers that don't require a configuration can be enabled or disabled with a flag. + // By default all publishers are disabled. timelinePublisher = true + jsonPublisher = false + + // Talaiot provides a few pre-defined publishers. + // Declaring a configuration for any of those publishers will enable them. taskDependencyGraphPublisher { html = true gexf = true } + influxDbPublisher { dbName = "tracking" url = "http://localhost:8086" taskMetricName = "task" buildMetricName = "build" } - customPublisher = CustomPublisher() + + // You can also define your own custom publishers: + customPublishers( + CustomPublisher(), + HelloPublisher() + ) } metrics { - // Talaiot provides a few methods to disable a group of metrics at once - // By default all groups are enabled + // Talaiot provides a few methods to disable a group of metrics at once. + // By default all groups are enabled. performanceMetrics = false gradleSwitchesMetrics = false environmentMetrics = false @@ -65,13 +77,18 @@ talaiot { class CustomPublisher : Publisher { override fun publish(report: ExecutionReport) { println("[CustomPublisher] : Number of tasks = ${report.tasks?.size}") - println("[CustomPublisher] : HelloMetric = ${report.customProperties.buildProperties["hello"]}") println("[CustomPublisher] : Kotlin = ${report.customProperties.buildProperties["kotlin"]}") println("[CustomPublisher] : Java = ${report.customProperties.buildProperties["java"]}") println("[CustomPublisher] : PID = ${report.customProperties.taskProperties["pid"]}") } } +class HelloPublisher : Publisher { + override fun publish(report: ExecutionReport) { + println("[HelloPublisher] : HelloMetric = ${report.customProperties.buildProperties["hello"]}") + } +} + class HelloMetric : SimpleMetric( provider = { "Hello!" }, assigner = { report, value -> report.customProperties.buildProperties["hello"] = value } From 1b86d5b7c17aca3df7cfcd731cbaeba67900a7b4 Mon Sep 17 00:00:00 2001 From: Mozart Petter Date: Sat, 16 May 2020 15:48:35 +0900 Subject: [PATCH 8/9] Update README.md --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b1e5e29a..846c748d 100644 --- a/README.md +++ b/README.md @@ -335,8 +335,20 @@ Talaiot will send to the RethinkDb server defined in the configuration the value #### Custom Publishers -Talaiot allows using custom Publishers defined by the requirements of your environment, in case you are using another implementation. -Check [here](https://github.com/cdsap/Talaiot/wiki/Publishers#custompublisher) how to define a custom publisher +Talaiot allows using custom publishers defined by the requirements of your environment, in case you are using another implementation. + +``` +talaiot { + publishers { + // You can define one or more custom publishers: + customPublishers( + MyCustomPublisher() + ) + } +} +``` + +Read more about it in the [Publishers wiki page](https://github.com/cdsap/Talaiot/wiki/Publishers#custompublishers) ### Metrics We can include extra information on the build and task tracked data during the build. This information will be added to the default metrics defined. From 9c21da776cad8cde6843d1ea3790c71af4852727 Mon Sep 17 00:00:00 2001 From: Mozart Petter Date: Mon, 18 May 2020 14:18:29 +0900 Subject: [PATCH 9/9] Update IntegrationSpec.kt --- .../src/test/kotlin/com/cdsap/talaiot/e2e/IntegrationSpec.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/talaiot/src/test/kotlin/com/cdsap/talaiot/e2e/IntegrationSpec.kt b/talaiot/src/test/kotlin/com/cdsap/talaiot/e2e/IntegrationSpec.kt index ab608c4d..d2975b9c 100644 --- a/talaiot/src/test/kotlin/com/cdsap/talaiot/e2e/IntegrationSpec.kt +++ b/talaiot/src/test/kotlin/com/cdsap/talaiot/e2e/IntegrationSpec.kt @@ -42,7 +42,7 @@ class DefaultConfigurationSpec : StringSpec({ logger = com.cdsap.talaiot.logger.LogTracker.Mode.INFO publishers { jsonPublisher = true - customPublisher = new JsonPublisher(getGradle()) + customPublishers(new JsonPublisher(getGradle())) } }