@@ -30,26 +30,16 @@ import kotlin.time.toDuration
3030 * interval.
3131 */
3232class Agent (options : AgentOptions , instrumentation : Instrumentation ? ) : AgentBase(options) {
33- /* * Converts binary data to XML. */
34- private val generator: JaCoCoXmlReportGenerator
3533
3634 /* * Regular dump task. */
3735 private var timer: Timer ? = null
3836
3937 /* * Stores the XML files. */
4038 private val uploader = options.createUploader(instrumentation)
4139
42- /* * Constructor. */
4340 init {
4441 logger.info(" Upload method: {}" , uploader.describe())
4542 retryUnsuccessfulUploads(options, uploader)
46- generator = JaCoCoXmlReportGenerator (
47- options.classDirectoriesOrZips,
48- options.locationIncludeFilter,
49- options.duplicateClassFileBehavior,
50- options.ignoreUncoveredClasses,
51- LoggingUtils .wrap(logger)
52- )
5343
5444 if (options.shouldDumpInIntervals()) {
5545 val period = options.dumpIntervalInMinutes.toDuration(DurationUnit .MINUTES ).inWholeMilliseconds
@@ -131,9 +121,12 @@ class Agent(options: AgentOptions, instrumentation: Instrumentation?) : AgentBas
131121 }
132122
133123 /* *
134- * Dumps the current execution data, converts it, writes it to the output directory defined in [. options] and
124+ * Dumps the current execution data, converts it, writes it to the output directory defined in [options] and
135125 * uploads it if an uploader is configured. Logs any errors, never throws an exception.
126+ *
127+ * Synchronized because this can be triggered concurrently by the timer and by the HTTP /dump endpoint.
136128 */
129+ @Synchronized
137130 override fun dumpReport () {
138131 logger.debug(" Starting dump" )
139132
@@ -155,6 +148,14 @@ class Agent(options: AgentOptions, instrumentation: Instrumentation?) : AgentBas
155148 return
156149 }
157150
151+ val generator = JaCoCoXmlReportGenerator (
152+ options.classDirectoriesOrZips,
153+ options.locationIncludeFilter,
154+ options.duplicateClassFileBehavior,
155+ options.ignoreUncoveredClasses,
156+ LoggingUtils .wrap(logger)
157+ )
158+
158159 try {
159160 benchmark(" Generating the XML report" ) {
160161 val outputFile = options.createNewFileInOutputDirectory(" jacoco" , " xml" )
0 commit comments