Skip to content

Commit

Permalink
Fixed inconsistent number of total methods (javaMethods, methodChange…
Browse files Browse the repository at this point in the history
…s) in BuildInfo.
  • Loading branch information
viktorbll committed May 13, 2020
1 parent 8b9f38a commit 7a60de1
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions core/src/main/kotlin/admindata/BuildManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,29 @@ class AgentBuildManager(
.map { ParsedClass(it.className, it.bytes) }
.filter { it.anyCode() }
.associateBy { it.name }
val classesBytes: Map<String, ByteArray> = parsedClasses.mapValues { it.value.bytes }
val currentMethods: Map<String, List<Method>> = parsedClasses.mapValues { it.value.methods() }
val bundleCoverage = parsedClasses.mapValues { it.value.bytes }.bundle()
val bundleClasses = bundleCoverage.packages.flatMap { it.classes }.associate { c ->
c.name to c.methods.map { m -> m.name to m.desc }.toSet()
}
val filteredClasses = parsedClasses.filterKeys { it in bundleClasses.keys }
val classBytes: Map<String, ByteArray> = filteredClasses.mapValues {
it.value.bytes
}
val currentMethods: Map<String, List<Method>> = filteredClasses.mapValues { (_, c) ->
val allowedMethods = bundleClasses.getValue(c.name)
c.methods().filter { (it.name to it.desc) in allowedMethods }
}
val build = updateAndGet(buildVersion) {
copy(
info = info.copy(
javaMethods = currentMethods,
classesBytes = classesBytes
classesBytes = classBytes
)
)
}
val parentVersion = build.info.parentVersion
val prevMethods = buildMap[parentVersion]?.info?.javaMethods ?: mapOf()
val coverageBuilder = CoverageBuilder()
val analyzer = Analyzer(ExecutionDataStore(), coverageBuilder)
//TODO remove jacoco usage
classesBytes.map { (className, bytes) ->
analyzer.analyzeClass(bytes, className)
}
val bundleCoverage = coverageBuilder.getBundle("")
bundleCoverage.packages.flatMap { it.classes }
updateAndGet(buildVersion) {
copy(
info = info.copy(
Expand All @@ -109,3 +113,10 @@ class AgentBuildManager(
}[version]!!

}

fun Map<String, ByteArray>.bundle(): IBundleCoverage = CoverageBuilder().also { builder ->
val analyzer = Analyzer(ExecutionDataStore(), builder)
forEach { (className, bytes) ->
analyzer.analyzeClass(bytes, className)
}
}.getBundle("")

0 comments on commit 7a60de1

Please sign in to comment.