1
1
package io.github.thanosfisherman.serenador.listeners
2
2
3
- import io.github.thanosfisherman.serenador.CommandExecutor
4
- import io.github.thanosfisherman.serenador.executeCustom
5
- import io.github.thanosfisherman.serenador.executeFailure
6
- import io.github.thanosfisherman.serenador.executeSuccess
3
+ import io.github.thanosfisherman.serenador.commandexecutors.CommandExecutor
7
4
import io.github.thanosfisherman.serenador.extensions.SerenadorExtension
5
+ import io.github.thanosfisherman.serenador.repositories.PhraseRepo
8
6
import org.gradle.BuildListener
9
7
import org.gradle.BuildResult
10
- import org.gradle.api.Project
11
8
import org.gradle.api.initialization.Settings
12
9
import org.gradle.api.invocation.Gradle
13
10
14
- class MyBuildListener (private val project : Project , private val serenadorExt : SerenadorExtension ) : BuildListener {
11
+ class MyBuildListener constructor(
12
+ private val commandExecutor : CommandExecutor ,
13
+ private val phraseRepo : PhraseRepo ,
14
+ private val serenadorExt : SerenadorExtension
15
+ ) : BuildListener {
15
16
override fun settingsEvaluated (settings : Settings ) {
16
17
}
17
18
@@ -22,21 +23,27 @@ class MyBuildListener(private val project: Project, private val serenadorExt: Se
22
23
}
23
24
24
25
override fun buildFinished (result : BuildResult ) {
25
- val executor = CommandExecutor (project)
26
+
26
27
if (result.failure != null ) {
27
- customOrDefault(serenadorExt.phraseBook.failPhrases, true , executor )
28
+ customOrDefault(serenadorExt.phraseBook.failPhrases, true , commandExecutor )
28
29
} else {
29
- customOrDefault(serenadorExt.phraseBook.successPhrases, false , executor )
30
+ customOrDefault(serenadorExt.phraseBook.successPhrases, false , commandExecutor )
30
31
}
31
32
}
32
33
33
34
private fun customOrDefault (phrases : List <String >, isFail : Boolean , executor : CommandExecutor ) {
34
35
if (phrases.isEmpty() && isFail) {
35
- executor.executeFailure()
36
+ val result = executor.execute(phraseRepo.getFailPhrasesWithVoice().random())
37
+ if (result.exitValue == 1 ) {
38
+ executor.execute(phraseRepo.getFailPhrases().random())
39
+ }
36
40
} else if (phrases.isEmpty()) {
37
- executor.executeSuccess()
41
+ val result = executor.execute(phraseRepo.getSuccessPhrasesWithVoice().random())
42
+ if (result.exitValue == 1 ) {
43
+ executor.execute(phraseRepo.getSuccessPhrases().random())
44
+ }
38
45
} else {
39
- executor.executeCustom( phrases)
46
+ executor.execute(phraseRepo.getCustomPhrases( phrases).random() )
40
47
}
41
48
}
42
49
}
0 commit comments