1
1
package systems.danger.kotlin
2
2
3
3
import systems.danger.kotlin.json.JsonParser
4
+ import systems.danger.kotlin.models.danger.ConcurrentDangerResults
4
5
import systems.danger.kotlin.models.danger.DSL
5
6
import systems.danger.kotlin.models.danger.DangerDSL
6
- import systems.danger.kotlin.models.danger.DangerResults
7
7
import systems.danger.kotlin.models.git.FilePath
8
8
import systems.danger.kotlin.sdk.DangerContext
9
9
import systems.danger.kotlin.sdk.Violation
10
10
import java.io.File
11
+ import java.util.concurrent.atomic.AtomicReference
11
12
12
13
/* *
13
14
* Main Danger runner
@@ -23,23 +24,23 @@ internal class MainDangerRunner(jsonInputFilePath: FilePath, jsonOutputPath: Fil
23
24
24
25
val danger: DangerDSL = JsonParser .decodeJson<DSL >(jsonInputFilePath).danger
25
26
26
- private val dangerResults : DangerResults = DangerResults ()
27
+ private val concurrentDangerResults : ConcurrentDangerResults = ConcurrentDangerResults ()
27
28
28
29
override val fails: List <Violation >
29
30
get() {
30
- return dangerResults .fails.toList ()
31
+ return concurrentDangerResults .fails.get ()
31
32
}
32
33
override val warnings: List <Violation >
33
34
get() {
34
- return dangerResults .warnings.toList ()
35
+ return concurrentDangerResults .warnings.get ()
35
36
}
36
37
override val messages: List <Violation >
37
38
get() {
38
- return dangerResults .messages.toList ()
39
+ return concurrentDangerResults .messages.get ()
39
40
}
40
41
override val markdowns: List <Violation >
41
42
get() {
42
- return dangerResults .markdowns.toList ()
43
+ return concurrentDangerResults .markdowns.get ()
43
44
}
44
45
45
46
@@ -95,27 +96,34 @@ internal class MainDangerRunner(jsonInputFilePath: FilePath, jsonOutputPath: Fil
95
96
}
96
97
97
98
private fun warn (violation : Violation ) {
98
- dangerResults.warnings.add(violation)
99
- commit()
99
+ concurrentDangerResults.warnings.updateWith(violation)
100
100
}
101
101
102
102
private fun fail (violation : Violation ) {
103
- dangerResults.fails.add(violation)
104
- commit()
103
+ concurrentDangerResults.fails.updateWith(violation)
105
104
}
106
105
107
106
private fun message (violation : Violation ) {
108
- dangerResults.messages.add(violation)
109
- commit()
107
+ concurrentDangerResults.messages.updateWith(violation)
110
108
}
111
109
112
110
private fun markdown (violation : Violation ) {
113
- dangerResults.markdowns.add(violation)
111
+ concurrentDangerResults.markdowns.updateWith(violation)
112
+ }
113
+
114
+ private fun AtomicReference<MutableList<Violation>>.updateWith (violation : Violation ) {
115
+ this .getAndUpdate {
116
+ it.apply {
117
+ add(violation)
118
+ }
119
+ }
114
120
commit()
115
121
}
116
122
117
123
// commit all the inline violations into the json output file
118
124
private fun commit () {
119
- JsonParser .encodeJson(dangerResults, jsonOutputFile)
125
+ synchronized(this ) {
126
+ JsonParser .encodeJson(concurrentDangerResults.toDangerResults(), jsonOutputFile)
127
+ }
120
128
}
121
129
}
0 commit comments