Skip to content

Commit 58290c9

Browse files
committed
Make some tweaks to how JSPs and groups are handled
- Build up JSP hierarchy using nested groups - Build JSP paths up using / rather than ., to make them look more like file paths - Show group nodes in the treemap
1 parent 46ea318 commit 58290c9

File tree

6 files changed

+39
-25
lines changed

6 files changed

+39
-25
lines changed

codepulse/src/main/resources/toserve/pages/traces/PackageController.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
} else {
7575
var abbrevName
7676

77-
if (packageParentNode && packageParentNode.kind == 'group')
77+
if (node.kind != 'group' && packageParentNode && packageParentNode.kind == 'group')
7878
abbrevName = node.name
7979
else {
8080
var parentName = packageParentNode ? packageParentNode.name : '',

codepulse/src/main/resources/toserve/pages/traces/TreeProjector.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@
8686
// add `id` to the node in case the filter wants to use it
8787
node.id = id
8888

89-
if(node.kind == 'package' && packageFilter(node)){
89+
if((node.kind == 'group' || node.kind == 'package') && packageFilter(node)){
9090
markFiltered(id)
9191
partialAcceptAncestors(node)
9292
}
9393
}
9494

95-
function nearestPackageId(nodeId){
95+
function nearestPackageOrGroupId(nodeId){
9696
var node = rawNodes[nodeId]
9797
if(!node) return undefined
9898

99-
if(node.kind == 'package') return nodeId
100-
return nearestPackageId(node.parentId)
99+
if(node.kind == 'package' || node.kind == 'group') return nodeId
100+
return nearestPackageOrGroupId(node.parentId)
101101
}
102102

103103
// Second Pass through rawNodes - make a copy of rawNodes with only accepted nodes
@@ -110,8 +110,8 @@
110110
// - Other nodes are accepted if their nearest package
111111
// ancestor was 'fully' accepted (marked with a 2)
112112
if(
113-
(node.kind == 'package' && acceptedNodes[id]) ||
114-
(acceptedNodes[nearestPackageId(id)] == 2)
113+
((node.kind == 'group' || node.kind == 'package') && acceptedNodes[id]) ||
114+
(acceptedNodes[nearestPackageOrGroupId(id)] == 2)
115115
){
116116
nodesCopy[id] = $.extend(true, {}, rawNodes[id])
117117
}

codepulse/src/main/resources/toserve/pages/traces/traces.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ $(document).ready(function(){
293293
'calculateContent': (function(){
294294

295295
return function(node){
296-
if(node.kind == 'package'){
296+
if(node.kind == 'package' || node.kind == 'group'){
297297
return $('<div>')
298298
} else {
299299

@@ -333,7 +333,7 @@ $(document).ready(function(){
333333
var path = [], i = node
334334
while(i){
335335
path.unshift(i)
336-
if(i.kind == 'package') i = null
336+
if(i.kind == 'package' || i.kind == 'group') i = null
337337
else i = i.parent
338338
}
339339

codepulse/src/main/resources/toserve/widgets/codetreemap/treemap.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@
343343
.value(innerNodeSizing(widgetState))
344344
.sticky(false)
345345
.padding(function(d){
346-
if(d.kind == 'package' || d.kind == 'root') return [12, 1, 1, 1]
346+
if(d.kind == 'package' || d.kind == 'group' || d.kind == 'root') return [12, 1, 1, 1]
347347
else return 0
348348
})
349349

@@ -655,7 +655,7 @@
655655
// ignores root and package nodes
656656
function setHighlight(node){
657657
if(!node) return
658-
if(node.kind == 'package' || node.kind == 'root') return
658+
if(node.kind == 'package' || node.kind == 'group' || node.kind == 'root') return
659659

660660
var hd = node.highlightData
661661
if(hd) hd.isNew = true
@@ -682,7 +682,7 @@
682682
var kids = node.children || []
683683
kids.forEach(computeLineCounts)
684684

685-
if(node.kind == 'package' || node.kind == 'root'){
685+
if(node.kind == 'package' || node.kind == 'group' || node.kind == 'root'){
686686
node.widgetLineCount = d3.sum(kids, select('widgetLineCount'))
687687
} else {
688688
node.widgetLineCount = node.lineCount || 1
@@ -733,10 +733,10 @@
733733
* an array of progressively-shorter strings that can
734734
* be used to represent the name.
735735
*/
736-
function packageNameClippings(name){
736+
function nameClippings(name, sep){
737737
var clips = [name]
738-
var parts = name.split('.')
739-
for(var i=0; i<parts.length; i++) clips.push( parts.slice(i).join('.') )
738+
var parts = name.split(sep)
739+
for(var i=0; i<parts.length; i++) clips.push( parts.slice(i).join(sep) )
740740
clips.push("*")
741741
return clips
742742
}
@@ -788,9 +788,9 @@
788788
.attr('class', 'treemap-labels')
789789
.attr('transform', translate(widgetState.margin.left, widgetState.margin.top))
790790

791-
var packageNodes = treemapNodes.filter(function(d){ return d.kind == 'package' })
791+
var labeledNodes = treemapNodes.filter(function(d){ return d.kind == 'package' || d.kind == 'group' })
792792

793-
var labelSvg = labelsLayer.selectAll('text.treemap-label').data(packageNodes, select('id'))
793+
var labelSvg = labelsLayer.selectAll('text.treemap-label').data(labeledNodes, select('id'))
794794
labelSvg.exit().remove()
795795
labelSvg.enter().append('svg:text')
796796
.attr('class', 'treemap-label')
@@ -801,9 +801,12 @@
801801
.attr('y', function(d){ return d.y + 10 })
802802
.text(function(d){
803803
if(d.dy < 10) return ''
804-
var names = packageNameClippings(d.name).sort(function(a,b){
805-
return measure(b) - measure(a)
806-
})
804+
var nameSep
805+
if (d.kind == 'package') nameSep = '.'
806+
else nameSep = ' / '
807+
var names = nameClippings(d.name, nameSep).sort(function(a,b){
808+
return measure(b) - measure(a)
809+
})
807810
for(var i=0; i<names.length; i++){
808811
var n = names[i]
809812
if(measure(n) < d.dx - 4) return n

codepulse/src/main/scala/com/secdec/codepulse/data/bytecode/CodeForestBuilder.scala

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class CodeForestBuilder(defaultTracedGroups: List[String]) {
8080

8181
def getOrAddMethod(group: String, sig: MethodSignature, size: Int): CodeTreeNode = {
8282
val treePath = CodePath.parse(sig)
83-
val startNode = addGroup(group)
83+
val startNode = addRootGroup(group)
8484

8585
def recurse(parent: CodeTreeNode, path: CodePath): CodeTreeNode = path match {
8686
case CodePath.Package(name, childPath) => recurse(addChildPackage(parent, name), childPath)
@@ -94,20 +94,31 @@ class CodeForestBuilder(defaultTracedGroups: List[String]) {
9494
def getOrAddJsp(path: List[String], size: Int): CodeTreeNode = {
9595
def recurse(parent: CodeTreeNode, path: List[String]): CodeTreeNode = path match {
9696
case className :: Nil => addChildMethod(parent, className, size)
97-
case packageNode :: rest => recurse(addChildPackage(parent, packageNode), rest)
97+
case packageNode :: rest => recurse(addFolder(parent, packageNode), rest)
9898
}
9999

100-
recurse(addGroup(JSPGroupName), path)
100+
recurse(addRootGroup(JSPGroupName), path)
101101
}
102102

103-
protected def addGroup(name: String) = roots.find { node =>
103+
protected def addRootGroup(name: String) = roots.find { node =>
104104
node.name == name && node.kind == CodeTreeNodeKind.Grp
105105
} getOrElse {
106106
val node = nodeFactory.createGroupNode(name)
107107
roots.add(node)
108108
node
109109
}
110110

111+
protected def addFolder(parent: CodeTreeNode, name: String) = {
112+
val grpName = parent.name + " / " + name
113+
parent.findChild { node =>
114+
node.name == grpName && node.kind == CodeTreeNodeKind.Grp
115+
} getOrElse {
116+
val node = nodeFactory.createGroupNode(grpName)
117+
parent addChild node
118+
node
119+
}
120+
}
121+
111122
protected def addChildPackage(parent: CodeTreeNode, name: String) = {
112123
val pkgName = parent.kind match {
113124
case CodeTreeNodeKind.Grp => name

codepulse/src/main/scala/com/secdec/codepulse/data/jsp/JasperJspAdapter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class JasperJspAdapter extends JspAdapter {
5353
jspClasses.result.toList map { clazz =>
5454
val jspClassName = JasperUtils.makeJavaClass(clazz)
5555
val displayName = clazz.split('/').filter(!_.isEmpty).toList
56-
val node = codeForestBuilder.getOrAddJsp(displayName, 10)
56+
val node = codeForestBuilder.getOrAddJsp(displayName, 100)
5757
jspClassName -> node.id
5858
}
5959
}

0 commit comments

Comments
 (0)