Skip to content

Commit 471e237

Browse files
author
krystian.panek
committed
JCGay notifier clean up workaround
1 parent 3aa3ed0 commit 471e237

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

src/main/kotlin/com/cognifide/gradle/aem/api/AemConfig.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ class AemConfig(
575575
*/
576576
@Internal
577577
@JsonIgnore
578-
var notificationConfig: (AemNotifier) -> Notifier = { it.dorkbox() }
578+
var notificationConfig: (AemNotifier) -> Notifier = { it.factory() }
579579

580580
/**
581581
* Initialize defaults that depends on concrete type of project.

src/main/kotlin/com/cognifide/gradle/aem/api/AemNotifier.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,23 @@ class AemNotifier private constructor(private val project: Project) {
7878
}
7979

8080
fun custom(notifier: (title: String, text: String, level: LogLevel) -> Unit): Notifier {
81-
return object: Notifier {
81+
return object : Notifier {
8282
override fun notify(title: String, text: String, level: LogLevel) {
8383
notifier(title, text, level)
8484
}
8585
}
8686
}
8787

88+
fun factory(): Notifier {
89+
val name = project.properties["aem.notification.config"] ?: "dorkbox"
90+
91+
return when (name) {
92+
"dorkbox" -> dorkbox()
93+
"jcgay" -> jcgay()
94+
else -> throw AemException("Unsupported notifier: '$name'")
95+
}
96+
}
97+
8898
companion object {
8999

90100
const val IMAGE_PATH = "/com/cognifide/gradle/aem/META-INF/vault/definition/thumbnail.png"

src/main/kotlin/com/cognifide/gradle/aem/internal/notifier/JcGayNotifier.kt

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,44 @@ import fr.jcgay.notification.Notification
88
import fr.jcgay.notification.SendNotification
99
import org.gradle.api.Project
1010
import org.gradle.api.logging.LogLevel
11+
import org.gradle.util.GFileUtils
12+
import fr.jcgay.notification.Notifier as Base
1113

1214
class JcGayNotifier(
1315
val project: Project,
1416
val appBuilder: Application.Builder.() -> Unit,
1517
val messageBuilder: Notification.Builder.() -> Unit
1618
) : Notifier {
1719

18-
private val icon by lazy {
19-
Icon.create(javaClass.getResource(AemNotifier.IMAGE_PATH), "default")
20+
private val notifier by lazy {
21+
val props = project.rootProject.extensions.extraProperties
22+
if (!props.has(EXT_PROP)) {
23+
props.set(EXT_PROP, SendNotification()
24+
.setApplication(Application.builder()
25+
.id(AemPlugin.ID)
26+
.name(AemPlugin.NAME)
27+
.icon(icon)
28+
.apply(appBuilder)
29+
.build())
30+
.initNotifier())
31+
}
32+
33+
val notifier = props.get(EXT_PROP) as Base
34+
35+
if (project == project.rootProject) {
36+
project.gradle.buildFinished {
37+
notifier.close()
38+
39+
// TODO https://github.com/jcgay/send-notification/issues/10
40+
GFileUtils.deleteFileQuietly(project.file("null"))
41+
}
42+
}
43+
44+
notifier
2045
}
2146

22-
private val notifier by lazy {
23-
SendNotification()
24-
.setApplication(Application.builder()
25-
.id(AemPlugin.ID)
26-
.name(AemPlugin.NAME)
27-
.icon(icon)
28-
.apply(appBuilder)
29-
.build())
30-
.initNotifier()
47+
private val icon by lazy {
48+
Icon.create(javaClass.getResource(AemNotifier.IMAGE_PATH), "default")
3149
}
3250

3351
override fun notify(title: String, text: String, level: LogLevel) {
@@ -47,6 +65,8 @@ class JcGayNotifier(
4765

4866
companion object {
4967

68+
val EXT_PROP = JcGayNotifier::class.java.name
69+
5070
val LOG_LEVEL_NOTIFY_MAP = mapOf(
5171
LogLevel.ERROR to Notification.Level.ERROR,
5272
LogLevel.WARN to Notification.Level.WARNING

0 commit comments

Comments
 (0)